File:  [mozdev] / chimera / MainController.mm
Revision 1.14: download - view: text, annotated - select for diffs - revision graph
Tue Feb 5 05:00:16 2002 UTC (17 years, 10 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Impl cut copy paste etc. Some focus issues plague this feature still.

    1: /*
    2:  *  MainController.mm
    3:  */
    4: 
    5: #import "MainController.h"
    6: #import "BrowserWindowController.h"
    7: 
    8: #include "nsCOMPtr.h"
    9: #include "nsIServiceManager.h"
   10: #include "nsIIOService.h"
   11: #include "nsCocoaBrowserService.h"
   12: 
   13: static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
   14: 
   15: @implementation MainController
   16: 
   17: -(void)awakeFromNib
   18: {
   19:     [self newWindow: self];
   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"];
   34: }
   35: 
   36: -(IBAction)newWindow:(id)aSender
   37: {
   38:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
   39:     [controller focusURLBar];
   40: }
   41: 
   42: -(IBAction) openFile:(id)aSender
   43: {
   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:     }
   64: }
   65: 
   66: -(IBAction) openLocation:(id)aSender
   67: {
   68:     NSWindow* keyWindow = [mApplication keyWindow];
   69:     if (!keyWindow) {
   70:       [self openBrowserWindowWithURLString: @"about:blank"];
   71:       keyWindow = [mApplication keyWindow];
   72:     }
   73:     
   74:     [[keyWindow windowController] performAppropriateLocationAction];
   75: }
   76: 
   77: -(IBAction) savePage:(id)aSender
   78: {
   79:     NSWindow* keyWindow = [mApplication keyWindow];
   80:     if (keyWindow)
   81:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
   82: }
   83: 
   84: -(IBAction) printPage:(id)aSender
   85: {
   86:     NSWindow* keyWindow = [mApplication keyWindow];
   87:     if (keyWindow)
   88:       [[keyWindow windowController] printDocument];
   89: }
   90: 
   91: -(IBAction) toggleOfflineMode:(id)aSender
   92: {
   93:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
   94:     if (!ioService)
   95:         return;
   96:     PRBool offline = PR_FALSE;
   97:     ioService->GetOffline(&offline);
   98:     ioService->SetOffline(!offline);
   99:     mOffline = !offline;
  100:     
  101:     // Update the menu item text.
  102:     // Set the menu item's text to "Go Online" if we're currently
  103:     // offline.
  104:     if (mOffline)
  105:         [mOfflineMenuItem setTitle: @"Go Online"];
  106:     else
  107:         [mOfflineMenuItem setTitle: @"Work Offline"];
  108:         
  109:     // Indicate that we are working offline.
  110:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
  111: }
  112: 
  113: // Edit menu actions.
  114: -(IBAction) doCut:(id)aSender
  115: {
  116:     NSWindow* keyWindow = [mApplication keyWindow];
  117:     if (keyWindow)
  118:       [[keyWindow windowController] doCut];
  119: }
  120: 
  121: -(IBAction) doCopy:(id)aSender
  122: {
  123:     NSWindow* keyWindow = [mApplication keyWindow];
  124:     if (keyWindow)
  125:       [[keyWindow windowController] doCopy];
  126: }
  127: 
  128: -(IBAction) doPaste:(id)aSender
  129: {
  130:     NSWindow* keyWindow = [mApplication keyWindow];
  131:     if (keyWindow)
  132:       [[keyWindow windowController] doPaste];
  133: }
  134: 
  135: -(IBAction) doClear:(id)aSender
  136: {
  137:     NSWindow* keyWindow = [mApplication keyWindow];
  138:     if (keyWindow)
  139:       [[keyWindow windowController] doClear];
  140: }
  141: 
  142: -(IBAction) doSelectAll:(id)aSender
  143: {
  144:     NSWindow* keyWindow = [mApplication keyWindow];
  145:     if (keyWindow)
  146:       [[keyWindow windowController] doSelectAll];
  147: }
  148: 
  149: -(IBAction) findInPage:(id)aSender
  150: {
  151: 
  152: }
  153: 
  154: -(IBAction) back:(id)aSender
  155: {
  156:     [[[mApplication keyWindow] windowController] back: aSender]; 
  157: }
  158: 
  159: -(IBAction) forward:(id)aSender
  160: {
  161:     [[[mApplication keyWindow] windowController] forward: aSender]; 
  162: }
  163: 
  164: -(IBAction) reload:(id)aSender
  165: {
  166:     [[[mApplication keyWindow] windowController] reload: aSender]; 
  167: }
  168: 
  169: -(IBAction) stop:(id)aSender
  170: {
  171:     [[[mApplication keyWindow] windowController] stop: aSender]; 
  172: }
  173: 
  174: -(IBAction) home:(id)aSender
  175: {
  176:     [[[mApplication keyWindow] windowController] home: aSender];
  177: }
  178: 
  179: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
  180: {
  181:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
  182: }
  183: 
  184: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
  185: {
  186: 	BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  187:     [browser loadURL: aURL];
  188: 	[browser showWindow: self];
  189:     return browser;
  190: }
  191: 
  192: -(void)applicationWillTerminate: (NSNotification*)aNotification
  193: {
  194:     nsCocoaBrowserService::TermEmbedding();
  195: }
  196: @end

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