Skip to content

Commit

Permalink
Merge branch 'dev' into shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaShark committed Feb 4, 2024
2 parents 979aee1 + 8251db7 commit f42b3c4
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 34 deletions.
17 changes: 17 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
0A8685C82B552A590022534F /* DisabledAppTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8685C72B552A590022534F /* DisabledAppTab.swift */; };
0AC11B222B4D16A500F07198 /* WindowAccessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC11B212B4D16A500F07198 /* WindowAccessor.swift */; };
0AC11B242B4E46B300F07198 /* TapHandlerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AC11B232B4E46B300F07198 /* TapHandlerView.swift */; };
0AC8A84F2B6DFDD4006DA5CC /* SettingsAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 0AC8A84E2B6DFDD4006DA5CC /* SettingsAccess */; };
17BCAEF72B0DFF9000A7D372 /* EZNiuTransTranslateResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 17BCAEF52B0DFF9000A7D372 /* EZNiuTransTranslateResponse.m */; };
17BCAEF82B0DFF9000A7D372 /* EZNiuTransTranslate.m in Sources */ = {isa = PBXBuildFile; fileRef = 17BCAEF62B0DFF9000A7D372 /* EZNiuTransTranslate.m */; };
2721E4D02AFE920700A059AC /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 2721E4CF2AFE920700A059AC /* Alamofire */; };
Expand Down Expand Up @@ -834,6 +835,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0AC8A84F2B6DFDD4006DA5CC /* SettingsAccess in Frameworks */,
03022F192B3591AE00B63209 /* GoogleGenerativeAI in Frameworks */,
2721E4D02AFE920700A059AC /* Alamofire in Frameworks */,
03022F1F2B36CF3100B63209 /* SwiftShell in Frameworks */,
Expand Down Expand Up @@ -2484,6 +2486,7 @@
EA3B81FB2B52555C004C0E8B /* Defaults */,
967712E92B5B913600105E0F /* KeyHolder */,
03022F182B3591AE00B63209 /* GoogleGenerativeAI */,
0AC8A84E2B6DFDD4006DA5CC /* SettingsAccess */,
);
productName = Bob;
productReference = C99EEB182385796700FEE666 /* Easydict-debug.app */;
Expand Down Expand Up @@ -2545,6 +2548,7 @@
EA3B81FA2B52555C004C0E8B /* XCRemoteSwiftPackageReference "Defaults" */,
967712E82B5B913600105E0F /* XCRemoteSwiftPackageReference "KeyHolder" */,
03022F172B3591AE00B63209 /* XCRemoteSwiftPackageReference "generative-ai-swift" */,
0AC8A84D2B6DFDD4006DA5CC /* XCRemoteSwiftPackageReference "SettingsAccess" */,
);
productRefGroup = C99EEB192385796700FEE666 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3538,6 +3542,14 @@
minimumVersion = 1.8.0;
};
};
0AC8A84D2B6DFDD4006DA5CC /* XCRemoteSwiftPackageReference "SettingsAccess" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/orchetect/SettingsAccess";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.4.0;
};
};
2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Alamofire/Alamofire.git";
Expand Down Expand Up @@ -3640,6 +3652,11 @@
package = 03FD68B92B1DC59600FD388E /* XCRemoteSwiftPackageReference "CryptoSwift" */;
productName = CryptoSwift;
};
0AC8A84E2B6DFDD4006DA5CC /* SettingsAccess */ = {
isa = XCSwiftPackageProductDependency;
package = 0AC8A84D2B6DFDD4006DA5CC /* XCRemoteSwiftPackageReference "SettingsAccess" */;
productName = SettingsAccess;
};
2721E4CF2AFE920700A059AC /* Alamofire */ = {
isa = XCSwiftPackageProductDependency;
package = 2721E4CE2AFE920700A059AC /* XCRemoteSwiftPackageReference "Alamofire" */;
Expand Down
9 changes: 9 additions & 0 deletions Easydict.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@
"version" : "2.4.0"
}
},
{
"identity" : "settingsaccess",
"kind" : "remoteSourceControl",
"location" : "https://github.com/orchetect/SettingsAccess",
"state" : {
"revision" : "0fd73c8b5892e88acb13adb7f36a4ba9293a0061",
"version" : "1.4.0"
}
},
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
Expand Down
67 changes: 51 additions & 16 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -652,22 +652,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 @@ -1565,6 +1549,40 @@
}
}
},
"keep_prev_result_when_selected_text_is_empty" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Keep previous result when selected text is empty"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "划词翻译未选中文本时,保留上次结果"
}
}
}
},
"keep_result" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Keep Result:"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "保留结果:"
}
}
}
},
"language_detect_optimize" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -2364,6 +2382,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
6 changes: 6 additions & 0 deletions Easydict/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ let kHideMenuBarIconKey = "EZConfiguration_kHideMenuBarIconKey"
@DefaultsWrapper(.clearInput)
var clearInput: Bool

@DefaultsWrapper(.keepPrevResultWhenEmpty)
var keepPrevResultWhenEmpty: Bool

@DefaultsWrapper(.selectQueryTextWhenWindowActivate)
var selectQueryTextWhenWindowActivate: Bool

var disabledAutoSelect: Bool = false

