Annotation of chimera/BrowserWindowController.mm, revision 1.50

1.44      hyatt       1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
                      2: /* ***** BEGIN LICENSE BLOCK *****
                      3:  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
                      4:  *
                      5:  * The contents of this file are subject to the Netscape Public License
                      6:  * Version 1.1 (the "License"); you may not use this file except in
                      7:  * compliance with the License. You may obtain a copy of the License at
                      8:  * http://www.mozilla.org/NPL/
                      9:  *
                     10:  * Software distributed under the License is distributed on an "AS IS" basis,
                     11:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
                     12:  * for the specific language governing rights and limitations under the
                     13:  * License.
                     14:  *
                     15:  * The Original Code is mozilla.org code.
                     16:  *
                     17:  * The Initial Developer of the Original Code is 
                     18:  * Netscape Communications Corporation.
                     19:  * Portions created by the Initial Developer are Copyright (C) 2002
                     20:  * the Initial Developer. All Rights Reserved.
                     21:  *
                     22:  * Contributor(s):
                     23:  *
                     24:  * Alternatively, the contents of this file may be used under the terms of
                     25:  * either the GNU General Public License Version 2 or later (the "GPL"), or 
                     26:  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
                     27:  * in which case the provisions of the GPL or the LGPL are applicable instead
                     28:  * of those above. If you wish to allow use of your version of this file only
                     29:  * under the terms of either the GPL or the LGPL, and not to allow others to
                     30:  * use your version of this file under the terms of the NPL, indicate your
                     31:  * decision by deleting the provisions above and replace them with the notice
                     32:  * and other provisions required by the GPL or the LGPL. If you do not delete
                     33:  * the provisions above, a recipient may use your version of this file under
                     34:  * the terms of any one of the NPL, the GPL or the LGPL.
                     35:  *
                     36:  * ***** END LICENSE BLOCK ***** */
1.1       hyatt      37: 
                     38: #import "BrowserWindowController.h"
                     39: #import "MyBrowserView.h"
1.50    ! macserv    40: #import "IconTabViewItem.h"
1.1       hyatt      41: 
1.37      hyatt      42: #include "nsIWebNavigation.h"
                     43: 
1.1       hyatt      44: static NSString *BrowserToolbarIdentifier  = @"Browser Window Toolbar";
                     45: static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
                     46: static NSString *ForwardToolbarItemIdentifier  = @"Forward Toolbar Item";
                     47: static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item";
                     48: static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item";
                     49: static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item";
                     50: static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
                     51: static NSString *SidebarToolbarItemIdentifier  = @"Sidebar Toolbar Item";
1.11      macserv    52: static NSString *PrintToolbarItemIdentifier  = @"Print Toolbar Item";
1.1       hyatt      53: 
                     54: @interface BrowserWindowController(Private)
                     55: - (void)setupToolbar;
                     56: @end
                     57: 
                     58: @implementation BrowserWindowController
                     59: 
1.39      hyatt      60: -(void)enterModalSession
                     61: {
                     62:     mModalSession = [NSApp beginModalSessionForWindow: [self window]];
                     63:     [NSApp runModalSession: mModalSession];
                     64:     [NSApp endModalSession: mModalSession];
                     65:     mModalSession = nil;
                     66: }
                     67: 
1.35      hyatt      68: -(void)mouseMoved:(NSEvent*)aEvent
                     69: {
                     70:     if (mMoveReentrant)
                     71:         return;
                     72:         
                     73:     mMoveReentrant = YES;
                     74:     NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
                     75:     [view mouseMoved: aEvent];
                     76:     [super mouseMoved: aEvent];
                     77:     mMoveReentrant = NO;
                     78: }
                     79: 
1.41      macserv    80: - (id)initWithWindowNibName:(NSString *)windowNibName
1.4       hyatt      81: {
1.41      macserv    82:     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
                     83:         mInitialized = NO;
                     84:         mMoveReentrant = NO;
1.48      hyatt      85:         mShouldAutosave = YES;
1.41      macserv    86:     }
                     87:     return self;
