Skip to content

Commit

Permalink
Feature alter (#425)
Browse files Browse the repository at this point in the history
* feat: refuse hidden menu bar icon in old mode

* feat: hide menu bar in new mode

* chore: chore code

* fix: typo in hide menubar prompt

* Update Easydict/App/Localizable.xcstrings

Co-authored-by: phlpsong <103433299+phlpsong@users.noreply.github.com>

* Update Easydict/App/Localizable.xcstrings

Co-authored-by: phlpsong <103433299+phlpsong@users.noreply.github.com>

* fix: fix review localizable string

* fix: fix localizable string

* pref:  shortcut set up status func name

* Update Easydict/NewApp/View/SettingView/Tabs/GeneralTab.swift

Co-authored-by: phlpsong <103433299+phlpsong@users.noreply.github.com>

* Update Easydict/App/Localizable.xcstrings

Co-authored-by: Tisfeng <tisfeng@gmail.com>

* Update Easydict/App/Localizable.xcstrings

Co-authored-by: Tisfeng <tisfeng@gmail.com>

---------

Co-authored-by: Jerry <89069957+Jerry23011@users.noreply.github.com>
Co-authored-by: Tisfeng <tisfeng@gmail.com>
Co-authored-by: phlpsong <103433299+phlpsong@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 26, 2024
1 parent c9f735a commit ff5c7a1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
21 changes: 19 additions & 2 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1445,13 +1445,13 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Make sure you have set up a shortcut to trigger Easydict!\n\nIf you want to restore, open the settings page in the query window using the shortcut `Cmd + ,`, then cancel the [Hide Status Bar Icon] option."
"value" : "If you want to restore, open the settings page in the query window using the shortcut `Cmd + ,` then cancel the [Hide Status Bar Icon] option."
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "请确保已设置了触发 Easydict 的快捷!\n\n如需恢复,请在查词窗口使用快捷键 `Cmd + ,` 打开设置页,然后取消【隐藏菜单栏图标】选项。"
"value" : "如需恢复,请在查词窗口使用快捷键 `Cmd + ,` 打开设置页,然后取消【隐藏菜单栏图标】选项。"
}
}
}
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 再隐藏菜单栏图标。"
}
}
}
},
"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
39 changes: 37 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 !shortcutsHaveSetuped {
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,13 @@ struct GeneralTab: View {

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

private var shortcutsHaveSetuped: Bool {
Defaults[.inputShortcut] != nil || Defaults[.selectionShortcut] != nil
}

@State private var showRefuseAlert = false
@State private var showHideMenuBarIconAlert = false
}

@available(macOS 13, *)
Expand Down

0 comments on commit ff5c7a1

Please sign in to comment.