Annotation of chimera/BrowserWindowController.mm, revision 1.56

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

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