File:  [mozdev] / chimera / MainController.mm
Revision 1.15: download - view: text, annotated - select for diffs - revision graph
Tue Feb 5 06:19:25 2002 UTC (16 years, 10 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Oops. Cut/copy/paste much easier than I thought.

/*
 *  MainController.mm
 */

#import "MainController.h"
#import "BrowserWindowController.h"

#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsCocoaBrowserService.h"

static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";

@implementation MainController

-(void)awakeFromNib
{
    [self newWindow: self];
    
    // Initialize offline mode.
    mOffline = NO;
    nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
    if (!ioService)
        return;
    PRBool offline = PR_FALSE;
    ioService->GetOffline(&offline);
    mOffline = offline;
    
    // Set the menu item's text to "Go Online" if we're currently
    // offline.
    if (mOffline)
        [mOfflineMenuItem setTitle: @"Go Online"];
}

-(IBAction)newWindow:(id)aSender
{
    BrowserWindowController* controller = [self openBrowserWindowWithURLString:@"about:blank"];
    [controller focusURLBar];
}

-(IBAction) openFile:(id)aSender
{
    NSOpenPanel* openPanel = [[NSOpenPanel alloc] init];
    [openPanel setCanChooseFiles: YES];
    [openPanel setCanChooseDirectories: NO];
    [openPanel setAllowsMultipleSelection: NO];
    NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml",
                                                @"txt",@"text",
                                                @"gif",@"jpg",@"jpeg",@"png",@"bmp",
                                                nil];
    int result = [openPanel runModalForTypes: array];
    if (result == NSOKButton) {
        NSArray* urlArray = [openPanel URLs];
        if ([urlArray count] == 0)
            return;
        NSURL* url = [urlArray objectAtIndex: 0];
        NSWindow* keyWindow = [mApplication keyWindow];
        if (keyWindow)
            return [[keyWindow windowController] loadURL: url];
        else
            [self openBrowserWindowWithURL: url];
    }
}

-(IBAction) openLocation:(id)aSender
{
    NSWindow* keyWindow = [mApplication keyWindow];
    if (!keyWindow) {
      [self openBrowserWindowWithURLString: @"about:blank"];
      keyWindow = [mApplication keyWindow];
    }
    
    [[keyWindow windowController] performAppropriateLocationAction];
}

-(IBAction) savePage:(id)aSender
{
    NSWindow* keyWindow = [mApplication keyWindow];
    if (keyWindow)
      [[keyWindow windowController] saveDocument: mFilterView filterList: mFilterList];
}

-(IBAction) printPage:(id)aSender
{
    NSWindow* keyWindow = [mApplication keyWindow];
    if (keyWindow)
      [[keyWindow windowController] printDocument];
}

-(IBAction) toggleOfflineMode:(id)aSender
{
    nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
    if (!ioService)
        return;
    PRBool offline = PR_FALSE;
    ioService->GetOffline(&offline);
    ioService->SetOffline(!offline);
    mOffline = !offline;
    
    // Update the menu item text.
    // Set the menu item's text to "Go Online" if we're currently
    // offline.
    if (mOffline)
        [mOfflineMenuItem setTitle: @"Go Online"];
    else
        [mOfflineMenuItem setTitle: @"Work Offline"];
        
    // Indicate that we are working offline.
    [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil];
}

// Edit menu actions.
-(IBAction) findInPage:(id)aSender
{

}

-(IBAction) back:(id)aSender
{
    [[[mApplication keyWindow] windowController] back: aSender]; 
}

-(IBAction) forward:(id)aSender
{
    [[[mApplication keyWindow] windowController] forward: aSender]; 
}

-(IBAction) reload:(id)aSender
{
    [[[mApplication keyWindow] windowController] reload: aSender]; 
}

-(IBAction) stop:(id)aSender
{
    [[[mApplication keyWindow] windowController] stop: aSender]; 
}

-(IBAction) home:(id)aSender
{
    [[[mApplication keyWindow] windowController] home: aSender];
}

-(BrowserWindowController*)openBrowserWindowWithURLString: (NSString*)aURL
{
    return [self openBrowserWindowWithURL: [NSURL URLWithString:aURL]];
}

-(BrowserWindowController*)openBrowserWindowWithURL: (NSURL*)aURL
{
	BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
    [browser loadURL: aURL];
	[browser showWindow: self];
    return browser;
}

-(void)applicationWillTerminate: (NSNotification*)aNotification
{
    nsCocoaBrowserService::TermEmbedding();
}
@end

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