Implemented bookmarks menu.

svn path=/trunk/netsurf/; revision=11579
This commit is contained in:
Sven Weidauer 2011-02-01 10:27:54 +00:00
parent 84b4a01f4f
commit fac17d747b
6 changed files with 371 additions and 3 deletions

View File

@ -0,0 +1,35 @@
/*
* 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/>.
*/
#import <Cocoa/Cocoa.h>
@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

129
cocoa/BookmarksController.m Normal file
View File

@ -0,0 +1,129 @@
/*
* 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/>.
*/
#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

View File

@ -216,6 +216,7 @@
if (activeBrowser == [tabViewItem identifier]) {
[self setActiveBrowser: nil];
[(NetSurfApp *)NSApp setFrontTab: nil];
}
browser_window_destroy( [[tabViewItem identifier] browser] );

View File

@ -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 \

View File

@ -189,6 +189,8 @@
26376A4112F7FA67000F45FE /* HistoryWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HistoryWindow.xib; sourceTree = "<group>"; };
26376A4312F7FA86000F45FE /* HistoryWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryWindowController.h; sourceTree = "<group>"; };
26376A4412F7FA86000F45FE /* HistoryWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryWindowController.m; sourceTree = "<group>"; };
26376A8A12F7FF57000F45FE /* BookmarksController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BookmarksController.h; sourceTree = "<group>"; };
26376A8B12F7FF57000F45FE /* BookmarksController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BookmarksController.m; sourceTree = "<group>"; };
2639E20512F2ADEE00699678 /* coordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = coordinates.h; sourceTree = "<group>"; };
264C344112F0987E00D11246 /* gui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gui.h; sourceTree = "<group>"; };
265F30A712D6637E0048B600 /* NetSurf-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NetSurf-Info.plist"; sourceTree = "<group>"; };
@ -535,6 +537,15 @@
name = "Tree View";
sourceTree = "<group>";
};
26376A8C12F7FF5A000F45FE /* Bookmarks */ = {
isa = PBXGroup;
children = (
26376A8A12F7FF57000F45FE /* BookmarksController.h */,
26376A8B12F7FF57000F45FE /* BookmarksController.m */,
);
name = Bookmarks;
sourceTree = "<group>";
};
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 */,

View File

@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="24"/>
<integer value="853"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -546,6 +546,21 @@
</object>
</object>
</object>
<object class="NSMenuItem" id="603467951">
<reference key="NSMenu" ref="649796088"/>
<string key="NSTitle">Bookmarks</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="756751024"/>
<reference key="NSMixedImage" ref="908425081"/>
<string key="NSAction">submenuAction:</string>
<object class="NSMenu" key="NSSubmenu" id="1062528031">
<string key="NSTitle">Bookmarks</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
</object>
<object class="NSMenuItem" id="713487014">
<reference key="NSMenu" ref="649796088"/>
<string key="NSTitle">Window</string>
@ -646,6 +661,32 @@
<object class="NSCustomObject" id="1026802243">
<string key="NSClassName">NetSurfAppDelegate</string>
</object>
<object class="NSCustomObject" id="867741866">
<string key="NSClassName">BookmarksController</string>
</object>
<object class="NSMenu" id="509997857">
<string key="NSTitle">Default Bookmark Actions</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="844807595">
<reference key="NSMenu" ref="509997857"/>
<string key="NSTitle">Add bookmark</string>
<string key="NSKeyEquiv">d</string>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="756751024"/>
<reference key="NSMixedImage" ref="908425081"/>
</object>
<object class="NSMenuItem" id="832858329">
<reference key="NSMenu" ref="509997857"/>
<string key="NSTitle">Show bookmarks...</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="756751024"/>
<reference key="NSMixedImage" ref="908425081"/>
</object>
</object>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@ -954,6 +995,38 @@
</object>
<int key="connectionID">846</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="1062528031"/>
<reference key="destination" ref="867741866"/>
</object>
<int key="connectionID">851</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">defaultMenu</string>
<reference key="source" ref="867741866"/>
<reference key="destination" ref="509997857"/>
</object>
<int key="connectionID">856</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">addBookmark:</string>
<reference key="source" ref="867741866"/>
<reference key="destination" ref="844807595"/>
</object>
<int key="connectionID">857</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">showBookmarksWindow:</string>
<reference key="source" ref="867741866"/>
<reference key="destination" ref="832858329"/>
</object>
<int key="connectionID">858</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@ -995,6 +1068,7 @@
<reference ref="379814623"/>
<reference ref="586577488"/>
<reference ref="584895621"/>
<reference ref="603467951"/>
</object>
<reference key="parent" ref="0"/>
</object>
@ -1456,6 +1530,48 @@
<reference key="object" ref="72022292"/>
<reference key="parent" ref="720053764"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">847</int>
<reference key="object" ref="867741866"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">848</int>
<reference key="object" ref="603467951"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="1062528031"/>
</object>
<reference key="parent" ref="649796088"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">849</int>
<reference key="object" ref="1062528031"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<reference key="parent" ref="603467951"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">853</int>
<reference key="object" ref="509997857"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="844807595"/>
<reference ref="832858329"/>
</object>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">854</int>
<reference key="object" ref="844807595"/>
<reference key="parent" ref="509997857"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">855</int>
<reference key="object" ref="832858329"/>
<reference key="parent" ref="509997857"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@ -1583,6 +1699,14 @@
<string>833.IBPluginDependency</string>
<string>834.IBPluginDependency</string>
<string>838.IBPluginDependency</string>
<string>847.IBPluginDependency</string>
<string>848.IBPluginDependency</string>
<string>849.IBEditorWindowLastContentRect</string>
<string>849.IBPluginDependency</string>
<string>853.IBEditorWindowLastContentRect</string>
<string>853.IBPluginDependency</string>
<string>854.IBPluginDependency</string>
<string>855.IBPluginDependency</string>
<string>92.IBPluginDependency</string>
<string>92.ImportedFromIB2</string>
</object>
@ -1631,7 +1755,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>{{525, 802}, {197, 73}}</string>
<string>{{656, 815}, {352, 20}}</string>
<string>{{656, 815}, {446, 20}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>{74, 862}</string>
@ -1710,6 +1834,14 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{876, 809}, {64, 6}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{616, 718}, {206, 43}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
</object>
</object>
@ -1729,11 +1861,69 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">846</int>
<int key="maxID">858</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">BookmarksController</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="actions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addBookmark:</string>
<string>openBookmarkURL:</string>
<string>showBookmarksWindow:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addBookmark:</string>
<string>openBookmarkURL:</string>
<string>showBookmarksWindow:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBActionInfo">
<string key="name">addBookmark:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">openBookmarkURL:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">showBookmarksWindow:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">defaultMenu</string>
<string key="NS.object.0">NSMenu</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">defaultMenu</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">defaultMenu</string>
<string key="candidateClassName">NSMenu</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">BookmarksController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">BrowserView</string>
<string key="superclassName">ScrollableView</string>