Skip to content

Commit

Permalink
add setting options
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverAgain11 committed Mar 5, 2024
1 parent e844216 commit 738c278
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Easydict/Feature/PerferenceWindow/EZSettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ @interface EZSettingViewController () <NSComboBoxDelegate>
@property (nonatomic, strong) NSButton *clearInputButton;
@property (nonatomic, strong) NSButton *keepPrevResultButton;
@property (nonatomic, strong) NSButton *selectQueryTextWhenWindowActivateButton;
@property (nonatomic, strong) NSButton *automaticWordSegmentationButton;
@property (nonatomic, strong) NSButton *automaticallyRemoveCodeCommentSymbolsButton;

@property (nonatomic, strong) NSTextField *autoQueryLabel;
@property (nonatomic, strong) NSButton *autoQueryOCRTextButton;
Expand Down Expand Up @@ -415,7 +417,13 @@ - (void)setupUI {
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];


self.automaticWordSegmentationButton = [NSButton checkboxWithTitle:NSLocalizedString(@"automatic_word_segmentation", 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:)];
[self.contentView addSubview:self.automaticallyRemoveCodeCommentSymbolsButton];

NSTextField *autoQueryLabel = [NSTextField labelWithString:NSLocalizedString(@"auto_query", nil)];
autoQueryLabel.font = font;
[self.contentView addSubview:autoQueryLabel];
Expand Down Expand Up @@ -563,6 +571,8 @@ - (void)setupUI {
self.clearInputButton.mm_isOn = self.config.clearInput;
self.keepPrevResultButton.mm_isOn = self.config.keepPrevResultWhenEmpty;
self.selectQueryTextWhenWindowActivateButton.mm_isOn = self.config.selectQueryTextWhenWindowActivate;
self.automaticWordSegmentationButton.mm_isOn = self.config.automaticWordSegmentation;
self.automaticallyRemoveCodeCommentSymbolsButton.mm_isOn = self.config.automaticallyRemoveCodeCommentSymbols;
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 @@ -781,11 +791,22 @@ - (void)updateViewConstraints {
make.left.equalTo(self.clearInputButton);
make.top.equalTo(self.keepPrevResultButton.mas_bottom).offset(self.verticalPadding);
}];

[self.automaticallyRemoveCodeCommentSymbolsButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.clearInputButton);
make.top.equalTo(self.selectQueryTextWhenWindowActivateButton.mas_bottom).offset(self.verticalPadding);
}];

[self.automaticWordSegmentationButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.clearInputButton);
make.top.equalTo(self.automaticallyRemoveCodeCommentSymbolsButton.mas_bottom).offset(self.verticalPadding);
}];

[self.autoQueryLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.autoGetSelectedTextLabel);
make.top.equalTo(self.selectQueryTextWhenWindowActivateButton.mas_bottom).offset(self.verticalPadding);
make.top.equalTo(self.automaticWordSegmentationButton.mas_bottom).offset(self.verticalPadding);
}];

[self.autoQueryOCRTextButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.autoQueryLabel.mas_right).offset(self.horizontalPadding);
make.centerY.equalTo(self.autoQueryLabel);
Expand Down Expand Up @@ -1005,6 +1026,14 @@ - (void)selectQueryTextWhenWindowActivateButtonClicked:(NSButton *)sender {
self.config.selectQueryTextWhenWindowActivate = sender.mm_isOn;
}

- (void)automaticWordSegmentationButtonClicked:(NSButton *)sender {
self.config.automaticWordSegmentation = sender.mm_isOn;
}

- (void)automaticallyRemoveCodeCommentSymbolsButtonClicked:(NSButton *)sender {
self.config.automaticallyRemoveCodeCommentSymbols = sender.mm_isOn;
}

- (void)autoCopySelectedTextButtonClicked:(NSButton *)sender {
self.config.autoCopySelectedText = sender.mm_isOn;
}
Expand Down
4 changes: 4 additions & 0 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ struct GeneralTab: View {
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)
Toggle("automatically_remove_code_comment_symbols", isOn: $automaticallyRemoveCodeCommentSymbols)
Toggle("automatic_word_segmentation", isOn: $automaticWordSegmentation)
} header: {
Text("setting.general.input.header")
}
Expand Down Expand Up @@ -213,6 +215,8 @@ struct GeneralTab: View {
@Default(.clearInput) private var clearInput
@Default(.keepPrevResultWhenEmpty) private var keepPrevResultWhenEmpty
@Default(.selectQueryTextWhenWindowActivate) private var selectQueryTextWhenWindowActivate
@Default(.automaticWordSegmentation) var automaticWordSegmentation: Bool
@Default(.automaticallyRemoveCodeCommentSymbols) var automaticallyRemoveCodeCommentSymbols: Bool

@Default(.disableEmptyCopyBeep) private var disableEmptyCopyBeep
@Default(.autoPlayAudio) private var autoPlayAudio
Expand Down

0 comments on commit 738c278

Please sign in to comment.