Annotation of chimera/BrowserWindowController.mm, revision 1.48

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

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