Revision: 29952
          http://sourceforge.net/p/bibdesk/svn/29952
Author:   hofman
Date:     2026-01-17 17:59:45 +0000 (Sat, 17 Jan 2026)
Log Message:
-----------
Don't call action when selecting search field in button bar. Tile button bar 
only once when changes are made.

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-17 16:00:19 UTC (rev 29951)
+++ trunk/bibdesk/BDSKButtonBar.h       2026-01-17 17:59:45 UTC (rev 29952)
@@ -51,6 +51,7 @@
     BDSKImagePopUpButton *overflowButton;
     __weak id target;
     SEL action;
+    BOOL needsTile;
 }
 
 @property (nonatomic, nullable, weak) id target;

Modified: trunk/bibdesk/BDSKButtonBar.m
===================================================================
--- trunk/bibdesk/BDSKButtonBar.m       2026-01-17 16:00:19 UTC (rev 29951)
+++ trunk/bibdesk/BDSKButtonBar.m       2026-01-17 17:59:45 UTC (rev 29952)
@@ -66,6 +66,7 @@
         action = NULL;
         hasAddButton = YES;
         hasRemoveButton = NO;
+        needsTile = NO;
     }
     return self;
 }
@@ -75,6 +76,12 @@
     [self tile];
 }
 
+- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
+    [super viewWillMoveToWindow:newWindow];
+    if (newWindow && needsTile)
+        [self tile];
+}
+
 - (NSButton *)newButtonWithImageName:(NSString *)imageName {
     NSButton *button = [[NSButton alloc] init];
     [button setBezelStyle:NSBezelStyleRoundRect];
@@ -117,7 +124,7 @@
     [button setAction:@selector(clickButton:)];
     [button setState:NSControlStateValueOff];
     [buttons addObject:button];
-    [self tile];
+    needsTile = YES;
 }
 
 - (void)removeButtonWithIdentifier:(NSString *)identifier reuse:(BOOL)reuse{
@@ -131,7 +138,7 @@
             [button setTarget:nil];
             [button removeFromSuperviewWithoutNeedingDisplay];
             [buttons removeObject:button];
-            [self tile];
+            needsTile = YES;
             break;
         }
     }
@@ -148,12 +155,14 @@
 - (void)setSelectedIdentifier:(NSString *)identifier {
        for (NSButton *button in buttons) {
         if ([[button identifier] isEqual:identifier]) {
-            // simulates a button click like -performClick: but without the 
highlighting
-            [button setNextState];
-            [self clickButton:button];
-            break;
+            if ([button state] == NSControlStateValueOff)
+                [button setState:NSControlStateValueOn];
+        } else if ([button state] == NSControlStateValueOn) {
+            [button setState:NSControlStateValueOff];
         }
     }
+    if (needsTile)
+        [self tile];
 }
 
 - (void)clickButton:(id)sender {
@@ -195,15 +204,19 @@
 - (void)setHasAddButton:(BOOL)flag {
     if (flag != hasAddButton) {
         hasAddButton = flag;
+        needsTile = YES;
+    }
+    if (needsTile)
         [self tile];
-    }
 }
 
 - (void)setHasRemoveButton:(BOOL)flag {
     if (flag != hasRemoveButton) {
         hasRemoveButton = flag;
+        needsTile = YES;
+    }
+    if (needsTile)
         [self tile];
-    }
 }
 
 - (void)addOverflowButtonInFrame:(NSRect)bounds {
@@ -294,6 +307,7 @@
                origin.x += NSWidth([button frame]) + BUTTON_SEPARATION;
         previousButton = button;
        }
+    needsTile = NO;
 }
 
 @end

Modified: trunk/bibdesk/BibDocument_Search.m
===================================================================
--- trunk/bibdesk/BibDocument_Search.m  2026-01-17 16:00:19 UTC (rev 29951)
+++ trunk/bibdesk/BibDocument_Search.m  2026-01-17 17:59:45 UTC (rev 29952)
@@ -305,13 +305,14 @@
     searchButtonBar = [[BDSKButtonBar alloc] 
initWithFrame:[searchButtonEdgeView contentRect]];
     [searchButtonEdgeView setContentView:searchButtonBar];
     
-    [searchButtonBar setTarget:self];
-    
     for (NSString *field in [[NSUserDefaults standardUserDefaults] 
stringArrayForKey:BDSKQuickSearchFieldsKey]) {
         if ([field isEqualToString:BDSKFileContentSearchString] == NO && 
[field isEqualToString:BDSKSkimNotesString] == NO)
             [searchButtonBar addButtonWithIdentifier:field 
title:titleForSearchField(field)];
     }
     
+    [searchButtonBar setTarget:self];
+    [searchButtonBar setAction:@selector(updateSearch:)];
+    
     NSButton *button = [searchButtonBar addButton];
     [button setTarget:self];
     [button setAction:@selector(addSearchField:)];
@@ -360,8 +361,6 @@
         
         if ([[searchButtonBar selectedIdentifier] 
isEqualToString:BDSKAllFieldsString] == NO)
             [searchButtonBar setSelectedIdentifier:BDSKAllFieldsString];
-        
-        [searchButtonBar setAction:@selector(updateSearch:)];
     }
 }
 
@@ -371,7 +370,6 @@
         
         [self removeControlView:BDSKControlViewSearch];
         
-        [searchButtonBar setAction:NULL];
         [searchButtonBar setSelectedIdentifier:BDSKAllFieldsString];
         
         if ([tmpSortKey isEqualToString:BDSKRelevanceString])
@@ -412,11 +410,11 @@
             BOOL canRemove = [buttons count] > 2 || ([buttons count] == 2 && 
[[[buttons lastObject] identifier] isEqualToString:BDSKFileContentSearchString] 
== NO);
             [searchButtonBar setHasRemoveButton:canRemove];
             
-            [searchButtonBar setAction:NULL];
             [searchButtonBar setSelectedIdentifier:selectedSearchButton];
-            [searchButtonBar setAction:@selector(updateSearch:)];
-            if ([searchButtonBar selectedIdentifier] == nil)
+            if ([searchButtonBar selectedIdentifier] == nil) {
                 [searchButtonBar setSelectedIdentifier:BDSKAllFieldsString];
+                [self updateSearch:searchButtonBar];
+            }
         } else {
             [searchButtonBar setSelectedIdentifier:BDSKAllFieldsString];
         }

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