Annotation of chimera/MainController.mm, revision 1.19

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

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