1.4       hyatt      88: }
                     89: 
1.48      hyatt      90: -(void)autosaveWindowFrame
                     91: {
                     92:   if (mShouldAutosave)
                     93:     [[self window] saveFrameUsingName: @"NavigatorWindow"];
                     94: }
                     95: 
                     96: -(void)disableAutosave
                     97: {
                     98:   mShouldAutosave = NO;
                     99: }
                    100: 
1.17      hyatt     101: - (void)windowWillClose:(NSNotification *)notification
                    102: {
1.49      hyatt     103:   printf("Window will close notification.\n");
                    104:   [mSidebarBookmarksDataSource windowClosing];
1.48      hyatt     105: 
1.49      hyatt     106:   [self autosaveWindowFrame];
                    107:   [self autorelease];
1.17      hyatt     108: }
                    109: 
1.7       hyatt     110: - (void)dealloc
                    111: {
1.49      hyatt     112:   printf("Browser controller died.\n");
1.40      hyatt     113: 
1.49      hyatt     114:   // Loop over all tabs, and tell them that the window is closed.
                    115:   int numTabs = [mTabBrowser numberOfTabViewItems];
                    116:   for (int i = 0; i < numTabs; i++) {
                    117:     NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
                    118:     [[item view] windowClosed];
                    119:   }
                    120:   [mSidebarBrowserView windowClosed];
                    121: 
                    122:   [mProgress release];
                    123:   
                    124:   [super dealloc];
1.7       hyatt     125: }
                    126: 
