Annotation of chimera/BrowserWindowController.mm, revision 1.19

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

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