Revision: 3906
http://skim-app.svn.sourceforge.net/skim-app/?rev=3906&view=rev
Author: hofman
Date: 2008-05-20 02:49:31 -0700 (Tue, 20 May 2008)
Log Message:
-----------
Update submenus of bookmarks menu lazily by setting the app controller as
delegate.
Modified Paths:
--------------
trunk/SKApplicationController.m
trunk/SKBookmark.m
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2008-05-19 18:14:00 UTC (rev 3905)
+++ trunk/SKApplicationController.m 2008-05-20 09:49:31 UTC (rev 3906)
@@ -306,37 +306,38 @@
#pragma mark Support
-- (void)addMenuItemsForBookmarks:(NSArray *)bookmarks toMenu:(NSMenu *)menu {
- int i, iMax = [bookmarks count];
- for (i = 0; i < iMax; i++) {
- SKBookmark *bm = [bookmarks objectAtIndex:i];
- if ([bm bookmarkType] == SKBookmarkTypeFolder) {
- NSString *label = [bm label];
- NSMenu *submenu = [[[NSMenu allocWithZone:[NSMenu menuZone]]
initWithTitle:[bm label]] autorelease];
- NSMenuItem *item = [menu addItemWithTitle:label ? label : @""
action:NULL keyEquivalent:@""];
- [item setImage:[bm icon]];
- [item setSubmenu:submenu];
- [self addMenuItemsForBookmarks:[bm children] toMenu:submenu];
- } else if ([bm bookmarkType] == SKBookmarkTypeSeparator) {
- [menu addItem:[NSMenuItem separatorItem]];
- } else {
- NSString *label = [bm label];
- NSMenuItem *item = [menu addItemWithTitle:label ? label : @""
action:@selector(openBookmark:) keyEquivalent:@""];
- [item setTarget:self];
- [item setRepresentedObject:bm];
- [item setImage:[bm icon]];
- }
- }
-}
-
- (void)menuNeedsUpdate:(NSMenu *)menu {
- NSArray *bookmarks = [[SKBookmarkController sharedBookmarkController]
bookmarks];
- int i = [menu numberOfItems];
- while (--i > 1)
+ NSMenu *supermenu = [menu supermenu];
+ NSMenuItem *item = [supermenu itemAtIndex:[supermenu
indexOfItemWithSubmenu:menu]];
+ SKBookmark *bm = [item representedObject];
+ if ([bm isKindOfClass:[SKBookmark class]] == NO) bm = nil;
+ NSArray *bookmarks = bm ? [bm children] : [[SKBookmarkController
sharedBookmarkController] bookmarks];
+ int i = [menu numberOfItems], numFixed = bm ? 0 : 2, numBookmarks =
[bookmarks count];
+ while (i-- > numFixed)
[menu removeItemAtIndex:i];
- if ([bookmarks count] > 0)
+ if (numFixed > 0 && numBookmarks > 0)
[menu addItem:[NSMenuItem separatorItem]];
- [self addMenuItemsForBookmarks:bookmarks toMenu:menu];
+ for (i = 0; i < numBookmarks; i++) {
+ bm = [bookmarks objectAtIndex:i];
+ switch ([bm bookmarkType]) {
+ case SKBookmarkTypeFolder:
+ item = [menu addItemWithTitle:[bm label] action:NULL
keyEquivalent:@""];
+ [item setRepresentedObject:bm];
+ [item setImage:[bm icon]];
+ [item setSubmenu:[[[NSMenu allocWithZone:[NSMenu menuZone]]
initWithTitle:[bm label]] autorelease]];
+ [[item submenu] setDelegate:self];
+ break;
+ case SKBookmarkTypeSeparator:
+ [menu addItem:[NSMenuItem separatorItem]];
+ break;
+ default:
+ item = [menu addItemWithTitle:[bm label]
action:@selector(openBookmark:) keyEquivalent:@""];
+ [item setTarget:self];
+ [item setRepresentedObject:bm];
+ [item setImage:[bm icon]];
+ break;
+ }
+ }
}
- (void)sendRemoteButtonEvent:(RemoteControlEventIdentifier)event
pressedDown:(BOOL)pressedDown remoteControl:(RemoteControl *)remoteControl {
Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m 2008-05-19 18:14:00 UTC (rev 3905)
+++ trunk/SKBookmark.m 2008-05-20 09:49:31 UTC (rev 3906)
@@ -295,7 +295,7 @@
}
- (NSString *)label {
- return label;
+ return label ? label : @"";
}
- (void)setLabel:(NSString *)newLabel {
@@ -351,7 +351,7 @@
}
- (NSString *)label {
- return label;
+ return label ? label : @"";
}
- (void)setLabel:(NSString *)newLabel {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit