Defaulting to unified toolbar on Big Sur and above.

Search item now stays in the toolbar for the longest
This commit is contained in:
Michael Starke
2021-11-04 14:23:19 +01:00
parent 43bc4d7ae1
commit 6b7fdc081b
3 changed files with 18 additions and 11 deletions

View File

@@ -173,7 +173,7 @@ NSString *const kMPDepricatedSettingsKeyAutotypeHideAccessibiltyWarning = @"Au
kMPSettingsKeyHideAfterCopyToClipboard: @NO, kMPSettingsKeyHideAfterCopyToClipboard: @NO,
kMPSettingsKeyFaviconDownloadMethod: @(MPFaviconDownloadMethodDirect), // Download directly from host kMPSettingsKeyFaviconDownloadMethod: @(MPFaviconDownloadMethodDirect), // Download directly from host
kMPSettingsKeyGloablAutotypeAlwaysShowCandidateSelection: @NO, kMPSettingsKeyGloablAutotypeAlwaysShowCandidateSelection: @NO,
kMPSettingsKeyUseUnifiedToolbar: @NO // Do not use unified toolbar under Big Sur and above kMPSettingsKeyUseUnifiedToolbar: @YES // Do not use unified toolbar under Big Sur and above
}; };
}); });
return standardDefaults; return standardDefaults;

View File

@@ -36,7 +36,7 @@ APPKIT_EXTERN NSString *const MPToolbarItemIdentifierAutotype;
@class MPDocument; @class MPDocument;
@interface MPToolbarDelegate : NSObject <NSToolbarDelegate, NSTextFieldDelegate> @interface MPToolbarDelegate : NSObject <NSToolbarDelegate, NSSearchFieldDelegate>
@property (weak, readonly) NSSearchField *searchField; @property (weak, readonly) NSSearchField *searchField;
@property (weak) NSToolbar *toolbar; @property (weak) NSToolbar *toolbar;

View File

