File:  [mozdev] / chimera / MainController.mm
Revision 1.19: download - view: text, annotated - select for diffs - revision graph
Sat Feb 9 23:17:02 2002 UTC (17 years, 8 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Rearranging the menus and making bookmarks show up in the menu.

    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:     [mBookmarksMenu setAutoenablesItems: NO];
   22:     
   23:     mMenuBookmarks = new BookmarksService(nil);
   24:     mMenuBookmarks->AddObserver();
   25:     mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
   26:     
   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"];
   40: }
   41: 
   42: -(IBAction)newWindow:(id)aSender
   43: {
   44:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
   45:     [controller focusURLBar];
   46: }
   47: 
   48: -(IBAction) openFile:(id)aSender
   49: {
   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:     }
   70: }
   71: 
   72: -(IBAction) openLocation:(id)aSender
   73: {
   74:     NSWindow* keyWindow = [mApplication keyWindow];
   75:     if (!keyWindow) {
   76:       [self openBrowserWindowWithURLString: @"about:blank"];
   77:       keyWindow = [mApplication keyWindow];
   78:     }
   79:     
   80:     [[keyWindow windowController] performAppropriateLocationAction];
   81: }
   82: 
   83: -(IBAction) savePage:(id)aSender
   84: {
   85:     NSWindow* keyWindow = [mApplication keyWindow];
   86:     if (keyWindow)
   87:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
   88: }
   89: 
   90: -(IBAction) printPage:(id)aSender
   91: {
   92:     NSWindow* keyWindow = [mApplication keyWindow];
   93:     if (keyWindow)
   94:       [[keyWindow windowController] printDocument];
   95: }
   96: 
   97: -(IBAction) printPreview:(id)aSender
   98: {
   99:     NSWindow* keyWindow = [mApplication keyWindow];
  100:     if (keyWindow)
  101:       [[keyWindow windowController] printPreview];
  102: }
  103: 
  104: -(IBAction) toggleOfflineMode:(id)aSender
  105: {
  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.
  123:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
  124: }
  125: 
  126: // Edit menu actions.
  127: -(IBAction) findInPage:(id)aSender
  128: {
  129:     NSWindow* keyWindow = [mApplication keyWindow];
  130:     if (keyWindow)
  131:       [[keyWindow windowController] findInPage];
  132: }
  133: 
  134: -(IBAction) findAgain:(id)aSender
  135: {
  136:     NSWindow* keyWindow = [mApplication keyWindow];
  137:     if (keyWindow)
  138:       [[keyWindow windowController] findAgain];
  139: }
  140: 
  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: 
  166: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
  167: {
  168:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
  169: }
  170: 
  171: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
  172: {
  173: 	BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  174:     [browser loadURL: aURL];
  175: 	[browser showWindow: self];
  176:     return browser;
  177: }
  178: 
  179: -(void)applicationWillTerminate: (NSNotification*)aNotification
  180: {
  181:     mMenuBookmarks->RemoveObserver();
  182:     delete mMenuBookmarks;
  183:     nsCocoaBrowserService::TermEmbedding();
  184: }
  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: 
  194: @end

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