var isRecordingSelectTextShortcutKey: Bool = false
Expand Down
1 change: 1 addition & 0 deletions Easydict/Feature/Configuration/EZConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef NS_ENUM(NSUInteger, EZAppearenceType) {
@property (nonatomic, assign) BOOL allowCrashLog;
@property (nonatomic, assign) BOOL allowAnalytics;
@property (nonatomic, assign) BOOL clearInput;
@property (nonatomic, assign) BOOL keepPrevResult;

// TODO: Need to move them. These are read/write properties only and will not be stored locally, only for external use.
/// Only use when showing NSOpenPanel to select disabled apps.
Expand Down
10 changes: 10 additions & 0 deletions Easydict/Feature/Configuration/EZConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
static NSString *const kAllowCrashLogKey = @"EZConfiguration_kAllowCrashLogKey";
static NSString *const kAllowAnalyticsKey = @"EZConfiguration_kAllowAnalyticsKey";
static NSString *const kClearInputKey = @"EZConfiguration_kClearInputKey";
static NSString *const kKeepPrevResultKey = @"EZConfiguration_kKeepPrevResultKey";
static NSString *const kTranslationControllerFontKey = @"EZConfiguration_kTranslationControllerFontKey";
static NSString *const kApperanceKey = @"EZConfiguration_kApperanceKey";

Expand Down Expand Up @@ -126,6 +127,7 @@ - (void)setup {
self.allowCrashLog = [NSUserDefaults mm_readBool:kAllowCrashLogKey defaultValue:YES];
self.allowAnalytics = [NSUserDefaults mm_readBool:kAllowAnalyticsKey defaultValue:YES];
self.clearInput = [NSUserDefaults mm_readBool:kClearInputKey defaultValue:NO];
self.keepPrevResult = [NSUserDefaults mm_readBool:kKeepPrevResultKey defaultValue:YES];

self.fontSizes = @[@(1), @(1.1), @(1.2), @(1.3), @(1.4)];
[[NSUserDefaults standardUserDefaults]registerDefaults:@{kTranslationControllerFontKey: @(0)}];
Expand Down Expand Up @@ -432,6 +434,14 @@ - (void)setClearInput:(BOOL)clearInput {
[self logSettings:@{@"clear_input" : @(clearInput)}];
}

- (void)setKeepPrevResult:(BOOL)keepPrevResult {
_keepPrevResult = keepPrevResult;

[NSUserDefaults mm_write:@(keepPrevResult) forKey:kKeepPrevResultKey];

[self logSettings:@{@"keep_prev_result": @(keepPrevResult)}];
}

- (void)setFontSizeIndex:(NSInteger)fontSizeIndex {
NSInteger targetIndex = MIN(_fontSizes.count-1, MAX(fontSizeIndex, 0));

Expand Down
48 changes: 38 additions & 10 deletions Easydict/Feature/PerferenceWindow/EZSettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +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) NSButton *keepPrevResultButton;
@property (nonatomic, strong) NSButton *selectQueryTextWhenWindowActivateButton;

@property (nonatomic, strong) NSTextField *autoQueryLabel;
@property (nonatomic, strong) NSButton *autoQueryOCRTextButton;
Expand Down Expand Up @@ -395,14 +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];

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 @@ -546,6 +557,8 @@ - (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 @@ -747,19 +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.keepPrevResultButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.clearInputButton);
make.top.equalTo(self.clearInputButton.mas_bottom).offset(self.verticalPadding);
}];
[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.clearInputButton.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 @@ -967,6 +987,14 @@ - (void)clearInputButtonClicked:(NSButton *)sender {
self.config.clearInput = sender.mm_isOn;
}

- (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,6 +527,9 @@ - (void)focusInputTextView {
[NSApp activateIgnoringOtherApps:YES];

[self.baseQueryWindow makeFirstResponder:self.queryView.textView];
if (Configuration.shared.selectQueryTextWhenWindowActivate) {
self.queryView.textView.selectedRange = NSMakeRange(0, self.inputText.length);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,6 @@ - (void)showFloatingWindow:(EZBaseQueryWindow *)window atPoint:(CGPoint)point {
[window.queryViewController focusInputTextView];

[self updateFloatingWindowType:window.windowType];

// mainWindow has been ordered out before, so we need to order back.
if ([EZMainQueryWindow isAlive]) {
[self.mainWindow orderBack:nil];
}
}

- (void)updateFloatingWindowType:(EZWindowType)floatingWindowType {
Expand Down Expand Up @@ -694,9 +689,14 @@ - (void)selectTextTranslate {
NSLog(@"selectTextTranslate windowType: %@", @(windowType));
self.eventMonitor.actionType = EZActionTypeShortcutQuery;
[self.eventMonitor getSelectedText:^(NSString *_Nullable text) {
// If text is nil, currently, we choose to clear input.
self.selectedText = [text trim] ?: @"";
self.actionType = self.eventMonitor.actionType;

// Clear query if text is nil and user don't want to keep the last result.
if (!text && !Configuration.shared.keepPrevResultWhenEmpty) {
text = @"";
}
self.selectedText = [text trim];

[self showFloatingWindowType:windowType queryText:self.selectedText];
}];
}
Expand Down
2 changes: 2 additions & 0 deletions Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ extension Defaults.Keys {
static let allowCrashLog = Key<Bool>("EZConfiguration_kAllowCrashLogKey", default: true)
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
11 changes: 10 additions & 1 deletion Easydict/NewApp/View/MenuItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2023 izual. All rights reserved.
//

import SettingsAccess
import Sparkle
import SwiftUI
import ZipArchive
Expand Down Expand Up @@ -92,10 +93,18 @@ struct MenuItemView: View {
@ViewBuilder
private var settingItem: some View {
if #available(macOS 14.0, *) {
SettingsLink()
SettingsLink {
Text("Settings...")
} preAction: {
NSLog("打开设置")
NSApp.activate(ignoringOtherApps: true)
} postAction: {
// nothing to do
}
} else {
Button("Settings...") {
NSLog("打开设置")
NSApp.activate(ignoringOtherApps: true)
NSApplication.shared.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
}
}
Expand Down
Loading

0 comments on commit f42b3c4

Please sign in to comment.