From e07095a4d315fa06ea4dbbce821d02cbf06972b8 Mon Sep 17 00:00:00 2001 From: Reed Harston Date: Fri, 12 Jan 2024 16:57:51 -0800 Subject: [PATCH 1/4] Added another KeyboardShortcuts.Recorder.init that takes LocalizedStringKey --- Sources/KeyboardShortcuts/Recorder.swift | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Sources/KeyboardShortcuts/Recorder.swift b/Sources/KeyboardShortcuts/Recorder.swift index 5e2f71a8..cc8ed959 100644 --- a/Sources/KeyboardShortcuts/Recorder.swift +++ b/Sources/KeyboardShortcuts/Recorder.swift @@ -114,7 +114,7 @@ extension KeyboardShortcuts.Recorder { - Parameter onChange: Callback which will be called when the keyboard shortcut is changed/removed by the user. This can be useful when you need more control. For example, when migrating from a different keyboard shortcut solution and you need to store the keyboard shortcut somewhere yourself instead of relying on the built-in storage. However, it's strongly recommended to just rely on the built-in storage when possible. */ public init( - _ title: String, + _ title: LocalizedStringKey, name: KeyboardShortcuts.Name, onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil ) { @@ -128,6 +128,29 @@ extension KeyboardShortcuts.Recorder { } } +@available(macOS 10.15, *) +extension KeyboardShortcuts.Recorder { + /** + - Parameter title: The title of the keyboard shortcut recorder, describing its purpose. + - Parameter name: Strongly-typed keyboard shortcut name. + - Parameter onChange: Callback which will be called when the keyboard shortcut is changed/removed by the user. This can be useful when you need more control. For example, when migrating from a different keyboard shortcut solution and you need to store the keyboard shortcut somewhere yourself instead of relying on the built-in storage. However, it's strongly recommended to just rely on the built-in storage when possible. + */ + @_disfavoredOverload + public init( + _ title: S, + name: KeyboardShortcuts.Name, + onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil + ) where S : StringProtocol { + self.init( + for: name, + onChange: onChange, + hasLabel: true + ) { + Text(title) + } + } +} + @available(macOS 10.15, *) extension KeyboardShortcuts.Recorder { /** From cd493590c85c293d4be3a15e01b146e3f1086b3c Mon Sep 17 00:00:00 2001 From: Reed Harston Date: Fri, 12 Jan 2024 17:09:38 -0800 Subject: [PATCH 2/4] Added text to the previews to show the new initializer working --- Sources/KeyboardShortcuts/Recorder.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/KeyboardShortcuts/Recorder.swift b/Sources/KeyboardShortcuts/Recorder.swift index cc8ed959..d8dfa399 100644 --- a/Sources/KeyboardShortcuts/Recorder.swift +++ b/Sources/KeyboardShortcuts/Recorder.swift @@ -174,18 +174,18 @@ extension KeyboardShortcuts.Recorder { @available(macOS 10.15, *) #Preview { - KeyboardShortcuts.Recorder(for: .init("xcodePreview")) + KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview")) .environment(\.locale, .init(identifier: "en")) } @available(macOS 10.15, *) #Preview { - KeyboardShortcuts.Recorder(for: .init("xcodePreview")) + KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview")) .environment(\.locale, .init(identifier: "zh-Hans")) } @available(macOS 10.15, *) #Preview { - KeyboardShortcuts.Recorder(for: .init("xcodePreview")) + KeyboardShortcuts.Recorder("record_shortcut", name: .init("xcodePreview")) .environment(\.locale, .init(identifier: "ru")) } #endif From 9e6300dc0a3770ee99914f2af321d5f05dbbd3d4 Mon Sep 17 00:00:00 2001 From: Reed Harston Date: Sat, 13 Jan 2024 20:58:30 -0800 Subject: [PATCH 3/4] Switch back to String --- Sources/KeyboardShortcuts/Recorder.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/KeyboardShortcuts/Recorder.swift b/Sources/KeyboardShortcuts/Recorder.swift index d8dfa399..d116bca5 100644 --- a/Sources/KeyboardShortcuts/Recorder.swift +++ b/Sources/KeyboardShortcuts/Recorder.swift @@ -136,11 +136,11 @@ extension KeyboardShortcuts.Recorder { - Parameter onChange: Callback which will be called when the keyboard shortcut is changed/removed by the user. This can be useful when you need more control. For example, when migrating from a different keyboard shortcut solution and you need to store the keyboard shortcut somewhere yourself instead of relying on the built-in storage. However, it's strongly recommended to just rely on the built-in storage when possible. */ @_disfavoredOverload - public init( - _ title: S, + public init( + _ title: String, name: KeyboardShortcuts.Name, onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil - ) where S : StringProtocol { + ) { self.init( for: name, onChange: onChange, From 926089a72108f78aa1aef092e743b4e73239f668 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 14 Jan 2024 13:18:01 +0700 Subject: [PATCH 4/4] Update Recorder.swift --- Sources/KeyboardShortcuts/Recorder.swift | 38 ++++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/KeyboardShortcuts/Recorder.swift b/Sources/KeyboardShortcuts/Recorder.swift index d116bca5..c4181817 100644 --- a/Sources/KeyboardShortcuts/Recorder.swift +++ b/Sources/KeyboardShortcuts/Recorder.swift @@ -130,25 +130,25 @@ extension KeyboardShortcuts.Recorder { @available(macOS 10.15, *) extension KeyboardShortcuts.Recorder { - /** - - Parameter title: The title of the keyboard shortcut recorder, describing its purpose. - - Parameter name: Strongly-typed keyboard shortcut name. - - Parameter onChange: Callback which will be called when the keyboard shortcut is changed/removed by the user. This can be useful when you need more control. For example, when migrating from a different keyboard shortcut solution and you need to store the keyboard shortcut somewhere yourself instead of relying on the built-in storage. However, it's strongly recommended to just rely on the built-in storage when possible. - */ - @_disfavoredOverload - public init( - _ title: String, - name: KeyboardShortcuts.Name, - onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil - ) { - self.init( - for: name, - onChange: onChange, - hasLabel: true - ) { - Text(title) - } - } + /** + - Parameter title: The title of the keyboard shortcut recorder, describing its purpose. + - Parameter name: Strongly-typed keyboard shortcut name. + - Parameter onChange: Callback which will be called when the keyboard shortcut is changed/removed by the user. This can be useful when you need more control. For example, when migrating from a different keyboard shortcut solution and you need to store the keyboard shortcut somewhere yourself instead of relying on the built-in storage. However, it's strongly recommended to just rely on the built-in storage when possible. + */ + @_disfavoredOverload + public init( + _ title: String, + name: KeyboardShortcuts.Name, + onChange: ((KeyboardShortcuts.Shortcut?) -> Void)? = nil + ) { + self.init( + for: name, + onChange: onChange, + hasLabel: true + ) { + Text(title) + } + } } @available(macOS 10.15, *)