Annotation of chimera/BrowserWindowController.mm, revision 1.22

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

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