Skip to content

Commit

Permalink
feat(Select Translate): make auto select query text behavior when win…
Browse files Browse the repository at this point in the history
…dow got activated a standalone option
  • Loading branch information
yam-liu committed Feb 4, 2024
1 parent a3dbcbf commit 7af6f42
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 38 deletions.
33 changes: 17 additions & 16 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down Expand Up @@ -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" : {
Expand Down
3 changes: 3 additions & 0 deletions Easydict/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 25 additions & 21 deletions Easydict/Feature/PerferenceWindow/EZSettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ @interface EZSettingViewController () <NSComboBoxDelegate>
@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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -558,6 +558,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;
Expand Down Expand Up @@ -759,27 +760,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);
Expand Down Expand Up @@ -991,6 +991,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extension Defaults.Keys {
static let allowAnalytics = Key<Bool>("EZConfiguration_kAllowAnalyticsKey", default: true)
static let clearInput = Key<Bool>("EZConfiguration_kClearInputKey", default: true)
static let keepPrevResultWhenEmpty = Key<Bool>("EZConfiguration_kKeepPrevResultKey", default: true)
static let selectQueryTextWhenWindowActivate = Key<Bool>("EZConfiguration_kSelectQueryTextWhenWindowActivate", default: false)
static let enableBetaNewApp = Key<Bool>("EZConfiguration_kEnableBetaNewAppKey", default: false)

static let enableBetaFeature = Key<Bool>("EZBetaFeatureKey", default: false)
Expand Down
2 changes: 2 additions & 0 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7af6f42

Please sign in to comment.