Annotation of chimera/BrowserWindowController.mm, revision 1.49

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

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