File:  [mozdev] / chimera / MainController.mm
Revision 1.28: download - view: text, annotated - select for diffs - revision graph
Sat Mar 9 08:39:35 2002 UTC (17 years, 7 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
Removing old RDF support.

    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 "MainController.h"
   39: #import "BrowserWindowController.h"
   40: #include "BookmarksService.h"
   41: #include "nsCOMPtr.h"
   42: #include "nsIServiceManager.h"
   43: #include "nsIIOService.h"
   44: #include "nsCocoaBrowserService.h"
   45: 
   46: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
   47: 
   48: @implementation MainController
   49: 
   50: -(id)init
   51: {
   52:     if ( self = [super init] ) {
   53:         mSplashScreen = [NSWindow alloc] initWithSize
   54:     }
   55: }
   56: 
   57: -(void)dealloc
   58: {
   59:     [super dealloc];
   60:     printf("Main controller died.\n");
   61: }
   62: 
   63: -(void)awakeFromNib
   64: {
   65:     [self newWindow: self];
   66:     
   67:     [mBookmarksMenu setAutoenablesItems: NO];
   68:     
   69:     mMenuBookmarks = new BookmarksService(nil);
   70:     mMenuBookmarks->AddObserver();
   71:     mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
   72:     BookmarksService::gMainController = self;
   73:     
   74:     // Initialize offline mode.
   75:     mOffline = NO;
   76:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
   77:     if (!ioService)
   78:         return;
   79:     PRBool offline = PR_FALSE;
   80:     ioService->GetOffline(&offline);
   81:     mOffline = offline;
   82:     
   83:     // Set the menu item's text to "Go Online" if we're currently
   84:     // offline.
   85:     if (mOffline)
   86:         [mOfflineMenuItem setTitle: @"Go Online"];
   87: }
   88: 
   89: -(IBAction)newWindow:(id)aSender
   90: {
   91:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
   92:     [controller focusURLBar];
   93: }
   94: 
   95: -(IBAction)newTab:(id)aSender
   96: {
   97:     NSWindow* keyWindow = [mApplication keyWindow];
   98:     if (keyWindow)
   99:         [[keyWindow windowController] newTab];
  100: }
  101: 
  102: -(IBAction)closeTab:(id)aSender
  103: {
  104:     NSWindow* keyWindow = [mApplication keyWindow];
  105:     if (keyWindow)
  106:         [[keyWindow windowController] closeTab];
  107: }
  108: 
  109: -(IBAction) previousTab:(id)aSender
  110: {
  111:     NSWindow* keyWindow = [mApplication keyWindow];
  112:     if (keyWindow)
  113:         [[keyWindow windowController] previousTab];
  114: }
  115: 
  116: -(IBAction) nextTab:(id)aSender;
  117: {
  118:     NSWindow* keyWindow = [mApplication keyWindow];
  119:     if (keyWindow)
  120:         [[keyWindow windowController] nextTab];
  121: }
  122: 
  123: -(IBAction) openFile:(id)aSender
  124: {
  125:     NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
  126:     [openPanel setCanChooseFiles: YES];
  127:     [openPanel setCanChooseDirectories: NO];
  128:     [openPanel setAllowsMultipleSelection: NO];
  129:     NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
  130:                                                 @"txt",@"text",
  131:                                                 @"gif",@"jpg",@"jpeg",@"png",@"bmp",
  132:                                                 nil];
  133:     int result = [openPanel runModalForTypes: array];
  134:     if (result == NSOKButton) {
  135:         NSArray* urlArray = [openPanel URLs];
  136:         if ([urlArray count] == 0)
  137:             return;
  138:         NSURL* url = [urlArray objectAtIndex: 0];
  139:         NSWindow* keyWindow = [mApplication keyWindow];
  140:         if (keyWindow)
  141:             return [[keyWindow windowController] loadURL: url];
  142:         else
  143:             [self openBrowserWindowWithURL: url];
  144:     }
  145: }
  146: 
  147: -(IBAction) openLocation:(id)aSender
  148: {
  149:     NSWindow* keyWindow = [mApplication keyWindow];
  150:     if (!keyWindow) {
  151:       [self openBrowserWindowWithURLString: @"about:blank"];
  152:       keyWindow = [mApplication keyWindow];
  153:     }
  154:     
  155:     [[keyWindow windowController] performAppropriateLocationAction];
  156: }
  157: 
  158: -(IBAction) savePage:(id)aSender
  159: {
  160:     NSWindow* keyWindow = [mApplication keyWindow];
  161:     if (keyWindow)
  162:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
  163: }
  164: 
  165: -(IBAction) printPage:(id)aSender
  166: {
  167:     NSWindow* keyWindow = [mApplication keyWindow];
  168:     if (keyWindow)
  169:       [[keyWindow windowController] printDocument];
  170: }
  171: 
  172: -(IBAction) printPreview:(id)aSender
  173: {
  174:     NSWindow* keyWindow = [mApplication keyWindow];
  175:     if (keyWindow)
  176:       [[keyWindow windowController] printPreview];
  177: }
  178: 
  179: -(IBAction) toggleOfflineMode:(id)aSender
  180: {
  181:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
  182:     if (!ioService)
  183:         return;
  184:     PRBool offline = PR_FALSE;
  185:     ioService->GetOffline(&offline);
  186:     ioService->SetOffline(!offline);
  187:     mOffline = !offline;
  188:     
  189:     // Update the menu item text.
  190:     // Set the menu item's text to "Go Online" if we're currently
  191:     // offline.
  192:     if (mOffline)
  193:         [mOfflineMenuItem setTitle: @"Go Online"];
  194:     else
  195:         [mOfflineMenuItem setTitle: @"Work Offline"];
  196:         
  197:     // Indicate that we are working offline.
  198:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
  199: }
  200: 
  201: // Edit menu actions.
  202: -(IBAction) findInPage:(id)aSender
  203: {
  204:     NSWindow* keyWindow = [mApplication keyWindow];
  205:     if (keyWindow)
  206:       [[keyWindow windowController] findInPage];
  207: }
  208: 
  209: -(IBAction) findAgain:(id)aSender
  210: {
  211:     NSWindow* keyWindow = [mApplication keyWindow];
  212:     if (keyWindow)
  213:       [[keyWindow windowController] findAgain];
  214: }
  215: 
  216: -(IBAction) goBack:(id)aSender
  217: {
  218:     [[[mApplication keyWindow] windowController] back: aSender]; 
  219: }
  220: 
  221: -(IBAction) goForward:(id)aSender
  222: {
  223:     [[[mApplication keyWindow] windowController] forward: aSender]; 
  224: }
  225: 
  226: -(IBAction) doReload:(id)aSender
  227: {
  228:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) reload: aSender]; 
  229: }
  230: 
  231: -(IBAction) doStop:(id)aSender
  232: {
  233:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) stop: aSender]; 
  234: }
  235: 
  236: -(IBAction) goHome:(id)aSender
  237: {
  238:     [[[mApplication keyWindow] windowController] home: aSender];
  239: }
  240: 
  241: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
  242: {
  243:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
  244: }
  245: 
  246: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
  247: {
  248: 	BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  249:     [browser loadURL: aURL];
  250: 	[browser showWindow: self];
  251:     return browser;
  252: }
  253: 
  254: -(void)applicationWillTerminate: (NSNotification*)aNotification
  255: {
  256:     printf("Termination notification.\n");
  257:     mMenuBookmarks->RemoveObserver();
  258:     delete mMenuBookmarks;
  259:     mMenuBookmarks = nsnull;
  260:     nsCocoaBrowserService::TermEmbedding();
  261: }
  262: 
  263: // Bookmarks menu actions.
  264: -(IBAction) addBookmark:(id)aSender
  265: {
  266:     NSWindow* keyWindow = [mApplication keyWindow];
  267:     if (keyWindow)
  268:       [[keyWindow windowController] addBookmark];
  269: }
  270: 
  271: -(IBAction) openMenuBookmark:(id)aSender
  272: {
  273:     NSWindow* keyWindow = [mApplication keyWindow];
  274:     if (!keyWindow) {
  275:         [self openBrowserWindowWithURLString: @"about:blank"];
  276:         keyWindow = [mApplication keyWindow];
  277:     }
  278: 
  279:     BookmarksService::OpenMenuBookmark([keyWindow windowController], aSender);
  280: }
  281: 
  282: - (MVPreferencesController *)preferencesController
  283: {
  284:     if (!preferencesController) {
  285:         preferencesController = [[MVPreferencesController sharedInstance] retain];
  286:     }
  287:     return preferencesController;
  288: }
  289: 
  290: - (void)displayPreferencesWindow:sender
  291: {
  292:     [[self preferencesController] showPreferences:nil] ;
  293: }
  294: 
  295: 
  296: @end

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