Revision: 14551
          http://sourceforge.net/p/skim-app/code/14551
Author:   hofman
Date:     2024-10-13 16:26:16 +0000 (Sun, 13 Oct 2024)
Log Message:
-----------
Use binding for style popup button population. We need to hide and disable the 
Multiple effects placeholder item in code, and shift the index binding by one 
as binding the tags is not possible, and the tag is inconsistently populated 
(or not).

Modified Paths:
--------------
    trunk/Base.lproj/TransitionSheet.xib
    trunk/SKPresentationOptionsSheetController.h
    trunk/SKPresentationOptionsSheetController.m

Modified: trunk/Base.lproj/TransitionSheet.xib
===================================================================
--- trunk/Base.lproj/TransitionSheet.xib        2024-10-12 22:55:28 UTC (rev 
14550)
+++ trunk/Base.lproj/TransitionSheet.xib        2024-10-13 16:26:16 UTC (rev 
14551)
@@ -113,10 +113,11 @@
                                     <connections>
                                         <accessibilityConnection 
property="link" destination="30" id="458"/>
                                         <accessibilityConnection 
property="title" destination="9" id="49"/>
-                                        <binding destination="127" 
name="selectedTag" keyPath="selection.style" id="1Ft-0h-GCx">
+                                        <binding destination="-2" 
name="content" keyPath="availableTransitions" id="MC5-zR-e2X"/>
+                                        <binding destination="127" 
name="selectedIndex" keyPath="selection.style" previousBinding="MC5-zR-e2X" 
id="jEk-cF-O9P">
                                             <dictionary key="options">
-                                                <real 
key="NSMultipleValuesPlaceholder" value="-1"/>
-                                                <real 
key="NSNoSelectionPlaceholder" value="-1"/>
+                                                <integer 
key="NSMultipleValuesPlaceholder" value="0"/>
+                                                <string 
key="NSValueTransformerName">SKPlusOne</string>
                                             </dictionary>
                                         </binding>
                                     </connections>

Modified: trunk/SKPresentationOptionsSheetController.h
===================================================================
--- trunk/SKPresentationOptionsSheetController.h        2024-10-12 22:55:28 UTC 
(rev 14550)
+++ trunk/SKPresentationOptionsSheetController.h        2024-10-13 16:26:16 UTC 
(rev 14551)
@@ -53,6 +53,7 @@
     NSLayoutConstraint *boxLeadingConstraint;
     NSLayoutConstraint *tableWidthConstraint;
     NSArrayController *arrayController;
+    NSArray<NSString *> *availableTransitions;
     BOOL separate;
     SKLabeledTransitionInfo *transition;
     NSArray<SKLabeledTransitionInfo *> *transitions;
@@ -70,6 +71,8 @@
 @property (nonatomic, nullable, strong) IBOutlet NSLayoutConstraint 
*boxLeadingConstraint, *tableWidthConstraint;
 @property (nonatomic, nullable, strong) IBOutlet NSArrayController 
*arrayController;
 
+@property (nonatomic, readonly) NSArray<NSString *> *availableTransitions;
+
 @property (nonatomic) BOOL separate;
 @property (nonatomic, copy) NSArray<SKLabeledTransitionInfo *> *transitions;
 

Modified: trunk/SKPresentationOptionsSheetController.m
===================================================================
--- trunk/SKPresentationOptionsSheetController.m        2024-10-12 22:55:28 UTC 
(rev 14550)
+++ trunk/SKPresentationOptionsSheetController.m        2024-10-13 16:26:16 UTC 
(rev 14551)
@@ -73,6 +73,9 @@
 #define SKTouchBarItemIdentifierOK     
@"net.sourceforge.skim-app.touchbar-item.OK"
 #define SKTouchBarItemIdentifierCancel 
@"net.sourceforge.skim-app.touchbar-item.cancel"
 
+@interface SKPlusOneTransformer : NSValueTransformer
+@end
+
 #pragma mark -
 
 @interface SKPresentationOptionsSheetController ()
@@ -86,8 +89,13 @@
 
 @implementation SKPresentationOptionsSheetController
 
-@synthesize notesDocumentPopUpButton, tableView, stylePopUpButton, okButton, 
cancelButton, previewButton, tableWidthConstraint, boxLeadingConstraint, 
arrayController, separate, transitions;
+@synthesize notesDocumentPopUpButton, tableView, stylePopUpButton, okButton, 
cancelButton, previewButton, tableWidthConstraint, boxLeadingConstraint, 
arrayController, availableTransitions, separate, transitions;
 
++ (void)initialize {
+    SKINITIALIZE;
+    [NSValueTransformer setValueTransformer:[[SKPlusOneTransformer alloc] 
init] forName:@"SKPlusOne"];
+}
+
 - (instancetype)initForController:(SKMainWindowController *)aController {
     self = [super init];
     if (self) {
@@ -106,6 +114,12 @@
             separate = NO;
         }
         
+        NSMutableArray *titles = [NSMutableArray 
arrayWithObject:NSLocalizedString(@"Multiple effects", @"Menu item title")];
+        [SKTransitionInfo enumerateTransitionsUsingBlock:^(SKTransitionStyle 
style, NSString *name, NSString *localizedName){
+            [titles addObject:localizedName];
+        }];
+        availableTransitions = [titles copy];
+        
         [self startObservingTransitions:transitions];
     }
     return self;
@@ -225,24 +239,10 @@
 }
 
 - (void)windowDidLoad {
-    // add the filter names to the popup
-    NSMutableSet *titles = [NSMutableSet set];
-    [stylePopUpButton removeAllItems];
-    [SKTransitionInfo enumerateTransitionsUsingBlock:^(SKTransitionStyle 
style, NSString *name, NSString *localizedName){
-        while ([titles containsObject:localizedName])
-            localizedName = [localizedName stringByAppendingString:@" "];
-        [titles addObject:localizedName];
-        [stylePopUpButton addItemWithTitle:localizedName];
-        [[stylePopUpButton lastItem] setTag:style];
-    }];
-    [stylePopUpButton addItemWithTitle:NSLocalizedString(@"Multiple effects", 
@"Menu item title")];
-    [[stylePopUpButton lastItem] setTag:-1];
-    [[stylePopUpButton lastItem] setHidden:YES];
-    [[stylePopUpButton lastItem] setEnabled:NO];
+    // hide and disable the "Multiple effects" placeholder item
+    [[stylePopUpButton itemAtIndex:0] setHidden:YES];
+    [[stylePopUpButton itemAtIndex:0] setEnabled:NO];
     
-    [arrayController setSelectionIndex:0];
-    [stylePopUpButton selectItemWithTag:[[transitions firstObject] style]];
-    
     [[notesDocumentPopUpButton itemAtIndex:1] setRepresentedObject:[controller 
document]];
     [[notesDocumentPopUpButton itemAtIndex:2] setRepresentedObject:[controller 
document]];
 
@@ -664,3 +664,25 @@
 }
 
 @end
+
+#pragma mark -
+
+@implementation SKPlusOneTransformer
+
++ (Class)transformedValueClass {
+    return [NSNumber class];
+}
+
++ (BOOL)allowsReverseTransformation {
+    return YES;
+}
+
+- (id)transformedValue:(id)value {
+    return [NSNumber numberWithInteger:[value integerValue] + 1];
+}
+
+- (id)reverseTransformedValue:(id)value {
+    return [NSNumber numberWithInteger:[value integerValue] - 1];
+}
+
+@end

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