From fac17d747b50712a42d1bc4b79576feac67fd2db Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Tue, 1 Feb 2011 10:27:54 +0000 Subject: Implemented bookmarks menu. svn path=/trunk/netsurf/; revision=11579 --- cocoa/BookmarksController.h | 35 ++++++ cocoa/BookmarksController.m | 129 +++++++++++++++++++++ cocoa/BrowserWindowController.m | 1 + cocoa/Makefile.target | 1 + cocoa/NetSurf.xcodeproj/project.pbxproj | 12 ++ cocoa/res/MainMenu.xib | 196 +++++++++++++++++++++++++++++++- 6 files changed, 371 insertions(+), 3 deletions(-) create mode 100644 cocoa/BookmarksController.h create mode 100644 cocoa/BookmarksController.m diff --git a/cocoa/BookmarksController.h b/cocoa/BookmarksController.h new file mode 100644 index 000000000..0e43d207a --- /dev/null +++ b/cocoa/BookmarksController.h @@ -0,0 +1,35 @@ +/* + * Copyright 2011 Sven Weidauer + * + * 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 . + */ + +#import + +@class Tree; + +@interface BookmarksController : NSObject { + Tree *tree; + NSMapTable *nodeForMenu; + NSMenu *defaultMenu; +} + +@property (readwrite, retain, nonatomic) IBOutlet NSMenu *defaultMenu; + +- (IBAction) openBookmarkURL: (id) sender; +- (IBAction) showBookmarksWindow: (id) sender; +- (IBAction) addBookmark: (id) sender; + +@end diff --git a/cocoa/BookmarksController.m b/cocoa/BookmarksController.m new file mode 100644 index 000000000..6e0c963d2 --- /dev/null +++ b/cocoa/BookmarksController.m @@ -0,0 +1,129 @@ +/* + * Copyright 2011 Sven Weidauer + * + * 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 . + */ + +#import "cocoa/BookmarksController.h" +#import "cocoa/Tree.h" +#import "cocoa/NetsurfApp.h" +#import "cocoa/BrowserViewController.h" + +#import "desktop/hotlist.h" +#import "desktop/tree.h" +#import "desktop/tree_url_node.h" + +@implementation BookmarksController + +@synthesize defaultMenu; + +- init; +{ + if ((self = [super init]) == nil) return nil; + + tree = [[Tree alloc] initWithFlags: hotlist_get_tree_flags()]; + hotlist_initialise( [tree tree], "/Users/sven/hotlist", "" ); + nodeForMenu = NSCreateMapTable( NSNonOwnedPointerMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0 ); + + return self; +} + +- (void) dealloc; +{ + NSFreeMapTable( nodeForMenu ); + hotlist_cleanup( "/Users/sven/hotlist" ); + [tree release]; + [super dealloc]; +} + +- (void) menuNeedsUpdate: (NSMenu *)menu +{ + for (NSMenuItem *item in [menu itemArray]) { + if ([item hasSubmenu]) NSMapRemove( nodeForMenu, [item submenu] ); + [menu removeItem: item]; + } + + bool hasSeparator = true; + struct node *node = (struct node *)NSMapGet( nodeForMenu, menu ); + if (node == NULL) { + for (NSMenuItem *item in [defaultMenu itemArray]) { + [menu addItem: [[item copy] autorelease]]; + } + hasSeparator = false; + node = [tree rootNode]; + } + + for (struct node *child = tree_node_get_child( node ); + child != NULL; + child = tree_node_get_next( child )) { + + if (tree_node_is_deleted( child )) continue; + + if (!hasSeparator) { + [menu addItem: [NSMenuItem separatorItem]]; + hasSeparator = true; + } + + NSString *title = [NSString stringWithUTF8String: tree_url_node_get_title( child )]; + + NSMenuItem *item = [menu addItemWithTitle: title action: NULL keyEquivalent: @""]; + if (tree_node_is_folder( child )) { + NSMenu *subMenu = [[[NSMenu alloc] initWithTitle: title] autorelease]; + NSMapInsert( nodeForMenu, subMenu, child ); + [subMenu setDelegate: self]; + [menu setSubmenu: subMenu forItem: item]; + } else { + [item setRepresentedObject: [NSString stringWithUTF8String: tree_url_node_get_url( child )]]; + [item setTarget: self]; + [item setAction: @selector( openBookmarkURL: )]; + } + } +} + +- (IBAction) openBookmarkURL: (id) sender; +{ + const char *url = [[sender representedObject] UTF8String]; + NSParameterAssert( url != NULL ); + + BrowserViewController *tab = [(NetSurfApp *)NSApp frontTab]; + if (tab != nil) { + browser_window_go( [tab browser], url, NULL, true ); + } else { + browser_window_create( url, NULL, NULL, true, false ); + } +} + +- (IBAction) showBookmarksWindow: (id) sender; +{ + NSLog( @"TODO: show bookmarks window" ); +} + +- (IBAction) addBookmark: (id) sender; +{ + NSLog( @"TODO: add bookmark" ); +} + +- (BOOL) validateUserInterfaceItem: (id) item; +{ + SEL action = [item action]; + + if (action == @selector( addBookmark: )) { + return [(NetSurfApp *)NSApp frontTab] != nil; + } + + return YES; +} + +@end diff --git a/cocoa/BrowserWindowController.m b/cocoa/BrowserWindowController.m index 5e80db2fb..9fe221434 100644 --- a/cocoa/BrowserWindowController.m +++ b/cocoa/BrowserWindowController.m @@ -216,6 +216,7 @@ if (activeBrowser == [tabViewItem identifier]) { [self setActiveBrowser: nil]; + [(NetSurfApp *)NSApp setFrontTab: nil]; } browser_window_destroy( [[tabViewItem identifier] browser] ); diff --git a/cocoa/Makefile.target b/cocoa/Makefile.target index b281cc44c..2fcbdf1e3 100644 --- a/cocoa/Makefile.target +++ b/cocoa/Makefile.target @@ -63,6 +63,7 @@ endif # S_COCOA are sources purely for the Mac OS X build S_COCOA := \ + BookmarksController.m \ BrowserView.m \ BrowserViewController.m \ BrowserWindowController.m \ diff --git a/cocoa/NetSurf.xcodeproj/project.pbxproj b/cocoa/NetSurf.xcodeproj/project.pbxproj index 7b799fd77..f8238f25f 100644 --- a/cocoa/NetSurf.xcodeproj/project.pbxproj +++ b/cocoa/NetSurf.xcodeproj/project.pbxproj @@ -189,6 +189,8 @@ 26376A4112F7FA67000F45FE /* HistoryWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HistoryWindow.xib; sourceTree = ""; }; 26376A4312F7FA86000F45FE /* HistoryWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryWindowController.h; sourceTree = ""; }; 26376A4412F7FA86000F45FE /* HistoryWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryWindowController.m; sourceTree = ""; }; + 26376A8A12F7FF57000F45FE /* BookmarksController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BookmarksController.h; sourceTree = ""; }; + 26376A8B12F7FF57000F45FE /* BookmarksController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BookmarksController.m; sourceTree = ""; }; 2639E20512F2ADEE00699678 /* coordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coordinates.h; sourceTree = ""; }; 264C344112F0987E00D11246 /* gui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gui.h; sourceTree = ""; }; 265F30A712D6637E0048B600 /* NetSurf-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NetSurf-Info.plist"; sourceTree = ""; }; @@ -535,6 +537,15 @@ name = "Tree View"; sourceTree = ""; }; + 26376A8C12F7FF5A000F45FE /* Bookmarks */ = { + isa = PBXGroup; + children = ( + 26376A8A12F7FF57000F45FE /* BookmarksController.h */, + 26376A8B12F7FF57000F45FE /* BookmarksController.m */, + ); + name = Bookmarks; + sourceTree = ""; + }; 265F303F12D6637E0048B600 /* Cocoa Frontend */ = { isa = PBXGroup; children = ( @@ -542,6 +553,7 @@ 26CDD26712E74453004FC66B /* Download */, 26CDD26612E7441E004FC66B /* Views */, 263769A812F7EBC3000F45FE /* Tree View */, + 26376A8C12F7FF5A000F45FE /* Bookmarks */, 26CDD26812E74461004FC66B /* NSApplication */, 26CDD26912E7446E004FC66B /* Platform Interface */, 265F310F12D663C20048B600 /* Resources */, diff --git a/cocoa/res/MainMenu.xib b/cocoa/res/MainMenu.xib index 028a970a5..596c9ec83 100644 --- a/cocoa/res/MainMenu.xib +++ b/cocoa/res/MainMenu.xib @@ -12,7 +12,7 @@ YES - + YES @@ -546,6 +546,21 @@ + + + Bookmarks + + 2147483647 + + + submenuAction: + + Bookmarks + + YES + + + Window @@ -646,6 +661,32 @@ NetSurfAppDelegate + + BookmarksController + + + Default Bookmark Actions + + YES + + + Add bookmark + d + 1048576 + 2147483647 + + + + + + Show bookmarks... + + 2147483647 + + + + + @@ -954,6 +995,38 @@ 846 + + + delegate + + + + 851 + + + + defaultMenu + + + + 856 + + + + addBookmark: + + + + 857 + + + + showBookmarksWindow: + + + + 858 + @@ -995,6 +1068,7 @@ + @@ -1456,6 +1530,48 @@ + + 847 + + + + + 848 + + + YES + + + + + + 849 + + + YES + + + + + 853 + + + YES + + + + + + + 854 + + + + + 855 + + + @@ -1583,6 +1699,14 @@ 833.IBPluginDependency 834.IBPluginDependency 838.IBPluginDependency + 847.IBPluginDependency + 848.IBPluginDependency + 849.IBEditorWindowLastContentRect + 849.IBPluginDependency + 853.IBEditorWindowLastContentRect + 853.IBPluginDependency + 854.IBPluginDependency + 855.IBPluginDependency 92.IBPluginDependency 92.ImportedFromIB2 @@ -1631,7 +1755,7 @@ com.apple.InterfaceBuilder.CocoaPlugin {{525, 802}, {197, 73}} - {{656, 815}, {352, 20}} + {{656, 815}, {446, 20}} com.apple.InterfaceBuilder.CocoaPlugin {74, 862} @@ -1710,6 +1834,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{876, 809}, {64, 6}} + com.apple.InterfaceBuilder.CocoaPlugin + {{616, 718}, {206, 43}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -1729,11 +1861,69 @@ - 846 + 858 YES + + BookmarksController + NSObject + + YES + + YES + addBookmark: + openBookmarkURL: + showBookmarksWindow: + + + YES + id + id + id + + + + YES + + YES + addBookmark: + openBookmarkURL: + showBookmarksWindow: + + + YES + + addBookmark: + id + + + openBookmarkURL: + id + + + showBookmarksWindow: + id + + + + + defaultMenu + NSMenu + + + defaultMenu + + defaultMenu + NSMenu + + + + IBProjectSource + BookmarksController.h + + BrowserView ScrollableView -- cgit v1.2.3