-
-
Notifications
You must be signed in to change notification settings - Fork 44
feat: いい感じ変換の設定をMagic Conversionウィンドウに統合 #265
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
base: main
Are you sure you want to change the base?
Changes from all commits
5395031
cba5a90
c7de270
dbc082c
0dfa86d
a17702a
4a9de06
b8c3d5a
52290e2
c583cd6
4a7d563
79812ba
8d8b4d2
81bd30b
2c7607c
37144ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import Cocoa | ||
|
|
||
| /// キーボードショートカットを表す構造体 | ||
| public struct KeyboardShortcut: Codable, Equatable, Hashable, Sendable { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 入れてもいいんだけど将来的になんか困りそうじゃない?そうでもないか?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. うーん?具体的なシナリオってある? |
||
| public var key: String | ||
| public var modifiers: EventModifierFlags | ||
|
|
||
| public init(key: String, modifiers: EventModifierFlags) { | ||
| self.key = key | ||
| self.modifiers = modifiers | ||
| } | ||
|
|
||
| /// デフォルトのショートカット(Control+S) | ||
| public static let defaultTransformShortcut = KeyboardShortcut( | ||
| key: "s", | ||
| modifiers: .control | ||
| ) | ||
|
|
||
| /// 表示用の文字列(例: "⌃S") | ||
| public var displayString: String { | ||
| var result = "" | ||
|
|
||
| if modifiers.contains(.control) { | ||
| result += "⌃" | ||
| } | ||
| if modifiers.contains(.option) { | ||
| result += "⌥" | ||
| } | ||
| if modifiers.contains(.shift) { | ||
| result += "⇧" | ||
| } | ||
| if modifiers.contains(.command) { | ||
| result += "⌘" | ||
| } | ||
|
|
||
| result += key.uppercased() | ||
| return result | ||
| } | ||
| } | ||
|
|
||
| /// NSEvent.ModifierFlagsをCodable/Sendableにするためのラッパー | ||
| public struct EventModifierFlags: Codable, Equatable, Hashable, Sendable { | ||
| private var rawValue: UInt | ||
|
|
||
| public init(rawValue: UInt) { | ||
| self.rawValue = rawValue | ||
| } | ||
|
|
||
| public init(from nsModifiers: NSEvent.ModifierFlags) { | ||
| self.rawValue = nsModifiers.rawValue | ||
| } | ||
|
|
||
| public var nsModifierFlags: NSEvent.ModifierFlags { | ||
| NSEvent.ModifierFlags(rawValue: rawValue) | ||
| } | ||
|
|
||
| public static let control = EventModifierFlags(from: .control) | ||
| public static let option = EventModifierFlags(from: .option) | ||
| public static let shift = EventModifierFlags(from: .shift) | ||
| public static let command = EventModifierFlags(from: .command) | ||
|
|
||
| public func contains(_ other: EventModifierFlags) -> Bool { | ||
| (rawValue & other.rawValue) == other.rawValue | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このファイルも同じ理由で、実装可能な部分はなるべくCore/側に置いてほしい。今はほとんどのConfigはCore/側に移動してる。 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| @_spi(Core) import Core | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @_spi(Core)って何……? |
||
| import Foundation | ||
|
|
||
| protocol KeyboardShortcutConfigItem: ConfigItem<KeyboardShortcut> { | ||
| static var `default`: KeyboardShortcut { get } | ||
| } | ||
|
|
||
| extension KeyboardShortcutConfigItem { | ||
| public var value: KeyboardShortcut { | ||
| get { | ||
| guard let data = UserDefaults.standard.data(forKey: Self.key) else { | ||
| return Self.default | ||
| } | ||
| do { | ||
| let decoded = try JSONDecoder().decode(KeyboardShortcut.self, from: data) | ||
| return decoded | ||
| } catch { | ||
| return Self.default | ||
| } | ||
| } | ||
| nonmutating set { | ||
| do { | ||
| let encoded = try JSONEncoder().encode(newValue) | ||
| UserDefaults.standard.set(encoded, forKey: Self.key) | ||
| } catch { | ||
| // エンコード失敗時は何もしない | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension Config { | ||
| /// いい感じ変換のキーボードショートカット | ||
| public struct TransformShortcut: KeyboardShortcutConfigItem { | ||
| public init() {} | ||
|
|
||
| public static let `default`: KeyboardShortcut = .defaultTransformShortcut | ||
| public static let key: String = "dev.ensan.inputmethod.azooKeyMac.preference.transform_shortcut" | ||
| } | ||
| } | ||
|
|
||
| protocol StringConfigItemWithDefault: ConfigItem<String> { | ||
| static var `default`: String { get } | ||
| } | ||
|
|
||
| extension StringConfigItemWithDefault { | ||
| public var value: String { | ||
| get { | ||
| let stored = UserDefaults.standard.string(forKey: Self.key) ?? "" | ||
| return stored.isEmpty ? Self.default : stored | ||
| } | ||
| nonmutating set { | ||
| UserDefaults.standard.set(newValue, forKey: Self.key) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension Config { | ||
| /// 英数キーダブルタップのプロンプト | ||
| public struct EisuDoubleTapPrompt: StringConfigItemWithDefault { | ||
| public init() {} | ||
|
|
||
| public static let `default`: String = "english" | ||
| public static let key: String = "dev.ensan.inputmethod.azooKeyMac.preference.eisu_double_tap_prompt" | ||
| } | ||
|
|
||
| /// かなキーダブルタップのプロンプト | ||
| public struct KanaDoubleTapPrompt: StringConfigItemWithDefault { | ||
| public init() {} | ||
|
|
||
| public static let `default`: String = "japanese" | ||
| public static let key: String = "dev.ensan.inputmethod.azooKeyMac.preference.kana_double_tap_prompt" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このファイルなんだけど、Apple Platform非依存のロジックに関しては
Core/側で管理していきたいので、NSEvent部分以外を上手くCore/の方に書いてほしい。