Annotation of chimera/MainController.mm, revision 1.26

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

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