Annotation of chimera/MainController.mm, revision 1.34

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.32      hyatt      96:   // If we have a key window, have it autosave its dimensions before
                     97:   // we open a new window.  That ensures the size ends up matching.
                     98:   NSWindow* keyWindow = [mApplication keyWindow];
                     99:   if (keyWindow)
                    100:     [[keyWindow windowController] autosaveWindowFrame];
                    101: 
                    102:   // Now open the new window.
                    103:   BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
                    104:   [controller focusURLBar];
                    105: }  
1.4       hyatt     106: 
1.22      hyatt     107: -(IBAction)newTab:(id)aSender
                    108: {
                    109:     NSWindow* keyWindow = [mApplication keyWindow];
                    110:     if (keyWindow)
1.26      macserv   111:         [[keyWindow windowController] newTab];
                    112: }
                    113: 
                    114: -(IBAction)closeTab:(id)aSender
                    115: {
                    116:     NSWindow* keyWindow = [mApplication keyWindow];
                    117:     if (keyWindow)
                    118:         [[keyWindow windowController] closeTab];
                    119: }
                    120: 
                    121: -(IBAction) previousTab:(id)aSender
                    122: {
                    123:     NSWindow* keyWindow = [mApplication keyWindow];
                    124:     if (keyWindow)
                    125:         [[keyWindow windowController] previousTab];
                    126: }
                    127: 
                    128: -(IBAction) nextTab:(id)aSender;
                    129: {
                    130:     NSWindow* keyWindow = [mApplication keyWindow];
                    131:     if (keyWindow)
                    132:         [[keyWindow windowController] nextTab];
1.22      hyatt     133: }
                    134: 
1.4       hyatt     135: -(IBAction) openFile:(id)aSender
                    136: {
1.5       hyatt     137:     NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
                    138:     [openPanel setCanChooseFiles: YES];
                    139:     [openPanel setCanChooseDirectories: NO];
                    140:     [openPanel setAllowsMultipleSelection: NO];
                    141:     NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
                    142:                                                 @"txt",@"text",
                    143:                                                 @"gif",@"jpg",@"jpeg",@"png",@"bmp",
                    144:                                                 nil];
                    145:     int result = [openPanel runModalForTypes: array];
                    146:     if (result == NSOKButton) {
                    147:         NSArray* urlArray = [openPanel URLs];
                    148:         if ([urlArray count] == 0)
                    149:             return;
                    150:         NSURL* url = [urlArray objectAtIndex: 0];
1.33      macserv   151:         // ----------------------
                    152:         [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
                    153:         // ----------------------
1.5       hyatt     154:         NSWindow* keyWindow = [mApplication keyWindow];
                    155:         if (keyWindow)
                    156:             return [[keyWindow windowController] loadURL: url];
                    157:         else
                    158:             [self openBrowserWindowWithURL: url];
                    159:     }
1.4       hyatt     160: }
                    161: 
                    162: -(IBAction) openLocation:(id)aSender
                    163: {
                    164:     NSWindow* keyWindow = [mApplication keyWindow];
                    165:     if (!keyWindow) {
1.5       hyatt     166:       [self openBrowserWindowWithURLString: @"about:blank"];
1.4       hyatt     167:       keyWindow = [mApplication keyWindow];
                    168:     }
                    169:     
1.6       macserv   170:     [[keyWindow windowController] performAppropriateLocationAction];
1.1       hyatt     171: }
                    172: 
1.7       hyatt     173: -(IBAction) savePage:(id)aSender
                    174: {
                    175:     NSWindow* keyWindow = [mApplication keyWindow];
                    176:     if (keyWindow)
1.8       hyatt     177:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
1.7       hyatt     178: }
                    179: 
1.9       hyatt     180: -(IBAction) printPage:(id)aSender
                    181: {
                    182:     NSWindow* keyWindow = [mApplication keyWindow];
                    183:     if (keyWindow)
                    184:       [[keyWindow windowController] printDocument];
                    185: }
                    186: 
1.16      hyatt     187: -(IBAction) printPreview:(id)aSender
                    188: {
                    189:     NSWindow* keyWindow = [mApplication keyWindow];
                    190:     if (keyWindow)
                    191:       [[keyWindow windowController] printPreview];
                    192: }
                    193: 
1.7       hyatt     194: -(IBAction) toggleOfflineMode:(id)aSender
                    195: {
1.10      hyatt     196:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                    197:     if (!ioService)
                    198:         return;
                    199:     PRBool offline = PR_FALSE;
                    200:     ioService->GetOffline(&offline);
                    201:     ioService->SetOffline(!offline);
                    202:     mOffline = !offline;
                    203:     
                    204:     // Update the menu item text.
                    205:     // Set the menu item's text to "Go Online" if we're currently
                    206:     // offline.
                    207:     if (mOffline)
                    208:         [mOfflineMenuItem setTitle: @"Go Online"];
                    209:     else
                    210:         [mOfflineMenuItem setTitle: @"Work Offline"];
                    211:         
                    212:     // Indicate that we are working offline.
1.11      hyatt     213:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
1.7       hyatt     214: }
                    215: 
