Initial attempt at showing bookmarks in the menu
This commit is contained in:
parent
32aa63c2fc
commit
7adefe0a05
|
@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#define TAG_MENU_CUT 201
|
||||
#define TAG_MENU_PASTE 203
|
||||
#define TAG_SUBMENU_HISTORY 500
|
||||
#define TAG_SUBMENU_BOOKMARKS 900
|
||||
|
||||
@interface AppDelegate: NSResponder<NSApplicationDelegate> {
|
||||
@private
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#import "FindPanelController.h"
|
||||
#import "HistoryWindowController.h"
|
||||
#import "Website.h"
|
||||
#import "BookmarkFolder.h"
|
||||
#import "BookmarksWindowController.h"
|
||||
|
||||
#define MAX_RECENT_HISTORY 10
|
||||
|
@ -63,6 +64,40 @@ static nserror set_defaults(struct nsoption_s *defaults)
|
|||
}
|
||||
}
|
||||
|
||||
static NSMenuItem *menuItemForItem(id item) {
|
||||
if ([item isKindOfClass: [BookmarkFolder class]]) {
|
||||
NSMenu *menu = [[[NSMenu alloc] initWithTitle: [item name]] autorelease];
|
||||
NSArray *children = [item children];
|
||||
for (NSUInteger i = 0; i < [children count]; i++) {
|
||||
NSMenuItem *menuItem = menuItemForItem([children objectAtIndex: i]);
|
||||
[menu addItem: menuItem];
|
||||
}
|
||||
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle: [item name]
|
||||
action: nil keyEquivalent: nil];
|
||||
[menuItem setSubmenu: menu];
|
||||
return [menuItem autorelease];
|
||||
} else {
|
||||
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle: [item name]
|
||||
action: @selector(open) keyEquivalent: nil];
|
||||
[menuItem setTarget: item];
|
||||
return [menuItem autorelease];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)bookmarksUpdated: (NSNotification*)aNotification {
|
||||
NSLog(@"Updated bookmarks...");
|
||||
NSArray *bookmarks = [[BookmarkFolder rootBookmarkFolder] children];
|
||||
NSMenu *bookmarksMenu = [[[NSApp menu] itemWithTag: TAG_SUBMENU_BOOKMARKS] submenu];
|
||||
for (NSInteger i = 0; i < [bookmarksMenu numberOfItems] - 2; i++) {
|
||||
[bookmarksMenu removeItemAtIndex: 2];
|
||||
}
|
||||
id item;
|
||||
for (NSUInteger i = 0; i < [bookmarks count]; i++) {
|
||||
item = [bookmarks objectAtIndex: i];
|
||||
[bookmarksMenu insertItem: menuItemForItem(item) atIndex: 2 + i];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)awakeFromNib {
|
||||
NSLog(@"App awake from nib");
|
||||
recentHistory = [[NSMutableArray alloc] init];
|
||||
|
@ -70,6 +105,11 @@ static nserror set_defaults(struct nsoption_s *defaults)
|
|||
selector: @selector(historyUpdated:)
|
||||
name: WebsiteHistoryUpdatedNotificationName
|
||||
object: nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||
selector: @selector(bookmarksUpdated:)
|
||||
name: BookmarksUpdatedNotificationName
|
||||
object: nil];
|
||||
[self bookmarksUpdated: nil];
|
||||
[self historyUpdated: nil];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
/*
|
||||
* This notification is actually posted in the CreateBookmarkPanel, and
|
||||
* BookmarksWindowController, Rather than calling it in the individual mutating methods
|
||||
* to avoid spamming it for bulk operations, which only the above classes know about.
|
||||
*/
|
||||
#define BookmarksUpdatedNotificationName @"BookmarksUpdatedNotification"
|
||||
|
||||
#define BOOKMARKS_PATH @"/.config/NetSurf/Bookmarks"
|
||||
#define UNSORTED_NAME @"Unsorted"
|
||||
|
||||
|
|
|
@ -127,7 +127,6 @@ lazy-loaded when requested.
|
|||
} else {
|
||||
NSLog(@"Failed to move child");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-(void)updateChild: (id)child {
|
||||
|
|
|
@ -99,6 +99,8 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
copiedItems = nil;
|
||||
}
|
||||
[outlineView reloadData];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
BookmarksUpdatedNotificationName object: self];
|
||||
}
|
||||
|
||||
-(void)remove: (id)sender {
|
||||
|
@ -109,6 +111,8 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
[[item parentFolder] removeChild: item];
|
||||
}
|
||||
[outlineView reloadData];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
BookmarksUpdatedNotificationName object: self];
|
||||
}
|
||||
|
||||
-(void)open: (id)sender {
|
||||
|
@ -142,6 +146,8 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
[item addChild: folder];
|
||||
[folder release];
|
||||
[outlineView reloadData];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
BookmarksUpdatedNotificationName object: self];
|
||||
}
|
||||
|
||||
-(void)showWindow: (id)sender {
|
||||
|
@ -230,6 +236,8 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
} else if ([item isKindOfClass: [BookmarkFolder class]]) {
|
||||
[(BookmarkFolder*)item setName: object];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
BookmarksUpdatedNotificationName object: self];
|
||||
}
|
||||
-(NSArray*)selectedItems {
|
||||
NSEnumerator *selected = [outlineView selectedRowEnumerator];
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
BookmarkFolder *destination = [bookmarkFolders objectAtIndex: [folderButton
|
||||
indexOfSelectedItem]];
|
||||
[destination addChild: toSave];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:
|
||||
BookmarksUpdatedNotificationName object: self];
|
||||
[toSave release];
|
||||
[self close];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue