Revision: 29257
          http://sourceforge.net/p/bibdesk/svn/29257
Author:   hofman
Date:     2025-05-01 15:15:35 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Use bindings for record syntax popup, using custom value controller for 
selection ta handle case insensitivity and nil placeholder title. No need for 
type properties in controller, so bind directtly to serverInfo instance

Modified Paths:
--------------
    trunk/bibdesk/BDSKSearchGroupSheetController.h
    trunk/bibdesk/BDSKSearchGroupSheetController.m
    trunk/bibdesk/BDSKServerInfo.h
    trunk/bibdesk/BDSKServerInfo.m
    trunk/bibdesk/Base.lproj/BDSKSearchGroupSheet.xib
    trunk/bibdesk/de.lproj/Localizable.strings
    trunk/bibdesk/en.lproj/Localizable.strings
    trunk/bibdesk/fr.lproj/Localizable.strings

Modified: trunk/bibdesk/BDSKSearchGroupSheetController.h
===================================================================
--- trunk/bibdesk/BDSKSearchGroupSheetController.h      2025-05-01 12:06:16 UTC 
(rev 29256)
+++ trunk/bibdesk/BDSKSearchGroupSheetController.h      2025-05-01 15:15:35 UTC 
(rev 29257)
@@ -113,9 +113,8 @@
 @property (nonatomic, getter=isEditable) BOOL editable;
 @property (nonatomic, getter=isResettable) BOOL resettable;
 
-@property (nonatomic) NSInteger typeTag;
-
 @property (nonatomic, readonly) NSArray *databases;
+@property (nonatomic, readonly) NSArray *recordSyntaxes;
 
 @property (nonatomic, copy) BDSKServerInfo *serverInfo;
 

Modified: trunk/bibdesk/BDSKSearchGroupSheetController.m
===================================================================
--- trunk/bibdesk/BDSKSearchGroupSheetController.m      2025-05-01 12:06:16 UTC 
(rev 29256)
+++ trunk/bibdesk/BDSKSearchGroupSheetController.m      2025-05-01 15:15:35 UTC 
(rev 29257)
@@ -52,17 +52,27 @@
 
 #define BDSKTouchBarItemIdentifierButtons 
@"edu.ucsd.mmccrack.bibdesk.touchbar-item.buttons"
 
+#define BDSKUppercaseOrDefaultTransformerName @"BDSKUppercaseOrDefault"
+
+@interface BDSKUppercaseOrDefaultTransformer: NSValueTransformer
+@end
+
+#pragma mark -
+
 @implementation BDSKSearchGroupSheetController
 
 @synthesize serverPopup, nameField, addressField, portField, databaseField, 
passwordField, userField, syntaxPopup, encodingComboBox, 
removeDiacriticsButton, liteButton, editButton, addRemoveButton, serverView, 
revealButton, okButton, cancelButton, bottomConstraint, objectController, 
custom, editable, resettable, serverInfo;
-@dynamic typeTag, databases, undoManager;
+@dynamic databases, recordSyntaxes, undoManager;
 
++ (void)initialize {
+    BDSKINITIALIZE;
+    [NSValueTransformer 
setValueTransformer:[[BDSKUppercaseOrDefaultTransformer alloc] init] 
forName:BDSKUppercaseOrDefaultTransformerName];
+}
+
 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
     NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
-    if ([@"typeTag" isEqualToString:key])
-        keyPaths = [keyPaths setByAddingObject:@"serverInfo"];
-    else if ([@"databases" isEqualToString:key])
-        keyPaths = [keyPaths setByAddingObject:@"typeTag"];
+    if ([@"databases" isEqualToString:key] || [@"recordSyntaxes" 
isEqualToString:key])
+        keyPaths = [keyPaths setByAddingObject:@"serverInfo.type"];
     return keyPaths;
 }
 
@@ -100,31 +110,6 @@
     [self selectPredefinedServer:serverPopup];
 }
 
