Annotation of chimera/MainController.mm, revision 1.48

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: 
1.36      pinkerto   47: 
1.10      hyatt      48: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
                     49: 
1.1       hyatt      50: @implementation MainController
                     51: 
1.30      macserv    52: -(id)init
                     53: {
                     54:     if ( (self = [super init]) ) {
1.48    ! macserv    55:         mSplashScreen = [[SplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:NSMakeRect(0,0,0,0)];
        !            56:         mFindDialog = nil;
        !            57:         mMenuBookmarks = nil;
1.30      macserv    58:     }
                     59:     return self;
                     60: }
                     61: 
1.21      hyatt      62: -(void)dealloc
                     63: {
                     64:     [super dealloc];
1.36      pinkerto   65:     [mFindDialog release];
1.21      hyatt      66:     printf("Main controller died.\n");
                     67: }
                     68: 
1.1       hyatt      69: -(void)awakeFromNib
1.35      macserv    70: {    
1.4       hyatt      71:     [self newWindow: self];
1.35      macserv    72:     
                     73:     [mSplashScreen close];
1.31      macserv    74: 
1.19      hyatt      75:     [mBookmarksMenu setAutoenablesItems: NO];
1.44      hyatt      76:     mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil);
1.19      hyatt      77:     mMenuBookmarks->AddObserver();
                     78:     mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
1.20      hyatt      79:     BookmarksService::gMainController = self;
1.19      hyatt      80:     
1.10      hyatt      81:     // Initialize offline mode.
                     82:     mOffline = NO;
                     83:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                     84:     if (!ioService)
                     85:         return;
                     86:     PRBool offline = PR_FALSE;
                     87:     ioService->GetOffline(&offline);
                     88:     mOffline = offline;
                     89:     
                     90:     // Set the menu item's text to "Go Online" if we're currently
                     91:     // offline.
                     92:     if (mOffline)
                     93:         [mOfflineMenuItem setTitle: @"Go Online"];
1.30      macserv    94: 
1.1       hyatt      95: }
                     96: 
                     97: -(IBAction)newWindow:(id)aSender
                     98: {
1.32      hyatt      99:   // If we have a key window, have it autosave its dimensions before
                    100:   // we open a new window.  That ensures the size ends up matching.
1.46      pinkerto  101:   NSWindow* mainWindow = [mApplication mainWindow];
1.47      hyatt     102:   if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] )
1.46      pinkerto  103:     [[mainWindow windowController] autosaveWindowFrame];
1.32      hyatt     104: 
                    105:   // Now open the new window.
                    106:   BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
                    107:   [controller focusURLBar];
                    108: }  
1.4       hyatt     109: 
1.22      hyatt     110: -(IBAction)newTab:(id)aSender
                    111: {
1.46      pinkerto  112:   [[[mApplication mainWindow] windowController] newTab];
1.26      macserv   113: }
                    114: 
                    115: -(IBAction)closeTab:(id)aSender
                    116: {
1.46      pinkerto  117:   [[[mApplication mainWindow] windowController] closeTab];
1.26      macserv   118: }
                    119: 
                    120: -(IBAction) previousTab:(id)aSender
                    121: {
1.46      pinkerto  122:   [[[mApplication mainWindow] windowController] previousTab];
1.26      macserv   123: }
                    124: 
                    125: -(IBAction) nextTab:(id)aSender;
                    126: {
1.46      pinkerto  127:  [[[mApplication mainWindow] windowController] nextTab];
1.22      hyatt     128: }
                    129: 
1.4       hyatt     130: -(IBAction) openFile:(id)aSender
                    131: {
1.5       hyatt     132:     NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
                    133:     [openPanel setCanChooseFiles: YES];
                    134:     [openPanel setCanChooseDirectories: NO];
                    135:     [openPanel setAllowsMultipleSelection: NO];
                    136:     NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
                    137:                                                 @"txt",@"text",
                    138:                                                 @"gif",@"jpg",@"jpeg",@"png",@"bmp",
                    139:                                                 nil];
                    140:     int result = [openPanel runModalForTypes: array];
                    141:     if (result == NSOKButton) {
                    142:         NSArray* urlArray = [openPanel URLs];
                    143:         if ([urlArray count] == 0)
                    144:             return;
                    145:         NSURL* url = [urlArray objectAtIndex: 0];
1.33      macserv   146:         // ----------------------
                    147:         [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url];
                    148:         // ----------------------
1.46      pinkerto  149:         NSWindow* mainWindow = [mApplication mainWindow];
                    150:         if (mainWindow) {
                    151:           [[mainWindow windowController] loadURL: url];
                    152:           [[[[mainWindow windowController] getMyBrowserView] getBrowserView] setActive: YES];
1.40      hyatt     153:         }
1.5       hyatt     154:         else
1.40      hyatt     155:           [self openBrowserWindowWithURL: url];
1.5       hyatt     156:     }
1.4       hyatt     157: }
                    158: 
                    159: -(IBAction) openLocation:(id)aSender
                    160: {
1.46      pinkerto  161:     NSWindow* mainWindow = [mApplication mainWindow];
                    162:     if (!mainWindow) {
1.5       hyatt     163:       [self openBrowserWindowWithURLString: @"about:blank"];
1.46      pinkerto  164:       mainWindow = [mApplication mainWindow];
1.4       hyatt     165:     }
                    166:     
1.46      pinkerto  167:     [[mainWindow windowController] performAppropriateLocationAction];
1.1       hyatt     168: }
                    169: 
