From 4ea38d727a495691dc7dd8a899f48b8cbe72ef42 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sun, 31 Mar 2024 16:50:56 +0800 Subject: [PATCH 1/6] perf: rename to quick action button --- Easydict/App/Localizable.xcstrings | 18 +++++++++- .../ViewController/View/Titlebar/EZTitlebar.h | 2 +- .../ViewController/View/Titlebar/EZTitlebar.m | 33 ++++++++++--------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 1e17f074b..9c24fec7d 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -2432,6 +2432,22 @@ } } }, + "quick_action" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Quick action" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "快捷动作" + } + } + } + }, "quick_link" : { "localizations" : { "en" : { @@ -2685,7 +2701,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "模型名字,多个模型使用逗号(,)分隔" } } diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h index 59dc68c71..0a9f934a7 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h @@ -31,7 +31,7 @@ typedef void(^EZTitlebarActionBlock)(EZTitlebarAction); @property (nonatomic, strong) EZOpenLinkButton *favoriteButton; -@property (nonatomic, strong) EZOpenLinkButton *settingButton; +@property (nonatomic, strong) EZOpenLinkButton *quickActionButton; @property (nonatomic, copy) EZTitlebarActionBlock menuActionBlock; diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m index 8b694579c..df0b96446 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m @@ -10,6 +10,7 @@ #import "EZTitleBarMoveView.h" #import "NSObject+EZWindowType.h" #import "NSImage+EZResize.h" +#import "NSImage+EZSymbolmage.h" #import "NSObject+EZDarkMode.h" #import "EZBaseQueryWindow.h" #import "EZConfiguration.h" @@ -67,38 +68,38 @@ - (void)setup { } }]; - [self setupSettingButton]; + [self setupQuickActionButton]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConstraints) name:EZQuickLinkButtonUpdateNotification object:nil]; } -- (void)setupSettingButton { - EZOpenLinkButton *button = [[EZOpenLinkButton alloc] init]; +- (void)setupQuickActionButton { + EZOpenLinkButton *quickActionButton = [[EZOpenLinkButton alloc] init]; NSImage *image = [[NSImage imageWithSystemSymbolName:@"switch.2" accessibilityDescription:nil] imageWithSymbolConfiguration:[NSImageSymbolConfiguration configurationWithScale:NSImageSymbolScaleLarge]]; + image = [NSImage ez_imageWithSymbolName:@"switch.2"]; + quickActionButton.image = image; + quickActionButton.toolTip = NSLocalizedString(@"quick_action", nil); + self.quickActionButton = quickActionButton; - button.image = image; - self.settingButton = button; - button.clickBlock = nil; + mm_weakify(self); + [quickActionButton setClickBlock:^(EZButton * _Nonnull button) { + mm_strongify(self); + [self showMenu]; + }]; NSColor *lightTintColor = [NSColor mm_colorWithHexString:@"#797A7F"]; NSColor *darkTintColor = [NSColor mm_colorWithHexString:@"#C0C1C4"]; CGSize imageSize = CGSizeMake(20, 20); - [button excuteLight:^(EZButton *button) { + [quickActionButton excuteLight:^(EZButton *button) { button.image = [[image imageWithTintColor:lightTintColor] resizeToSize:imageSize]; } dark:^(EZButton *button) { button.image = [[image imageWithTintColor:darkTintColor] resizeToSize:imageSize]; }]; - [button mas_makeConstraints:^(MASConstraintMaker *make) { + [quickActionButton mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(24); }]; - - mm_weakify(self); - [button setMouseUpBlock:^(EZButton *_Nonnull button) { - mm_strongify(self); - [self showMenu]; - }]; } - (void)updateConstraints { @@ -138,7 +139,7 @@ - (void)updateConstraints { }]; if (Configuration.shared.showSettingQuickLink) { - [self.stackView addArrangedSubview:self.settingButton]; + [self.stackView addArrangedSubview:self.quickActionButton]; } // Google @@ -248,7 +249,7 @@ - (void)showMenu { [menu addItem:[NSMenuItem separatorItem]]; [menu addItem:item3]; - [menu popUpBelowView:self.settingButton]; + [menu popUpBelowView:self.quickActionButton]; } - (void)clickAutomaticallyRemoveCodeCommentSymbols { From 43d11faadb8d48bb34f863a1390afe7ff5263fa5 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sun, 31 Mar 2024 17:40:11 +0800 Subject: [PATCH 2/6] refactor: improve quick action menu --- .../ViewController/View/Titlebar/EZTitlebar.h | 10 +-- .../ViewController/View/Titlebar/EZTitlebar.m | 64 ++++++++++++------- .../EZBaseQueryViewController.h | 2 +- .../EZBaseQueryViewController.m | 6 +- .../BaseQueryWindow/EZBaseQueryWindow.m | 6 +- 5 files changed, 53 insertions(+), 35 deletions(-) diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h index 0a9f934a7..89f26af66 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h @@ -12,12 +12,12 @@ NS_ASSUME_NONNULL_BEGIN -typedef NS_ENUM(NSUInteger, EZTitlebarAction) { - EZTitlebarActionRemoveCommentBlockSymbols, - EZTitlebarActionWordsSegmentation, +typedef NS_ENUM(NSUInteger, EZTitlebarQuickAction) { + EZTitlebarQuickActionRemoveCommentBlockSymbols, + EZTitlebarQuickActionWordsSegmentation, }; -typedef void(^EZTitlebarActionBlock)(EZTitlebarAction); +typedef void(^EZTitlebarQuickActionBlock)(EZTitlebarQuickAction); @interface EZTitlebar : NSView @@ -33,7 +33,7 @@ typedef void(^EZTitlebarActionBlock)(EZTitlebarAction); @property (nonatomic, strong) EZOpenLinkButton *quickActionButton; -@property (nonatomic, copy) EZTitlebarActionBlock menuActionBlock; +@property (nonatomic, copy) EZTitlebarQuickActionBlock menuQuickActionBlock; @end diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m index df0b96446..3526353d5 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m @@ -20,6 +20,7 @@ @interface EZTitlebar () @property (nonatomic, strong) NSStackView *stackView; +@property (nonatomic, strong) NSMenu *quickActionMenu; @end @@ -32,6 +33,44 @@ - (instancetype)initWithFrame:(NSRect)frameRect { return self; } +- (NSMenu *)quickActionMenu { + if (!_quickActionMenu) { + NSMenu *menu = [NSMenu new]; + NSArray *menuSections = @[ + @[ + @{@"title": @"remove_code_comment_symbols", @"action": NSStringFromSelector(@selector(clickAutomaticallyRemoveCodeCommentSymbols))}, + @{@"title": @"word_segmentation", @"action": NSStringFromSelector(@selector(clickAutomaticWordSegmentation))} + ], + @[ + @{@"title": @"go_to_settings", @"action": NSStringFromSelector(@selector(goToSettings))} + ] + /** + Just fix localization warning. + + NSLocalizedString(@"remove_code_comment_symbols", nil); + NSLocalizedString(@"word_segmentation", nil); + */ + ]; + + for (NSArray *section in menuSections) { + for (NSDictionary *itemDict in section) { + NSString *titleKey = itemDict[@"title"]; + NSString *title = NSLocalizedString(titleKey, nil); + SEL action = NSSelectorFromString(itemDict[@"action"]); + NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:title action:action keyEquivalent:@""]; + menuItem.target = self; + [menu addItem:menuItem]; + } + // Add separatorItem + if (section != menuSections.lastObject) { + [menu addItem:[NSMenuItem separatorItem]]; + } + } + _quickActionMenu = menu; + } + return _quickActionMenu; +} + - (void)setup { // EZTitleBarMoveView *moveView = [[EZTitleBarMoveView alloc] init]; // moveView.wantsLayer = YES; @@ -84,7 +123,7 @@ - (void)setupQuickActionButton { mm_weakify(self); [quickActionButton setClickBlock:^(EZButton * _Nonnull button) { mm_strongify(self); - [self showMenu]; + [self.quickActionMenu popUpBelowView:self.quickActionButton]; }]; NSColor *lightTintColor = [NSColor mm_colorWithHexString:@"#797A7F"]; @@ -233,31 +272,12 @@ - (void)updatePinButtonImage { }]; } -- (void)showMenu { - NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Menu"]; - NSMenuItem *item1 = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"remove_code_comment_symbols", nil) action:@selector(clickAutomaticallyRemoveCodeCommentSymbols) keyEquivalent:@""]; - item1.target = self; - - NSMenuItem *item2 = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"word_segmentation", nil) action:@selector(clickAutomaticWordSegmentation) keyEquivalent:@""]; - item2.target = self; - - NSMenuItem *item3 = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"go_to_settings", nil) action:@selector(goToSettings) keyEquivalent:@""]; - item3.target = self; - - [menu addItem:item1]; - [menu addItem:item2]; - [menu addItem:[NSMenuItem separatorItem]]; - [menu addItem:item3]; - - [menu popUpBelowView:self.quickActionButton]; -} - - (void)clickAutomaticallyRemoveCodeCommentSymbols { - _menuActionBlock(EZTitlebarActionRemoveCommentBlockSymbols); + _menuQuickActionBlock(EZTitlebarQuickActionRemoveCommentBlockSymbols); } - (void)clickAutomaticWordSegmentation { - _menuActionBlock(EZTitlebarActionWordsSegmentation); + _menuQuickActionBlock(EZTitlebarQuickActionWordsSegmentation); } - (void)goToSettings { diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.h b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.h index c6a0136a6..42cd85c3a 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.h +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.h @@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)disableReplaceTextButton; -- (void)receiveTitlebarAction:(EZTitlebarAction)action; +- (void)receiveTitlebarAction:(EZTitlebarQuickAction)action; @end diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index 19b5d85f3..253dee975 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -651,13 +651,13 @@ - (void)scrollToEndOfTextView { [self.queryView scrollToEndOfTextView]; } -- (void)receiveTitlebarAction:(EZTitlebarAction)action { +- (void)receiveTitlebarAction:(EZTitlebarQuickAction)action { switch (action) { - case EZTitlebarActionWordsSegmentation: { + case EZTitlebarQuickActionWordsSegmentation: { self.inputText = [self.inputText segmentWords]; break; } - case EZTitlebarActionRemoveCommentBlockSymbols: { + case EZTitlebarQuickActionRemoveCommentBlockSymbols: { self.inputText = [self.inputText removeCommentBlockSymbols]; break; } diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m index d9f3e59b2..b1057896a 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m @@ -57,11 +57,9 @@ - (void)setupUI { }]; mm_weakify(self); - self.titleBar.menuActionBlock = ^(EZTitlebarAction action) { + self.titleBar.menuQuickActionBlock = ^(EZTitlebarQuickAction action) { mm_strongify(self); - if (self.queryViewController) { - [self.queryViewController receiveTitlebarAction:action]; - } + [self.queryViewController receiveTitlebarAction:action]; }; } From d11ac3cf7f37cdfd8d230ced96ab99efe2ce6bd9 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sun, 31 Mar 2024 22:19:34 +0800 Subject: [PATCH 3/6] feat: add action to replace newline with space --- Easydict/App/Localizable.xcstrings | 62 ++++++++++++------- .../EZSettingViewController.m | 2 +- .../ViewController/View/Titlebar/EZTitlebar.h | 1 + .../ViewController/View/Titlebar/EZTitlebar.m | 36 ++++++++--- .../EZBaseQueryViewController.m | 3 + .../View/SettingView/Tabs/GeneralTab.swift | 2 +- 6 files changed, 73 insertions(+), 33 deletions(-) diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 9c24fec7d..113cff573 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -501,34 +501,34 @@ } } }, - "automatic_word_segmentation" : { + "automatically_remove_code_comment_symbols" : { "localizations" : { "en" : { "stringUnit" : { "state" : "translated", - "value" : "Automatically splitting words: key_value —> key value" + "value" : "Automatically remove code comment symbols「/*#」" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "单词自动分词 key_value —> key value" + "value" : "自动去除代码注释符号「/*#」" } } } }, - "automatically_remove_code_comment_symbols" : { + "automatically_split_words" : { "localizations" : { "en" : { "stringUnit" : { "state" : "translated", - "value" : "Automatically remove code comment symbols「/*#」" + "value" : "Automatically split words: key_value —> key value" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "自动去除代码注释符号「/*#」" + "value" : "单词自动分词 key_value —> key value" } } } @@ -2442,7 +2442,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "快捷动作" } } @@ -2513,6 +2513,22 @@ } } }, + "replace_newline_with_space" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Replace newline with space" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "将「换行符」替换为「空格」" + } + } + } + }, "replace_text" : { "localizations" : { "en" : { @@ -4220,6 +4236,22 @@ } } }, + "split_words" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Split words" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "单词分词" + } + } + } + }, "stop_play_audio" : { "localizations" : { "en" : { @@ -4419,22 +4451,6 @@ } } }, - "word_segmentation" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Splitting words" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "单词分词" - } - } - } - }, "Youdao" : { "extractionState" : "manual", "localizations" : { diff --git a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m index 2a9b06e06..00e4cfe29 100644 --- a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m @@ -418,7 +418,7 @@ - (void)setupUI { self.selectQueryTextWhenWindowActivateButton = [NSButton checkboxWithTitle:selectQueryTextWhenWindowActivateTitle target:self action:@selector(selectQueryTextWhenWindowActivateButtonClicked:)]; [self.contentView addSubview:self.selectQueryTextWhenWindowActivateButton]; - self.automaticWordSegmentationButton = [NSButton checkboxWithTitle:NSLocalizedString(@"automatic_word_segmentation", nil) target:self action:@selector(automaticWordSegmentationButtonClicked:)]; + self.automaticWordSegmentationButton = [NSButton checkboxWithTitle:NSLocalizedString(@"automatically_split_words", nil) target:self action:@selector(automaticWordSegmentationButtonClicked:)]; [self.contentView addSubview:self.automaticWordSegmentationButton]; self.automaticallyRemoveCodeCommentSymbolsButton = [NSButton checkboxWithTitle:NSLocalizedString(@"automatically_remove_code_comment_symbols", nil) target:self action:@selector(automaticallyRemoveCodeCommentSymbolsButtonClicked:)]; diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h index 89f26af66..0048b5e0d 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSUInteger, EZTitlebarQuickAction) { EZTitlebarQuickActionRemoveCommentBlockSymbols, EZTitlebarQuickActionWordsSegmentation, + EZTitlebarQuickActionReplaceNewlineWithSpace, }; typedef void(^EZTitlebarQuickActionBlock)(EZTitlebarQuickAction); diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m index 3526353d5..9eae2ca69 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m @@ -38,20 +38,34 @@ - (NSMenu *)quickActionMenu { NSMenu *menu = [NSMenu new]; NSArray *menuSections = @[ @[ - @{@"title": @"remove_code_comment_symbols", @"action": NSStringFromSelector(@selector(clickAutomaticallyRemoveCodeCommentSymbols))}, - @{@"title": @"word_segmentation", @"action": NSStringFromSelector(@selector(clickAutomaticWordSegmentation))} + @{ + @"title" : @"replace_newline_with_space", + @"action" : NSStringFromSelector(@selector(replaceNewlineWithSpace)) + }, + @{ + @"title" : @"remove_code_comment_symbols", + @"action" : NSStringFromSelector(@selector(removeCodeCommentSymbols)) + }, + @{ + @"title" : @"split_words", + @"action" : NSStringFromSelector(@selector(splitWords)) + } ], @[ - @{@"title": @"go_to_settings", @"action": NSStringFromSelector(@selector(goToSettings))} + @{ + @"title" : @"go_to_settings", + @"action" : NSStringFromSelector(@selector(goToSettings)) + } ] /** Just fix localization warning. + NSLocalizedString(@"replace_newline_with_space", nil); NSLocalizedString(@"remove_code_comment_symbols", nil); - NSLocalizedString(@"word_segmentation", nil); + NSLocalizedString(@"split_words", nil); */ ]; - + for (NSArray *section in menuSections) { for (NSDictionary *itemDict in section) { NSString *titleKey = itemDict[@"title"]; @@ -121,7 +135,7 @@ - (void)setupQuickActionButton { self.quickActionButton = quickActionButton; mm_weakify(self); - [quickActionButton setClickBlock:^(EZButton * _Nonnull button) { + [quickActionButton setClickBlock:^(EZButton *_Nonnull button) { mm_strongify(self); [self.quickActionMenu popUpBelowView:self.quickActionButton]; }]; @@ -272,11 +286,17 @@ - (void)updatePinButtonImage { }]; } -- (void)clickAutomaticallyRemoveCodeCommentSymbols { +#pragma mark - Actions + +- (void)replaceNewlineWithSpace { + _menuQuickActionBlock(EZTitlebarQuickActionReplaceNewlineWithSpace); +} + +- (void)removeCodeCommentSymbols { _menuQuickActionBlock(EZTitlebarQuickActionRemoveCommentBlockSymbols); } -- (void)clickAutomaticWordSegmentation { +- (void)splitWords { _menuQuickActionBlock(EZTitlebarQuickActionWordsSegmentation); } diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index 253dee975..fdca86d91 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -661,6 +661,9 @@ - (void)receiveTitlebarAction:(EZTitlebarQuickAction)action { self.inputText = [self.inputText removeCommentBlockSymbols]; break; } + case EZTitlebarQuickActionReplaceNewlineWithSpace: { + self.inputText = [self.inputText stringByReplacingOccurrencesOfString:@"\n" withString:@" "]; + } default: break; } diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index e4674ff4f..a210391c5 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -119,7 +119,7 @@ struct GeneralTab: View { Toggle("keep_prev_result_when_selected_text_is_empty", isOn: $keepPrevResultWhenEmpty) Toggle("select_query_text_when_window_activate", isOn: $selectQueryTextWhenWindowActivate) Toggle("automatically_remove_code_comment_symbols", isOn: $automaticallyRemoveCodeCommentSymbols) - Toggle("automatic_word_segmentation", isOn: $automaticWordSegmentation) + Toggle("automatically_split_words", isOn: $automaticWordSegmentation) } header: { Text("setting.general.input.header") } From f568a54bb103736c23b152261174e5402f20c717 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sun, 31 Mar 2024 22:34:37 +0800 Subject: [PATCH 4/6] perf: refresh title bar views when changing language --- Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m index 9eae2ca69..1940f06f9 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m @@ -123,7 +123,9 @@ - (void)setup { [self setupQuickActionButton]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConstraints) name:EZQuickLinkButtonUpdateNotification object:nil]; + NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; + [defaultCenter addObserver:self selector:@selector(updateConstraints) name:EZQuickLinkButtonUpdateNotification object:nil]; + [defaultCenter addObserver:self selector:@selector(updateConstraints) name:NSNotification.languagePreferenceChanged object:nil]; } - (void)setupQuickActionButton { @@ -170,11 +172,13 @@ - (void)updateConstraints { make.top.equalTo(self).offset(EZTitlebarHeight_28 - pinButtonWidth); }]; + // Remove and new views to refresh the UI. for (NSView *view in self.stackView.arrangedSubviews) { [self.stackView removeArrangedSubview:view]; [view removeFromSuperview]; } [self.stackView removeFromSuperview]; + self.quickActionMenu = nil; self.stackView = [[NSStackView alloc] init]; self.stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal; From 70c94b2281996110775d57b8f413b3fb53028cb8 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Mon, 1 Apr 2024 00:05:51 +0800 Subject: [PATCH 5/6] fix: title bar buttons toolTip did not change when changing language --- .../Feature/Configuration/Configuration.swift | 6 +- .../EZSettingViewController.m | 4 +- .../ViewController/View/Titlebar/EZTitlebar.h | 2 - .../ViewController/View/Titlebar/EZTitlebar.m | 420 ++++++++++-------- .../Configuration+Defaults.swift | 2 +- .../View/SettingView/Tabs/GeneralTab.swift | 2 +- 6 files changed, 235 insertions(+), 201 deletions(-) diff --git a/Easydict/Feature/Configuration/Configuration.swift b/Easydict/Feature/Configuration/Configuration.swift index f73c44218..b549fdc0b 100644 --- a/Easydict/Feature/Configuration/Configuration.swift +++ b/Easydict/Feature/Configuration/Configuration.swift @@ -122,7 +122,7 @@ class Configuration: NSObject { @DefaultsWrapper(.enableBetaFeature) private(set) var beta: Bool - @DefaultsWrapper(.showSettingQuickLink) var showSettingQuickLink: Bool + @DefaultsWrapper(.showQuickActionButton) var showQuickActionButton: Bool var cancellables: [AnyCancellable] = [] @@ -323,7 +323,7 @@ class Configuration: NSObject { ) cancellables.append( - Defaults.publisher(.showSettingQuickLink, options: []) + Defaults.publisher(.showQuickActionButton, options: []) .removeDuplicates() .sink { [weak self] _ in self?.didSetShowSettingQuickLink() @@ -537,7 +537,7 @@ extension Configuration { func didSetShowSettingQuickLink() { postUpdateQuickLinkButtonNotification() - logSettings(["showSettingQuickLink": showSettingQuickLink]) + logSettings(["showSettingQuickLink": showQuickActionButton]) } fileprivate func didSetHideMenuBarIcon() { diff --git a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m index 00e4cfe29..d2b3ba9b8 100644 --- a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m @@ -584,7 +584,7 @@ - (void)setupUI { self.showGoogleQuickLinkButton.mm_isOn = self.config.showGoogleQuickLink; self.showEudicQuickLinkButton.mm_isOn = self.config.showEudicQuickLink; self.showAppleDictionaryQuickLinkButton.mm_isOn = self.config.showAppleDictionaryQuickLink; - self.showSettingQuickLinkButton.mm_isOn = self.config.showSettingQuickLink; + self.showSettingQuickLinkButton.mm_isOn = self.config.showQuickActionButton; self.hideMenuBarIconButton.mm_isOn = self.config.hideMenuBarIcon; if (@available(macOS 13.0, *)) { self.enableBetaNewAppButton.mm_isOn = self.config.enableBetaNewApp; @@ -1059,7 +1059,7 @@ - (void)showAppleDictionaryQuickLinkButtonClicked:(NSButton *)sender { } - (void)showSettingQuickLinkButtonClicked:(NSButton *)sender { - self.config.showSettingQuickLink = sender.mm_isOn; + self.config.showQuickActionButton = sender.mm_isOn; } - (void)hideMenuBarIconButtonClicked:(NSButton *)sender { diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h index 0048b5e0d..915cc098f 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h @@ -30,8 +30,6 @@ typedef void(^EZTitlebarQuickActionBlock)(EZTitlebarQuickAction); @property (nonatomic, strong) EZOpenLinkButton *googleButton; @property (nonatomic, strong) EZOpenLinkButton *appleDictionaryButton; -@property (nonatomic, strong) EZOpenLinkButton *favoriteButton; - @property (nonatomic, strong) EZOpenLinkButton *quickActionButton; @property (nonatomic, copy) EZTitlebarQuickActionBlock menuQuickActionBlock; diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m index 1940f06f9..296809011 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m @@ -22,6 +22,13 @@ @interface EZTitlebar () @property (nonatomic, strong) NSStackView *stackView; @property (nonatomic, strong) NSMenu *quickActionMenu; +@property (nonatomic, assign) CGSize buttonSize; +@property (nonatomic, assign) CGFloat buttonWidth; +@property (nonatomic, assign) CGFloat buttonPadding; + +@property (nonatomic, assign) CGSize imageSize; +@property (nonatomic, assign) CGFloat imageWidth; + @end @implementation EZTitlebar @@ -33,6 +40,148 @@ - (instancetype)initWithFrame:(NSRect)frameRect { return self; } + +- (void)setup { + self.buttonWidth = 24; + self.imageWidth = 20; + self.buttonPadding = 4; + + self.buttonSize = CGSizeMake(self.buttonWidth, self.buttonWidth); + self.imageSize = CGSizeMake(self.imageWidth, self.imageWidth); + + NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; + [defaultCenter addObserver:self selector:@selector(updateConstraints) name:EZQuickLinkButtonUpdateNotification object:nil]; + [defaultCenter addObserver:self selector:@selector(updateConstraints) name:NSNotification.languagePreferenceChanged object:nil]; +} + + +- (void)updateConstraints { + // Remove and dealloc all views to refresh UI. + for (NSView *subview in self.subviews) { + [subview removeFromSuperview]; + } + + // Reset buttons to update toolTip. + _quickActionMenu = nil; + _quickActionButton = nil; + _googleButton = nil; + _eudicButton = nil; + _appleDictionaryButton = nil; + _stackView = nil; + + [self addSubview:self.pinButton]; + [self updatePinButton]; + [self quickActionMenu]; + + CGFloat margin = EZHorizontalCellSpacing_10; + CGFloat topOffset = EZTitlebarHeight_28 - self.buttonWidth; + + [self.pinButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.width.height.mas_equalTo(self.buttonWidth); + make.left.inset(margin); + make.top.equalTo(self).offset(topOffset); + }]; + + [self addSubview:self.stackView]; + [self.stackView mas_remakeConstraints:^(MASConstraintMaker *make) { + make.top.equalTo(self).offset(topOffset); + make.right.equalTo(self).offset(-margin); + }]; + + if (Configuration.shared.showQuickActionButton) { + [self.stackView addArrangedSubview:self.quickActionButton]; + } + + // Google + if (Configuration.shared.showGoogleQuickLink) { + [self.stackView addArrangedSubview:self.googleButton]; + } + + // Apple Dictionary + if (Configuration.shared.showAppleDictionaryQuickLink) { + [self.stackView addArrangedSubview:self.appleDictionaryButton]; + } + + // Eudic + if (Configuration.shared.showEudicQuickLink) { + // !!!: Note that some applications have multiple channel versions. Refer: https://github.com/tisfeng/Raycast-Easydict/issues/16 + BOOL installedEudic = [self checkInstalledApp:@[ @"com.eusoft.freeeudic", @"com.eusoft.eudic" ]]; + if (installedEudic) { + [self.stackView addArrangedSubview:self.eudicButton]; + } + } + + [super updateConstraints]; +} + + +#pragma mark - Actions + +- (void)replaceNewlineWithSpace { + _menuQuickActionBlock(EZTitlebarQuickActionReplaceNewlineWithSpace); +} + +- (void)removeCodeCommentSymbols { + _menuQuickActionBlock(EZTitlebarQuickActionRemoveCommentBlockSymbols); +} + +- (void)splitWords { + _menuQuickActionBlock(EZTitlebarQuickActionWordsSegmentation); +} + +- (void)goToSettings { + if ([[Configuration shared] enableBetaNewApp]) { + [[NSNotificationCenter defaultCenter] postNotificationName:EZOpenSettingsNotification object:nil]; + } else { + [EZPreferencesWindowController.shared show]; + } +} + +#pragma mark - Getter && Setter + +- (EZOpenLinkButton *)pinButton { + if (!_pinButton) { + EZOpenLinkButton *pinButton = [[EZOpenLinkButton alloc] init]; + _pinButton = pinButton; + + pinButton.contentTintColor = [NSColor clearColor]; + pinButton.clickBlock = nil; + self.pin = NO; + + mm_weakify(self); + [pinButton setMouseDownBlock:^(EZButton *_Nonnull button) { + // NSLog(@"pin mouse down, state: %ld", button.buttonState); + mm_strongify(self); + self.pin = !self.pin; + }]; + + [pinButton setMouseUpBlock:^(EZButton *_Nonnull button) { + // NSLog(@"pin mouse up, state: %ld", button.buttonState); + mm_strongify(self); + BOOL oldPin = !self.pin; + + // This means clicked pin button. + if (button.state == EZButtonHoverState) { + self.pin = !oldPin; + } else if (button.buttonState == EZButtonNormalState) { + self.pin = oldPin; + } + }]; + } + return _pinButton; +} + +- (NSStackView *)stackView { + if (!_stackView) { + _stackView = [[NSStackView alloc] init]; + _stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal; + _stackView.spacing = self.buttonPadding; + _stackView.alignment = NSLayoutAttributeCenterY; + _stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionRightToLeft; + } + return _stackView; +} + - (NSMenu *)quickActionMenu { if (!_quickActionMenu) { NSMenu *menu = [NSMenu new]; @@ -85,186 +234,112 @@ - (NSMenu *)quickActionMenu { return _quickActionMenu; } -- (void)setup { - // EZTitleBarMoveView *moveView = [[EZTitleBarMoveView alloc] init]; - // moveView.wantsLayer = YES; - // moveView.layer.backgroundColor = NSColor.clearColor.CGColor; - // [self addSubview:moveView]; - // [moveView mas_makeConstraints:^(MASConstraintMaker *make) { - // make.edges.equalTo(self); - // }]; - - EZOpenLinkButton *pinButton = [[EZOpenLinkButton alloc] init]; - [self addSubview:pinButton]; - self.pinButton = pinButton; - pinButton.contentTintColor = [NSColor clearColor]; - pinButton.clickBlock = nil; - self.pin = NO; - - mm_weakify(self); - [pinButton setMouseDownBlock:^(EZButton *_Nonnull button) { - // NSLog(@"pin mouse down, state: %ld", button.buttonState); - mm_strongify(self); - self.pin = !self.pin; - }]; - - [pinButton setMouseUpBlock:^(EZButton *_Nonnull button) { - // NSLog(@"pin mouse up, state: %ld", button.buttonState); - mm_strongify(self); - BOOL oldPin = !self.pin; +- (EZOpenLinkButton *)quickActionButton { + if (!_quickActionButton) { + EZOpenLinkButton *quickActionButton = [[EZOpenLinkButton alloc] init]; + _quickActionButton = quickActionButton; + NSImage *image = [[NSImage imageWithSystemSymbolName:@"switch.2" accessibilityDescription:nil] imageWithSymbolConfiguration:[NSImageSymbolConfiguration configurationWithScale:NSImageSymbolScaleLarge]]; + image = [NSImage ez_imageWithSymbolName:@"switch.2"]; + quickActionButton.image = image; + quickActionButton.toolTip = NSLocalizedString(@"quick_action", nil); - // This means clicked pin button. - if (button.state == EZButtonHoverState) { - self.pin = !oldPin; - } else if (button.buttonState == EZButtonNormalState) { - self.pin = oldPin; - } - }]; - - [self setupQuickActionButton]; - - NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; - [defaultCenter addObserver:self selector:@selector(updateConstraints) name:EZQuickLinkButtonUpdateNotification object:nil]; - [defaultCenter addObserver:self selector:@selector(updateConstraints) name:NSNotification.languagePreferenceChanged object:nil]; -} - -- (void)setupQuickActionButton { - EZOpenLinkButton *quickActionButton = [[EZOpenLinkButton alloc] init]; - NSImage *image = [[NSImage imageWithSystemSymbolName:@"switch.2" accessibilityDescription:nil] imageWithSymbolConfiguration:[NSImageSymbolConfiguration configurationWithScale:NSImageSymbolScaleLarge]]; - image = [NSImage ez_imageWithSymbolName:@"switch.2"]; - quickActionButton.image = image; - quickActionButton.toolTip = NSLocalizedString(@"quick_action", nil); - self.quickActionButton = quickActionButton; - - mm_weakify(self); - [quickActionButton setClickBlock:^(EZButton *_Nonnull button) { - mm_strongify(self); - [self.quickActionMenu popUpBelowView:self.quickActionButton]; - }]; - - NSColor *lightTintColor = [NSColor mm_colorWithHexString:@"#797A7F"]; - NSColor *darkTintColor = [NSColor mm_colorWithHexString:@"#C0C1C4"]; - CGSize imageSize = CGSizeMake(20, 20); - - [quickActionButton excuteLight:^(EZButton *button) { - button.image = [[image imageWithTintColor:lightTintColor] resizeToSize:imageSize]; - } dark:^(EZButton *button) { - button.image = [[image imageWithTintColor:darkTintColor] resizeToSize:imageSize]; - }]; - - [quickActionButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.size.mas_equalTo(24); - }]; + mm_weakify(self); + [quickActionButton setClickBlock:^(EZButton *_Nonnull button) { + mm_strongify(self); + [self.quickActionMenu popUpBelowView:self.quickActionButton]; + }]; + + NSColor *lightTintColor = [NSColor mm_colorWithHexString:@"#797A7F"]; + NSColor *darkTintColor = [NSColor mm_colorWithHexString:@"#C0C1C4"]; + CGSize imageSize = CGSizeMake(20, 20); + + [quickActionButton excuteLight:^(EZButton *button) { + button.image = [[image imageWithTintColor:lightTintColor] resizeToSize:imageSize]; + } dark:^(EZButton *button) { + button.image = [[image imageWithTintColor:darkTintColor] resizeToSize:imageSize]; + }]; + + [quickActionButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.size.mas_equalTo(24); + }]; + } + return _quickActionButton; } -- (void)updateConstraints { - CGFloat kButtonWidth_24 = 24; - CGFloat kImagenWidth_20 = 20; - CGFloat kButtonPadding_4 = 4; - - CGSize buttonSize = CGSizeMake(kButtonWidth_24, kButtonWidth_24); - CGSize imageSize = CGSizeMake(kImagenWidth_20, kImagenWidth_20); - - [self.pinButton mas_makeConstraints:^(MASConstraintMaker *make) { - CGFloat pinButtonWidth = 24; - make.width.height.mas_equalTo(pinButtonWidth); - make.left.inset(11); - make.top.equalTo(self).offset(EZTitlebarHeight_28 - pinButtonWidth); - }]; - - // Remove and new views to refresh the UI. - for (NSView *view in self.stackView.arrangedSubviews) { - [self.stackView removeArrangedSubview:view]; - [view removeFromSuperview]; - } - [self.stackView removeFromSuperview]; - self.quickActionMenu = nil; - - self.stackView = [[NSStackView alloc] init]; - self.stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal; - self.stackView.spacing = kButtonPadding_4; - self.stackView.alignment = NSLayoutAttributeCenterY; - self.stackView.userInterfaceLayoutDirection = NSUserInterfaceLayoutDirectionRightToLeft; - [self addSubview:self.stackView]; - - CGFloat quickLinkButtonTopOffset = EZTitlebarHeight_28 - kButtonWidth_24; - CGFloat quickLinkButtonRightOffset = 12; - - [self.stackView mas_remakeConstraints:^(MASConstraintMaker *make) { - make.top.equalTo(self).offset(quickLinkButtonTopOffset); - make.right.equalTo(self).offset(-quickLinkButtonRightOffset); - }]; - - if (Configuration.shared.showSettingQuickLink) { - [self.stackView addArrangedSubview:self.quickActionButton]; - } - - // Google - if (Configuration.shared.showGoogleQuickLink) { +- (EZOpenLinkButton *)googleButton { + if (!_googleButton) { EZOpenLinkButton *googleButton = [[EZOpenLinkButton alloc] init]; - [self addSubview:googleButton]; - self.googleButton = googleButton; - self.favoriteButton = googleButton; + _googleButton = googleButton; googleButton.link = EZGoogleWebSearchURL; - googleButton.image = [[NSImage imageNamed:@"google_icon"] resizeToSize:imageSize]; + googleButton.image = [[NSImage imageNamed:@"google_icon"] resizeToSize:self.imageSize]; googleButton.toolTip = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"open_in_google", nil), @" ⌘+⏎"]; googleButton.contentTintColor = NSColor.clearColor; [googleButton mas_remakeConstraints:^(MASConstraintMaker *make) { - make.size.mas_equalTo(buttonSize); + make.size.mas_equalTo(self.buttonSize); }]; - - [self.stackView addArrangedSubview:googleButton]; } - - // Apple Dictionary - if (Configuration.shared.showAppleDictionaryQuickLink) { + return _googleButton; +} + +- (EZOpenLinkButton *)appleDictionaryButton { + if (!_appleDictionaryButton) { EZOpenLinkButton *appleDictButton = [[EZOpenLinkButton alloc] init]; - [self addSubview:appleDictButton]; - self.appleDictionaryButton = appleDictButton; - self.favoriteButton = appleDictButton; + _appleDictionaryButton = appleDictButton; appleDictButton.link = EZAppleDictionaryAppURLScheme; - appleDictButton.image = [[NSImage imageNamed:EZServiceTypeAppleDictionary] resizeToSize:imageSize]; + appleDictButton.image = [[NSImage imageNamed:EZServiceTypeAppleDictionary] resizeToSize:self.imageSize]; appleDictButton.toolTip = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"open_in_apple_dictionary", nil), @"⌘+⇧+D"]; appleDictButton.contentTintColor = NSColor.clearColor; [appleDictButton mas_remakeConstraints:^(MASConstraintMaker *make) { - make.size.mas_equalTo(buttonSize); + make.size.mas_equalTo(self.buttonSize); }]; - [self.stackView addArrangedSubview:appleDictButton]; } - - // Eudic - if (Configuration.shared.showEudicQuickLink) { + return _appleDictionaryButton; +} + +- (EZOpenLinkButton *)eudicButton { + if (!_eudicButton) { EZOpenLinkButton *eudicButton = [[EZOpenLinkButton alloc] init]; + _eudicButton = eudicButton; - // !!!: Note that some applications have multiple channel versions. Ref: https://github.com/tisfeng/Raycast-Easydict/issues/16 - BOOL installedEudic = [self checkInstalledApp:@[ @"com.eusoft.freeeudic", @"com.eusoft.eudic" ]]; - eudicButton.hidden = !installedEudic; - if (installedEudic) { - [self addSubview:eudicButton]; - self.eudicButton = eudicButton; - self.favoriteButton = eudicButton; - - eudicButton.link = EZEudicAppURLScheme; - eudicButton.image = [[NSImage imageNamed:@"Eudic"] resizeToSize:imageSize]; - eudicButton.toolTip = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"open_in_eudic", nil), @"⌘+⇧+⏎"]; - eudicButton.contentTintColor = NSColor.clearColor; - - [eudicButton mas_remakeConstraints:^(MASConstraintMaker *make) { - make.size.mas_equalTo(buttonSize); - }]; - [self.stackView addArrangedSubview:eudicButton]; - } + eudicButton.link = EZEudicAppURLScheme; + eudicButton.image = [[NSImage imageNamed:@"Eudic"] resizeToSize:self.imageSize]; + eudicButton.toolTip = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"open_in_eudic", nil), @"⌘+⇧+⏎"]; + eudicButton.contentTintColor = NSColor.clearColor; + + [eudicButton mas_remakeConstraints:^(MASConstraintMaker *make) { + make.size.mas_equalTo(self.buttonSize); + }]; } - - [super updateConstraints]; + return _eudicButton; } -- (void)updatePinButtonImage { + +- (BOOL)pin { + EZBaseQueryWindow *window = (EZBaseQueryWindow *)self.window; + return window.pin; +} + +- (void)setPin:(BOOL)pin { + EZBaseQueryWindow *window = (EZBaseQueryWindow *)self.window; + window.pin = pin; + + [self updatePinButton]; +} + +#pragma mark - + + +- (void)updatePinButton { + NSString *shortcut = @"⌘+P"; + NSString *action = self.pin ? NSLocalizedString(@"unpin", nil) : NSLocalizedString(@"pin", nil); + self.pinButton.toolTip = [NSString stringWithFormat:@"%@, %@", action, shortcut]; + + CGFloat imageWidth = 18; CGSize imageSize = CGSizeMake(imageWidth, imageWidth); @@ -290,45 +365,6 @@ - (void)updatePinButtonImage { }]; } -#pragma mark - Actions - -- (void)replaceNewlineWithSpace { - _menuQuickActionBlock(EZTitlebarQuickActionReplaceNewlineWithSpace); -} - -- (void)removeCodeCommentSymbols { - _menuQuickActionBlock(EZTitlebarQuickActionRemoveCommentBlockSymbols); -} - -- (void)splitWords { - _menuQuickActionBlock(EZTitlebarQuickActionWordsSegmentation); -} - -- (void)goToSettings { - if ([[Configuration shared] enableBetaNewApp]) { - [[NSNotificationCenter defaultCenter] postNotificationName:EZOpenSettingsNotification object:nil]; - } else { - [EZPreferencesWindowController.shared show]; - } -} - -#pragma mark - Setter && Getter - -- (BOOL)pin { - EZBaseQueryWindow *window = (EZBaseQueryWindow *)self.window; - return window.pin; -} - -- (void)setPin:(BOOL)pin { - EZBaseQueryWindow *window = (EZBaseQueryWindow *)self.window; - window.pin = pin; - NSString *shortcut = @"⌘+P"; - NSString *action = pin ? NSLocalizedString(@"unpin", nil) : NSLocalizedString(@"pin", nil); - self.pinButton.toolTip = [NSString stringWithFormat:@"%@, %@", action, shortcut]; - - [self updatePinButtonImage]; -} - /// Check if installed app according to bundle id array - (BOOL)checkInstalledApp:(NSArray *)bundleIds { for (NSString *bundleId in bundleIds) { diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index b082f6694..805e0a531 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -60,7 +60,7 @@ extension Defaults.Keys { static let showGoogleQuickLink = Key("EZConfiguration_kShowGoogleLinkKey", default: true) static let showEudicQuickLink = Key("EZConfiguration_kShowEudicLinkKey", default: true) static let showAppleDictionaryQuickLink = Key("EZConfiguration_kShowAppleDictionaryLinkKey", default: true) - static let showSettingQuickLink = Key("EZConfiguration_kShowSettingQuickLink", default: true) + static let showQuickActionButton = Key("EZConfiguration_kShowSettingQuickLink", default: true) static let hideMenuBarIcon = Key("EZConfiguration_kHideMenuBarIconKey", default: false) static let fixedWindowPosition = Key( "EZConfiguration_kShowFixedWindowPositionKey", diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index a210391c5..c9b3c4a8f 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -278,7 +278,7 @@ struct GeneralTab: View { @Default(.showGoogleQuickLink) private var showGoogleQuickLink @Default(.showEudicQuickLink) private var showEudicQuickLink @Default(.showAppleDictionaryQuickLink) private var showAppleDictionaryQuickLink - @Default(.showSettingQuickLink) private var showSettingQuickLink + @Default(.showQuickActionButton) private var showSettingQuickLink @Default(.hideMainWindow) private var hideMainWindow @Default(.launchAtStartup) private var launchAtStartup From 5be1c3e3259cbd98da7d7938a6a217d577a7822d Mon Sep 17 00:00:00 2001 From: tisfeng Date: Mon, 1 Apr 2024 00:13:38 +0800 Subject: [PATCH 6/6] perf: rename variable --- Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h | 3 +-- Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m | 6 +++--- .../Window/BaseQueryWindow/EZBaseQueryWindow.m | 2 +- Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h index 915cc098f..dad869835 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h @@ -7,7 +7,6 @@ // #import -#import "EZHoverButton.h" #import "EZOpenLinkButton.h" NS_ASSUME_NONNULL_BEGIN @@ -32,7 +31,7 @@ typedef void(^EZTitlebarQuickActionBlock)(EZTitlebarQuickAction); @property (nonatomic, strong) EZOpenLinkButton *quickActionButton; -@property (nonatomic, copy) EZTitlebarQuickActionBlock menuQuickActionBlock; +@property (nonatomic, copy) EZTitlebarQuickActionBlock menuActionBlock; @end diff --git a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m index 296809011..1e85296a6 100644 --- a/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m +++ b/Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m @@ -118,15 +118,15 @@ - (void)updateConstraints { #pragma mark - Actions - (void)replaceNewlineWithSpace { - _menuQuickActionBlock(EZTitlebarQuickActionReplaceNewlineWithSpace); + _menuActionBlock(EZTitlebarQuickActionReplaceNewlineWithSpace); } - (void)removeCodeCommentSymbols { - _menuQuickActionBlock(EZTitlebarQuickActionRemoveCommentBlockSymbols); + _menuActionBlock(EZTitlebarQuickActionRemoveCommentBlockSymbols); } - (void)splitWords { - _menuQuickActionBlock(EZTitlebarQuickActionWordsSegmentation); + _menuActionBlock(EZTitlebarQuickActionWordsSegmentation); } - (void)goToSettings { diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m index b1057896a..b9e17dd38 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryWindow.m @@ -57,7 +57,7 @@ - (void)setupUI { }]; mm_weakify(self); - self.titleBar.menuQuickActionBlock = ^(EZTitlebarQuickAction action) { + self.titleBar.menuActionBlock = ^(EZTitlebarQuickAction action) { mm_strongify(self); [self.queryViewController receiveTitlebarAction:action]; }; diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index c9b3c4a8f..29b10555c 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -144,7 +144,7 @@ struct GeneralTab: View { Toggle("show_google_quick_link", isOn: $showGoogleQuickLink) Toggle("show_eudic_quick_link", isOn: $showEudicQuickLink) Toggle("show_apple_dictionary_quick_link", isOn: $showAppleDictionaryQuickLink) - Toggle("show_setting_quick_link", isOn: $showSettingQuickLink) + Toggle("show_setting_quick_link", isOn: $showQuickActionButton) } header: { Text("setting.general.quick_link.header") } @@ -278,7 +278,7 @@ struct GeneralTab: View { @Default(.showGoogleQuickLink) private var showGoogleQuickLink @Default(.showEudicQuickLink) private var showEudicQuickLink @Default(.showAppleDictionaryQuickLink) private var showAppleDictionaryQuickLink - @Default(.showQuickActionButton) private var showSettingQuickLink + @Default(.showQuickActionButton) private var showQuickActionButton @Default(.hideMainWindow) private var hideMainWindow @Default(.launchAtStartup) private var launchAtStartup