2011-01-13 20:20:13 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-01-31 22:12:00 +03:00
|
|
|
#import "cocoa/NetSurfAppDelegate.h"
|
2011-01-31 18:13:38 +03:00
|
|
|
#import "cocoa/SearchWindowController.h"
|
2011-01-31 21:38:03 +03:00
|
|
|
#import "cocoa/PreferencesWindowController.h"
|
2011-02-01 11:39:35 +03:00
|
|
|
#import "cocoa/HistoryWindowController.h"
|
2011-01-13 20:20:13 +03:00
|
|
|
|
|
|
|
#import "desktop/browser.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#import "utils/nsoption.h"
|
2013-02-22 18:53:57 +04:00
|
|
|
#import "utils/messages.h"
|
2014-02-03 22:12:44 +04:00
|
|
|
#import "utils/utils.h"
|
2014-07-06 22:36:12 +04:00
|
|
|
#import "utils/nsurl.h"
|
2011-01-13 20:20:13 +03:00
|
|
|
|
|
|
|
@interface NetSurfAppDelegate ()
|
|
|
|
|
|
|
|
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NetSurfAppDelegate
|
|
|
|
|
2011-02-01 11:39:35 +03:00
|
|
|
@synthesize history;
|
2011-01-31 18:13:38 +03:00
|
|
|
@synthesize search;
|
2011-01-31 21:38:03 +03:00
|
|
|
@synthesize preferences;
|
2011-01-13 20:20:13 +03:00
|
|
|
|
|
|
|
- (void) newDocument: (id) sender;
|
|
|
|
{
|
2013-02-14 22:21:11 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
if (nsoption_charp(homepage_url) != NULL) {
|
|
|
|
error = nsurl_create(nsoption_charp(homepage_url), &url);
|
|
|
|
} else {
|
|
|
|
error = nsurl_create(NETSURF_HOMEPAGE, &url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error == NSERROR_OK) {
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_HISTORY,
|
2013-02-14 22:21:11 +04:00
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
2011-01-13 20:20:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openDocument: (id) sender;
|
|
|
|
{
|
2013-02-22 18:53:57 +04:00
|
|
|
nsurl *u;
|
2013-02-14 22:21:11 +04:00
|
|
|
nserror error;
|
|
|
|
|
2011-01-13 20:20:13 +03:00
|
|
|
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
|
|
|
[openPanel setAllowsMultipleSelection: YES];
|
|
|
|
if ([openPanel runModalForTypes: nil] == NSOKButton) {
|
|
|
|
for (NSURL *url in [openPanel URLs]) {
|
2013-02-22 18:53:57 +04:00
|
|
|
error = nsurl_create([[url absoluteString] UTF8String], &u);
|
2013-02-14 22:21:11 +04:00
|
|
|
if (error == NSERROR_OK) {
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_HISTORY,
|
2013-02-22 18:53:57 +04:00
|
|
|
u,
|
2013-02-14 22:21:11 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2013-02-22 18:53:57 +04:00
|
|
|
nsurl_unref(u);
|
2013-02-14 22:21:11 +04:00
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
2011-01-13 20:20:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
|
|
|
|
{
|
2013-02-14 22:21:11 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
NSString *urlAsString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
|
|
|
|
|
|
|
|
error = nsurl_create([urlAsString UTF8String], &url);
|
|
|
|
if (error == NSERROR_OK) {
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_HISTORY,
|
2013-02-14 22:21:11 +04:00
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
2011-01-13 20:20:13 +03:00
|
|
|
}
|
|
|
|
|
2011-01-31 18:13:38 +03:00
|
|
|
- (IBAction) showSearchWindow: (id) sender;
|
|
|
|
{
|
|
|
|
if (search == nil) {
|
|
|
|
[self setSearch: [[[SearchWindowController alloc] init] autorelease]];
|
|
|
|
}
|
|
|
|
[[search window] makeKeyAndOrderFront: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) searchForward: (id) sender;
|
|
|
|
{
|
|
|
|
[search search: SearchForward];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) searchBackward: (id) sender;
|
|
|
|
{
|
|
|
|
[search search: SearchBackward];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) validateMenuItem: (id) item;
|
|
|
|
{
|
|
|
|
SEL action = [item action];
|
|
|
|
|
|
|
|
if (action == @selector( searchForward: )) {
|
|
|
|
return [search canGoForward];
|
|
|
|
} else if (action == @selector( searchBackward: )) {
|
|
|
|
return [search canGoBack];
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2011-01-31 21:38:03 +03:00
|
|
|
- (IBAction) showPreferences: (id) sender;
|
|
|
|
{
|
|
|
|
if (preferences == nil) {
|
|
|
|
[self setPreferences: [[[PreferencesWindowController alloc] init] autorelease]];
|
|
|
|
}
|
|
|
|
[preferences showWindow: sender];
|
|
|
|
}
|
|
|
|
|
2011-02-01 11:39:35 +03:00
|
|
|
- (IBAction) showGlobalHistory: (id) sender;
|
|
|
|
{
|
|
|
|
if (history == nil) {
|
|
|
|
[self setHistory: [[[HistoryWindowController alloc] init] autorelease]];
|
|
|
|
}
|
|
|
|
[history showWindow: sender];
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:20:13 +03:00
|
|
|
// Application delegate methods
|
|
|
|
|
|
|
|
- (BOOL) applicationOpenUntitledFile: (NSApplication *)sender;
|
|
|
|
{
|
|
|
|
[self newDocument: self];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
|
|
|
|
[appleEventManager setEventHandler:self
|
|
|
|
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
|
|
|
|
forEventClass:kInternetEventClass andEventID:kAEGetURL];
|
|
|
|
}
|
|
|
|
|
2011-05-19 20:04:54 +04:00
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
|
|
|
{
|
2013-02-14 22:21:11 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
NSURL *urltxt = [NSURL fileURLWithPath: filename];
|
|
|
|
|
|
|
|
error = nsurl_create([[urltxt absoluteString] UTF8String], &url);
|
|
|
|
if (error == NSERROR_OK) {
|
2014-02-10 18:08:45 +04:00
|
|
|
error = browser_window_create(BW_CREATE_HISTORY,
|
2013-02-14 22:21:11 +04:00
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
2011-05-19 20:04:54 +04:00
|
|
|
}
|
|
|
|
|
2011-01-13 20:20:13 +03:00
|
|
|
|
|
|
|
@end
|