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

Feature alter #425

Merged
merged 16 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
21 changes: 19 additions & 2 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "请确保已设置了触发 Easydict 的快捷!\n\n如需恢复,请在查词窗口使用快捷键 `Cmd + ,` 打开设置页,然后取消【隐藏菜单栏图标】选项。"
"value" : "请确保已设置了触发 Easydict 的快捷键!\n\n如需恢复,请在查词窗口使用快捷键 `Cmd + ,` 打开设置页,然后取消【隐藏菜单栏图标】选项。"
AkaShark marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -1775,7 +1775,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "反馈"
}
}
Expand Down Expand Up @@ -2334,6 +2334,23 @@
}
}
},
"refuse_hide_menu_bar_icon_msg" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Now Detected that there is not set input translation shortcut key or selection translation shortcut key!\n\nSet the shortcut key to make sure you can go Easydict and hide the menu bar icon."
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "检测到当前未设置输入翻译快捷键或划词翻译快捷键!\n\n请先设置快捷键确保可以触发 Easydict 再隐藏菜单栏图标"
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
},
"replace_text" : {
"localizations" : {
"en" : {
Expand Down
11 changes: 11 additions & 0 deletions Easydict/Feature/PerferenceWindow/EZSettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,17 @@ - (void)showAppleDictionaryQuickLinkButtonClicked:(NSButton *)sender {


- (void)hideMenuBarIconButtonClicked:(NSButton *)sender {
// if user not set select shortcut and input shortcut not allow hidden menu bar icon
if (self.selectionShortcutView.shortcutValue == nil &&
self.inputShortcutView.shortcutValue == nil) {
sender.mm_isOn = NO;
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:NSLocalizedString(@"ok", nil)];
alert.messageText = NSLocalizedString(@"hide_menu_bar_icon", nil);
alert.informativeText = NSLocalizedString(@"refuse_hide_menu_bar_icon_msg", nil);
[alert beginSheetModalForWindow:[self window] completionHandler:nil];
return;
}
// !!!: EZFloatingWindowLevel shouldn't be higher than kCGModalPanelWindowLevel (8)
if (sender.mm_isOn) {
NSAlert *alert = [[NSAlert alloc] init];
Expand Down
45 changes: 43 additions & 2 deletions Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import SwiftUI
@available(macOS 13, *)
struct GeneralTab: View {
@Environment(\.colorScheme) var colorScheme

var body: some View {
Form {
Section {
Expand Down Expand Up @@ -137,7 +136,17 @@ struct GeneralTab: View {
Toggle(isOn: $hideMainWindow) {
Text("hide_main_window")
}
Toggle(isOn: $hideMenuBarIcon) {
Toggle(isOn: $hideMenuBarIcon.didSet(execute: { state in
if state {
// user is not set input shortcut and selection shortcut not allow hide menu bar
if !detectSetShortcutStatus {
Defaults[.hideMenuBarIcon] = false
showRefuseAlert = true
} else {
showHideMenuBarIconAlert = true
}
}
})) {
Text("hide_menu_bar_icon")
}
Picker(
Expand All @@ -155,6 +164,25 @@ struct GeneralTab: View {
}
}
.formStyle(.grouped)
.alert("hide_menu_bar_icon", isPresented: $showRefuseAlert) {
Button("ok") {
showRefuseAlert = false
}
} message: {
Text("refuse_hide_menu_bar_icon_msg")
}
.alert("hide_menu_bar_icon", isPresented: $showHideMenuBarIconAlert) {
HStack {
Button("ok") {
showHideMenuBarIconAlert = false
}
Button("cancel") {
Defaults[.hideMenuBarIcon] = false
}
}
} message: {
Text("hide_menu_bar_icon_msg")
}
}

@Default(.autoSelectText) private var autoSelectText
Expand Down Expand Up @@ -197,6 +225,19 @@ struct GeneralTab: View {

@Default(.fontSizeOptionIndex) private var fontSizeOptionIndex
@Default(.selectedMenuBarIcon) private var selectedMenuBarIcon

private var detectSetShortcutStatus: Bool {
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
if Defaults[.inputShortcut] == nil,
Defaults[.selectionShortcut] == nil
{
false
} else {
true
}
}

@State private var showRefuseAlert: Bool = false
AkaShark marked this conversation as resolved.
Show resolved Hide resolved
@State private var showHideMenuBarIconAlert = false
}

@available(macOS 13, *)
Expand Down