1.1       hyatt     127: - (void)windowDidLoad
                    128: {
1.35      hyatt     129:     [super windowDidLoad];
1.48      hyatt     130: 
                    131:     // Get our saved dimensions.
                    132:     [[self window] setFrameUsingName: @"NavigatorWindow"];
1.35      hyatt     133:     
1.39      hyatt     134:     if (mModalSession)
                    135:       [NSApp stopModal: mModalSession];
                    136:       
1.4       hyatt     137:     mInitialized = YES;
1.38      hyatt     138:     
                    139:     // Retain with a single extra refcount.  This allows the MyBrowserViews
                    140:     // to remove the progress meter from its superview without having to 
                    141:     // worry about retaining and releasing it.
                    142:     [mProgress retain];
                    143:     
1.34      hyatt     144:     [[self window] setAcceptsMouseMovedEvents: YES];
                    145:     
1.1       hyatt     146:     [self setupToolbar];
1.30      hyatt     147: 
1.41      macserv   148: //  03/03/2002 mlj Changing strategy a bit here.  The addTab: method was
                    149: // duplicating a lot of the code found here.  I have moved it to that method.
                    150: // We now remove the IB tab, then add one of our own.
                    151: 
                    152:     [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
                    153:     [self newTab];
1.4       hyatt     154:     
                    155:     if (mURL) {
                    156:       [self loadURL: mURL];
                    157:       [mURL release];
                    158:     }
1.18      hyatt     159:     
                    160:     [mSidebarDrawer setDelegate: self];
1.50    ! macserv   161: 
        !           162:     [mSidebarTabView addTabViewItem: //testing...
        !           163:         [[[IconTabViewItem alloc] initWithIdentifier:nil withTabIcon:[NSImage imageNamed:@"bookicon"]] autorelease]];
1.18      hyatt     164: }
                    165: 
1.22      hyatt     166: - (void)drawerWillOpen: (NSNotification*)aNotification
                    167: {
                    168:     [mSidebarBookmarksDataSource ensureBookmarks];
                    169: }
                    170: 
1.18      hyatt     171: - (void)drawerDidOpen:(NSNotification *)aNotification
                    172: {
1.23      hyatt     173:     // XXXdwh This is temporary.
                    174:     [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
1.1       hyatt     175: }
                    176: 
1.19      hyatt     177: - (void)drawerDidClose:(NSNotification *)aNotification
                    178: {
                    179:     // Unload the Gecko web page in "My Panels" to save memory.
                    180:     [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
                    181: }
                    182: 
1.1       hyatt     183: - (void)setupToolbar
                    184: {
                    185:     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
                    186:     
                    187:     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
                    188:     [toolbar setAllowsUserCustomization:YES];
                    189:     [toolbar setAutosavesConfiguration:YES];
                    190:     [toolbar setDelegate:self];
                    191:     [[self window] setToolbar:toolbar];
                    192: }
                    193: 
                    194: 
                    195: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
                    196: {
                    197:     return [NSArray arrayWithObjects:  BackToolbarItemIdentifier,
                    198:                                         ForwardToolbarItemIdentifier,
                    199:                                         ReloadToolbarItemIdentifier,
                    200:                                         StopToolbarItemIdentifier,
                    201:                                         HomeToolbarItemIdentifier,
                    202:                                         LocationToolbarItemIdentifier,
                    203:                                         SidebarToolbarItemIdentifier,
1.11      macserv   204:                                         PrintToolbarItemIdentifier,
1.1       hyatt     205:                                         NSToolbarCustomizeToolbarItemIdentifier,
                    206:                                         NSToolbarFlexibleSpaceItemIdentifier,
                    207:                                         NSToolbarSpaceItemIdentifier,
                    208:                                         NSToolbarSeparatorItemIdentifier,
                    209:                                         nil];
                    210: }
                    211: 
                    212: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
                    213: {
                    214:     return [NSArray arrayWithObjects:  BackToolbarItemIdentifier,
                    215:                                         ForwardToolbarItemIdentifier,
                    216:                                         ReloadToolbarItemIdentifier,
                    217:                                         StopToolbarItemIdentifier,
                    218:                                         HomeToolbarItemIdentifier,
                    219:                                         LocationToolbarItemIdentifier,
                    220:                                         SidebarToolbarItemIdentifier,
                    221:                                         nil];
                    222: }
                    223: 
                    224: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
                    225:       itemForItemIdentifier:(NSString *)itemIdent
                    226:   willBeInsertedIntoToolbar:(BOOL)willBeInserted
                    227: {
                    228:     NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
                    229:     if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
                    230:         [toolbarItem setLabel:@"Back"];
                    231:         [toolbarItem setPaletteLabel:@"Go Back"];
                    232:         [toolbarItem setToolTip:@"Go back one page"];
                    233:         [toolbarItem setImage:[NSImage imageNamed:@"back"]];
                    234:         [toolbarItem setTarget:self];
                    235:         [toolbarItem setAction:@selector(back:)];
                    236:     } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
                    237:         [toolbarItem setLabel:@"Forward"];
                    238:         [toolbarItem setPaletteLabel:@"Go Forward"];
                    239:         [toolbarItem setToolTip:@"Go forward one page"];
                    240:         [toolbarItem setImage:[NSImage imageNamed:@"forward"]];
                    241:         [toolbarItem setTarget:self];
                    242:         [toolbarItem setAction:@selector(forward:)];
                    243:     } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
                    244:         [toolbarItem setLabel:@"Reload"];
                    245:         [toolbarItem setPaletteLabel:@"Reload Page"];
                    246:         [toolbarItem setToolTip:@"Reload current page"];
                    247:         [toolbarItem setImage:[NSImage imageNamed:@"reload"]];
                    248:         [toolbarItem setTarget:self];
                    249:         [toolbarItem setAction:@selector(reload:)];
                    250:     } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
                    251:         [toolbarItem setLabel:@"Stop"];
                    252:         [toolbarItem setPaletteLabel:@"Stop Loading"];
                    253:         [toolbarItem setToolTip:@"Stop loading this page"];
                    254:         [toolbarItem setImage:[NSImage imageNamed:@"stop"]];
                    255:         [toolbarItem setTarget:self];
                    256:         [toolbarItem setAction:@selector(stop:)];
                    257:     } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
                    258:         [toolbarItem setLabel:@"Home"];
                    259:         [toolbarItem setPaletteLabel:@"Go Home"];
                    260:         [toolbarItem setToolTip:@"Go to home page"];
                    261:         [toolbarItem setImage:[NSImage imageNamed:@"home"]];
                    262:         [toolbarItem setTarget:self];
                    263:         [toolbarItem setAction:@selector(home:)];
                    264:     } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
                    265:         [toolbarItem setLabel:@"Sidebar"];
                    266:         [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
                    267:         [toolbarItem setToolTip:@"Show or hide the Sidebar"];
                    268:         [toolbarItem setImage:[NSImage imageNamed:@"sidebar"]];
                    269:         [toolbarItem setTarget:self];
                    270:         [toolbarItem setAction:@selector(toggleSidebar:)];
                    271:     } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
                    272:         
                    273:         NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
                    274:         
                    275:         [toolbarItem setLabel:@"Location"];
                    276:         [toolbarItem setPaletteLabel:@"Location"];
                    277:         [toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
                    278:         [toolbarItem setView:mLocationToolbarView];
                    279:         [toolbarItem setMinSize:NSMakeSize(128,32)];
                    280:         [toolbarItem setMaxSize:NSMakeSize(2560,32)];
                    281:         
                    282:         [menuFormRep setTarget:self];
1.5       macserv   283:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
1.1       hyatt     284:         [menuFormRep setTitle:[toolbarItem label]];
                    285:         
                    286:         [toolbarItem setMenuFormRepresentation:menuFormRep];
1.5       macserv   287:         mLocationToolbarItem = toolbarItem;
1.11      macserv   288: 
                    289:     } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
                    290:         [toolbarItem setLabel:@"Print"];
                    291:         [toolbarItem setPaletteLabel:@"Print"];
                    292:         [toolbarItem setToolTip:@"Print this page"];
                    293:         [toolbarItem setImage:[NSImage imageNamed:@"print"]];
                    294:         [toolbarItem setTarget:self];
                    295:         [toolbarItem setAction:@selector(printDocument)];