1.7       hyatt     170: -(IBAction) savePage:(id)aSender
                    171: {
1.46      pinkerto  172:   [[[mApplication mainWindow] windowController] saveDocument: mFilterView filterList: mFilterList];
1.7       hyatt     173: }
                    174: 
1.9       hyatt     175: -(IBAction) printPage:(id)aSender
                    176: {
1.46      pinkerto  177:   [[[mApplication mainWindow] windowController] printDocument];
1.9       hyatt     178: }
                    179: 
1.16      hyatt     180: -(IBAction) printPreview:(id)aSender
                    181: {
1.46      pinkerto  182:   [[[mApplication mainWindow] windowController] printPreview];
1.16      hyatt     183: }
                    184: 
1.7       hyatt     185: -(IBAction) toggleOfflineMode:(id)aSender
                    186: {
1.10      hyatt     187:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                    188:     if (!ioService)
                    189:         return;
                    190:     PRBool offline = PR_FALSE;
                    191:     ioService->GetOffline(&offline);
                    192:     ioService->SetOffline(!offline);
                    193:     mOffline = !offline;
                    194:     
                    195:     // Update the menu item text.
                    196:     // Set the menu item's text to "Go Online" if we're currently
                    197:     // offline.
                    198:     if (mOffline)
                    199:         [mOfflineMenuItem setTitle: @"Go Online"];
                    200:     else
                    201:         [mOfflineMenuItem setTitle: @"Work Offline"];
                    202:         
                    203:     // Indicate that we are working offline.
1.11      hyatt     204:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
1.7       hyatt     205: }
                    206: 
1.13      hyatt     207: // Edit menu actions.
1.36      pinkerto  208: 
                    209: 
                    210: //
                    211: // -findInPage
                    212: //
                    213: // Called in response to "Find" in edit menu. Opens the find dialog. We only keep
                    214: // one around for the whole app to use, showing/hiding as we see fit.
                    215: //
1.13      hyatt     216: -(IBAction) findInPage:(id)aSender
1.16      hyatt     217: {
1.36      pinkerto  218:   if ( !mFindDialog )
                    219:      mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"];
                    220:   [mFindDialog showWindow:self];
1.16      hyatt     221: }
                    222: 
1.39      pinkerto  223: 
                    224: //
                    225: // -findAgain
                    226: //
                    227: // Called in response to "Find Again" in edit menu. Tells the find controller
                    228: // to find the next occurrance of what's already been found.
                    229: //
1.16      hyatt     230: -(IBAction) findAgain:(id)aSender
1.13      hyatt     231: {
1.39      pinkerto  232:   if ( mFindDialog )
                    233:     [mFindDialog findAgain:aSender];
                    234:   else
                    235:     NSBeep();
1.13      hyatt     236: }
                    237: 
1.23      hyatt     238: -(IBAction) goBack:(id)aSender
1.2       hyatt     239: {
1.46      pinkerto  240:     [[[mApplication mainWindow] windowController] back: aSender]; 
1.2       hyatt     241: }
                    242: 
1.23      hyatt     243: -(IBAction) goForward:(id)aSender
1.2       hyatt     244: {
1.46      pinkerto  245:     [[[mApplication mainWindow] windowController] forward: aSender]; 
1.2       hyatt     246: }
                    247: 
1.23      hyatt     248: -(IBAction) doReload:(id)aSender
1.2       hyatt     249: {
1.46      pinkerto  250:     [(BrowserWindowController*)([[mApplication mainWindow] windowController]) reload: aSender]; 
1.2       hyatt     251: }
                    252: 
1.23      hyatt     253: -(IBAction) doStop:(id)aSender
1.2       hyatt     254: {
1.46      pinkerto  255:     [(BrowserWindowController*)([[mApplication mainWindow] windowController]) stop: aSender]; 
1.2       hyatt     256: }
                    257: 
1.23      hyatt     258: -(IBAction) goHome:(id)aSender
1.2       hyatt     259: {
1.46      pinkerto  260:     [[[mApplication mainWindow] windowController] home: aSender];
1.2       hyatt     261: }
                    262: 
