Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings to shortcuts #416

Merged
merged 34 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d36ff43
add button and menu
NeverAgain11 Feb 20, 2024
ae816e4
add action to the menu
NeverAgain11 Feb 21, 2024
ccd1dc3
replace setting icon
NeverAgain11 Feb 21, 2024
e3c37dd
Merge branch 'dev' into add_setting_icon_to_shortcuts
tisfeng Feb 21, 2024
c930758
Update Easydict/App/Localizable.xcstrings
NeverAgain11 Feb 22, 2024
2ec768a
Update Easydict/App/Localizable.xcstrings
NeverAgain11 Feb 22, 2024
deb8785
Update Easydict/App/Localizable.xcstrings
NeverAgain11 Feb 22, 2024
57ee6b0
Fix the setting button frame and set the color for light and dark mode.
NeverAgain11 Feb 22, 2024
9206a42
fix: open settings in appKit
phlpsong Feb 22, 2024
faa70aa
fix: conflicts with NSAppleEventManager issue
phlpsong Feb 23, 2024
f3fe566
fix: check os when open settings
phlpsong Feb 23, 2024
bcf739c
fix: optimize logic
phlpsong Feb 23, 2024
7bc4bf4
Merge pull request #1 from phlpsong/open_settings_appkit
NeverAgain11 Feb 23, 2024
51ac703
allows hiding the setting icon.
NeverAgain11 Feb 23, 2024
2ceeefd
Merge branch 'dev' into add_setting_icon_to_shortcuts
tisfeng Feb 23, 2024
fb8be8a
perf: improve quick action menu item title
tisfeng Feb 23, 2024
9946f2a
Merge branch 'dev' into add_setting_icon_to_shortcuts
tisfeng Feb 25, 2024
f1e65bd
Merge branch 'dev' into add_setting_icon_to_shortcuts
phlpsong Feb 25, 2024
dac93f0
Merge branch 'dev' into add_setting_icon_to_shortcuts
NeverAgain11 Feb 25, 2024
9abef85
Merge branch 'dev' into add_setting_icon_to_shortcuts
tisfeng Feb 26, 2024
b3eb427
perf: update Localizable.xcstrings
tisfeng Feb 27, 2024
e5d9dc4
perf(UI): change quick setting button tint color to light blue
tisfeng Feb 27, 2024
ab77224
Merge branch 'dev' into add_setting_icon_to_shortcuts
tisfeng Feb 27, 2024
c9d60ce
Merge remote-tracking branch 'tisfeng/dev' into add_setting_icon_to_s…
NeverAgain11 Mar 2, 2024
196b74b
Revert "perf(UI): change quick setting button tint color to light blue"
NeverAgain11 Mar 2, 2024
e844216
Change the actions in the quick settings.
NeverAgain11 Mar 5, 2024
738c278
add setting options
NeverAgain11 Mar 5, 2024
c95d8c9
Merge remote-tracking branch 'tisfeng/dev' into add_setting_icon_to_s…
NeverAgain11 Mar 5, 2024
941e263
Merge branch 'dev' into add_setting_icon_to_shortcuts
tisfeng Mar 5, 2024
3ff7fed
perf: improve handling title bar action
tisfeng Mar 6, 2024
f8e8116
perf: move handleInputText to NSString category
tisfeng Mar 6, 2024
f261da3
update Localizable.xcstrings
NeverAgain11 Mar 7, 2024
9c5bf73
perf: update Localizable.xcstrings
tisfeng Mar 7, 2024
b4cf1f1
Merge branch 'dev' into add_setting_icon_to_shortcuts
tisfeng Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,38 @@
}
}
},
"automatic_word_segmentation" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "English word auto-splitting"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "英语单词自动分词"
}
}
}
},
"automatically_remove_code_comment_symbols" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Automatically remove code comment symbols"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "自动去除代码注释符号"
}
}
}
},
"avoid_conflict_with_PopClip_display" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1366,6 +1398,22 @@
}
}
},
"go_to_settings" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Go to Settings"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "前往设置"
}
}
}
},
"google_translate" : {
"localizations" : {
"en" : {
Expand Down
6 changes: 6 additions & 0 deletions Easydict/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ let kHideMenuBarIconKey = "EZConfiguration_kHideMenuBarIconKey"
@DefaultsWrapper(.selectQueryTextWhenWindowActivate)
var selectQueryTextWhenWindowActivate: Bool

@DefaultsWrapper(.automaticWordSegmentation)
var automaticWordSegmentation: Bool

@DefaultsWrapper(.automaticallyRemoveCodeCommentSymbols)
var automaticallyRemoveCodeCommentSymbols: Bool

var disabledAutoSelect: Bool = false

var isRecordingSelectTextShortcutKey: Bool = false
Expand Down
22 changes: 12 additions & 10 deletions Easydict/Feature/ViewController/Model/EZQueryModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,22 @@ - (NSString *)handleInputText:(NSString *)inputText {

_anchoredDraggable_State --> anchored Draggable State
*/
if ([queryText isSingleWord]) {
// If text is an English word, like LaTeX, we don't split it.
BOOL isEnglishWord = [EZAppleDictionary.shared queryDictionaryForText:queryText language:EZLanguageEnglish];
if (!isEnglishWord) {
// If text has quotes, like 'UIKit', we don't split it.
if ([queryText hasQuotesPair]) {
queryText = [queryText tryToRemoveQuotes];
} else {
queryText = [queryText splitCodeText];
if (Configuration.shared.automaticWordSegmentation) {
if ([queryText isSingleWord]) {
// If text is an English word, like LaTeX, we don't split it.
BOOL isEnglishWord = [EZAppleDictionary.shared queryDictionaryForText:queryText language:EZLanguageEnglish];
if (!isEnglishWord) {
// If text has quotes, like 'UIKit', we don't split it.
if ([queryText hasQuotesPair]) {
queryText = [queryText tryToRemoveQuotes];
} else {
queryText = [queryText splitCodeText];
}
}
}
}

if (Configuration.shared.beta) {
if (Configuration.shared.automaticallyRemoveCodeCommentSymbols) {
// Remove prefix [//,#,*,] and join texts.
queryText = [queryText removeCommentBlockSymbols];
NeverAgain11 marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
2 changes: 2 additions & 0 deletions Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, strong) EZOpenLinkButton *favoriteButton;

@property (nonatomic, strong) EZOpenLinkButton *settingButton;

@end

NS_ASSUME_NONNULL_END
108 changes: 82 additions & 26 deletions Easydict/Feature/ViewController/View/Titlebar/EZTitlebar.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
#import "EZBaseQueryWindow.h"
#import "EZConfiguration.h"
#import "Easydict-Swift.h"
#import "EZPreferencesWindowController.h"

@interface EZTitlebar ()

@property (nonatomic, strong) NSStackView *stackView;

@end

@implementation EZTitlebar
Expand Down Expand Up @@ -64,7 +67,26 @@ - (void)setup {
}
}];

[self setupSettingButton];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConstraints) name:EZQuickLinkButtonUpdateNotification object:nil];

}

- (void)setupSettingButton {
EZOpenLinkButton *button = [[EZOpenLinkButton alloc] init];
NSImage *image = [[NSImage imageWithSystemSymbolName:@"switch.2" accessibilityDescription:nil]imageWithSymbolConfiguration:[NSImageSymbolConfiguration configurationWithScale:NSImageSymbolScaleLarge]];

button.image = image;
self.settingButton = button;
button.clickBlock = nil;
NeverAgain11 marked this conversation as resolved.
Show resolved Hide resolved

mm_weakify(self);
[button setMouseUpBlock:^(EZButton *_Nonnull button) {
mm_strongify(self);
[self showMenu];

}];
}

- (void)updateConstraints {
Expand All @@ -82,15 +104,25 @@ - (void)updateConstraints {
make.top.equalTo(self).offset(EZTitlebarHeight_28 - pinButtonWidth);
}];

[self.googleButton removeFromSuperview];
[self.eudicButton removeFromSuperview];
[self.appleDictionaryButton removeFromSuperview];
for (NSView *view in self.stackView.arrangedSubviews) {
[self.stackView removeArrangedSubview:view];
[view removeFromSuperview];
}
[self.stackView removeFromSuperview];

self.stackView = [[NSStackView alloc] init];
self.stackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
self.stackView.spacing = kButtonPadding_4;
self.stackView.alignment = NSLayoutAttributeCenterY;
[self addSubview:self.stackView];

NSView *lastView;
CGFloat quickLinkButtonTopOffset = EZTitlebarHeight_28 - kButtonWidth_24;
CGFloat quickLinkButtonRightOffset = 12;

// TODO: We should refactor it later.
[self.stackView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(quickLinkButtonTopOffset);
make.right.equalTo(self).offset(-quickLinkButtonRightOffset);
}];

// Google
if (Configuration.shared.showGoogleQuickLink) {
Expand All @@ -105,15 +137,10 @@ - (void)updateConstraints {
googleButton.contentTintColor = NSColor.clearColor;

[googleButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(quickLinkButtonTopOffset);
make.size.mas_equalTo(buttonSize);
if (lastView) {
make.right.equalTo(lastView.mas_left).offset(-kButtonPadding_4);
} else {
make.right.equalTo(self).offset(-quickLinkButtonRightOffset);
}
}];
lastView = googleButton;

[self.stackView addArrangedSubview:googleButton];
}

// Apple Dictionary
Expand All @@ -129,15 +156,9 @@ - (void)updateConstraints {
appleDictButton.contentTintColor = NSColor.clearColor;

[appleDictButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(quickLinkButtonTopOffset);
make.size.mas_equalTo(buttonSize);
if (lastView) {
make.right.equalTo(lastView.mas_left).offset(-kButtonPadding_4);
} else {
make.right.equalTo(self).offset(-quickLinkButtonRightOffset);
}
}];
lastView = appleDictButton;
[self.stackView insertArrangedSubview:appleDictButton atIndex:0];
}

// Eudic
Expand All @@ -158,18 +179,17 @@ - (void)updateConstraints {
eudicButton.contentTintColor = NSColor.clearColor;

[eudicButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(quickLinkButtonTopOffset);
make.size.mas_equalTo(buttonSize);
if (lastView) {
make.right.equalTo(lastView.mas_left).offset(-kButtonPadding_4);
} else {
make.right.equalTo(self).offset(-quickLinkButtonRightOffset);
}
}];
lastView = eudicButton;
[self.stackView insertArrangedSubview:eudicButton atIndex:0];
}
}

