Revision: 12806
          http://sourceforge.net/p/skim-app/code/12806
Author:   hofman
Date:     2022-03-02 10:24:05 +0000 (Wed, 02 Mar 2022)
Log Message:
-----------
Hidden preference to collapse all sublevels in the TOC ignoring the settings 
from the PDF

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

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2022-03-02 10:08:05 UTC (rev 12805)
+++ trunk/SKMainWindowController.m      2022-03-02 10:24:05 UTC (rev 12806)
@@ -182,6 +182,8 @@
 
 #define SKUseSettingsFromPDFKey @"SKUseSettingsFromPDF"
 
+#define SKCollapseTOCSublevelsKey @"SKCollapseTOCSublevels"
+
 #if SDK_BEFORE(10_11)
 @interface NSCollectionView (SKElCapitanExtensions)
 - (BOOL)allowsEmptySelection;
@@ -808,8 +810,8 @@
     return dict;
 }
 
-- (void)expandOutline:(PDFOutline *)anOutline forExpansionState:(NSDictionary 
*)info {
-    BOOL isExpanded = info ? [[info valueForKey:EXPANDED_KEY] boolValue] : 
[anOutline isOpen];
+- (void)expandOutline:(PDFOutline *)anOutline forExpansionState:(NSDictionary 
*)info level:(NSInteger)level {
+    BOOL isExpanded = info ? [[info valueForKey:EXPANDED_KEY] boolValue] : 
level < 0 ? [anOutline isOpen] : level < 2;
     if (isExpanded && anOutline) {
         NSUInteger i, iMax = [anOutline numberOfChildren];
         NSMutableArray *children = [[NSMutableArray alloc] init];
@@ -817,12 +819,13 @@
             [children addObject:[anOutline childAtIndex:i]];
         if ([anOutline parent])
             [leftSideController.tocOutlineView expandItem:anOutline];
+        if (level >= 0) ++level;
         NSArray *childrenStates = [info valueForKey:CHILDREN_KEY];
         NSEnumerator *infoEnum = nil;
         if (childrenStates && [[children valueForKey:LABEL_KEY] 
isEqualToArray:[childrenStates valueForKey:LABEL_KEY]])
             infoEnum = [childrenStates objectEnumerator];
         for (PDFOutline *child in children)
-            [self expandOutline:child forExpansionState:[infoEnum nextObject]];
+            [self expandOutline:child forExpansionState:[infoEnum nextObject] 
level:level];
         [children release];
     }
 }
@@ -863,8 +866,10 @@
     
     // If this is a reload following a TeX run and the user just killed the 
outline for some reason, we get a crash if the outlineView isn't reloaded, so 
no longer make it conditional on pdfOutline != nil
     [ov reloadData];
-    if (outlineRoot)
-        [self expandOutline:outlineRoot forExpansionState:info];
+    if (outlineRoot) {
+        NSInteger level = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKCollapseTOCSublevelsKey] ? ([outlineRoot numberOfChildren] > 1) : 
-1;
+        [self expandOutline:outlineRoot forExpansionState:info level:level];
+    }
     mwcFlags.updatingOutlineSelection = 0;
     [self updateOutlineSelection];
     

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to