diff --git a/frontends/gnustep/AppDelegate.h b/frontends/gnustep/AppDelegate.h
index 669211297..80b3618f3 100644
--- a/frontends/gnustep/AppDelegate.h
+++ b/frontends/gnustep/AppDelegate.h
@@ -26,6 +26,7 @@ along with this program. If not, see .
#define TAG_MENU_CUT 201
#define TAG_MENU_PASTE 203
#define TAG_SUBMENU_HISTORY 500
+#define TAG_SUBMENU_BOOKMARKS 900
@interface AppDelegate: NSResponder {
@private
diff --git a/frontends/gnustep/AppDelegate.m b/frontends/gnustep/AppDelegate.m
index f47939220..eb7a83e04 100644
--- a/frontends/gnustep/AppDelegate.m
+++ b/frontends/gnustep/AppDelegate.m
@@ -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];
}
diff --git a/frontends/gnustep/BookmarkFolder.h b/frontends/gnustep/BookmarkFolder.h
index 837ac3d4a..b1c137b3b 100644
--- a/frontends/gnustep/BookmarkFolder.h
+++ b/frontends/gnustep/BookmarkFolder.h
@@ -1,5 +1,12 @@
#import
+/*
+* 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"
diff --git a/frontends/gnustep/BookmarkFolder.m b/frontends/gnustep/BookmarkFolder.m
index 3a65cee1f..0e8c86f75 100644
--- a/frontends/gnustep/BookmarkFolder.m
+++ b/frontends/gnustep/BookmarkFolder.m
@@ -127,7 +127,6 @@ lazy-loaded when requested.
} else {
NSLog(@"Failed to move child");
}
-
}
-(void)updateChild: (id)child {
diff --git a/frontends/gnustep/BookmarksWindowController.m b/frontends/gnustep/BookmarksWindowController.m
index 74ee1fdea..9cbd7b93d 100644
--- a/frontends/gnustep/BookmarksWindowController.m
+++ b/frontends/gnustep/BookmarksWindowController.m
@@ -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];
diff --git a/frontends/gnustep/CreateBookmarkPanelController.m b/frontends/gnustep/CreateBookmarkPanelController.m
index f57afdb21..c3a2fc7de 100644
--- a/frontends/gnustep/CreateBookmarkPanelController.m
+++ b/frontends/gnustep/CreateBookmarkPanelController.m
@@ -39,6 +39,8 @@
BookmarkFolder *destination = [bookmarkFolders objectAtIndex: [folderButton
indexOfSelectedItem]];
[destination addChild: toSave];
+ [[NSNotificationCenter defaultCenter] postNotificationName:
+ BookmarksUpdatedNotificationName object: self];
[toSave release];
[self close];
}