1.13      hyatt     216: // Edit menu actions.
                    217: -(IBAction) findInPage:(id)aSender
1.16      hyatt     218: {
1.17      hyatt     219:     NSWindow* keyWindow = [mApplication keyWindow];
                    220:     if (keyWindow)
                    221:       [[keyWindow windowController] findInPage];
1.16      hyatt     222: }
                    223: 
                    224: -(IBAction) findAgain:(id)aSender
1.13      hyatt     225: {
1.17      hyatt     226:     NSWindow* keyWindow = [mApplication keyWindow];
                    227:     if (keyWindow)
                    228:       [[keyWindow windowController] findAgain];
1.13      hyatt     229: }
                    230: 
1.23      hyatt     231: -(IBAction) goBack:(id)aSender
1.2       hyatt     232: {
                    233:     [[[mApplication keyWindow] windowController] back: aSender]; 
                    234: }
                    235: 
1.23      hyatt     236: -(IBAction) goForward:(id)aSender
1.2       hyatt     237: {
                    238:     [[[mApplication keyWindow] windowController] forward: aSender]; 
                    239: }
                    240: 
1.23      hyatt     241: -(IBAction) doReload:(id)aSender
1.2       hyatt     242: {
1.23      hyatt     243:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) reload: aSender]; 
1.2       hyatt     244: }
                    245: 
1.23      hyatt     246: -(IBAction) doStop:(id)aSender
1.2       hyatt     247: {
1.23      hyatt     248:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) stop: aSender]; 
1.2       hyatt     249: }
                    250: 
1.23      hyatt     251: -(IBAction) goHome:(id)aSender
1.2       hyatt     252: {
                    253:     [[[mApplication keyWindow] windowController] home: aSender];
                    254: }
                    255: 
1.5       hyatt     256: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
                    257: {
                    258:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
                    259: }
                    260: 
                    261: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
1.1       hyatt     262: {
1.3       macserv   263:  BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
1.34    ! hyatt     264:   [browser loadURL: aURL];
1.3       macserv   265:  [browser showWindow: self];
1.34    ! hyatt     266:   return browser;
1.1       hyatt     267: }
                    268: 
1.12      hyatt     269: -(void)applicationWillTerminate: (NSNotification*)aNotification
                    270: {
1.24      hyatt     271:     printf("Termination notification.\n");
1.19      hyatt     272:     mMenuBookmarks->RemoveObserver();
                    273:     delete mMenuBookmarks;
1.24      hyatt     274:     mMenuBookmarks = nsnull;
1.12      hyatt     275:     nsCocoaBrowserService::TermEmbedding();
                    276: }
1.18      hyatt     277: 
                    278: // Bookmarks menu actions.
                    279: -(IBAction) addBookmark:(id)aSender
                    280: {
                    281:     NSWindow* keyWindow = [mApplication keyWindow];
                    282:     if (keyWindow)
                    283:       [[keyWindow windowController] addBookmark];
                    284: }
                    285: 
1.20      hyatt     286: -(IBAction) openMenuBookmark:(id)aSender
                    287: {
                    288:     NSWindow* keyWindow = [mApplication keyWindow];
                    289:     if (!keyWindow) {
                    290:         [self openBrowserWindowWithURLString: @"about:blank"];
                    291:         keyWindow = [mApplication keyWindow];
                    292:     }
                    293: 
                    294:     BookmarksService::OpenMenuBookmark([keyWindow windowController], aSender);
                    295: }
1.25      macserv   296: 
                    297: - (MVPreferencesController *)preferencesController
                    298: {
                    299:     if (!preferencesController) {
                    300:         preferencesController = [[MVPreferencesController sharedInstance] retain];
                    301:     }
                    302:     return preferencesController;
                    303: }
                    304: 
                    305: - (void)displayPreferencesWindow:sender
                    306: {
                    307:     [[self preferencesController] showPreferences:nil] ;
                    308: }
                    309: 
1.30      macserv   310: - (IBAction)showAboutBox:(id)sender
                    311: {
                    312:     [[AboutBox sharedInstance] showPanel:sender];
                    313: }
1.33      macserv   314: 
                    315: - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
                    316: {
                    317:     NSWindow* keyWindow = [mApplication keyWindow];
                    318: 
                    319:     if (keyWindow) {
                    320:         [[keyWindow windowController] loadURL:[NSURL fileURLWithPath:filename]];
                    321:     } else {
                    322:         [self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]];
                    323:     }
                    324:     
                    325:     return YES;
                    326:     
                    327: }
                    328: 
1.25      macserv   329: 
1.1       hyatt     330: @end

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