Annotation of chimera/MainController.mm, revision 1.11

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"
                     11: 
                     12: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
                     13: 
1.1       hyatt      14: @implementation MainController
                     15: 
                     16: -(void)awakeFromNib
                     17: {
1.4       hyatt      18:     [self newWindow: self];
1.10      hyatt      19:     
                     20:     // Initialize offline mode.
                     21:     mOffline = NO;
                     22:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                     23:     if (!ioService)
                     24:         return;
                     25:     PRBool offline = PR_FALSE;
                     26:     ioService->GetOffline(&offline);
                     27:     mOffline = offline;
                     28:     
                     29:     // Set the menu item's text to "Go Online" if we're currently
                     30:     // offline.
                     31:     if (mOffline)
                     32:         [mOfflineMenuItem setTitle: @"Go Online"];
1.1       hyatt      33: }
                     34: 
                     35: -(IBAction)newWindow:(id)aSender
                     36: {
1.5       hyatt      37:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
1.4       hyatt      38:     [controller focusURLBar];
                     39: }
                     40: 
                     41: -(IBAction) openFile:(id)aSender
                     42: {
1.5       hyatt      43:     NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
                     44:     [openPanel setCanChooseFiles: YES];
                     45:     [openPanel setCanChooseDirectories: NO];
                     46:     [openPanel setAllowsMultipleSelection: NO];
                     47:     NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
                     48:                                                 @"txt",@"text",
                     49:                                                 @"gif",@"jpg",@"jpeg",@"png",@"bmp",
                     50:                                                 nil];
                     51:     int result = [openPanel runModalForTypes: array];
                     52:     if (result == NSOKButton) {
                     53:         NSArray* urlArray = [openPanel URLs];
                     54:         if ([urlArray count] == 0)
                     55:             return;
                     56:         NSURL* url = [urlArray objectAtIndex: 0];
                     57:         NSWindow* keyWindow = [mApplication keyWindow];
                     58:         if (keyWindow)
                     59:             return [[keyWindow windowController] loadURL: url];
                     60:         else
                     61:             [self openBrowserWindowWithURL: url];
                     62:     }
1.4       hyatt      63: }
                     64: 
                     65: -(IBAction) openLocation:(id)aSender
                     66: {
                     67:     NSWindow* keyWindow = [mApplication keyWindow];
                     68:     if (!keyWindow) {
1.5       hyatt      69:       [self openBrowserWindowWithURLString: @"about:blank"];
1.4       hyatt      70:       keyWindow = [mApplication keyWindow];
                     71:     }
                     72:     
1.6       macserv    73:     [[keyWindow windowController] performAppropriateLocationAction];
1.1       hyatt      74: }
                     75: 
1.7       hyatt      76: -(IBAction) savePage:(id)aSender
                     77: {
                     78:     NSWindow* keyWindow = [mApplication keyWindow];
                     79:     if (keyWindow)
1.8       hyatt      80:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
1.7       hyatt      81: }
                     82: 
1.9       hyatt      83: -(IBAction) printPage:(id)aSender
                     84: {
                     85:     NSWindow* keyWindow = [mApplication keyWindow];
                     86:     if (keyWindow)
                     87:       [[keyWindow windowController] printDocument];
                     88: }
                     89: 
1.7       hyatt      90: -(IBAction) toggleOfflineMode:(id)aSender
                     91: {
1.10      hyatt      92:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
                     93:     if (!ioService)
                     94:         return;
                     95:     PRBool offline = PR_FALSE;
                     96:     ioService->GetOffline(&offline);
                     97:     ioService->SetOffline(!offline);
                     98:     mOffline = !offline;
                     99:     
                    100:     // Update the menu item text.
                    101:     // Set the menu item's text to "Go Online" if we're currently
                    102:     // offline.
                    103:     if (mOffline)
                    104:         [mOfflineMenuItem setTitle: @"Go Online"];
                    105:     else
                    106:         [mOfflineMenuItem setTitle: @"Work Offline"];
                    107:         
                    108:     // Indicate that we are working offline.
1.11    ! hyatt     109:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
1.7       hyatt     110: }
                    111: 
1.2       hyatt     112: -(IBAction) back:(id)aSender
                    113: {
                    114:     [[[mApplication keyWindow] windowController] back: aSender]; 
                    115: }
                    116: 
                    117: -(IBAction) forward:(id)aSender
                    118: {
                    119:     [[[mApplication keyWindow] windowController] forward: aSender]; 
                    120: }
                    121: 
                    122: -(IBAction) reload:(id)aSender
                    123: {
                    124:     [[[mApplication keyWindow] windowController] reload: aSender]; 
                    125: }
                    126: 
                    127: -(IBAction) stop:(id)aSender
                    128: {
                    129:     [[[mApplication keyWindow] windowController] stop: aSender]; 
                    130: }
                    131: 
                    132: -(IBAction) home:(id)aSender
                    133: {
                    134:     [[[mApplication keyWindow] windowController] home: aSender];
                    135: }
                    136: 
1.5       hyatt     137: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
                    138: {
                    139:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
                    140: }
                    141: 
                    142: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
1.1       hyatt     143: {
1.3       macserv   144:        BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
1.5       hyatt     145:     [browser loadURL: aURL];
1.3       macserv   146:        [browser showWindow: self];
1.4       hyatt     147:     return browser;
1.1       hyatt     148: }
                    149: 
                    150: @end

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