Annotation of chimera/BrowserWindowController.mm, revision 1.21

1.2       macserv     1: /*
                      2:  *  BrowserWindowController.mm
                      3:  */
1.1       hyatt       4: 
                      5: #import "BrowserWindowController.h"
                      6: #import "MyBrowserView.h"
                      7: 
                      8: static NSString *BrowserToolbarIdentifier      = @"Browser Window Toolbar";
                      9: static NSString *BackToolbarItemIdentifier     = @"Back Toolbar Item";
                     10: static NSString *ForwardToolbarItemIdentifier  = @"Forward Toolbar Item";
                     11: static NSString *ReloadToolbarItemIdentifier   = @"Reload Toolbar Item";
                     12: static NSString *StopToolbarItemIdentifier     = @"Stop Toolbar Item";
                     13: static NSString *HomeToolbarItemIdentifier     = @"Home Toolbar Item";
                     14: static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
                     15: static NSString *SidebarToolbarItemIdentifier  = @"Sidebar Toolbar Item";
1.11      macserv    16: static NSString *PrintToolbarItemIdentifier    = @"Print Toolbar Item";
1.1       hyatt      17: 
                     18: @interface BrowserWindowController(Private)
                     19: - (void)setupToolbar;
                     20: @end
                     21: 
                     22: @implementation BrowserWindowController
                     23: 
1.4       hyatt      24: - (id)init 
                     25: {
                     26:     mInitialized = NO;
                     27:     return [super init];
                     28: }
                     29: 
1.17      hyatt      30: - (void)windowWillClose:(NSNotification *)notification
                     31: {
                     32:     [self autorelease];
1.21    ! hyatt      33:     [mSidebarBookmarksDataSource windowClosing];
1.17      hyatt      34: }
                     35: 
1.7       hyatt      36: - (void)dealloc
                     37: {
1.10      hyatt      38:     [mBrowserView windowClosed];
1.7       hyatt      39:     [super dealloc];
                     40: }
                     41: 
1.1       hyatt      42: - (void)windowDidLoad
                     43: {
1.4       hyatt      44:     mInitialized = YES;
1.1       hyatt      45:     [self setupToolbar];
1.4       hyatt      46:     
                     47:     if (mURL) {
                     48:       [self loadURL: mURL];
                     49:       [mURL release];
                     50:     }
1.18      hyatt      51:     
                     52:     [mSidebarDrawer setDelegate: self];
                     53: }
                     54: 
                     55: - (void)drawerDidOpen:(NSNotification *)aNotification
                     56: {
1.21    ! hyatt      57:     //[[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
1.20      hyatt      58:     
                     59:     [mSidebarBookmarksDataSource ensureBookmarks];
1.1       hyatt      60: }
                     61: 