1.1       hyatt     296:     } else {
                    297:         toolbarItem = nil;
                    298:     }
                    299:         
                    300:     return toolbarItem;
                    301: }
                    302: 
                    303: // This method handles the enabling/disabling of the toolbar buttons.
                    304: - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
                    305: {
                    306:   // Check the action and see if it matches.
                    307:   SEL action = [theItem action];
                    308:   if (action == @selector(back:))
                    309:     return [[mBrowserView getBrowserView] canGoBack];
                    310:   else if (action == @selector(forward:))
                    311:     return [[mBrowserView getBrowserView] canGoForward];
                    312:   else if (action == @selector(reload:))
                    313:     return [mBrowserView isBusy] == NO;
                    314:   else if (action == @selector(stop:))
                    315:     return [mBrowserView isBusy];
                    316:   else
                    317:     return YES;
                    318: }
                    319:    
1.5       macserv   320: - (void)updateToolbarItems
1.1       hyatt     321: {
                    322:   [[[self window] toolbar] validateVisibleItems];
                    323: }
                    324: 
1.5       macserv   325: - (void)performAppropriateLocationAction
                    326: {
                    327:     if ( [[[self window] toolbar] isVisible] ) {
                    328:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
                    329:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
                    330:             [self focusURLBar];
                    331:         } else {
                    332:             [self beginLocationSheet];
                    333:         }
                    334:     } else {
                    335:         [self beginLocationSheet];
                    336:     }
                    337: }
                    338: 
                    339: - (void)focusURLBar
1.3       hyatt     340: {
                    341:     [mURLBar selectText: self];
                    342: }
                    343: 
