Annotation of chimera/BrowserWindowController.mm, revision 1.24

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

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