Revision: 28620
http://sourceforge.net/p/bibdesk/svn/28620
Author: hofman
Date: 2024-01-16 17:21:26 +0000 (Tue, 16 Jan 2024)
Log Message:
-----------
Use NSSearchToolbarItem for search field when available
Modified Paths:
--------------
trunk/bibdesk/BibDocument_Toolbar.m
Modified: trunk/bibdesk/BibDocument_Toolbar.m
===================================================================
--- trunk/bibdesk/BibDocument_Toolbar.m 2024-01-16 16:44:47 UTC (rev 28619)
+++ trunk/bibdesk/BibDocument_Toolbar.m 2024-01-16 17:21:26 UTC (rev 28620)
@@ -61,6 +61,16 @@
#define BibDocumentTouchBarDeleteItemIdentifier
@"edu.ucsd.mmccrack.bibdesk.touchbar-item.delete"
#define BibDocumentTouchBarQuickLookItemIdentifier
@"edu.ucsd.mmccrack.bibdesk.touchbar-item.quickLook"
+#if SDK_BEFORE_11_0
+@interface NSSearchToolbarItem : NSToolbarItem
+@property (strong) NSSearchField *searchField;
+@property BOOL resignsFirstResponderWithCancel;
+@property CGFloat preferredWidthForSearchField;
+- (void)beginSearchInteraction;
+- (void)endSearchInteraction;
+@end
+#endif
+
@implementation BibDocument (Toolbar)
#pragma mark Toolbar
@@ -69,7 +79,7 @@
- (void) setupToolbar {
// Create a new toolbar instance, and attach it to our document window
NSToolbar *toolbar = [[NSToolbar alloc]
initWithIdentifier:BibDocumentToolbarIdentifier];
- BDSKToolbarItem *item;
+ NSToolbarItem *item;
NSMenuItem *menuItem;
toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:9];
@@ -139,20 +149,26 @@
action:@selector(makeSearchFieldKey:)
keyEquivalent:@""];
[menuItem setTarget:self];
- item = [[BDSKToolbarItem alloc]
initWithItemIdentifier:BibDocumentToolbarSearchItemIdentifier];
+ if (@available(macOS 11.0, *)) {
+#if SDK_BEFORE_11_0
+ NSSearchToolbarItem *searchItem =
[[NSClassFromString(@"NSSearchToolbarItem") alloc]
initWithItemIdentifier:BibDocumentToolbarSearchItemIdentifier];
+#else
+ NSSearchToolbarItem *searchItem = [[NSSearchToolbarItem alloc]
initWithItemIdentifier:BibDocumentToolbarSearchItemIdentifier];
+#endif
+ [searchItem setSearchField:searchField];
+ [searchItem setPreferredWidthForSearchField:400.0];
+ item = searchItem;
+ } else {
+ item = [[BDSKToolbarItem alloc]
initWithItemIdentifier:BibDocumentToolbarSearchItemIdentifier];
+ [item setView:searchField];
+ [item setMinSize:NSMakeSize(140.0, 22.0)];
+ [item setMaxSize:NSMakeSize(240.0, 22.0)];
+ }
[item setLabel:NSLocalizedString(@"Search", @"Toolbar item label")];
[item setPaletteLabel:NSLocalizedString(@"Search", @"Toolbar item label")];
[item setTarget:self];
- [item setView:searchField];
[item setAction:@selector(search:)];
[item setMenuFormRepresentation:menuItem];
- if (@available(macOS 11.0, *)) {
- [searchField setTranslatesAutoresizingMaskIntoConstraints:NO];
- [searchField addConstraints:@[[NSLayoutConstraint
constraintWithItem:searchField attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil
attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:140.0],
[NSLayoutConstraint constraintWithItem:searchField
attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual
toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0
constant:200.0]]];
- } else {
- [item setMinSize:NSMakeSize(140.0, 22.0)];
- [item setMaxSize:NSMakeSize(240.0, 22.0)];
- }
[toolbarItems setObject:item
forKey:BibDocumentToolbarSearchItemIdentifier];
// Action
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