1.5       macserv   344: - (void)beginLocationSheet
                    345: {
                    346:     [NSApp beginSheet: mLocationSheetWindow
                    347:        modalForWindow: [self window]
                    348:         modalDelegate: nil
                    349:        didEndSelector: nil
                    350:           contextInfo: nil];
                    351: }
                    352: 
                    353: - (IBAction)endLocationSheet:(id)sender
                    354: {
                    355:     [mLocationSheetWindow orderOut:self];
                    356:     [NSApp endSheet:mLocationSheetWindow returnCode:1];
                    357:     [self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
1.32      hyatt     358:     
                    359:     // Focus and activate our content area.
                    360:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   361: }
                    362: 
                    363: - (IBAction)goToLocationFromToolbarURLField:(id)sender
                    364: {
                    365:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
1.32      hyatt     366:     
                    367:     // Focus and activate our content area.
                    368:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   369: }
                    370: 
1.7       hyatt     371: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
1.6       hyatt     372: {
1.7       hyatt     373:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
1.6       hyatt     374: }
                    375: 
1.12      hyatt     376: - (void)printDocument
                    377: {
                    378:     [[mBrowserView getBrowserView] printDocument];
                    379: }
                    380: 
1.15      hyatt     381: - (void)printPreview
                    382: {
                    383:     [[mBrowserView getBrowserView] printPreview];
                    384: }
                    385: 
1.16      hyatt     386: - (void)findInPage
                    387: {
                    388:     [[mBrowserView getBrowserView] findInPage];
                    389: }
                    390: 
                    391: - (void)findAgain
                    392: {
                    393:     [[mBrowserView getBrowserView] findAgain];
1.22      hyatt     394: }
                    395: 
                    396: - (void)addBookmark
                    397: {
                    398:     // XXXdwh Hack.  Just go to the sidebar for now until we get our
                    399:     // menu data source going.
                    400:     [mSidebarBookmarksDataSource ensureBookmarks];
                    401:     [mSidebarBookmarksDataSource addBookmark: self];
1.16      hyatt     402: }
                    403: 
1.5       macserv   404: - (IBAction)back:(id)aSender
1.1       hyatt     405: {
                    406:   [[mBrowserView getBrowserView] goBack];
                    407: }
                    408: 
1.5       macserv   409: - (IBAction)forward:(id)aSender
1.1       hyatt     410: {
                    411:   [[mBrowserView getBrowserView] goForward];
                    412: }
                    413: 
1.5       macserv   414: - (IBAction)reload:(id)aSender
1.1       hyatt     415: {
                    416:   [[mBrowserView getBrowserView] reload: 0];
                    417: }
                    418: 
1.5       macserv   419: - (IBAction)stop:(id)aSender
1.1       hyatt     420: {
1.37      hyatt     421:   [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
1.1       hyatt     422: }
                    423: 
1.5       macserv   424: - (IBAction)home:(id)aSender
1.1       hyatt     425: {
1.5       macserv   426:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.1       hyatt     427: }
                    428: 
1.5       macserv   429: - (IBAction)toggleSidebar:(id)aSender
1.1       hyatt     430: {
1.36      hyatt     431:     NSResponder* resp = [[self window] firstResponder];
                    432:     [[self window] makeFirstResponder: nil];
                    433:     
1.31      hyatt     434:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )   {
1.34      hyatt     435:         // XXXHack to bypass sidebar crashes.
1.1       hyatt     436:         [mSidebarDrawer open];
                    437:     } else {
                    438:         [mSidebarDrawer close];
                    439:     }
1.36      hyatt     440:     
                    441:     [[self window] makeFirstResponder: resp];
1.1       hyatt     442: }
                    443: 
1.4       hyatt     444: -(void)loadURL:(NSURL*)aURL
1.1       hyatt     445: {
1.32      hyatt     446:     if (mInitialized) {
1.4       hyatt     447:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
1.32      hyatt     448:     }
1.4       hyatt     449:     else {
                    450:         mURL = aURL;
                    451:         [mURL retain];
                    452:     }
1.1       hyatt     453: }
1.5       macserv   454: 
                    455: - (void)updateLocationFields:(NSString *)locationString
                    456: {
                    457: /* //commenting this out because it doesn't work right yet.
                    458:     if ( [locationString length] > 30 ) {
                    459:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
                    460:             [NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
                    461:     } else {
                    462:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
                    463:             [NSString stringWithFormat:@"Location: %@", locationString]];
                    464:     }
                    465: */
                    466: 
                    467:     [mURLBar setStringValue:locationString];
                    468:     [mLocationSheetURLField setStringValue:locationString];
                    469: 
                    470:     [[self window] update];
                    471:     [[self window] display];
1.8       hyatt     472: }
1.27      hyatt     473: 
                    474: -(void)newTab
                    475: {
1.28      hyatt     476:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
1.47      hyatt     477:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
                    478:     [newView setTab: newTab];
1.41      macserv   479: 
                    480:     [newTab setLabel: @"Untitled"];
                    481:     [newTab setView: newView];
                    482: 
1.28      hyatt     483:     [mTabBrowser addTabViewItem: newTab];
1.42      macserv   484: 
1.28      hyatt     485:     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.42      macserv   486: 
1.28      hyatt     487:     [mTabBrowser selectLastTabViewItem: self];
1.42      macserv   488: 
1.29      hyatt     489:     if ( [[[self window] toolbar] isVisible] ) {
                    490:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
                    491:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
                    492:             [self focusURLBar];
1.42      macserv   493:         }
1.29      hyatt     494:     }
1.42      macserv   495: }
                    496: 
                    497: -(void)closeTab
                    498: {
1.49      hyatt     499:   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
                    500:     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
                    501:     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
                    502:   }