[self.settingButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(buttonSize);
}];
[self.stackView addArrangedSubview:self.settingButton];

[super updateConstraints];
}

Expand Down Expand Up @@ -199,6 +219,42 @@ - (void)updatePinButtonImage {
}];
}

- (void)showMenu {
NSMenu * menu = [[NSMenu alloc]initWithTitle:@"Menu"];
NSMenuItem * item1 = [[NSMenuItem alloc]initWithTitle:NSLocalizedString(@"automatically_remove_code_comment_symbols", nil) action:@selector(clickAutomaticallyRemoveCodeCommentSymbols) keyEquivalent:@""];
item1.target = self;
if (Configuration.shared.automaticallyRemoveCodeCommentSymbols) {
item1.state = NSControlStateValueOn;
}

NSMenuItem * item2 = [[NSMenuItem alloc]initWithTitle:NSLocalizedString(@"automatic_word_segmentation", nil) action:@selector(clickAutomaticWordSegmentation) keyEquivalent:@""];
NeverAgain11 marked this conversation as resolved.
Show resolved Hide resolved
item2.target = self;
if (Configuration.shared.automaticWordSegmentation) {
item2.state = NSControlStateValueOn;
}

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 popUpMenuPositioningItem:nil atLocation:[NSEvent mouseLocation] inView:nil];
}

