Annotation of chimera/MainController.mm, revision 1.18

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

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