Revision: 28410
          http://sourceforge.net/p/bibdesk/svn/28410
Author:   hofman
Date:     2023-10-29 22:03:31 +0000 (Sun, 29 Oct 2023)
Log Message:
-----------
make sure window items are sorted, make sure all sub window items are added to 
the menu

Modified Paths:
--------------
    trunk/bibdesk/BDSKApplication.m

Modified: trunk/bibdesk/BDSKApplication.m
===================================================================
--- trunk/bibdesk/BDSKApplication.m     2023-10-29 15:26:42 UTC (rev 28409)
+++ trunk/bibdesk/BDSKApplication.m     2023-10-29 22:03:31 UTC (rev 28410)
@@ -96,12 +96,13 @@
         [[NSNotificationCenter defaultCenter] 
postNotificationName:BDSKFlagsChangedNotification object:self];
 }
 
-- (void)reorganizeWindowsItems {
+- (void)reorganizeWindowsItem:(NSWindow *)aWindow {
     NSMenu *windowsMenu = [self windowsMenu];
     NSInteger nItems = [windowsMenu numberOfItems];
     NSInteger i = nItems;
     NSMutableArray *mainItems = [NSMutableArray array];
     NSMutableArray *auxItems = [NSMutableArray array];
+    NSMutableArray *toSort = nil;
     NSMapTable *subItems = [NSMapTable strongToStrongObjectsMapTable];
     NSMenuItem *item;
     
@@ -112,33 +113,48 @@
         NSWindow *window = [item target];
         NSWindowController *wc = [window windowController];
         NSDocument *doc = [wc document];
+        NSMutableArray *items = nil;
         
         if (doc == nil) {
-            [auxItems insertObject:item atIndex:0];
+            items = auxItems;
         } else if ([wc isEqual:[[doc windowControllers] firstObject]]) {
-            [mainItems insertObject:item atIndex:0];
+            items = mainItems;
         } else {
-            NSMutableArray *subArray = [subItems objectForKey:doc];
-            if (subArray == nil) {
-                subArray = [NSMutableArray array];
-                [subItems setObject:subArray forKey:doc];
+            items = [subItems objectForKey:doc];
+            if (items == nil) {
+                items = [NSMutableArray array];
+                [subItems setObject:items forKey:doc];
             }
-            [subArray insertObject:item atIndex:0];
             [item setIndentationLevel:1];
         }
+        if (window == aWindow)
+            toSort = items;
+        [items insertObject:item atIndex:0];
         [windowsMenu removeItemAtIndex:i];
     }
     
+    if ([toSort count] > 1)
+        [toSort sortUsingDescriptors:@[[[[NSSortDescriptor alloc] 
initWithKey:@"title" ascending:YES selector:@selector(caseInsensitiveCompare:)] 
autorelease]]];
+    
     for (item in mainItems) {
         [windowsMenu addItem:item];
-        NSArray *subArray = [subItems objectForKey:[[[item target] 
windowController] document]];
+        NSDocument *doc = [[[item target] windowController] document];
+        NSArray *subArray = [subItems objectForKey:doc];
         if ([subArray count]) {
             NSMenuItem *subItem;
             for (subItem in subArray)
                 [windowsMenu addItem:subItem];
         }
+        [subItems removeObjectForKey:doc];
     }
     
+    if ([subItems count]) {
+        for (NSDocument *doc in subItems) {
+            for (item in [subItems objectForKey:doc])
+                [windowsMenu addItem:item];
+        }
+    }
+    
     for (item in auxItems)
         [windowsMenu addItem:item];
 }
@@ -146,13 +162,13 @@
 - (void)addWindowsItem:(NSWindow *)aWindow title:(NSString *)aString 
filename:(BOOL)isFilename {
     [super addWindowsItem:aWindow title:aString filename:isFilename];
     
-    [self reorganizeWindowsItems];
+    [self reorganizeWindowsItem:aWindow];
 }
 
 - (void)changeWindowsItem:(NSWindow *)aWindow title:(NSString *)aString 
filename:(BOOL)isFilename {
     [super changeWindowsItem:aWindow title:aString filename:isFilename];
     
-    [self reorganizeWindowsItems];
+    [self reorganizeWindowsItem:aWindow];
 }
 
 - (void)removeWindowsItem:(NSWindow *)aWindow {

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



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to