version 1.14, 2002/02/05 05:00:16
|
version 1.38, 2002/04/09 17:17:11
|
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]; |
|
mMenuBookmarks = new BookmarksService(nil); |
|
mMenuBookmarks->AddObserver(); |
|
mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull); |
|
BookmarksService::gMainController = self; |
|
|
// Initialize offline mode. |
// Initialize offline mode. |
mOffline = NO; |
mOffline = NO; |
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID)); |
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID)); |
Line 31 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 55 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]; |
return [[keyWindow windowController] loadURL: url]; |
Line 88 static const char* ioServiceContractID =
|
Line 187 static const char* ioServiceContractID =
|
[[keyWindow windowController] printDocument]; |
[[keyWindow windowController] printDocument]; |
} |
} |
|
|
|
-(IBAction) printPreview:(id)aSender |
|
{ |
|
NSWindow* keyWindow = [mApplication keyWindow]; |
|
if (keyWindow) |
|
[[keyWindow windowController] printPreview]; |
|
} |
|
|
-(IBAction) toggleOfflineMode:(id)aSender |
-(IBAction) toggleOfflineMode:(id)aSender |
{ |
{ |
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID)); |
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID)); |
Line 111 static const char* ioServiceContractID =
|
Line 217 static const char* ioServiceContractID =
|
} |
} |
|
|
// Edit menu actions. |
// Edit menu actions. |
-(IBAction) doCut:(id)aSender | |
| |
| // |
| // -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 |
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; | if ( !mFindDialog ) |
if (keyWindow) | mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"]; |
[[keyWindow windowController] doCut]; | [mFindDialog showWindow:self]; |
} |
} |
|
|
-(IBAction) doCopy:(id)aSender | -(IBAction) findAgain:(id)aSender |
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; |
NSWindow* keyWindow = [mApplication keyWindow]; |
if (keyWindow) |
if (keyWindow) |
[[keyWindow windowController] doCopy]; | [[keyWindow windowController] findAgain]; |
} |
} |
|
|
-(IBAction) doPaste:(id)aSender | -(IBAction) goBack:(id)aSender |
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; | [[[mApplication keyWindow] windowController] back: aSender]; |
if (keyWindow) | |
[[keyWindow windowController] doPaste]; | |
} |
} |
|
|
-(IBAction) doClear:(id)aSender | -(IBAction) goForward:(id)aSender |
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; | [[[mApplication keyWindow] windowController] forward: aSender]; |
if (keyWindow) | |
[[keyWindow windowController] doClear]; | |
} |
} |
|
|
-(IBAction) doSelectAll:(id)aSender | -(IBAction) doReload:(id)aSender |
{ |
{ |
NSWindow* keyWindow = [mApplication keyWindow]; | [(BrowserWindowController*)([[mApplication keyWindow] windowController]) reload: aSender]; |
if (keyWindow) | |
[[keyWindow windowController] doSelectAll]; | |
} |
} |
|
|
-(IBAction) findInPage:(id)aSender | -(IBAction) doStop:(id)aSender |
{ |
{ |
|
[(BrowserWindowController*)([[mApplication keyWindow] windowController]) stop: aSender]; |
|
} |
|
|
|
-(IBAction) goHome:(id)aSender |
|
{ |
|
[[[mApplication keyWindow] windowController] home: aSender]; |
} |
} |
|
|
-(IBAction) back:(id)aSender | -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL |
{ |
{ |
[[[mApplication keyWindow] windowController] back: aSender]; | return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]]; |
} |
} |
|
|
-(IBAction) forward:(id)aSender | -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL |
{ |
{ |
[[[mApplication keyWindow] windowController] forward: aSender]; | BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; |
| [browser loadURL: aURL]; |
| [browser showWindow: self]; |
| return browser; |
| } |
| |
| -(void)applicationWillTerminate: (NSNotification*)aNotification |
| { |
| printf("Termination notification.\n"); |
| |
| // Autosave one of the windows. |
| NSWindow* keyWindow = [mApplication keyWindow]; |
| if (keyWindow) |
| [[keyWindow windowController] autosaveWindowFrame]; |
| |
| mMenuBookmarks->RemoveObserver(); |
| delete mMenuBookmarks; |
| mMenuBookmarks = nsnull; |
| nsCocoaBrowserService::TermEmbedding(); |
} |
} |
|
|
-(IBAction) reload:(id)aSender | // Bookmarks menu actions. |
| -(IBAction) addBookmark:(id)aSender |
{ |
{ |
[[[mApplication keyWindow] windowController] reload: aSender]; | NSWindow* keyWindow = [mApplication keyWindow]; |
| if (keyWindow) |
| [[keyWindow windowController] addBookmark]; |
} |
} |
|
|
-(IBAction) stop:(id)aSender | -(IBAction) openMenuBookmark:(id)aSender |
{ |
{ |
[[[mApplication keyWindow] windowController] stop: aSender]; | NSWindow* keyWindow = [mApplication keyWindow]; |
| if (!keyWindow) { |
| [self openBrowserWindowWithURLString: @"about:blank"]; |
| keyWindow = [mApplication keyWindow]; |
| } |
| |
| BookmarksService::OpenMenuBookmark([keyWindow windowController], aSender); |
} |
} |
|
|
-(IBAction) home:(id)aSender | - (MVPreferencesController *)preferencesController |
{ |
{ |
[[[mApplication keyWindow] windowController] home: aSender]; | if (!preferencesController) { |
| preferencesController = [[MVPreferencesController sharedInstance] retain]; |
| } |
| return preferencesController; |
} |
} |
|
|
-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL | - (void)displayPreferencesWindow:sender |
{ |
{ |
return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]]; | [[self preferencesController] showPreferences:nil] ; |
} |
} |
|
|
-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL | - (IBAction)showAboutBox:(id)sender |
{ |
{ |
BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; | [[AboutBox sharedInstance] showPanel:sender]; |
[browser loadURL: aURL]; | |
[browser showWindow: self]; | |
return browser; | |
} |
} |
|
|
-(void)applicationWillTerminate: (NSNotification*)aNotification | - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename |
{ |
{ |
nsCocoaBrowserService::TermEmbedding(); | NSWindow* keyWindow = [mApplication keyWindow]; |
| |
| if (keyWindow) { |
| [[keyWindow windowController] loadURL:[NSURL fileURLWithPath:filename]]; |
| } else { |
| [self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]]; |
| } |
| |
| return YES; |
| |
} |
} |
|
|
|
|
@end |
@end |