Annotation of chimera/BrowserWindowController.mm, revision 1.51

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

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