1.42      macserv   503: }
                    504: 
                    505: - (void)previousTab
                    506: {
                    507:     [mTabBrowser selectPreviousTabViewItem:self];
                    508: }
                    509: 
                    510: - (void)nextTab
                    511: {
                    512:     [mTabBrowser selectNextTabViewItem:self];
1.28      hyatt     513: }
1.27      hyatt     514: 
1.28      hyatt     515: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
                    516: {
1.41      macserv   517:     // Disconnect the old view, if one has been designated.
                    518:     // If the window has just been opened, none has been.
                    519:     if ( mBrowserView ) {
                    520:         [mBrowserView disconnectView];
                    521:     }
1.28      hyatt     522:     // Connect up the new view
                    523:     mBrowserView = [aTabViewItem view];
1.30      hyatt     524:        
1.28      hyatt     525:     // Make the new view the primary content area.
1.47      hyatt     526:     [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
1.28      hyatt     527:         progress: mProgress windowController: self];
1.27      hyatt     528: }
1.28      hyatt     529: 
1.31      hyatt     530: -(MyBrowserView*)getMyBrowserView
                    531: {
                    532:     return mBrowserView;
                    533: }
1.45      hyatt     534: 
                    535: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
                    536: {
1.48      hyatt     537:   // Autosave our dimensions before we open a new window.  That ensures the size ends up matching.
                    538:   [self autosaveWindowFrame];
                    539: 
                    540:   BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
                    541:   [browser loadURL: aURL];
                    542:   if (aLoadInBG)
                    543:     [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
                    544:   else
                    545:     [browser showWindow: self];
                    546: 
                    547:   // XXXdwh Focus the content area.
1.47      hyatt     548: }
                    549: 
                    550: -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
                    551: {
                    552:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
                    553:     
                    554:     NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
                    555:     int index = [mTabBrowser indexOfTabViewItem: selectedTab];
                    556:     [mTabBrowser insertTabViewItem: newTab atIndex: index+1];
                    557:     
                    558:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
                    559:     [newView setTab: newTab];
                    560:     
                    561:     [newTab setLabel: @"Loading..."];
                    562:     [newTab setView: newView];
                    563: 
                    564:     [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
                    565: 
                    566:     if (!aLoadInBG)
                    567:         [mTabBrowser selectTabViewItem: newTab];
                    568:         
                    569:     // XXXdwh Focus the content area.
1.45      hyatt     570: }
1.1       hyatt     571: @end
                    572: 

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