Skip to content

Commit

Permalink
UserDef // +useShiftQuestionToCallServiceMenu.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Feb 29, 2024
1 parent 85b8cee commit b0bcc1b
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,24 @@ extension InputHandler {
}
}

// MARK: - Flipping pages by using symbol menu keys (when they are not occupied).
// MARK: - Calling Service Menu Key through "Shift+?" (if enabled).

var candidateTextServiceMenuRunning: Bool {
state.node.containsCandidateServices && state.type == .ofSymbolTable
}

serviceMenu: if prefs.useShiftQuestionToCallServiceMenu, input.commonKeyModifierFlags == .shift, input.text == "?" {
if candidateTextServiceMenuRunning { break serviceMenu }
let handled = handleServiceMenuInitiation(
candidateText: highlightedCandidate.value,
reading: highlightedCandidate.keyArray
)
if handled { return true }
}

// MARK: - Flipping pages or Calling Service Menu by the Symbol Menu Key.

if input.isSymbolMenuPhysicalKey {
let candidateTextServiceMenuRunning = state.node.containsCandidateServices && state.type == .ofSymbolTable
switch input.commonKeyModifierFlags {
case .shift, [],
.option where !candidateTextServiceMenuRunning:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ public extension SettingsPanesCocoa {
UserDef.kMoveCursorAfterSelectingCandidate.render(fixWidth: innerContentWidth)
UserDef.kUseDynamicCandidateWindowOrigin.render(fixWidth: innerContentWidth)
UserDef.kDodgeInvalidEdgeCandidateCursorPosition.render(fixWidth: innerContentWidth)
UserDef.kUseShiftQuestionToCallServiceMenu
.render(fixWidth: innerContentWidth) { renderable in
renderable.currentControl?.target = self
renderable.currentControl?.action = #selector(self.performCandidateKeysSanityCheck(_:))
}
UserDef.kUseJKtoMoveCompositorCursorInCandidateState
.render(fixWidth: innerContentWidth) { renderable in
renderable.currentControl?.target = self
renderable.currentControl?.action = #selector(self.useJKToMoveBufferCursorDidSet(_:))
renderable.currentControl?.action = #selector(self.performCandidateKeysSanityCheck(_:))
}
}?.boxed()
NSView()
Expand Down Expand Up @@ -91,7 +96,7 @@ public extension SettingsPanesCocoa {
window.callAlert(title: title.localized, text: explanation.localized)
}

@IBAction func useJKToMoveBufferCursorDidSet(_: NSControl) {
@IBAction func performCandidateKeysSanityCheck(_: NSControl) {
// 利用該變數的 didSet 屬性自糾。
PrefMgr.shared.candidateKeys = PrefMgr.shared.candidateKeys
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public struct VwrSettingsPaneCandidates: View {
@AppStorage(wrappedValue: false, UserDef.kUseJKtoMoveCompositorCursorInCandidateState.rawValue)
private var useJKtoMoveCompositorCursorInCandidateState: Bool

@AppStorage(wrappedValue: true, UserDef.kUseShiftQuestionToCallServiceMenu.rawValue)
public var useShiftQuestionToCallServiceMenu: Bool

@AppStorage(wrappedValue: true, UserDef.kMoveCursorAfterSelectingCandidate.rawValue)
private var moveCursorAfterSelectingCandidate: Bool

Expand Down Expand Up @@ -72,6 +75,12 @@ public struct VwrSettingsPaneCandidates: View {
.disabled(useRearCursorMode)
}
UserDef.kDodgeInvalidEdgeCandidateCursorPosition.bind($dodgeInvalidEdgeCandidateCursorPosition).render()
UserDef.kUseShiftQuestionToCallServiceMenu.bind(
$useShiftQuestionToCallServiceMenu.didChange {
// 利用該變數的 didSet 屬性自糾。
PrefMgr.shared.candidateKeys = PrefMgr.shared.candidateKeys
}
).render()
UserDef.kUseJKtoMoveCompositorCursorInCandidateState.bind(
$useJKtoMoveCompositorCursorInCandidateState.didChange {
// 利用該變數的 didSet 屬性自糾。
Expand Down
3 changes: 3 additions & 0 deletions Packages/vChewing_Shared/Sources/Shared/PrefMgr_Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ import SwiftExtension
@AppProperty(key: UserDef.kUseJKtoMoveCompositorCursorInCandidateState.rawValue, defaultValue: false)
public var useJKtoMoveCompositorCursorInCandidateState: Bool

@AppProperty(key: UserDef.kUseShiftQuestionToCallServiceMenu.rawValue, defaultValue: true)
public var useShiftQuestionToCallServiceMenu: Bool

@AppProperty(key: UserDef.kMoveCursorAfterSelectingCandidate.rawValue, defaultValue: true)
public dynamic var moveCursorAfterSelectingCandidate: Bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import SwiftExtension

public extension PrefMgr {
func validate(candidateKeys: String) -> String? {
let excluded = useJKtoMoveCompositorCursorInCandidateState ? "jk" : ""
var excluded = ""
if useJKtoMoveCompositorCursorInCandidateState { excluded.append("jk") }
if useShiftQuestionToCallServiceMenu { excluded.append("?") }
excluded.append(IMEApp.isKeyboardJIS ? "_" : "`~")
return CandidateKey.validate(keys: candidateKeys, excluding: excluded)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public protocol PrefMgrProtocol {
var shouldAutoReloadUserDataFiles: Bool { get set }
var useRearCursorMode: Bool { get set }
var useJKtoMoveCompositorCursorInCandidateState: Bool { get set }
var useShiftQuestionToCallServiceMenu: Bool { get set }
var moveCursorAfterSelectingCandidate: Bool { get set }
var dodgeInvalidEdgeCandidateCursorPosition: Bool { get set }
var useDynamicCandidateWindowOrigin: Bool { get set }
Expand Down
6 changes: 6 additions & 0 deletions Packages/vChewing_Shared/Sources/Shared/UserDef/UserDef.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum UserDef: String, CaseIterable, Identifiable {
case kShouldAutoReloadUserDataFiles = "ShouldAutoReloadUserDataFiles"
case kUseRearCursorMode = "UseRearCursorMode"
case kUseJKtoMoveCompositorCursorInCandidateState = "UseJKtoMoveCompositorCursorInCandidateState"
case kUseShiftQuestionToCallServiceMenu = "UseShiftQuestionToCallServiceMenu"
case kUseDynamicCandidateWindowOrigin = "UseDynamicCandidateWindowOrigin"
case kUseHorizontalCandidateList = "UseHorizontalCandidateList"
case kChooseCandidateUsingSpace = "ChooseCandidateUsingSpace"
Expand Down Expand Up @@ -180,6 +181,7 @@ public extension UserDef {
case .kShouldAutoReloadUserDataFiles: return .bool
case .kUseRearCursorMode: return .bool
case .kUseJKtoMoveCompositorCursorInCandidateState: return .bool
case .kUseShiftQuestionToCallServiceMenu: return .bool
case .kUseDynamicCandidateWindowOrigin: return .bool
case .kUseHorizontalCandidateList: return .bool
case .kChooseCandidateUsingSpace: return .bool
Expand Down Expand Up @@ -344,6 +346,10 @@ public extension UserDef {
shortTitle: "i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.shortTitle",
description: "i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.description"
)
case .kUseShiftQuestionToCallServiceMenu: return .init(
userDef: self,
shortTitle: "i18n:UserDef.kUseShiftQuestionToCallServiceMenu.shortTitle"
)
case .kUseDynamicCandidateWindowOrigin: return .init(
userDef: self, shortTitle: "Adjust candidate window location according to current node length"
)
Expand Down
1 change: 1 addition & 0 deletions Source/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
"i18n:UserDef.kSpecifyCmdOptCtrlEnterBehavior.shortTitle" = "Command+Option+Ctrl+Enter:";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.description" = "⚠︎ This will automatically prevent J and K from being used as candidate keys. Also, this won't work with ‘%quick’ candidates in cassette mode.";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.shortTitle" = "Use J / K to Move Buffer Cursor While Choosing Candidates";
"i18n:UserDef.kUseShiftQuestionToCallServiceMenu.shortTitle" = "Also use Shift+? to call Service Menu in Candidate Window";
"IBM" = "IBM";
"If disabled, this will insert space instead." = "If disabled, this will insert space instead.";
"If not filling the weight, it will be 0.0, the maximum one. An ideal weight situates in [-9.5, 0], making itself can be captured by the walking algorithm. The exception is -114.514, the disciplinary weight. The walking algorithm will ignore it unless it is the unique result." = "If not filling the weight, it will be 0.0, the maximum one. An ideal weight situates in [-9.5, 0], making itself can be captured by the walking algorithm. The exception is -114.514, the disciplinary weight. The walking algorithm will ignore it unless it is the unique result.";
Expand Down
1 change: 1 addition & 0 deletions Source/Resources/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
"i18n:UserDef.kSpecifyCmdOptCtrlEnterBehavior.shortTitle" = "Command+Option+Ctrl+Enter:";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.description" = "⚠︎ これで「J / K」キーは言選り用キー陣列から自動的に外されます。尚、この機能はカセットモードの「%quick」による早速候補入力状態では利用できません。";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.shortTitle" = "候補陳列が見えるとき、「J / K」キーで入力緩衝列のカーソルを移す";
"i18n:UserDef.kUseShiftQuestionToCallServiceMenu.shortTitle" = "候補陳列ウィンドウで「Shift+?」でもサービスメニューを呼出";
"IBM" = "IBM 配列";
"If disabled, this will insert space instead." = "未チェックの場合、スペースを挿入。";
"If not filling the weight, it will be 0.0, the maximum one. An ideal weight situates in [-9.5, 0], making itself can be captured by the walking algorithm. The exception is -114.514, the disciplinary weight. The walking algorithm will ignore it unless it is the unique result." = "優先度を記入しなかった場合、最高値「0」はデフォルト値です。理想な優先度の範囲は [-9.5, 0] 以内で、ウォーキング算法に捕まれられます。例外は懲戒値「-114.514」で、優先度を最低に極めた値であり、唯一結果のない場合、ウォーキング算法に無視されます。";
Expand Down
1 change: 1 addition & 0 deletions Source/Resources/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
"i18n:UserDef.kSpecifyCmdOptCtrlEnterBehavior.shortTitle" = "Command+Option+Ctrl+Enter:";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.description" = "⚠︎ 这将自动禁止 J / K 键用作选字键。另外,该功能在磁带模式的“%quick”快速选字状态下无效。";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.shortTitle" = "在选字窗显示时允许以 J / K 键移动组字区游标";
"i18n:UserDef.kUseShiftQuestionToCallServiceMenu.shortTitle" = "允许在选字窗内也使用「Shift+?」叫出服务选单";
"IBM" = "IBM 排列";
"If disabled, this will insert space instead." = "取消勾选的话,该按键会插入空格。";
"If not filling the weight, it will be 0.0, the maximum one. An ideal weight situates in [-9.5, 0], making itself can be captured by the walking algorithm. The exception is -114.514, the disciplinary weight. The walking algorithm will ignore it unless it is the unique result." = "不填写权重的话,预设权重为最高值「0」。理想的权重范围在 [-9.5, 0] 这个闭区间内,可以被爬轨算法自动抓到。例外就是惩戒权重「-114.514」,属于极端降权。这种情况下,除非是唯一结果,否则会被爬轨算法忽略掉。";
Expand Down
1 change: 1 addition & 0 deletions Source/Resources/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
"i18n:UserDef.kSpecifyCmdOptCtrlEnterBehavior.shortTitle" = "Command+Option+Ctrl+Enter:";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.description" = "⚠︎ 這將自動禁止 J / K 鍵用作選字鍵。另外,該功能在磁帶模式的「%quick」快速選字狀態下無效。";
"i18n:UserDef.kUseJKtoMoveCompositorCursorInCandidateState.shortTitle" = "在選字窗顯示時允許以 J / K 鍵移動組字區游標";
"i18n:UserDef.kUseShiftQuestionToCallServiceMenu.shortTitle" = "允許在選字窗內也使用「Shift+?」叫出服務選單";
"IBM" = "IBM 排列";
"If disabled, this will insert space instead." = "取消勾選的話,該按鍵會插入空格。";
"If not filling the weight, it will be 0.0, the maximum one. An ideal weight situates in [-9.5, 0], making itself can be captured by the walking algorithm. The exception is -114.514, the disciplinary weight. The walking algorithm will ignore it unless it is the unique result." = "不填寫權重的話,預設權重為最高值「0」。理想的權重範圍在 [-9.5, 0] 這個閉區間內,可以被爬軌算法自動抓到。例外就是懲戒權重「-114.514」,屬於極端降權。這種情況下,除非是唯一結果,否則會被爬軌算法忽略掉。";
Expand Down

0 comments on commit b0bcc1b

Please sign in to comment.