Revision: 29951
          http://sourceforge.net/p/bibdesk/svn/29951
Author:   hofman
Date:     2026-01-17 16:00:19 +0000 (Sat, 17 Jan 2026)
Log Message:
-----------
set actions for search bar add and remove bbuttons from document

Modified Paths:
--------------
    trunk/bibdesk/BDSKButtonBar.h
    trunk/bibdesk/BDSKButtonBar.m
    trunk/bibdesk/BibDocument_Search.m

Modified: trunk/bibdesk/BDSKButtonBar.h
===================================================================
--- trunk/bibdesk/BDSKButtonBar.h       2026-01-16 16:48:31 UTC (rev 29950)
+++ trunk/bibdesk/BDSKButtonBar.h       2026-01-17 16:00:19 UTC (rev 29951)
@@ -50,11 +50,11 @@
     BOOL hasAddButton, hasRemoveButton;
     BDSKImagePopUpButton *overflowButton;
     __weak id target;
-    SEL action, addAction, removeAction;
+    SEL action;
 }
 
 @property (nonatomic, nullable, weak) id target;
-@property (nonatomic, nullable) SEL action, addAction, removeAction;
+@property (nonatomic, nullable) SEL action;
 
 @property (nonatomic) BOOL hasAddButton, hasRemoveButton;
 

Modified: trunk/bibdesk/BDSKButtonBar.m
===================================================================
--- trunk/bibdesk/BDSKButtonBar.m       2026-01-16 16:48:31 UTC (rev 29950)
+++ trunk/bibdesk/BDSKButtonBar.m       2026-01-17 16:00:19 UTC (rev 29951)
@@ -52,8 +52,8 @@
 
 @implementation BDSKButtonBar
 
-@synthesize target, action, addAction, removeAction, buttons, hasAddButton, 
hasRemoveButton, addButton, removeButton;
-@dynamic selectedIdentifier;
+@synthesize target, action, buttons, hasAddButton, hasRemoveButton;
+@dynamic selectedIdentifier, addButton, removeButton;
 
 // @@ Dark mode
 
@@ -81,8 +81,6 @@
     [[button cell] setControlSize:NSControlSizeSmall];
     [button setImagePosition:NSImageOnly];
     [button setImage:[NSImage imageNamed:imageName]];
-    [button setTarget:self];
-    [button setAction:@selector(clickButton:)];
     CGFloat height = [button fittingSize].height;
     [button setFrameSize:NSMakeSize(height, height)];
     return button;
