version 1.19, 2002/02/09 23:17:02
|
version 1.41, 2002/04/14 08:43:03
|
Line 1
|
Line 1
|
/* | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
* MainController.mm | /* ***** BEGIN LICENSE BLOCK ***** |
*/ | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
| * |
| * The contents of this file are subject to the Netscape Public License |
| * Version 1.1 (the "License"); you may not use this file except in |
| * compliance with the License. You may obtain a copy of the License at |
| * http://www.mozilla.org/NPL/ |
| * |
| * Software distributed under the License is distributed on an "AS IS" basis, |
| * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| * for the specific language governing rights and limitations under the |
| * License. |
| * |
| * The Original Code is mozilla.org code. |
| * |
| * The Initial Developer of the Original Code is |
| * Netscape Communications Corporation. |
| * Portions created by the Initial Developer are Copyright (C) 2002 |
| * the Initial Developer. All Rights Reserved. |
| * |
| * Contributor(s): |
| * |
| * Alternatively, the contents of this file may be used under the terms of |
| * either the GNU General Public License Version 2 or later (the "GPL"), or |
| * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| * in which case the provisions of the GPL or the LGPL are applicable instead |
| * of those above. If you wish to allow use of your version of this file only |
| * under the terms of either the GPL or the LGPL, and not to allow others to |
| * use your version of this file under the terms of the NPL, indicate your |
| * decision by deleting the provisions above and replace them with the notice |
| * and other provisions required by the GPL or the LGPL. If you do not delete |
| * the provisions above, a recipient may use your version of this file under |
| * the terms of any one of the NPL, the GPL or the LGPL. |
| * |
| * ***** END LICENSE BLOCK ***** */ |
|
|
#import "MainController.h" |
#import "MainController.h" |
#import "BrowserWindowController.h" |
#import "BrowserWindowController.h" |
| #include "BookmarksService.h" |
#include "nsCOMPtr.h" |
#include "nsCOMPtr.h" |
#include "nsIServiceManager.h" |
#include "nsIServiceManager.h" |
#include "nsIIOService.h" |
#include "nsIIOService.h" |
#include "nsCocoaBrowserService.h" |
#include "nsCocoaBrowserService.h" |
|
#import "AboutBox.h" |
|
|
|
|
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; |
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; |
|
|
@implementation MainController |
@implementation MainController |
|
|
-(void)awakeFromNib | -(id)init |
{ |
{ |
|
if ( (self = [super init]) ) { |
|
mSplashScreen = [[SplashScreenWindow alloc] splashImage:nil withFade:YES withStatusRect:NSMakeRect(0,0,0,0)]; |
|
} |
|
mFindDialog = nil; |
|
mMenuBookmarks = nil; |
|
return self; |
|
} |
|
|
|
-(void)dealloc |
|
{ |
|
[super dealloc]; |
|
[mFindDialog release]; |
|
printf("Main controller died.\n"); |
|
} |
|
|
|
-(void)awakeFromNib |
|
{ |
[self newWindow: self]; |
[self newWindow: self]; |
|
|
|
[mSplashScreen close]; |
|
|
[mBookmarksMenu setAutoenablesItems: NO]; |
[mBookmarksMenu setAutoenablesItems: NO]; |
|
|
mMenuBookmarks = new BookmarksService(nil); |
mMenuBookmarks = new BookmarksService(nil); |
mMenuBookmarks->AddObserver(); |
mMenuBookmarks->AddObserver(); |
mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull); |
mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull); |
|
BookmarksService::gMainController = self; |
|
|
// Initialize offline mode. |
// Initialize offline mode. |
mOffline = NO; |
mOffline = NO; |
Line 37 static const char* ioServiceContractID =
|
Line 91 static const char* ioServiceContractID =
|
// offline. |
// offline. |
if (mOffline) |
if (mOffline) |
[mOfflineMenuItem setTitle: @"Go Online"]; |
[mOfflineMenuItem setTitle: @"Go Online"]; |
|
|
} |
} |
|
|
-(IBAction)newWindow:(id)aSender |
-(IBAction)newWindow:(id)aSender |
{ |
{ |
BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"]; | // If we have a key window, have it autosave its dimensions before |
[controller focusURLBar]; | // we open a new window. That ensures the size ends up matching. |
| NSWindow* keyWindow = [mApplication keyWindow]; |
| if ( keyWindow && [keyWindow respondsToSelector:@selector(autosaveWindowFrame)] ) |
| [[keyWindow windowController] autosaveWindowFrame]; |
| |
| // Now open the new window. |
| BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"]; |
| [controller focusURLBar]; |
| } |
| |
| -(IBAction)newTab:(id)aSender |
| { |
| NSWindow* keyWindow = [mApplication keyWindow]; |
| if (keyWindow) |
| [[keyWindow windowController] newTab]; |
| } |
| |
| -(IBAction)closeTab:(id)aSender |
| { |
| NSWindow* keyWindow = [mApplication keyWindow]; |
| if (keyWindow) |
| [[keyWindow windowController] closeTab]; |
| } |
| |
| -(IBAction) previousTab:(id)aSender |
| { |
| NSWindow* keyWindow = [mApplication keyWindow]; |
| if (keyWindow) |
| [[keyWindow windowController] previousTab]; |
| } |
| |
| -(IBAction) nextTab:(id)aSender; |
| { |
| NSWindow* keyWindow = [mApplication keyWindow]; |
| if (keyWindow) |
| [[keyWindow windowController] nextTab]; |
} |
} |
|
|
-(IBAction) openFile:(id)aSender |
-(IBAction) openFile:(id)aSender |
Line 61 static const char* ioServiceContractID =
|
Line 151 static const char* ioServiceContractID =
|
if ([urlArray count] == 0) |
if ([urlArray count] == 0) |
return; |
return; |
NSURL* url = [urlArray objectAtIndex: 0]; |
NSURL* url = [urlArray objectAtIndex: 0]; |
|
// ---------------------- |
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url]; |
|
// ---------------------- |
NSWindow* keyWindow = [mApplication keyWindow]; |
NSWindow* keyWindow = [mApplication keyWindow]; |
if (keyWindow) | if (keyWindow) { |
return [[keyWindow windowController] loadURL: url]; | [[keyWindow windowController] loadURL: url]; |
| [[[[keyWindow windowController] getMyBrowserView] getBrowserView] setActive: YES]; |
| } |
else |
else |
[self openBrowserWindowWithURL: url]; | [self openBrowserWindowWithURL: url]; |
} |
} |
} |
} |
|
|
Line 124 static const char* ioServiceContractID =
|
Line 219 static const char* ioServiceContractID =
|
} |
} |
|
|
// Edit menu actions. |
// Edit menu actions. |
|
|
|
|
|
// |
|
// -findInPage |
|
// |
|
// Called in response to "Find" in edit menu. Opens the find dialog. We only keep |
|
// one around for the whole app to use, showing/hiding as we see fit. |
|
// |
-(IBAction) findInPage:(id)aSender |
-(IBAction) findInPage:(id)aSender |
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; | if ( !mFindDialog ) |
if (keyWindow) | mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"]; |
[[keyWindow windowController] findInPage]; | [mFindDialog showWindow:self]; |
} |
} |
|
|
|
|
|
// |
|
// -findAgain |
|
// |
|
// Called in response to "Find Again" in edit menu. Tells the find controller |
|
// to find the next occurrance of what's already been found. |
|
// |
-(IBAction) findAgain:(id)aSender |
-(IBAction) findAgain:(id)aSender |
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; | if ( mFindDialog ) |
if (keyWindow) | [mFindDialog findAgain:aSender]; |
[[keyWindow windowController] findAgain]; | else |
| NSBeep(); |
} |
} |
|
|
-(IBAction) back:(id)aSender | -(IBAction) goBack:(id)aSender |
{ |
{ |
[[[mApplication keyWindow] windowController] back: aSender]; |
[[[mApplication keyWindow] windowController] back: aSender]; |
} |
} |
|
|
-(IBAction) forward:(id)aSender | -(IBAction) goForward:(id)aSender |
{ |
{ |
[[[mApplication keyWindow] windowController] forward: aSender]; |
[[[mApplication keyWindow] windowController] forward: aSender]; |
} |
} |
|
|
-(IBAction) reload:(id)aSender | -(IBAction) doReload:(id)aSender |
{ |
{ |
[[[mApplication keyWindow] windowController] reload: aSender]; | [(BrowserWindowController*)([[mApplication keyWindow] windowController]) reload: aSender]; |
} |
} |
|
|
-(IBAction) stop:(id)aSender | -(IBAction) doStop:(id)aSender |
{ |
{ |
[[[mApplication keyWindow] windowController] stop: aSender]; | [(BrowserWindowController*)([[mApplication keyWindow] windowController]) stop: aSender]; |
} |
} |
|
|
-(IBAction) home:(id)aSender | -(IBAction) goHome:(id)aSender |
{ |
{ |
[[[mApplication keyWindow] windowController] home: aSender]; |
[[[mApplication keyWindow] windowController] home: aSender]; |
} |
} |
Line 171 static const char* ioServiceContractID =
|
Line 282 static const char* ioServiceContractID =
|
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL |
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL |
{ |
{ |
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; |
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; |
[browser loadURL: aURL]; | [browser loadURL: aURL]; |
[browser showWindow: self]; |
[browser showWindow: self]; |
return browser; | return browser; |
} |
} |
|
|
-(void)applicationWillTerminate: (NSNotification*)aNotification |
-(void)applicationWillTerminate: (NSNotification*)aNotification |
{ |
{ |
|
printf("Termination notification.\n"); |
|
|
|
// Autosave one of the windows. |
|
NSWindow* keyWindow = [mApplication keyWindow]; |
|
if (keyWindow) |
|
[[keyWindow windowController] autosaveWindowFrame]; |
|
|
mMenuBookmarks->RemoveObserver(); |
mMenuBookmarks->RemoveObserver(); |
delete mMenuBookmarks; |
delete mMenuBookmarks; |
|
mMenuBookmarks = nsnull; |
nsCocoaBrowserService::TermEmbedding(); |
nsCocoaBrowserService::TermEmbedding(); |
} |
} |
|
|
Line 188 static const char* ioServiceContractID =
|
Line 307 static const char* ioServiceContractID =
|
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; |
NSWindow* keyWindow = [mApplication keyWindow]; |
if (keyWindow) |
if (keyWindow) |
[[keyWindow windowController] addBookmark]; | [[keyWindow windowController] addBookmarkExtended: YES]; |
| } |
| |
| -(IBAction) openMenuBookmark:(id)aSender |
| { |
| NSWindow* keyWindow = [mApplication keyWindow]; |
| if (!keyWindow) { |
| [self openBrowserWindowWithURLString: @"about:blank"]; |
| keyWindow = [mApplication keyWindow]; |
| } |
| |
| BookmarksService::OpenMenuBookmark([keyWindow windowController], aSender); |
| } |
| |
| - (MVPreferencesController *)preferencesController |
| { |
| if (!preferencesController) { |
| preferencesController = [[MVPreferencesController sharedInstance] retain]; |
| } |
| return preferencesController; |
| } |
| |
| - (void)displayPreferencesWindow:sender |
| { |
| [[self preferencesController] showPreferences:nil] ; |
} |
} |
|
|
|
- (IBAction)showAboutBox:(id)sender |
|
{ |
|
[[AboutBox sharedInstance] showPanel:sender]; |
|
} |
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename |
|
{ |
|
NSWindow* keyWindow = [mApplication keyWindow]; |
|
|
|
if (keyWindow) { |
|
[[keyWindow windowController] loadURL:[NSURL fileURLWithPath:filename]]; |
|
} else { |
|
[self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]]; |
|
} |
|
|
|
return YES; |
|
|
|
} |
|
|
|
|
@end |
@end |