diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index c77854582..88d7edf5d 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -635,22 +635,6 @@ } } }, - "clear_input" : { - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Clear Input:" - } - }, - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "清空查询内容:" - } - } - } - }, "clear_input_when_translating" : { "localizations" : { "en" : { @@ -2381,6 +2365,23 @@ } } }, + "select_query_text_when_window_activate" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Select query text when window activate" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "打开窗口时自动选中文本" + } + } + } + }, "select_translate" : { "localizations" : { "en" : { diff --git a/Easydict/Feature/Configuration/Configuration.swift b/Easydict/Feature/Configuration/Configuration.swift index 7e97f324f..774f4a193 100644 --- a/Easydict/Feature/Configuration/Configuration.swift +++ b/Easydict/Feature/Configuration/Configuration.swift @@ -144,6 +144,9 @@ let kHideMenuBarIconKey = "EZConfiguration_kHideMenuBarIconKey" @DefaultsWrapper(.keepPrevResultWhenEmpty) var keepPrevResultWhenEmpty: Bool + @DefaultsWrapper(.selectQueryTextWhenWindowActivate) + var selectQueryTextWhenWindowActivate: Bool + var disabledAutoSelect: Bool = false var isRecordingSelectTextShortcutKey: Bool = false diff --git a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m index 7cdd2a85c..a0a5501de 100644 --- a/Easydict/Feature/PerferenceWindow/EZSettingViewController.m +++ b/Easydict/Feature/PerferenceWindow/EZSettingViewController.m @@ -74,11 +74,10 @@ @interface EZSettingViewController () @property (nonatomic, strong) NSTextField *playAudioLabel; @property (nonatomic, strong) NSButton *autoPlayAudioButton; -@property (nonatomic, strong) NSTextField *clearInputLabel; +@property (nonatomic, strong) NSTextField *inputFieldLabel; @property (nonatomic, strong) NSButton *clearInputButton; - -@property (nonatomic, strong) NSTextField *keepPrevResultLabel; @property (nonatomic, strong) NSButton *keepPrevResultButton; +@property (nonatomic, strong) NSButton *selectQueryTextWhenWindowActivateButton; @property (nonatomic, strong) NSTextField *autoQueryLabel; @property (nonatomic, strong) NSButton *autoQueryOCRTextButton; @@ -398,22 +397,23 @@ - (void)setupUI { self.autoPlayAudioButton = [NSButton checkboxWithTitle:autoPlayAudioTitle target:self action:@selector(autoPlayAudioButtonClicked:)]; [self.contentView addSubview:self.autoPlayAudioButton]; - NSTextField *clearInputLabel = [NSTextField labelWithString:NSLocalizedString(@"clear_input", nil)]; - clearInputLabel.font = font; - [self.contentView addSubview:clearInputLabel]; - self.clearInputLabel = clearInputLabel; + NSString *inputFieldLabelTitle = [NSString stringWithFormat:@"%@:", NSLocalizedString(@"setting.general.input.header", nil)]; + NSTextField *inputFieldLabel = [NSTextField labelWithString:inputFieldLabelTitle]; + inputFieldLabel.font = font; + [self.contentView addSubview:inputFieldLabel]; + self.inputFieldLabel = inputFieldLabel; NSString *clearInputTitle = NSLocalizedString(@"clear_input_when_translating", nil); self.clearInputButton = [NSButton checkboxWithTitle:clearInputTitle target:self action:@selector(clearInputButtonClicked:)]; [self.contentView addSubview:self.clearInputButton]; - self.keepPrevResultLabel = [NSTextField labelWithString:NSLocalizedString(@"keep_result", nil)]; - self.keepPrevResultLabel.font = font; - [self.contentView addSubview:self.keepPrevResultLabel]; - NSString *keepPrevResultTitle = NSLocalizedString(@"keep_prev_result_when_selected_text_is_empty", nil); self.keepPrevResultButton = [NSButton checkboxWithTitle:keepPrevResultTitle target:self action:@selector(keepPrevResultButtonClicked:)]; [self.contentView addSubview:self.keepPrevResultButton]; + + NSString *selectQueryTextWhenWindowActivateTitle = NSLocalizedString(@"select_query_text_when_window_activate", nil); + self.selectQueryTextWhenWindowActivateButton = [NSButton checkboxWithTitle:selectQueryTextWhenWindowActivateTitle target:self action:@selector(selectQueryTextWhenWindowActivateButtonClicked:)]; + [self.contentView addSubview:self.selectQueryTextWhenWindowActivateButton]; NSTextField *autoQueryLabel = [NSTextField labelWithString:NSLocalizedString(@"auto_query", nil)]; autoQueryLabel.font = font; @@ -556,6 +556,7 @@ - (void)setupUI { self.autoPlayAudioButton.mm_isOn = self.config.autoPlayAudio; self.clearInputButton.mm_isOn = self.config.clearInput; self.keepPrevResultButton.mm_isOn = self.config.keepPrevResultWhenEmpty; + self.selectQueryTextWhenWindowActivateButton.mm_isOn = self.config.selectQueryTextWhenWindowActivate; self.launchAtStartupButton.mm_isOn = self.config.launchAtStartup; self.hideMainWindowButton.mm_isOn = self.config.hideMainWindow; self.autoQueryOCRTextButton.mm_isOn = self.config.autoQueryOCRText; @@ -755,27 +756,26 @@ - (void)updateViewConstraints { }]; - [self.clearInputLabel mas_remakeConstraints:^(MASConstraintMaker *make) { + [self.inputFieldLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.autoGetSelectedTextLabel); make.top.equalTo(self.autoPlayAudioButton.mas_bottom).offset(self.verticalPadding); }]; [self.clearInputButton mas_remakeConstraints:^(MASConstraintMaker *make) { - make.left.equalTo(self.clearInputLabel.mas_right).offset(self.horizontalPadding); - make.centerY.equalTo(self.clearInputLabel); + make.left.equalTo(self.inputFieldLabel.mas_right).offset(self.horizontalPadding); + make.centerY.equalTo(self.inputFieldLabel); }]; - - [self.keepPrevResultLabel mas_remakeConstraints:^(MASConstraintMaker *make) { - make.right.equalTo(self.clearInputLabel); + [self.keepPrevResultButton mas_remakeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.clearInputButton); make.top.equalTo(self.clearInputButton.mas_bottom).offset(self.verticalPadding); }]; - [self.keepPrevResultButton mas_remakeConstraints:^(MASConstraintMaker *make) { - make.left.equalTo(self.keepPrevResultLabel.mas_right).offset(self.horizontalPadding); - make.centerY.equalTo(self.keepPrevResultLabel); + [self.selectQueryTextWhenWindowActivateButton mas_remakeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(self.clearInputButton); + make.top.equalTo(self.keepPrevResultButton.mas_bottom).offset(self.verticalPadding); }]; [self.autoQueryLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.autoGetSelectedTextLabel); - make.top.equalTo(self.keepPrevResultButton.mas_bottom).offset(self.verticalPadding); + make.top.equalTo(self.selectQueryTextWhenWindowActivateButton.mas_bottom).offset(self.verticalPadding); }]; [self.autoQueryOCRTextButton mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.autoQueryLabel.mas_right).offset(self.horizontalPadding); @@ -983,6 +983,10 @@ - (void)keepPrevResultButtonClicked:(NSButton *)sender { self.config.keepPrevResultWhenEmpty = sender.mm_isOn; } +- (void)selectQueryTextWhenWindowActivateButtonClicked:(NSButton *)sender { + self.config.selectQueryTextWhenWindowActivate = sender.mm_isOn; +} + - (void)autoCopySelectedTextButtonClicked:(NSButton *)sender { self.config.autoCopySelectedText = sender.mm_isOn; } diff --git a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m index ff6a081e3..44a5a5e5b 100644 --- a/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m +++ b/Easydict/Feature/ViewController/Window/BaseQueryWindow/EZBaseQueryViewController.m @@ -527,7 +527,9 @@ - (void)focusInputTextView { [NSApp activateIgnoringOtherApps:YES]; [self.baseQueryWindow makeFirstResponder:self.queryView.textView]; - self.queryView.textView.selectedRange = NSMakeRange(0, self.inputText.length); + if (Configuration.shared.selectQueryTextWhenWindowActivate) { + self.queryView.textView.selectedRange = NSMakeRange(0, self.inputText.length); + } } } diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index a477b6f9a..3b3305739 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -48,6 +48,7 @@ extension Defaults.Keys { static let allowAnalytics = Key("EZConfiguration_kAllowAnalyticsKey", default: true) static let clearInput = Key("EZConfiguration_kClearInputKey", default: true) static let keepPrevResultWhenEmpty = Key("EZConfiguration_kKeepPrevResultKey", default: true) + static let selectQueryTextWhenWindowActivate = Key("EZConfiguration_kSelectQueryTextWhenWindowActivate", default: false) static let enableBetaNewApp = Key("EZConfiguration_kEnableBetaNewAppKey", default: false) static let enableBetaFeature = Key("EZBetaFeatureKey", default: false) diff --git a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift index 3ce6cf5c8..cfbf2f2dd 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift @@ -79,6 +79,7 @@ struct GeneralTab: View { Section { Toggle("clear_input_when_translating", isOn: $clearInput) Toggle("keep_prev_result_when_selected_text_is_empty", isOn: $keepPrevResultWhenEmpty) + Toggle("select_query_text_when_window_activate", isOn: $selectQueryTextWhenWindowActivate) } header: { Text("setting.general.input.header") } @@ -163,6 +164,7 @@ struct GeneralTab: View { @Default(.clearInput) private var clearInput @Default(.keepPrevResultWhenEmpty) private var keepPrevResultWhenEmpty + @Default(.selectQueryTextWhenWindowActivate) private var selectQueryTextWhenWindowActivate @Default(.disableEmptyCopyBeep) private var disableEmptyCopyBeep @Default(.autoPlayAudio) private var autoPlayAudio