Annotation of chimera/MainController.mm, revision 1.21

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

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