File:  [mozdev] / chimera / MainController.mm
Revision 1.24: download - view: text, annotated - select for diffs - revision graph
Mon Feb 25 10:13:04 2002 UTC (17 years, 8 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Adding new build.

    1: /*
    2:  *  MainController.mm
    3:  */
    4: 
    5: #import "MainController.h"
    6: #import "BrowserWindowController.h"
    7: #include "BookmarksService.h"
    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)dealloc
   18: {
   19:     [super dealloc];
   20:     printf("Main controller died.\n");
   21: }
   22: 
   23: -(void)awakeFromNib
   24: {
   25:     [self newWindow: self];
   26:     
   27:     [mBookmarksMenu setAutoenablesItems: NO];
   28:     
   29:     mMenuBookmarks = new BookmarksService(nil);
   30:     mMenuBookmarks->AddObserver();
   31:     mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
   32:     BookmarksService::gMainController = self;
   33:     
   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"];
   47: }
   48: 
   49: -(IBAction)newWindow:(id)aSender
   50: {
   51:     BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
   52:     [controller focusURLBar];
   53: }
   54: 
   55: -(IBAction)newTab:(id)aSender
   56: {
   57:     NSWindow* keyWindow = [mApplication keyWindow];
   58:     if (keyWindow)
   59:       [[keyWindow windowController] newTab];
   60: }
   61: 
   62: -(IBAction) openFile:(id)aSender
   63: {
   64:     NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
   65:     [openPanel setCanChooseFiles: YES];
   66:     [openPanel setCanChooseDirectories: NO];
   67:     [openPanel setAllowsMultipleSelection: NO];
   68:     NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
   69:                                                 @"txt",@"text",
   70:                                                 @"gif",@"jpg",@"jpeg",@"png",@"bmp",
   71:                                                 nil];
   72:     int result = [openPanel runModalForTypes: array];
   73:     if (result == NSOKButton) {
   74:         NSArray* urlArray = [openPanel URLs];
   75:         if ([urlArray count] == 0)
   76:             return;
   77:         NSURL* url = [urlArray objectAtIndex: 0];
   78:         NSWindow* keyWindow = [mApplication keyWindow];
   79:         if (keyWindow)
   80:             return [[keyWindow windowController] loadURL: url];
   81:         else
   82:             [self openBrowserWindowWithURL: url];
   83:     }
   84: }
   85: 
   86: -(IBAction) openLocation:(id)aSender
   87: {
   88:     NSWindow* keyWindow = [mApplication keyWindow];
   89:     if (!keyWindow) {
   90:       [self openBrowserWindowWithURLString: @"about:blank"];
   91:       keyWindow = [mApplication keyWindow];
   92:     }
   93:     
   94:     [[keyWindow windowController] performAppropriateLocationAction];
   95: }
   96: 
   97: -(IBAction) savePage:(id)aSender
   98: {
   99:     NSWindow* keyWindow = [mApplication keyWindow];
  100:     if (keyWindow)
  101:       [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
  102: }
  103: 
  104: -(IBAction) printPage:(id)aSender
  105: {
  106:     NSWindow* keyWindow = [mApplication keyWindow];
  107:     if (keyWindow)
  108:       [[keyWindow windowController] printDocument];
  109: }
  110: 
  111: -(IBAction) printPreview:(id)aSender
  112: {
  113:     NSWindow* keyWindow = [mApplication keyWindow];
  114:     if (keyWindow)
  115:       [[keyWindow windowController] printPreview];
  116: }
  117: 
  118: -(IBAction) toggleOfflineMode:(id)aSender
  119: {
  120:     nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
  121:     if (!ioService)
  122:         return;
  123:     PRBool offline = PR_FALSE;
  124:     ioService->GetOffline(&offline);
  125:     ioService->SetOffline(!offline);
  126:     mOffline = !offline;
  127:     
  128:     // Update the menu item text.
  129:     // Set the menu item's text to "Go Online" if we're currently
  130:     // offline.
  131:     if (mOffline)
  132:         [mOfflineMenuItem setTitle: @"Go Online"];
  133:     else
  134:         [mOfflineMenuItem setTitle: @"Work Offline"];
  135:         
  136:     // Indicate that we are working offline.
  137:     [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
  138: }
  139: 
  140: // Edit menu actions.
  141: -(IBAction) findInPage:(id)aSender
  142: {
  143:     NSWindow* keyWindow = [mApplication keyWindow];
  144:     if (keyWindow)
  145:       [[keyWindow windowController] findInPage];
  146: }
  147: 
  148: -(IBAction) findAgain:(id)aSender
  149: {
  150:     NSWindow* keyWindow = [mApplication keyWindow];
  151:     if (keyWindow)
  152:       [[keyWindow windowController] findAgain];
  153: }
  154: 
  155: -(IBAction) goBack:(id)aSender
  156: {
  157:     [[[mApplication keyWindow] windowController] back: aSender]; 
  158: }
  159: 
  160: -(IBAction) goForward:(id)aSender
  161: {
  162:     [[[mApplication keyWindow] windowController] forward: aSender]; 
  163: }
  164: 
  165: -(IBAction) doReload:(id)aSender
  166: {
  167:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) reload: aSender]; 
  168: }
  169: 
  170: -(IBAction) doStop:(id)aSender
  171: {
  172:     [(BrowserWindowController*)([[mApplication keyWindow] windowController]) stop: aSender]; 
  173: }
  174: 
  175: -(IBAction) goHome:(id)aSender
  176: {
  177:     [[[mApplication keyWindow] windowController] home: aSender];
  178: }
  179: 
  180: -(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
  181: {
  182:     return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
  183: }
  184: 
  185: -(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
  186: {
  187: 	BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  188:     [browser loadURL: aURL];
  189: 	[browser showWindow: self];
  190:     return browser;
  191: }
  192: 
  193: -(void)applicationWillTerminate: (NSNotification*)aNotification
  194: {
  195:     printf("Termination notification.\n");
  196:     mMenuBookmarks->RemoveObserver();
  197:     delete mMenuBookmarks;
  198:     mMenuBookmarks = nsnull;
  199:     nsCocoaBrowserService::TermEmbedding();
  200: }
  201: 
  202: // Bookmarks menu actions.
  203: -(IBAction) addBookmark:(id)aSender
  204: {
  205:     NSWindow* keyWindow = [mApplication keyWindow];
  206:     if (keyWindow)
  207:       [[keyWindow windowController] addBookmark];
  208: }
  209: 
  210: -(IBAction) openMenuBookmark:(id)aSender
  211: {
  212:     NSWindow* keyWindow = [mApplication keyWindow];
  213:     if (!keyWindow) {
  214:         [self openBrowserWindowWithURLString: @"about:blank"];
  215:         keyWindow = [mApplication keyWindow];
  216:     }
  217: 
  218:     BookmarksService::OpenMenuBookmark([keyWindow windowController], aSender);
  219: }
  220: @end

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