1.19      hyatt      62: - (void)drawerDidClose:(NSNotification *)aNotification
                     63: {
                     64:     // Unload the Gecko web page in "My Panels" to save memory.
                     65:     [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
                     66: }
                     67: 
1.1       hyatt      68: - (void)setupToolbar
                     69: {
                     70:     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
                     71:     
                     72:     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
                     73:     [toolbar setAllowsUserCustomization:YES];
                     74:     [toolbar setAutosavesConfiguration:YES];
                     75:     [toolbar setDelegate:self];
                     76:     [[self window] setToolbar:toolbar];
                     77: }
                     78: 
                     79: 
                     80: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
                     81: {
                     82:     return [NSArray arrayWithObjects:  BackToolbarItemIdentifier,
                     83:                                         ForwardToolbarItemIdentifier,
                     84:                                         ReloadToolbarItemIdentifier,
                     85:                                         StopToolbarItemIdentifier,
                     86:                                         HomeToolbarItemIdentifier,
                     87:                                         LocationToolbarItemIdentifier,
                     88:                                         SidebarToolbarItemIdentifier,
1.11      macserv    89:                                         PrintToolbarItemIdentifier,
1.1       hyatt      90:                                         NSToolbarCustomizeToolbarItemIdentifier,
                     91:                                         NSToolbarFlexibleSpaceItemIdentifier,
                     92:                                         NSToolbarSpaceItemIdentifier,
                     93:                                         NSToolbarSeparatorItemIdentifier,
                     94:                                         nil];
                     95: }
                     96: 
                     97: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
                     98: {
                     99:     return [NSArray arrayWithObjects:  BackToolbarItemIdentifier,
                    100:                                         ForwardToolbarItemIdentifier,
                    101:                                         ReloadToolbarItemIdentifier,
                    102:                                         StopToolbarItemIdentifier,
                    103:                                         HomeToolbarItemIdentifier,
                    104:                                         LocationToolbarItemIdentifier,
                    105:                                         SidebarToolbarItemIdentifier,
                    106:                                         nil];
                    107: }
                    108: 
                    109: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
                    110:       itemForItemIdentifier:(NSString *)itemIdent
                    111:   willBeInsertedIntoToolbar:(BOOL)willBeInserted
                    112: {
                    113:     NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
                    114:     if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
                    115:         [toolbarItem setLabel:@"Back"];
                    116:         [toolbarItem setPaletteLabel:@"Go Back"];
                    117:         [toolbarItem setToolTip:@"Go back one page"];
                    118:         [toolbarItem setImage:[NSImage imageNamed:@"back"]];
                    119:         [toolbarItem setTarget:self];
                    120:         [toolbarItem setAction:@selector(back:)];
                    121:     } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
                    122:         [toolbarItem setLabel:@"Forward"];
                    123:         [toolbarItem setPaletteLabel:@"Go Forward"];
                    124:         [toolbarItem setToolTip:@"Go forward one page"];
                    125:         [toolbarItem setImage:[NSImage imageNamed:@"forward"]];
                    126:         [toolbarItem setTarget:self];
                    127:         [toolbarItem setAction:@selector(forward:)];
                    128:     } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
                    129:         [toolbarItem setLabel:@"Reload"];
                    130:         [toolbarItem setPaletteLabel:@"Reload Page"];
                    131:         [toolbarItem setToolTip:@"Reload current page"];
                    132:         [toolbarItem setImage:[NSImage imageNamed:@"reload"]];
                    133:         [toolbarItem setTarget:self];
                    134:         [toolbarItem setAction:@selector(reload:)];
                    135:     } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
                    136:         [toolbarItem setLabel:@"Stop"];
                    137:         [toolbarItem setPaletteLabel:@"Stop Loading"];
                    138:         [toolbarItem setToolTip:@"Stop loading this page"];
                    139:         [toolbarItem setImage:[NSImage imageNamed:@"stop"]];
                    140:         [toolbarItem setTarget:self];
                    141:         [toolbarItem setAction:@selector(stop:)];
                    142:     } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
                    143:         [toolbarItem setLabel:@"Home"];
                    144:         [toolbarItem setPaletteLabel:@"Go Home"];
                    145:         [toolbarItem setToolTip:@"Go to home page"];
                    146:         [toolbarItem setImage:[NSImage imageNamed:@"home"]];
                    147:         [toolbarItem setTarget:self];
                    148:         [toolbarItem setAction:@selector(home:)];
                    149:     } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
                    150:         [toolbarItem setLabel:@"Sidebar"];
                    151:         [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
                    152:         [toolbarItem setToolTip:@"Show or hide the Sidebar"];
                    153:         [toolbarItem setImage:[NSImage imageNamed:@"sidebar"]];
                    154:         [toolbarItem setTarget:self];
                    155:         [toolbarItem setAction:@selector(toggleSidebar:)];
                    156:     } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
                    157:         
                    158:         NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
                    159:         
                    160:         [toolbarItem setLabel:@"Location"];
                    161:         [toolbarItem setPaletteLabel:@"Location"];
                    162:         [toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
                    163:         [toolbarItem setView:mLocationToolbarView];
                    164:         [toolbarItem setMinSize:NSMakeSize(128,32)];
                    165:         [toolbarItem setMaxSize:NSMakeSize(2560,32)];
                    166:         
                    167:         [menuFormRep setTarget:self];
1.5       macserv   168:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
1.1       hyatt     169:         [menuFormRep setTitle:[toolbarItem label]];
                    170:         
                    171:         [toolbarItem setMenuFormRepresentation:menuFormRep];
1.5       macserv   172:         mLocationToolbarItem = toolbarItem;
1.11      macserv   173: 
                    174:     } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
                    175:         [toolbarItem setLabel:@"Print"];
                    176:         [toolbarItem setPaletteLabel:@"Print"];
                    177:         [toolbarItem setToolTip:@"Print this page"];
                    178:         [toolbarItem setImage:[NSImage imageNamed:@"print"]];
                    179:         [toolbarItem setTarget:self];
                    180:         [toolbarItem setAction:@selector(printDocument)];
1.1       hyatt     181:     } else {
                    182:         toolbarItem = nil;
                    183:     }
                    184:         
                    185:     return toolbarItem;
                    186: }
                    187: 
                    188: // This method handles the enabling/disabling of the toolbar buttons.
                    189: - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
                    190: {
                    191:   // Check the action and see if it matches.
                    192:   SEL action = [theItem action];
                    193:   if (action == @selector(back:))
                    194:     return [[mBrowserView getBrowserView] canGoBack];
                    195:   else if (action == @selector(forward:))
                    196:     return [[mBrowserView getBrowserView] canGoForward];
                    197:   else if (action == @selector(reload:))
                    198:     return [mBrowserView isBusy] == NO;
                    199:   else if (action == @selector(stop:))
                    200:     return [mBrowserView isBusy];
                    201:   else
                    202:     return YES;
                    203: }
                    204:    
