Annotation of chimera/MainController.mm, revision 1.25

1.3       macserv     1: /*
                      2:  *  MainController.mm
                      3:  */
1.1       hyatt       4: 
                      5: #import "MainController.h"
                      6: #import "BrowserWindowController.h"
1.20      hyatt       7: #include "BookmarksService.h"
1.10      hyatt       8: #include "nsCOMPtr.h"
                      9: #include "nsIServiceManager.h"
                     10: #include "nsIIOService.h"
1.12      hyatt      11: #include "nsCocoaBrowserService.h"
1.10      hyatt      12: 
                     13: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
                     14: 
1.1       hyatt      15: @implementation MainController
                     16: 
1.21      hyatt      17: -(void)dealloc
                     18: {
                     19:     [super dealloc];
                     20:     printf("Main controller died.\n");
                     21: }
                     22: 
1.1       hyatt      23: -(void)awakeFromNib
                     24: {
1.4       hyatt      25:     [self newWindow: self];
1.10      hyatt      26:     
1.19      hyatt      27:     [mBookmarksMenu setAutoenablesItems: NO];
                     28:     
                     29:     mMenuBookmarks = new BookmarksService(nil);
                     30:     mMenuBookmarks->AddObserver();
                     31:     mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
1.20      hyatt      32:     BookmarksService::gMainController = self;
1.19      hyatt      33:     
1.10      hyatt      34:     // Initialize offline mode.
                     35:     mOffline = NO;
                     36:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                     37:     if (!ioService)
                     38:         return;
                     39:     PRBool offline = PR_FALSE;
                     40:     ioService->GetOffline(&offline);
                     41:     mOffline = offline;
                     42:     
                     43:     // Set the menu item's text to "Go Online" if we're currently
                     44:     // offline.
                     45:     if (mOffline)
                     46:         [mOfflineMenuItem setTitle: @"Go Online"];
1.1       hyatt      47: }
                     48: 
                     49: -(IBAction)newWindow:(id)aSender
                     50: {
1.5       hyatt      51:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
1.4       hyatt      52:     [controller focusURLBar];
                     53: }
                     54: 
1.22      hyatt      55: -(IBAction)newTab:(id)aSender
                     56: {
                     57:     NSWindow* keyWindow = [mApplication keyWindow];
                     58:     if (keyWindow)
                     59:       [[keyWindow windowController] newTab];
                     60: }
                     61: 
1.4       hyatt      62: -(IBAction) openFile:(id)aSender
                     63: {
1.5       hyatt      64:     NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
                     65:     [openPanel setCanChooseFiles: YES];
                     66:     [openPanel setCanChooseDirectories: NO];
                     67:     [openPanel setAllowsMultipleSelection: NO];
                     68:     NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
                     69:                                                 @"txt",@"text",
                     70:                                                 @"gif",@"jpg",@"jpeg",@"png",@"bmp",
                     71:                                                 nil];
                     72:     int result = [openPanel runModalForTypes: array];
                     73:     if (result == NSOKButton) {
                     74:         NSArray* urlArray = [openPanel URLs];
                     75:         if ([urlArray count] == 0)
                     76:             return;
                     77:         NSURL* url = [urlArray objectAtIndex: 0];
                     78:         NSWindow* keyWindow = [mApplication keyWindow];
                     79:         if (keyWindow)
                     80:             return [[keyWindow windowController] loadURL: url];
                     81:         else
                     82:             [self openBrowserWindowWithURL: url];
                     83:     }
1.4       hyatt      84: }
                     85: 
                     86: -(IBAction) openLocation:(id)aSender
                     87: {
                     88:     NSWindow* keyWindow = [mApplication keyWindow];
                     89:     if (!keyWindow) {
1.5       hyatt      90:       [self openBrowserWindowWithURLString: @"about:blank"];
1.4       hyatt      91:       keyWindow = [mApplication keyWindow];
                     92:     }
                     93:     
1.6       macserv    94:     [[keyWindow windowController] performAppropriateLocationAction];
1.1       hyatt      95: }
                     96: 
1.7       hyatt      97: -(IBAction) savePage:(id)aSender
                     98: {
                     99:     NSWindow* keyWindow = [mApplication keyWindow];
                    100:     if (keyWindow)
1.8       hyatt     101:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
1.7       hyatt     102: }
                    103: 
1.9       hyatt     104: -(IBAction) printPage:(id)aSender
                    105: {
                    106:     NSWindow* keyWindow = [mApplication keyWindow];
                    107:     if (keyWindow)
                    108:       [[keyWindow windowController] printDocument];
                    109: }
                    110: 
1.16      hyatt     111: -(IBAction) printPreview:(id)aSender
                    112: {
                    113:     NSWindow* keyWindow = [mApplication keyWindow];
                    114:     if (keyWindow)
                    115:       [[keyWindow windowController] printPreview];
                    116: }
                    117: 
