Annotation of chimera/BrowserWindowController.mm, revision 1.20

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

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