Revision: 16772
          http://sourceforge.net/p/skim-app/code/16772
Author:   hofman
Date:     2026-11-01 17:40:03 +0000 (Sun, 01 Nov 2026)
Log Message:
-----------
use recursive function to find bookmarks for the current document

Modified Paths:
--------------
    trunk/SKBookmarkController.m

Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m        2026-11-01 17:12:39 UTC (rev 16771)
+++ trunk/SKBookmarkController.m        2026-11-01 17:40:03 UTC (rev 16772)
@@ -669,10 +669,26 @@
     return closedBms;
 }
 
+static void addBookmarksWithFileURLToArray(NSMutableArray *array, SKBookmark 
*bookmark, NSURL *fileURL) {
+    switch ([bookmark bookmarkType]) {
+        case SKBookmarkTypeBookmark:
+            if ([bookmark hasFileURL:fileURL])
+                [array addObject:bookmark];
+            break;
+        case SKBookmarkTypeFolder:
+            for (SKBookmark *bm in [bookmark children])
+                addBookmarksWithFileURLToArray(array, bm, fileURL);
+            break;
+        default:
+            break;
+    }
+}
+
 - (SKBookmark *)currentDocumentBookmark {
     NSURL *fileURL = [[[[NSApp mainWindow] windowController] document] 
fileURL];
     if ([fileURL checkResourceIsReachableAndReturnError:NULL]) {
-        NSArray *currentBookmarks = [[[self bookmarkRoot] entireContents] 
filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^(SKBookmark *bm, 
NSDictionary *bindings){ return [bm hasFileURL:fileURL]; }]];
+        NSMutableArray *currentBookmarks = [NSMutableArray array];
+        addBookmarksWithFileURLToArray(currentBookmarks, bookmarkRoot, 
fileURL);
         if ([currentBookmarks count] > 1) {
             return [[SKBookmark alloc] initFolderWithChildren:[[NSArray alloc] 
initWithArray:currentBookmarks copyItems:YES] label:NSLocalizedString(@"Current 
Document", @"Menu item title")];
         }
@@ -724,10 +740,6 @@
         
         if ([bookmark isKindOfClass:[SKBookmark class]]) {
             NSArray *bookmarks = [bookmark children];
-            if (tag == SKBookmarkTagClosedDocuments && [bookmarks count] == 0) 
{
-                bookmarks = [self closedDocumentBookmarks];
-                [bookmark insertChildren:bookmarks atIndexes:[NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange(0, [bookmarks count])]];
-            }
             if (tag == SKBookmarkTagBookmarksMenu) {
                 NSInteger i = [menu numberOfItems];
                 while (i-- > 0 && ([[menu itemAtIndex:i] isSeparatorItem] || 
[[menu itemAtIndex:i] representedObject]))
@@ -749,6 +761,10 @@
                 }
             } else {
                 [menu removeAllItems];
+                if (tag == SKBookmarkTagClosedDocuments && [bookmarks count] 
== 0) {
+                    bookmarks = [self closedDocumentBookmarks];
+                    [bookmark insertChildren:bookmarks atIndexes:[NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange(0, [bookmarks count])]];
+                }
             }
             if ([menu numberOfItems] > 0 && [bookmarks count] > 0)
                 [menu addItem:[NSMenuItem separatorItem]];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to