File:  [mozdev] / chimera / MainController.mm
Revision 1.21: download - view: text, annotated - select for diffs - revision graph
Sun Feb 10 01:12:05 2002 UTC (17 years, 10 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
The status bar is hooked up now.  Also adding debugging printfs.

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

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