File:  [mozdev] / chimera / BrowserWindowController.mm
Revision 1.55: download - view: text, annotated - select for diffs - revision graph
Mon Apr 8 22:30:20 2002 UTC (17 years, 2 months ago) by pinkerton
Branches: MAIN
CVS tags: HEAD
Make find window global to app, remove its cancel button, hookup find
functionality.

    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 ***** */
   37: 
   38: #import "BrowserWindowController.h"
   39: #import "MyBrowserView.h"
   40: #import "IconTabViewItem.h"
   41: 
   42: #include "nsIWebNavigation.h"
   43: #include "nsCocoaBrowserService.h"
   44: 
   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";
   53: static NSString *PrintToolbarItemIdentifier	= @"Print Toolbar Item";
   54: 
   55: @interface BrowserWindowController(Private)
   56: - (void)setupToolbar;
   57: - (void)setupSidebarTabs;
   58: @end
   59: 
   60: @implementation BrowserWindowController
   61: 
   62: -(void)enterModalSession
   63: {
   64:     mModalSession = [NSApp beginModalSessionForWindow: [self window]];
   65:     [NSApp runModalSession: mModalSession];
   66:     [NSApp endModalSession: mModalSession];
   67:     mModalSession = nil;
   68: }
   69: 
   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: 
   82: - (id)initWithWindowNibName:(NSString *)windowNibName
   83: {
   84:     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
   85:         if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
   86:             [self setShouldCascadeWindows:NO];
   87:         } else {
   88:             [self setShouldCascadeWindows:YES];
   89:         }
   90:         mInitialized = NO;
   91:         mMoveReentrant = NO;
   92:         mShouldAutosave = YES;
   93:     }
   94:     return self;
   95: }
   96: 
   97: -(void)autosaveWindowFrame
   98: {
   99:   if (mShouldAutosave)
  100:     [[self window] saveFrameUsingName: @"NavigatorWindow"];
  101: }
  102: 
  103: -(void)disableAutosave
  104: {
  105:   mShouldAutosave = NO;
  106: }
  107: 
  108: - (void)windowWillClose:(NSNotification *)notification
  109: {
  110:   printf("Window will close notification.\n");
  111:   [mSidebarBookmarksDataSource windowClosing];
  112: 
  113:   [self autosaveWindowFrame];
  114:   [self autorelease];
  115: }
  116: 
  117: - (void)dealloc
  118: {
  119:   printf("Browser controller died.\n");
  120: 
  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];
  132: }
  133: 
  134: - (void)windowDidLoad
  135: {
  136:     [super windowDidLoad];
  137: 
  138:     // Get our saved dimensions.
  139:     [[self window] setFrameUsingName: @"NavigatorWindow"];
  140:     
  141:     if (mModalSession)
  142:       [NSApp stopModal: mModalSession];
  143:       
  144:     mInitialized = YES;
  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:     
  151:     [[self window] setAcceptsMouseMovedEvents: YES];
  152:     
  153:     [self setupToolbar];
  154: 
  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];
  161:     
  162:     if (mURL) {
  163:       [self loadURL: mURL];
  164:       [mURL release];
  165:     }
  166:     
  167:     [mSidebarDrawer setDelegate: self];
  168: 
  169:     [self setupSidebarTabs];
  170: }
  171: 
  172: - (void)drawerWillOpen: (NSNotification*)aNotification
  173: {
  174:     [mSidebarBookmarksDataSource ensureBookmarks];
  175: }
  176: 
  177: - (void)drawerDidOpen:(NSNotification *)aNotification
  178: {
  179:     // XXXdwh This is temporary.
  180:     [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
  181:     [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
  182: }
  183: 
  184: - (void)drawerDidClose:(NSNotification *)aNotification
  185: {
  186:     // Unload the Gecko web page in "My Panels" to save memory.
  187:     [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
  188:     [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
  189: }
  190: 
  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,
  212:                                         PrintToolbarItemIdentifier,
  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"];
  276:         [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
  277:         [toolbarItem setTarget:self];
  278:         [toolbarItem setAction:@selector(toggleSidebar:)];
  279:         mSidebarToolbarItem = toolbarItem;
  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];
  292:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
  293:         [menuFormRep setTitle:[toolbarItem label]];
  294:         
  295:         [toolbarItem setMenuFormRepresentation:menuFormRep];
  296:         mLocationToolbarItem = toolbarItem;
  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)];
  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:    
  329: - (void)updateToolbarItems
  330: {
  331:   [[[self window] toolbar] validateVisibleItems];
  332: }
  333: 
  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
  349: {
  350:     [mURLBar selectText: self];
  351: }
  352: 
  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]]];
  367:     
  368:     // Focus and activate our content area.
  369:     [[mBrowserView getBrowserView] setActive: YES];
  370: }
  371: 
  372: - (IBAction)goToLocationFromToolbarURLField:(id)sender
  373: {
  374:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
  375:     
  376:     // Focus and activate our content area.
  377:     [[mBrowserView getBrowserView] setActive: YES];
  378: }
  379: 
  380: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
  381: {
  382:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
  383: }
  384: 
  385: - (void)printDocument
  386: {
  387:     [[mBrowserView getBrowserView] printDocument];
  388: }
  389: 
  390: - (void)printPreview
  391: {
  392:     [[mBrowserView getBrowserView] printPreview];
  393: }
  394: 
  395: - (void)findInPage:(NSString*)text
  396: {
  397:     [[mBrowserView getBrowserView] findInPage:text];
  398: }
  399: 
  400: - (void)findAgain
  401: {
  402:     [[mBrowserView getBrowserView] findAgain];
  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];
  411: }
  412: 
  413: - (IBAction)back:(id)aSender
  414: {
  415:   [[mBrowserView getBrowserView] goBack];
  416: }
  417: 
  418: - (IBAction)forward:(id)aSender
  419: {
  420:   [[mBrowserView getBrowserView] goForward];
  421: }
  422: 
  423: - (IBAction)reload:(id)aSender
  424: {
  425:   [[mBrowserView getBrowserView] reload: 0];
  426: }
  427: 
  428: - (IBAction)stop:(id)aSender
  429: {
  430:   [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
  431: }
  432: 
  433: - (IBAction)home:(id)aSender
  434: {
  435:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
  436: }
  437: 
  438: - (IBAction)toggleSidebar:(id)aSender
  439: {
  440:     NSResponder* resp = [[self window] firstResponder];
  441:     [[self window] makeFirstResponder: nil];
  442:     
  443:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) 	{
  444:         // XXXHack to bypass sidebar crashes.
  445:         [mSidebarDrawer open];
  446:     } else {
  447:         [mSidebarDrawer close];
  448:     }
  449:     
  450:     [[self window] makeFirstResponder: resp];
  451: }
  452: 
  453: 
  454: -(void)loadURL:(NSURL*)aURL
  455: {
  456:     if (mInitialized) {
  457:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
  458:     }
  459:     else {
  460:         mURL = aURL;
  461:         [mURL retain];
  462:     }
  463: }
  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];
  482: }
  483: 
  484: -(void)newTab
  485: {
  486:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
  487:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
  488:     [newView setTab: newTab];
  489: 
  490:     [newTab setLabel: @"Untitled"];
  491:     [newTab setView: newView];
  492: 
  493:     [mTabBrowser addTabViewItem: newTab];
  494: 
  495:     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
  496: 
  497:     [mTabBrowser selectLastTabViewItem: self];
  498: 
  499:     if ( [[[self window] toolbar] isVisible] ) {
  500:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
  501:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
  502:             [self focusURLBar];
  503:         }
  504:     }
  505: }
  506: 
  507: -(void)closeTab
  508: {
  509:   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
  510:     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
  511:     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
  512:   }
  513: }
  514: 
  515: - (void)previousTab
  516: {
  517:     [mTabBrowser selectPreviousTabViewItem:self];
  518: }
  519: 
  520: - (void)nextTab
  521: {
  522:     [mTabBrowser selectNextTabViewItem:self];
  523: }
  524: 
  525: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
  526: {
  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:     }
  532:     // Connect up the new view
  533:     mBrowserView = [aTabViewItem view];
  534:        
  535:     // Make the new view the primary content area.
  536:     [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
  537:         progress: mProgress windowController: self];
  538: }
  539: 
  540: -(MyBrowserView*)getMyBrowserView
  541: {
  542:     return mBrowserView;
  543: }
  544: 
  545: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
  546: {
  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.
  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.
  580: }
  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];
  598: 
  599:     [mSidebarTabView selectFirstTabViewItem:self];
  600: }
  601: 
  602: 
  603: @end
  604: 

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