Annotation of chimera/MainController.mm, revision 1.20

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

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