-- (void)changeOptions {
-    while ([syntaxPopup numberOfItems] > 1)
-        [syntaxPopup removeItemAtIndex:1];
-    if ([[[self serverInfo] type] isEqualToString:BDSKSearchGroupZoom])
-        [syntaxPopup addItemsWithTitles:[BDSKZoomGroupServer 
supportedRecordSyntaxes]];
-    else if ([[[self serverInfo] type] isEqualToString:BDSKSearchGroupSRU])
-        [syntaxPopup addItemsWithTitles:[BDSKSRUGroupServer 
supportedRecordSyntaxes]];
-    
-    NSString *value = [serverInfo recordSyntax];
-    if (value == nil) {
-        [syntaxPopup selectItemAtIndex:0];
-    } else {
-        NSMenuItem *item = nil;
-        for (item in [syntaxPopup itemArray]) {
-            if ([[item title] isCaseInsensitiveEqual:value])
-                break;
-        }
-        if (item == nil) {
-            [syntaxPopup addItemWithTitle:value];
-            item = [syntaxPopup lastItem];
-        }
-        [syntaxPopup selectItem:item];
-    }
-}
-
 - (void)handleServersChanged:(NSNotification *)note {
     if ([note object] != self) {
         NSString *name = nil;
@@ -342,27 +327,8 @@
     if (info != serverInfo) {
         serverInfo = [info mutableCopy];
     }
-    [self changeOptions];
 }
  
-- (NSInteger)typeTag {
-    return [serverInfo serverType];
-}
-
-- (void)setTypeTag:(NSInteger)tag {
-    if (tag != [serverInfo serverType]) {
-        switch (tag) {
-            case BDSKServerTypeEntrez: [serverInfo 
setType:BDSKSearchGroupEntrez]; break;
-            case BDSKServerTypeZoom:   [serverInfo 
setType:BDSKSearchGroupZoom];   break;
-            case BDSKServerTypeSRU:    [serverInfo 
setType:BDSKSearchGroupSRU];    break;
-            case BDSKServerTypeDBLP:   [serverInfo 
setType:BDSKSearchGroupDBLP];   break;
-            case BDSKServerTypeISI:    [serverInfo 
setType:BDSKSearchGroupISI];    break;
-            default: BDSKASSERT_NOT_REACHED("Unknown search type tag");
-        }
-        [self changeOptions];
-    }
-}
- 
 - (NSArray *)databases {
     switch ([serverInfo serverType]) {
         case BDSKServerTypeEntrez:
@@ -391,6 +357,30 @@
     }
 }
 
+- (NSArray *)recordSyntaxes {
+    static NSArray *defaultSyntaxes = nil;
+    if (defaultSyntaxes == nil)
+        defaultSyntaxes = @[NSLocalizedString(@"Default", @"Default syntax 
title")];
+    switch ([serverInfo serverType]) {
+        case BDSKServerTypeZoom:
+        {
+            static NSArray *zoomSyntaxes = nil;
+            if (zoomSyntaxes == nil)
+                zoomSyntaxes = [defaultSyntaxes 
arrayByAddingObjectsFromArray:[BDSKZoomGroupServer supportedRecordSyntaxes]];
+            return zoomSyntaxes;
+        }
+        case BDSKServerTypeSRU:
+        {
+            static NSArray *sruSyntaxes = nil;
+            if (sruSyntaxes == nil)
+                sruSyntaxes = [defaultSyntaxes 
arrayByAddingObjectsFromArray:[BDSKSRUGroupServer supportedRecordSyntaxes]];
+            return sruSyntaxes;
+        }
+        default:
+            return defaultSyntaxes;
+    }
+}
+
 #pragma mark NSEditor
 
 - (BOOL)commitEditing {
@@ -460,3 +450,25 @@
     return item;
 }
 @end
+
+#pragma mark -
+
+@implementation BDSKUppercaseOrDefaultTransformer
+
++ (Class)transformedValueClass {
+    return [NSString class];
+}
+
++ (BOOL)allowsReverseTransformation {
+    return YES;
+}
+
+- (id)transformedValue:(id)string {
+    return [string uppercaseString] ?: NSLocalizedString(@"Default", @"Default 
syntax title");
+}
+
+- (id)reverseTransformedValue:(id)string {
+    return [string isEqualToString:NSLocalizedString(@"Default", @"Default 
syntax title")] ? nil : string;
+}
+
+@end

Modified: trunk/bibdesk/BDSKServerInfo.h
===================================================================
--- trunk/bibdesk/BDSKServerInfo.h      2025-05-01 12:06:16 UTC (rev 29256)
+++ trunk/bibdesk/BDSKServerInfo.h      2025-05-01 15:15:35 UTC (rev 29257)
@@ -115,7 +115,9 @@
 @property (nonatomic) BOOL removeDiacritics;
 @property (nonatomic, getter=isSecure) BOOL secure;
 @property (nonatomic, getter=isLite) BOOL lite;
+@property (nonatomic) BDSKServerType serverType;
 
+
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/bibdesk/BDSKServerInfo.m
===================================================================
--- trunk/bibdesk/BDSKServerInfo.m      2025-05-01 12:06:16 UTC (rev 29256)
+++ trunk/bibdesk/BDSKServerInfo.m      2025-05-01 15:15:35 UTC (rev 29257)
@@ -385,7 +385,7 @@
 
 @implementation BDSKMutableServerInfo
 
-@dynamic type, name, database, host, port, password, username, recordSyntax, 
resultEncoding, removeDiacritics, secure, lite, options;
+@dynamic type, name, database, host, port, password, username, recordSyntax, 
resultEncoding, removeDiacritics, secure, lite, options, serverType;
 
 static NSSet *keysAffectedByType = nil;
 static NSSet *typeSet = nil;
@@ -516,6 +516,20 @@
     [self setOptionValue:(flag ? @"YES" : nil) forKey:LITE_KEY];
 }
 
+- (void)setServerType:(BDSKServerType)newServerType
+{
+    if (newServerType != [self serverType]) {
+        switch (newServerType) {
+            case BDSKServerTypeEntrez: [self setType:BDSKSearchGroupEntrez]; 
break;
+            case BDSKServerTypeZoom:   [self setType:BDSKSearchGroupZoom];   
break;
+            case BDSKServerTypeSRU:    [self setType:BDSKSearchGroupSRU];    
break;
+            case BDSKServerTypeDBLP:   [self setType:BDSKSearchGroupDBLP];   
break;
+            case BDSKServerTypeISI:    [self setType:BDSKSearchGroupISI];    
break;
+            default: BDSKASSERT_NOT_REACHED("Unknown search type tag");
+        }
+    }
+}
+
 - (BOOL)validateHost:(id *)value error:(NSError **)error {
     NSString *string = *value;
     if ([self isZoom] || [self isSRU]) {

Modified: trunk/bibdesk/Base.lproj/BDSKSearchGroupSheet.xib
===================================================================
--- trunk/bibdesk/Base.lproj/BDSKSearchGroupSheet.xib   2025-05-01 12:06:16 UTC 
(rev 29256)
+++ trunk/bibdesk/Base.lproj/BDSKSearchGroupSheet.xib   2025-05-01 15:15:35 UTC 
(rev 29257)
@@ -250,7 +250,13 @@
                                         <connections>
                                             <accessibilityConnection 
property="title" destination="275" id="528"/>
                                             <action selector="selectSyntax:" 
target="-2" id="285"/>
+                                            <binding destination="Ss4-cm-0Xw" 
name="content" keyPath="arrangedObjects" id="5f6-cF-wo4"/>
                                             <binding destination="-2" 
name="enabled" keyPath="editable" id="kvx-bY-Ybd"/>
+                                            <binding destination="569" 
name="selectedValue" keyPath="selection.recordSyntax" 
previousBinding="5f6-cF-wo4" id="XYa-va-8hu">
+                                                <dictionary key="options">
+                                                    <string 
key="NSValueTransformerName">BDSKUppercaseOrDefault</string>
+                                                </dictionary>
+                                            </binding>
                                             <binding destination="569" 
name="hidden2" keyPath="selection.DBLP" previousBinding="kiG-JE-AnU" 
id="pmX-i5-jr8">
                                                 <dictionary key="options">
                                                     <integer 
key="NSMultipleValuesPlaceholder" value="-1"/>
@@ -355,11 +361,6 @@
                                         <connections>
                                             <accessibilityConnection 
property="title" destination="304" id="529"/>
                                             <binding destination="-2" 
name="enabled" keyPath="editable" id="472"/>
-                                            <binding destination="569" 
name="hidden" keyPath="selection.zoom" previousBinding="472" id="BSK-ZG-U7W">
-                                                <dictionary key="options">
-                                                    <string 
key="NSValueTransformerName">NSNegateBoolean</string>
-                                                </dictionary>
-                                            </binding>
                                             <binding destination="569" 
name="value" keyPath="selection.resultEncoding" id="635">
                                                 <dictionary key="options">
                                                     <integer 
key="NSConditionallySetsEnabled" value="0"/>
@@ -366,6 +367,11 @@
                                                     <integer 
key="NSValidatesImmediately" value="1"/>
                                                 </dictionary>
                                             </binding>
+                                            <binding destination="569" 
name="hidden" keyPath="selection.zoom" previousBinding="472" id="BSK-ZG-U7W">
+                                                <dictionary key="options">
+                                                    <string 
key="NSValueTransformerName">NSNegateBoolean</string>
+                                                </dictionary>
+                                            </binding>
                                         </connections>
                                     </comboBox>
                                     <textField verticalHuggingPriority="750" 
translatesAutoresizingMaskIntoConstraints="NO" id="195">
@@ -463,11 +469,6 @@
                                         </buttonCell>
                                         <connections>
                                             <binding destination="-2" 
name="enabled" keyPath="editable" id="474"/>
-                                            <binding destination="569" 
name="hidden" keyPath="selection.zoom" previousBinding="474" id="Tm6-dI-xub">
-                                                <dictionary key="options">
-                                                    <string 
key="NSValueTransformerName">NSNegateBoolean</string>
-                                                </dictionary>
-                                            </binding>
                                             <binding destination="569" 
name="value" keyPath="selection.removeDiacritics" id="586">
                                                 <dictionary key="options">
                                                     <integer 
key="NSConditionallySetsEnabled" value="0"/>
@@ -474,6 +475,11 @@
                                                     <integer 
key="NSValidatesImmediately" value="1"/>
                                                 </dictionary>
                                             </binding>
+                                            <binding destination="569" 
name="hidden" keyPath="selection.zoom" previousBinding="474" id="Tm6-dI-xub">
+                                                <dictionary key="options">
+                                                    <string 
key="NSValueTransformerName">NSNegateBoolean</string>
+                                                </dictionary>
+                                            </binding>
                                         </connections>
                                     </button>
                                     <textField verticalHuggingPriority="750" 
translatesAutoresizingMaskIntoConstraints="NO" id="753">
@@ -593,7 +599,7 @@
                                         </buttonCell>
                                         <connections>
                                             <binding destination="-2" 
name="enabled" keyPath="editable" id="fXG-Yt-zCt"/>
-                                            <binding destination="-2" 
name="value" keyPath="typeTag" id="1xD-u4-Mkj">
+                                            <binding destination="569" 
name="value" keyPath="selection.serverType" id="XfF-qs-kE6">
                                                 <dictionary key="options">
                                                     <string 
key="NSValueTransformerName">BDSKIsZero</string>
                                                 </dictionary>
@@ -608,7 +614,7 @@
                                         </buttonCell>
                                         <connections>
                                             <binding destination="-2" 
name="enabled" keyPath="editable" id="1Yj-FP-dmy"/>
-                                            <binding destination="-2" 
name="value" keyPath="typeTag" id="U8D-YD-7LM">
+                                            <binding destination="569" 
name="value" keyPath="selection.serverType" id="a1D-iE-AtV">
                                                 <dictionary key="options">
                                                     <string 
key="NSValueTransformerName">BDSKIsOne</string>
                                                 </dictionary>
@@ -623,7 +629,7 @@
                                         </buttonCell>
                                         <connections>
                                             <binding destination="-2" 
name="enabled" keyPath="editable" id="wpl-Kv-HYb"/>
-                                            <binding destination="-2" 
name="value" keyPath="typeTag" id="LRN-wZ-1zH">
+                                            <binding destination="569" 
name="value" keyPath="selection.serverType" id="C0c-MV-V7r">
                                                 <dictionary key="options">
                                                     <string 
key="NSValueTransformerName">BDSKIsTwo</string>
                                                 </dictionary>
@@ -638,7 +644,7 @@
                                         </buttonCell>
                                         <connections>
                                             <binding destination="-2" 
name="enabled" keyPath="editable" id="0Mu-sG-L1U"/>
-                                            <binding destination="-2" 
name="value" keyPath="typeTag" id="uJt-eK-chF">
+                                            <binding destination="569" 
name="value" keyPath="selection.serverType" id="MZj-G7-BPM">
                                                 <dictionary key="options">
                                                     <string 
key="NSValueTransformerName">BDSKIsThree</string>
                                                 </dictionary>
@@ -851,5 +857,10 @@
                 <binding destination="-2" name="contentArray" 
keyPath="databases" id="VcY-Fs-Y39"/>
             </connections>
         </arrayController>
+        <arrayController id="Ss4-cm-0Xw" userLabel="Syntax Array Controller">
+            <connections>
+                <binding destination="-2" name="contentArray" 
keyPath="recordSyntaxes" id="5sq-4y-qry"/>
+            </connections>
+        </arrayController>
     </objects>
 </document>

Modified: trunk/bibdesk/de.lproj/Localizable.strings
===================================================================
(Binary files differ)

Modified: trunk/bibdesk/en.lproj/Localizable.strings
===================================================================
(Binary files differ)

Modified: trunk/bibdesk/fr.lproj/Localizable.strings
===================================================================
(Binary files differ)

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to