@@ -143,6 +143,7 @@ NSString *const MPToolbarItemIdentifierAutotype = @"TOOLBAR_AUTOTYPE";
menu.delegate = NSApp.mp_delegate.itemActionMenuDelegate; menu.delegate = NSApp.mp_delegate.itemActionMenuDelegate;
item.menuFormRepresentation = menuRepresentation; item.menuFormRepresentation = menuRepresentation;
item.view = popupButton; item.view = popupButton;
item.visibilityPriority = NSToolbarItemVisibilityPriorityHigh - 1;
} }
else if( [itemIdentifier isEqualToString:MPToolbarItemIdentifierAddEntry]) { else if( [itemIdentifier isEqualToString:MPToolbarItemIdentifierAddEntry]) {
MPContextButton *button = [[MPContextButton alloc] initWithFrame:NSMakeRect(0, 0, 32, 32)]; MPContextButton *button = [[MPContextButton alloc] initWithFrame:NSMakeRect(0, 0, 32, 32)];
@@ -167,7 +168,6 @@ NSString *const MPToolbarItemIdentifierAutotype = @"TOOLBAR_AUTOTYPE";
action:[self _actionForToolbarItemIdentifier:itemIdentifier] action:[self _actionForToolbarItemIdentifier:itemIdentifier]
keyEquivalent:@""]; keyEquivalent:@""];
item.menuFormRepresentation = menuRepresentation; item.menuFormRepresentation = menuRepresentation;
} }
else if( [itemIdentifier isEqualToString:MPToolbarItemIdentifierSearch]){ else if( [itemIdentifier isEqualToString:MPToolbarItemIdentifierSearch]){
NSSearchField *searchField = [[NSSearchField alloc] init]; NSSearchField *searchField = [[NSSearchField alloc] init];
@@ -177,14 +177,21 @@ NSString *const MPToolbarItemIdentifierAutotype = @"TOOLBAR_AUTOTYPE";
cell.cancelButtonCell.target = nil; cell.cancelButtonCell.target = nil;
searchField.recentsAutosaveName = @"RecentEntrySearches"; searchField.recentsAutosaveName = @"RecentEntrySearches";
item.view = searchField; item.view = searchField;
/* Use default size base on documentation */ item.visibilityPriority = NSToolbarItemVisibilityPriorityHigh;
item.minSize = NSMakeSize(140, 32);
item.maxSize = NSMakeSize(400, 32); if(@available(macOS 11, *)) {
// do not call any sizing API
}
else {
/* Use default size base on documentation */
item.minSize = NSMakeSize(140, 32);
item.maxSize = NSMakeSize(400, 32);
}
NSMenu *templateMenu = [self _allocateSearchMenuTemplate]; NSMenu *templateMenu = [self _allocateSearchMenuTemplate];
searchField.searchMenuTemplate = templateMenu; searchField.searchMenuTemplate = templateMenu;
searchField.placeholderString = NSLocalizedString(@"SEARCH_EVERYWHERE", @"Placeholder string displayed in the search field in the toolbar"); searchField.placeholderString = NSLocalizedString(@"SEARCH_EVERYWHERE", @"Placeholder string displayed in the search field in the toolbar");
/* 10.10 does not support NSSearchFieldDelegate */ searchField.delegate = self;
((NSTextField *)searchField).delegate = self;
self.searchField = searchField; self.searchField = searchField;
} }
else { else {
@@ -228,7 +235,7 @@ NSString *const MPToolbarItemIdentifierAutotype = @"TOOLBAR_AUTOTYPE";
MPToolbarItemIdentifierInspector: [MPIconHelper icon:MPIconSidebar], MPToolbarItemIdentifierInspector: [MPIconHelper icon:MPIconSidebar],
MPToolbarItemIdentifierHistory: [MPIconHelper icon:MPIconHistory], MPToolbarItemIdentifierHistory: [MPIconHelper icon:MPIconHistory],
MPToolbarItemIdentifierAutotype : [MPIconHelper icon:MPIconKeyboard] MPToolbarItemIdentifierAutotype : [MPIconHelper icon:MPIconKeyboard]
}; };
return imageDict; return imageDict;
} }
@@ -273,7 +280,7 @@ NSString *const MPToolbarItemIdentifierAutotype = @"TOOLBAR_AUTOTYPE";
MPToolbarItemIdentifierSearch: NSLocalizedString(@"SEARCH", @"Search input in Toolbar "), MPToolbarItemIdentifierSearch: NSLocalizedString(@"SEARCH", @"Search input in Toolbar "),
MPToolbarItemIdentifierHistory: NSLocalizedString(@"SHOW_HISTORY", @"Toolbar item to toggle history display"), MPToolbarItemIdentifierHistory: NSLocalizedString(@"SHOW_HISTORY", @"Toolbar item to toggle history display"),
MPToolbarItemIdentifierAutotype: NSLocalizedString(@"TOOLBAR_PERFORM_AUTOTYPE_FOR_ENTRY", @"Toolbar item to perform autotype") MPToolbarItemIdentifierAutotype: NSLocalizedString(@"TOOLBAR_PERFORM_AUTOTYPE_FOR_ENTRY", @"Toolbar item to perform autotype")
}; };
}); });
return labelDict[identifier]; return labelDict[identifier];
} }
@@ -291,7 +298,7 @@ NSString *const MPToolbarItemIdentifierAutotype = @"TOOLBAR_AUTOTYPE";
MPToolbarItemIdentifierInspector: @(MPActionToggleInspector), MPToolbarItemIdentifierInspector: @(MPActionToggleInspector),
MPToolbarItemIdentifierHistory: @(MPActionShowEntryHistory), MPToolbarItemIdentifierHistory: @(MPActionShowEntryHistory),
MPToolbarItemIdentifierAutotype: @(MPActionPerformAutotypeForSelectedEntry) MPToolbarItemIdentifierAutotype: @(MPActionPerformAutotypeForSelectedEntry)
}; };
}); });
MPActionType actionType = (MPActionType)[actionDict[identifier] integerValue]; MPActionType actionType = (MPActionType)[actionDict[identifier] integerValue];
return [MPActionHelper actionOfType:actionType]; return [MPActionHelper actionOfType:actionType];