- (void)clickAutomaticallyRemoveCodeCommentSymbols {
Configuration.shared.automaticallyRemoveCodeCommentSymbols = !Configuration.shared.automaticallyRemoveCodeCommentSymbols;
}

- (void)clickAutomaticWordSegmentation {
Configuration.shared.automaticWordSegmentation = !Configuration.shared.automaticWordSegmentation;
}

- (void)goToSettings {
[EZPreferencesWindowController.shared show];
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
}

#pragma mark - Setter && Getter

Expand Down
3 changes: 3 additions & 0 deletions Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ extension Defaults.Keys {
static let appearanceType = Key<AppearenceType>("EZConfiguration_kApperanceKey", default: .followSystem)
static let fontSizeOptionIndex = Key<UInt>("EZConfiguration_kTranslationControllerFontKey", default: 0)
static let selectedMenuBarIcon = Key<MenuBarIconType>("EZConfiguration_kSelectedMenuBarIconKey", default: .square)

static let automaticWordSegmentation = Key<Bool>("EZConfiguration_kAutomaticWordSegmentation", default: true)
static let automaticallyRemoveCodeCommentSymbols = Key<Bool>("EZConfiguration_kAutomaticallyRemoveCodeCommentSymbols", default: true)
}

extension Defaults.Keys {
Expand Down