1.5       hyatt     263: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
                    264: {
                    265:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
                    266: }
                    267: 
                    268: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
1.1       hyatt     269: {
1.3       macserv   270:  BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
1.34      hyatt     271:   [browser loadURL: aURL];
1.3       macserv   272:  [browser showWindow: self];
1.34      hyatt     273:   return browser;
1.1       hyatt     274: }
                    275: 
1.12      hyatt     276: -(void)applicationWillTerminate: (NSNotification*)aNotification
                    277: {
1.24      hyatt     278:     printf("Termination notification.\n");
1.37      hyatt     279: 
                    280:     // Autosave one of the windows.
1.46      pinkerto  281:     [[[mApplication mainWindow] windowController] autosaveWindowFrame];
1.37      hyatt     282:     
1.19      hyatt     283:     mMenuBookmarks->RemoveObserver();
                    284:     delete mMenuBookmarks;
1.24      hyatt     285:     mMenuBookmarks = nsnull;
1.12      hyatt     286:     nsCocoaBrowserService::TermEmbedding();
                    287: }
1.18      hyatt     288: 
                    289: // Bookmarks menu actions.
                    290: -(IBAction) addBookmark:(id)aSender
                    291: {
1.46      pinkerto  292:   [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: NO];
1.45      hyatt     293: }
                    294: 
                    295: -(IBAction) addFolder:(id)aSender
                    296: {
1.46      pinkerto  297:   [[[mApplication mainWindow] windowController] addBookmarkExtended: YES isFolder: YES];
1.45      hyatt     298: }
                    299: 
                    300: -(IBAction) addSeparator:(id)aSender
                    301: {
1.18      hyatt     302: }
                    303: 
1.20      hyatt     304: -(IBAction) openMenuBookmark:(id)aSender
                    305: {
1.46      pinkerto  306:     NSWindow* mainWind = [mApplication mainWindow];
                    307:     if (!mainWind) {
1.20      hyatt     308:         [self openBrowserWindowWithURLString: @"about:blank"];
1.46      pinkerto  309:         mainWind = [mApplication mainWindow];
1.20      hyatt     310:     }
                    311: 
1.46      pinkerto  312:     BookmarksService::OpenMenuBookmark([mainWind windowController], aSender);
1.20      hyatt     313: }
1.25      macserv   314: 
1.42      hyatt     315: -(IBAction)manageBookmarks: (id)aSender
                    316: {
1.46      pinkerto  317:   NSWindow* mainWindow = [mApplication mainWindow];
                    318:   if (!mainWindow) {
1.42      hyatt     319:     [self openBrowserWindowWithURLString: @"about:blank"];
1.46      pinkerto  320:     mainWindow = [mApplication mainWindow];
1.42      hyatt     321:   }
                    322: 
1.46      pinkerto  323:   [[mainWindow windowController] manageBookmarks: aSender];
1.42      hyatt     324: }
                    325: 
1.25      macserv   326: - (MVPreferencesController *)preferencesController
                    327: {
                    328:     if (!preferencesController) {
                    329:         preferencesController = [[MVPreferencesController sharedInstance] retain];
                    330:     }
                    331:     return preferencesController;
                    332: }
                    333: 
                    334: - (void)displayPreferencesWindow:sender
                    335: {
                    336:     [[self preferencesController] showPreferences:nil] ;
                    337: }
                    338: 
1.30      macserv   339: - (IBAction)showAboutBox:(id)sender
                    340: {
                    341:     [[AboutBox sharedInstance] showPanel:sender];
                    342: }
1.33      macserv   343: 
                    344: - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
                    345: {
1.46      pinkerto  346:     NSWindow* mainWindow = [mApplication mainWindow];
1.33      macserv   347: 
1.46      pinkerto  348:     if (mainWindow) {
                    349:         [[mainWindow windowController] loadURL:[NSURL fileURLWithPath:filename]];
1.33      macserv   350:     } else {
                    351:         [self openBrowserWindowWithURL:[NSURL fileURLWithPath:filename]];
                    352:     }
                    353:     
                    354:     return YES;
                    355:     
                    356: }
                    357: 
1.43      hyatt     358: - (IBAction)biggerTextSize:(id)aSender
                    359: {
1.46      pinkerto  360:   [[[mApplication mainWindow] windowController] biggerTextSize];
1.43      hyatt     361: }
                    362: 
                    363: - (IBAction)smallerTextSize:(id)aSender
                    364: {
1.46      pinkerto  365:   [[[mApplication mainWindow] windowController] smallerTextSize];
1.43      hyatt     366: }
                    367: 
                    368: - (IBAction)toggleSmoothText:(id)aSender
                    369: {
                    370:   // XXXdwh Grab the prefs service and just set the pref directly.
                    371:   
                    372: }
                    373: 
1.25      macserv   374: 
1.1       hyatt     375: @end

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