Annotation of chimera/MainController.mm, revision 1.28

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.10      hyatt      45: 
                     46: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
                     47: 
1.1       hyatt      48: @implementation MainController
                     49: 
1.28    ! macserv    50: -(id)init
        !            51: {
        !            52:     if ( self = [super init] ) {
        !            53:         mSplashScreen = [NSWindow alloc] initWithSize
        !            54:     }
        !            55: }
        !            56: 
1.21      hyatt      57: -(void)dealloc
                     58: {
                     59:     [super dealloc];
                     60:     printf("Main controller died.\n");
                     61: }
                     62: 
1.1       hyatt      63: -(void)awakeFromNib
                     64: {
1.4       hyatt      65:     [self newWindow: self];
1.10      hyatt      66:     
1.19      hyatt      67:     [mBookmarksMenu setAutoenablesItems: NO];
                     68:     
                     69:     mMenuBookmarks = new BookmarksService(nil);
                     70:     mMenuBookmarks->AddObserver();
                     71:     mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
1.20      hyatt      72:     BookmarksService::gMainController = self;
1.19      hyatt      73:     
1.10      hyatt      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"];
1.1       hyatt      87: }
                     88: 
                     89: -(IBAction)newWindow:(id)aSender
                     90: {
1.5       hyatt      91:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
1.4       hyatt      92:     [controller focusURLBar];
                     93: }
                     94: 
1.22      hyatt      95: -(IBAction)newTab:(id)aSender
                     96: {
                     97:     NSWindow* keyWindow = [mApplication keyWindow];
                     98:     if (keyWindow)
1.26      macserv    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];
1.22      hyatt     121: }
                    122: 
1.4       hyatt     123: -(IBAction) openFile:(id)aSender
                    124: {
1.5       hyatt     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:     }
1.4       hyatt     145: }
                    146: 
                    147: -(IBAction) openLocation:(id)aSender
                    148: {
                    149:     NSWindow* keyWindow = [mApplication keyWindow];
                    150:     if (!keyWindow) {
1.5       hyatt     151:       [self openBrowserWindowWithURLString: @"about:blank"];
1.4       hyatt     152:       keyWindow = [mApplication keyWindow];
                    153:     }
                    154:     
1.6       macserv   155:     [[keyWindow windowController] performAppropriateLocationAction];
1.1       hyatt     156: }
                    157: 
1.7       hyatt     158: -(IBAction) savePage:(id)aSender
                    159: {
                    160:     NSWindow* keyWindow = [mApplication keyWindow];
                    161:     if (keyWindow)
1.8       hyatt     162:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
1.7       hyatt     163: }
                    164: 
1.9       hyatt     165: -(IBAction) printPage:(id)aSender
                    166: {
                    167:     NSWindow* keyWindow = [mApplication keyWindow];
                    168:     if (keyWindow)
                    169:       [[keyWindow windowController] printDocument];
                    170: }
                    171: 
1.16      hyatt     172: -(IBAction) printPreview:(id)aSender
                    173: {
                    174:     NSWindow* keyWindow = [mApplication keyWindow];
                    175:     if (keyWindow)
                    176:       [[keyWindow windowController] printPreview];
                    177: }
                    178: 
1.7       hyatt     179: -(IBAction) toggleOfflineMode:(id)aSender
                    180: {
1.10      hyatt     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.
1.11      hyatt     198:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
1.7       hyatt     199: }
                    200: 
1.13      hyatt     201: // Edit menu actions.
                    202: -(IBAction) findInPage:(id)aSender
1.16      hyatt     203: {
1.17      hyatt     204:     NSWindow* keyWindow = [mApplication keyWindow];
                    205:     if (keyWindow)
                    206:       [[keyWindow windowController] findInPage];
1.16      hyatt     207: }
                    208: 
                    209: -(IBAction) findAgain:(id)aSender
1.13      hyatt     210: {
1.17      hyatt     211:     NSWindow* keyWindow = [mApplication keyWindow];
                    212:     if (keyWindow)
                    213:       [[keyWindow windowController] findAgain];
1.13      hyatt     214: }
                    215: 
1.23      hyatt     216: -(IBAction) goBack:(id)aSender
1.2       hyatt     217: {
                    218:     [[[mApplication keyWindow] windowController] back: aSender]; 
                    219: }
                    220: 
1.23      hyatt     221: -(IBAction) goForward:(id)aSender
1.2       hyatt     222: {
                    223:     [[[mApplication keyWindow] windowController] forward: aSender]; 
                    224: }
                    225: 
1.23      hyatt     226: -(IBAction) doReload:(id)aSender
1.2       hyatt     227: {
1.23      hyatt     228:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) reload: aSender]; 
1.2       hyatt     229: }
                    230: 
1.23      hyatt     231: -(IBAction) doStop:(id)aSender
1.2       hyatt     232: {
1.23      hyatt     233:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) stop: aSender]; 
1.2       hyatt     234: }
                    235: 
1.23      hyatt     236: -(IBAction) goHome:(id)aSender
1.2       hyatt     237: {
                    238:     [[[mApplication keyWindow] windowController] home: aSender];
                    239: }
                    240: 
1.5       hyatt     241: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
                    242: {
                    243:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
                    244: }
                    245: 
                    246: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
1.1       hyatt     247: {
1.3       macserv   248:  BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
1.5       hyatt     249:     [browser loadURL: aURL];
1.3       macserv   250:  [browser showWindow: self];
1.4       hyatt     251:     return browser;
1.1       hyatt     252: }
                    253: 
1.12      hyatt     254: -(void)applicationWillTerminate: (NSNotification*)aNotification
                    255: {
1.24      hyatt     256:     printf("Termination notification.\n");
1.19      hyatt     257:     mMenuBookmarks->RemoveObserver();
                    258:     delete mMenuBookmarks;
1.24      hyatt     259:     mMenuBookmarks = nsnull;
1.12      hyatt     260:     nsCocoaBrowserService::TermEmbedding();
                    261: }
1.18      hyatt     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: 
1.20      hyatt     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: }
1.25      macserv   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: 
1.1       hyatt     296: @end

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