Annotation of chimera/MainController.mm, revision 1.31

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

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