File:  [mozdev] / chimera / MainController.mm
Revision 1.28: download - view: text, annotated - select for diffs - revision graph
Sat Mar 9 08:39:35 2002 UTC (16 years, 9 months ago) by macserv
Branches: MAIN
CVS tags: HEAD
Removing old RDF support.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is 
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2002
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the NPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the NPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#import "MainController.h"
#import "BrowserWindowController.h"
#include "BookmarksService.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

-(id)init
{
    if ( self = [super init] ) {
        mSplashScreen = [NSWindow alloc] initWithSize
    }
}

-(void)dealloc
{
    [super dealloc];
    printf("Main controller died.\n");
}

-(void)awakeFromNib
{
    [self newWindow: self];
    
    [mBookmarksMenu setAutoenablesItems: NO];
    
    mMenuBookmarks = new BookmarksService(nil);
    mMenuBookmarks->AddObserver();
    mMenuBookmarks->ConstructBookmarksMenu(mBookmarksMenu, nsnull);
    BookmarksService::gMainController = 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)newTab:(id)aSender
{
    NSWindow* keyWindow = [mApplication keyWindow];
    if (keyWindow)
        [[keyWindow windowController] newTab];
}

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

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

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

-(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) printPreview:(id)aSender
{
    NSWindow* keyWindow = [mApplication keyWindow];
    if (keyWindow)
      [[keyWindow windowController] printPreview];
}

-(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
{
    NSWindow* keyWindow = [mApplication keyWindow];
    if (keyWindow)
      [[keyWindow windowController] findInPage];
}

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

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

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

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

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

-(IBAction) goHome:(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
{
    printf("Termination notification.\n");
    mMenuBookmarks->RemoveObserver();
    delete mMenuBookmarks;
    mMenuBookmarks = nsnull;
    nsCocoaBrowserService::TermEmbedding();
}

// Bookmarks menu actions.
-(IBAction) addBookmark:(id)aSender
{
    NSWindow* keyWindow = [mApplication keyWindow];
    if (keyWindow)
      [[keyWindow windowController] addBookmark];
}

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

    BookmarksService::OpenMenuBookmark([keyWindow windowController], aSender);
}

- (MVPreferencesController *)preferencesController
{
    if (!preferencesController) {
        preferencesController = [[MVPreferencesController sharedInstance] retain];
    }
    return preferencesController;
}

- (void)displayPreferencesWindow:sender
{
    [[self preferencesController] showPreferences:nil] ;
}


@end

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