Annotation of chimera/MainController.mm, revision 1.29

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

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