@@ -159,35 +157,41 @@
 }
 
 - (void)clickButton:(id)sender {
-    if ([sender isEqual:addButton]) {
-        [NSApp sendAction:[self addAction] to:[self target] from:self];
-    } else if ([sender isEqual:removeButton]) {
-        [NSApp sendAction:[self removeAction] to:[self target] from:self];
-    } else {
-        if ([sender isKindOfClass:[NSMenuItem class]])
-            sender = [sender representedObject];
-        BOOL didChangeSelection = NO;
-        for (NSButton *button in buttons) {
-            if ([button isEqual:sender]) {
-                // the button click already swaps the state
-                if ([button state] == NSControlStateValueOn)
-                    didChangeSelection = YES;
-                else
-                    [button setState:NSControlStateValueOn];
-            } else if ([button state] == NSControlStateValueOn) {
-                [button setState:NSControlStateValueOff];
+    if ([sender isKindOfClass:[NSMenuItem class]])
+        sender = [sender representedObject];
+    BOOL didChangeSelection = NO;
+    for (NSButton *button in buttons) {
+        if ([button isEqual:sender]) {
+            // the button click already swaps the state
+            if ([button state] == NSControlStateValueOn)
                 didChangeSelection = YES;
-            }
+            else
+                [button setState:NSControlStateValueOn];
+        } else if ([button state] == NSControlStateValueOn) {
+            [button setState:NSControlStateValueOff];
+            didChangeSelection = YES;
         }
-        if ([overflowButton superview]) {
-            for (NSMenuItem *item in [overflowButton itemArray])
-                [item setState:[[item representedObject] state]];
-        }
-        if (didChangeSelection && [self target] && [self action])
-            [NSApp sendAction:[self action] to:[self target] from:self];
     }
+    if ([overflowButton superview]) {
+        for (NSMenuItem *item in [overflowButton itemArray])
+            [item setState:[[item representedObject] state]];
+    }
+    if (didChangeSelection && [self target] && [self action])
+        [NSApp sendAction:[self action] to:[self target] from:self];
 }
 
+- (NSButton *)addButton {
+    if (addButton == nil)
+        addButton = [self newButtonWithImageName:NSImageNameAddTemplate];
+    return addButton;
+}
+
+- (NSButton *)removeButton {
+    if (removeButton == nil)
+        removeButton = [self newButtonWithImageName:NSImageNameRemoveTemplate];
+    return removeButton;
+}
+
 - (void)setHasAddButton:(BOOL)flag {
     if (flag != hasAddButton) {
         hasAddButton = flag;

Modified: trunk/bibdesk/BibDocument_Search.m
===================================================================
--- trunk/bibdesk/BibDocument_Search.m  2026-01-16 16:48:31 UTC (rev 29950)
+++ trunk/bibdesk/BibDocument_Search.m  2026-01-17 16:00:19 UTC (rev 29951)
@@ -306,15 +306,20 @@
     [searchButtonEdgeView setContentView:searchButtonBar];
     
     [searchButtonBar setTarget:self];
-    [searchButtonBar setAddAction:@selector(addSearchField:)];
-    [searchButtonBar setRemoveAction:@selector(removeSearchField:)];
-
+    
     for (NSString *field in [[NSUserDefaults standardUserDefaults] 
stringArrayForKey:BDSKQuickSearchFieldsKey]) {
         if ([field isEqualToString:BDSKFileContentSearchString] == NO && 
[field isEqualToString:BDSKSkimNotesString] == NO)
             [searchButtonBar addButtonWithIdentifier:field 
title:titleForSearchField(field)];
     }
     
-    [[searchButtonBar addButton] setToolTip:NSLocalizedString(@"Add a search 
field", @"Tool tip meessage")];
+    NSButton *button = [searchButtonBar addButton];
+    [button setTarget:self];
+    [button setAction:@selector(addSearchField:)];
+    [button setToolTip:NSLocalizedString(@"Add a search field", @"Tool tip 
meessage")];
+    button = [searchButtonBar removeButton];
+    [button setTarget:self];
+    [button setAction:@selector(removeSearchField:)];
+    [button setToolTip:NSLocalizedString(@"Remove a search field", @"Tool tip 
meessage")];
 }
 
 - (BOOL)addFileSearchItems {
@@ -347,8 +352,6 @@
         NSArray *buttons = [searchButtonBar buttons];
         BOOL canRemove = [buttons count] > 2 || ([buttons count] == 2 && 
[[[buttons lastObject] identifier] isEqualToString:BDSKFileContentSearchString] 
== NO);
         [searchButtonBar setHasRemoveButton:canRemove];
-        if (canRemove)
-            [[searchButtonBar removeButton] 
setToolTip:NSLocalizedString(@"Remove a search field", @"Tool tip meessage")];
         
         [self addControlView:BDSKControlViewSearch];
         
@@ -408,8 +411,6 @@
             NSArray *buttons = [searchButtonBar buttons];
             BOOL canRemove = [buttons count] > 2 || ([buttons count] == 2 && 
[[[buttons lastObject] identifier] isEqualToString:BDSKFileContentSearchString] 
== NO);
             [searchButtonBar setHasRemoveButton:canRemove];
-            if (canRemove)
-                [[searchButtonBar removeButton] 
setToolTip:NSLocalizedString(@"Remove a search field", @"Tool tip meessage")];
             
             [searchButtonBar setAction:NULL];
             [searchButtonBar setSelectedIdentifier:selectedSearchButton];

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