1.7       hyatt     118: -(IBAction) toggleOfflineMode:(id)aSender
                    119: {
1.10      hyatt     120:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                    121:     if (!ioService)
                    122:         return;
                    123:     PRBool offline = PR_FALSE;
                    124:     ioService->GetOffline(&offline);
                    125:     ioService->SetOffline(!offline);
                    126:     mOffline = !offline;
                    127:     
                    128:     // Update the menu item text.
                    129:     // Set the menu item's text to "Go Online" if we're currently
                    130:     // offline.
                    131:     if (mOffline)
                    132:         [mOfflineMenuItem setTitle: @"Go Online"];
                    133:     else
                    134:         [mOfflineMenuItem setTitle: @"Work Offline"];
                    135:         
                    136:     // Indicate that we are working offline.
1.11      hyatt     137:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
1.7       hyatt     138: }
                    139: 
1.13      hyatt     140: // Edit menu actions.
                    141: -(IBAction) findInPage:(id)aSender
1.16      hyatt     142: {
1.17      hyatt     143:     NSWindow* keyWindow = [mApplication keyWindow];
                    144:     if (keyWindow)
                    145:       [[keyWindow windowController] findInPage];
1.16      hyatt     146: }
                    147: 
                    148: -(IBAction) findAgain:(id)aSender
1.13      hyatt     149: {
1.17      hyatt     150:     NSWindow* keyWindow = [mApplication keyWindow];
                    151:     if (keyWindow)
                    152:       [[keyWindow windowController] findAgain];
1.13      hyatt     153: }
                    154: 
1.23      hyatt     155: -(IBAction) goBack:(id)aSender
1.2       hyatt     156: {
                    157:     [[[mApplication keyWindow] windowController] back: aSender]; 
                    158: }
                    159: 
1.23      hyatt     160: -(IBAction) goForward:(id)aSender
1.2       hyatt     161: {
                    162:     [[[mApplication keyWindow] windowController] forward: aSender]; 
                    163: }
                    164: 
1.23      hyatt     165: -(IBAction) doReload:(id)aSender
1.2       hyatt     166: {
1.23      hyatt     167:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) reload: aSender]; 
1.2       hyatt     168: }
                    169: 
1.23      hyatt     170: -(IBAction) doStop:(id)aSender
1.2       hyatt     171: {
1.23      hyatt     172:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) stop: aSender]; 
1.2       hyatt     173: }
                    174: 
1.23      hyatt     175: -(IBAction) goHome:(id)aSender
1.2       hyatt     176: {
                    177:     [[[mApplication keyWindow] windowController] home: aSender];
                    178: }
                    179: 
1.5       hyatt     180: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
                    181: {
                    182:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
                    183: }
                    184: 
                    185: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
1.1       hyatt     186: {
1.3       macserv   187:        BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
1.5       hyatt     188:     [browser loadURL: aURL];
1.3       macserv   189:        [browser showWindow: self];
1.4       hyatt     190:     return browser;
1.1       hyatt     191: }
                    192: 
1.12      hyatt     193: -(void)applicationWillTerminate: (NSNotification*)aNotification
                    194: {
1.24      hyatt     195:     printf("Termination notification.\n");
1.19      hyatt     196:     mMenuBookmarks->RemoveObserver();
                    197:     delete mMenuBookmarks;
1.24      hyatt     198:     mMenuBookmarks = nsnull;
1.12      hyatt     199:     nsCocoaBrowserService::TermEmbedding();
                    200: }
1.18      hyatt     201: 
                    202: // Bookmarks menu actions.
                    203: -(IBAction) addBookmark:(id)aSender
                    204: {
                    205:     NSWindow* keyWindow = [mApplication keyWindow];
                    206:     if (keyWindow)
                    207:       [[keyWindow windowController] addBookmark];
                    208: }
                    209: 
1.20      hyatt     210: -(IBAction) openMenuBookmark:(id)aSender
                    211: {
                    212:     NSWindow* keyWindow = [mApplication keyWindow];
                    213:     if (!keyWindow) {
                    214:         [self openBrowserWindowWithURLString: @"about:blank"];
                    215:         keyWindow = [mApplication keyWindow];
                    216:     }
                    217: 
                    218:     BookmarksService::OpenMenuBookmark([keyWindow windowController], aSender);
                    219: }
1.25    ! macserv   220: 
        !           221: - (MVPreferencesController *)preferencesController
        !           222: {
        !           223:     if (!preferencesController) {
        !           224:         preferencesController = [[MVPreferencesController sharedInstance] retain];
        !           225:     }
        !           226:     return preferencesController;
        !           227: }
        !           228: 
        !           229: - (void)displayPreferencesWindow:sender
        !           230: {
        !           231:     [[self preferencesController] showPreferences:nil] ;
        !           232: }
        !           233: 
        !           234: 
1.1       hyatt     235: @end

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