1.5       macserv   205: - (void)updateToolbarItems
1.1       hyatt     206: {
                    207:   [[[self window] toolbar] validateVisibleItems];
                    208: }
                    209: 
1.5       macserv   210: - (void)performAppropriateLocationAction
                    211: {
                    212:     if ( [[[self window] toolbar] isVisible] ) {
                    213:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
                    214:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
                    215:             [self focusURLBar];
                    216:         } else {
                    217:             [self beginLocationSheet];
                    218:         }
                    219:     } else {
                    220:         [self beginLocationSheet];
                    221:     }
                    222: }
                    223: 
                    224: - (void)focusURLBar
1.3       hyatt     225: {
                    226:     [mURLBar selectText: self];
                    227: }
                    228: 
1.5       macserv   229: - (void)beginLocationSheet
                    230: {
                    231:     [NSApp beginSheet: mLocationSheetWindow
                    232:        modalForWindow: [self window]
                    233:         modalDelegate: nil
                    234:        didEndSelector: nil
                    235:           contextInfo: nil];
                    236: }
                    237: 
                    238: - (IBAction)endLocationSheet:(id)sender
                    239: {
                    240:     [mLocationSheetWindow orderOut:self];
                    241:     [NSApp endSheet:mLocationSheetWindow returnCode:1];
                    242:     [self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
                    243: }
                    244: 
                    245: - (IBAction)goToLocationFromToolbarURLField:(id)sender
                    246: {
                    247:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
                    248: }
                    249: 
1.7       hyatt     250: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
1.6       hyatt     251: {
1.7       hyatt     252:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
1.6       hyatt     253: }
                    254: 
1.12      hyatt     255: - (void)printDocument
                    256: {
                    257:     [[mBrowserView getBrowserView] printDocument];
                    258: }
                    259: 
1.15      hyatt     260: - (void)printPreview
                    261: {
                    262:     [[mBrowserView getBrowserView] printPreview];
                    263: }
                    264: 
1.16      hyatt     265: - (void)findInPage
                    266: {
                    267:     [[mBrowserView getBrowserView] findInPage];
                    268: }
                    269: 
                    270: - (void)findAgain
                    271: {
                    272:     [[mBrowserView getBrowserView] findAgain];
                    273: }
                    274: 
1.5       macserv   275: - (IBAction)back:(id)aSender
1.1       hyatt     276: {
                    277:   [[mBrowserView getBrowserView] goBack];
                    278: }
                    279: 
1.5       macserv   280: - (IBAction)forward:(id)aSender
1.1       hyatt     281: {
                    282:   [[mBrowserView getBrowserView] goForward];
                    283: }
                    284: 
1.5       macserv   285: - (IBAction)reload:(id)aSender
1.1       hyatt     286: {
                    287:   [[mBrowserView getBrowserView] reload: 0];
                    288: }
                    289: 
1.5       macserv   290: - (IBAction)stop:(id)aSender
1.1       hyatt     291: {
                    292:   [[mBrowserView getBrowserView] stop: 0];
                    293: }
                    294: 
1.5       macserv   295: - (IBAction)home:(id)aSender
1.1       hyatt     296: {
1.5       macserv   297:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.1       hyatt     298: }
                    299: 
1.5       macserv   300: - (IBAction)toggleSidebar:(id)aSender
1.1       hyatt     301: {
                    302:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
                    303:         [mSidebarDrawer open];
                    304:     } else {
                    305:         [mSidebarDrawer close];
                    306:     }
                    307: }
                    308: 
1.4       hyatt     309: -(void)loadURL:(NSURL*)aURL
1.1       hyatt     310: {
1.4       hyatt     311:     if (mInitialized)
                    312:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
                    313:     else {
                    314:         mURL = aURL;
                    315:         [mURL retain];
                    316:     }
1.1       hyatt     317: }
1.5       macserv   318: 
                    319: - (void)updateLocationFields:(NSString *)locationString
                    320: {
                    321: /* //commenting this out because it doesn't work right yet.
                    322:     if ( [locationString length] > 30 ) {
                    323:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
                    324:             [NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
                    325:     } else {
                    326:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
                    327:             [NSString stringWithFormat:@"Location: %@", locationString]];
                    328:     }
                    329: */
                    330: 
                    331:     [mURLBar setStringValue:locationString];
                    332:     [mLocationSheetURLField setStringValue:locationString];
                    333: 
                    334:     [[self window] update];
                    335:     [[self window] display];
1.8       hyatt     336: }
1.1       hyatt     337: @end
                    338: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>