Minor tweaks
This commit is contained in:
parent
5e674337c1
commit
d2fc65f9c3
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1250"
|
||||
LastUpgradeVersion = "1410"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 55;
|
||||
objectVersion = 56;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
|
@ -119,7 +119,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 1240;
|
||||
LastUpgradeCheck = 1250;
|
||||
LastUpgradeCheck = 1410;
|
||||
TargetAttributes = {
|
||||
E36FB9452609BA43004272D9 = {
|
||||
CreatedOnToolsVersion = 12.4;
|
||||
|
@ -127,7 +127,7 @@
|
|||
};
|
||||
};
|
||||
buildConfigurationList = E36FB9412609BA43004272D9 /* Build configuration list for PBXProject "KeyboardShortcutsExample" */;
|
||||
compatibilityVersion = "Xcode 13.0";
|
||||
compatibilityVersion = "Xcode 14.0";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
|
@ -205,6 +205,7 @@
|
|||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
|
@ -266,6 +267,7 @@
|
|||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
|
@ -296,6 +298,7 @@
|
|||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"KeyboardShortcutsExample/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = "";
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
|
@ -322,6 +325,7 @@
|
|||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"KeyboardShortcutsExample/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = "";
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
|
|
|
@ -26,7 +26,7 @@ final class CallbackMenuItem: NSMenuItem {
|
|||
self.isChecked = isChecked
|
||||
self.isHidden = isHidden
|
||||
|
||||
if let keyModifiers = keyModifiers {
|
||||
if let keyModifiers {
|
||||
self.keyEquivalentModifierMask = keyModifiers
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ extension NSMenuItem {
|
|||
self.isChecked = isChecked
|
||||
self.isHidden = isHidden
|
||||
|
||||
if let keyModifiers = keyModifiers {
|
||||
if let keyModifiers {
|
||||
self.keyEquivalentModifierMask = keyModifiers
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// swift-tools-version:5.6
|
||||
// swift-tools-version:5.7
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "KeyboardShortcuts",
|
||||
defaultLocalization: "en",
|
||||
platforms: [
|
||||
.macOS(.v10_11)
|
||||
.macOS(.v10_13)
|
||||
],
|
||||
products: [
|
||||
.library(
|
||||
|
|
|
@ -113,7 +113,7 @@ enum CarbonKeyboardShortcuts {
|
|||
}
|
||||
|
||||
fileprivate static func handleEvent(_ event: EventRef?) -> OSStatus {
|
||||
guard let event = event else {
|
||||
guard let event else {
|
||||
return OSStatus(eventNotHandledErr)
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ public enum KeyboardShortcuts {
|
|||
import SwiftUI
|
||||
import KeyboardShortcuts
|
||||
|
||||
struct PreferencesView: View {
|
||||
struct SettingsScreen: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
// …
|
||||
|
@ -176,7 +176,7 @@ public enum KeyboardShortcuts {
|
|||
import SwiftUI
|
||||
import KeyboardShortcuts
|
||||
|
||||
struct PreferencesView: View {
|
||||
struct SettingsScreen: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
// …
|
||||
|
@ -202,10 +202,10 @@ public enum KeyboardShortcuts {
|
|||
|
||||
Setting it to `nil` removes the shortcut, even if the `Name` has a default shortcut defined. Use `.reset()` if you want it to respect the default shortcut.
|
||||
|
||||
You would usually not need this as the user would be the one setting the shortcut in a preferences user-interface, but it can be useful when, for example, migrating from a different keyboard shortcuts package.
|
||||
You would usually not need this as the user would be the one setting the shortcut in a settings user-interface, but it can be useful when, for example, migrating from a different keyboard shortcuts package.
|
||||
*/
|
||||
public static func setShortcut(_ shortcut: Shortcut?, for name: Name) {
|
||||
guard let shortcut = shortcut else {
|
||||
guard let shortcut else {
|
||||
userDefaultsRemove(name: name)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
"press_shortcut" = "Press Shortcut";
|
||||
"keyboard_shortcut_used_by_menu_item" = "This keyboard shortcut cannot be used as it’s already used by the “%@” menu item.";
|
||||
"keyboard_shortcut_used_by_system" = "This keyboard shortcut cannot be used as it’s already a system-wide keyboard shortcut.";
|
||||
"keyboard_shortcuts_can_be_changed" = "Most system-wide keyboard shortcuts can be changed in “System Preferences › Keyboard › Shortcuts”.";
|
||||
"keyboard_shortcuts_can_be_changed" = "Most system-wide keyboard shortcuts can be changed in “System Settings › Keyboard › Keyboard Shortcuts”.";
|
||||
|
|
|
@ -44,7 +44,7 @@ extension NSMenuItem {
|
|||
- Important: You will have to disable the global keyboard shortcut while the menu is open, as otherwise, the keyboard events will be buffered up and triggered when the menu closes. This is because `NSMenu` puts the thread in tracking-mode, which prevents the keyboard events from being received. You can listen to whether a menu is open by implementing `NSMenuDelegate#menuWillOpen` and `NSMenuDelegate#menuDidClose`. You then use `KeyboardShortcuts.disable` and `KeyboardShortcuts.enable`.
|
||||
*/
|
||||
public func setShortcut(for name: KeyboardShortcuts.Name?) {
|
||||
guard let name = name else {
|
||||
guard let name else {
|
||||
clearShortcut()
|
||||
AssociatedKeys.observer[self] = nil
|
||||
return
|
||||
|
@ -84,7 +84,7 @@ extension NSMenuItem {
|
|||
@_disfavoredOverload
|
||||
public func setShortcut(_ shortcut: KeyboardShortcuts.Shortcut?) {
|
||||
func set() {
|
||||
guard let shortcut = shortcut else {
|
||||
guard let shortcut else {
|
||||
clearShortcut()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ extension KeyboardShortcuts {
|
|||
self.defaultShortcut = defaultShortcut
|
||||
|
||||
if
|
||||
let defaultShortcut = defaultShortcut,
|
||||
let defaultShortcut,
|
||||
!userDefaultsContains(name: self)
|
||||
{
|
||||
setShortcut(defaultShortcut, for: self)
|
||||
|
|
|
@ -20,7 +20,7 @@ extension KeyboardShortcuts {
|
|||
/**
|
||||
A SwiftUI `View` that lets the user record a keyboard shortcut.
|
||||
|
||||
You would usually put this in your preferences window.
|
||||
You would usually put this in your settings window.
|
||||
|
||||
It automatically prevents choosing a keyboard shortcut that is already taken by the system or by the app's main menu by showing a user-friendly alert to the user.
|
||||
|
||||
|
@ -59,13 +59,24 @@ extension KeyboardShortcuts {
|
|||
|
||||
public var body: some View {
|
||||
if hasLabel {
|
||||
_Recorder(
|
||||
name: name,
|
||||
onChange: onChange
|
||||
)
|
||||
.formLabel {
|
||||
if #available(macOS 13, *) {
|
||||
LabeledContent {
|
||||
_Recorder(
|
||||
name: name,
|
||||
onChange: onChange
|
||||
)
|
||||
} label: {
|
||||
label
|
||||
}
|
||||
} else {
|
||||
_Recorder(
|
||||
name: name,
|
||||
onChange: onChange
|
||||
)
|
||||
.formLabel {
|
||||
label
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_Recorder(
|
||||
name: name,
|
||||
|
@ -77,7 +88,7 @@ extension KeyboardShortcuts {
|
|||
}
|
||||
|
||||
@available(macOS 10.15, *)
|
||||
extension KeyboardShortcuts.Recorder where Label == EmptyView {
|
||||
extension KeyboardShortcuts.Recorder<EmptyView> {
|
||||
/**
|
||||
- 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.
|
||||
|
@ -95,7 +106,7 @@ extension KeyboardShortcuts.Recorder where Label == EmptyView {
|
|||
}
|
||||
|
||||
@available(macOS 10.15, *)
|
||||
extension KeyboardShortcuts.Recorder where Label == Text {
|
||||
extension KeyboardShortcuts.Recorder<Text> {
|
||||
/**
|
||||
- Parameter title: The title of the keyboard shortcut recorder, describing its purpose.
|
||||
- Parameter name: Strongly-typed keyboard shortcut name.
|
||||
|
|
|
@ -5,7 +5,7 @@ extension KeyboardShortcuts {
|
|||
/**
|
||||
A `NSView` that lets the user record a keyboard shortcut.
|
||||
|
||||
You would usually put this in your preferences window.
|
||||
You would usually put this in your settings window.
|
||||
|
||||
It automatically prevents choosing a keyboard shortcut that is already taken by the system or by the app's main menu by showing a user-friendly alert to the user.
|
||||
|
||||
|
@ -15,7 +15,7 @@ extension KeyboardShortcuts {
|
|||
import Cocoa
|
||||
import KeyboardShortcuts
|
||||
|
||||
final class PreferencesViewController: NSViewController {
|
||||
final class SettingsViewController: NSViewController {
|
||||
override func loadView() {
|
||||
view = NSView()
|
||||
|
||||
|
@ -120,7 +120,7 @@ extension KeyboardShortcuts {
|
|||
private func setUpEvents() {
|
||||
observer = NotificationCenter.default.addObserver(forName: .shortcutByNameDidChange, object: nil, queue: nil) { [weak self] notification in
|
||||
guard
|
||||
let self = self,
|
||||
let self,
|
||||
let nameInNotification = notification.userInfo?["name"] as? KeyboardShortcuts.Name,
|
||||
nameInNotification == self.shortcutName
|
||||
else {
|
||||
|
@ -177,7 +177,7 @@ extension KeyboardShortcuts {
|
|||
KeyboardShortcuts.isPaused = true // The position here matters.
|
||||
|
||||
eventMonitor = LocalEventMonitor(events: [.keyDown, .leftMouseUp, .rightMouseUp]) { [weak self] event in
|
||||
guard let self = self else {
|
||||
guard let self else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ extension KeyboardShortcuts {
|
|||
NSAlert.showModal(
|
||||
for: self.window,
|
||||
title: "keyboard_shortcut_used_by_system".localized,
|
||||
// TODO: Add button to offer to open the relevant system preference pane for the user.
|
||||
// TODO: Add button to offer to open the relevant system settings pane for the user.
|
||||
message: "keyboard_shortcuts_can_be_changed".localized
|
||||
)
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ extension KeyboardShortcuts.Shortcut {
|
|||
|
||||
// Some characters cannot be automatically translated.
|
||||
if
|
||||
let key = key,
|
||||
let key,
|
||||
let character = keyToCharacterMapping[key]
|
||||
{
|
||||
return character
|
||||
|
@ -274,7 +274,7 @@ extension KeyboardShortcuts.Shortcut {
|
|||
|
||||
guard keyString.count <= 1 else {
|
||||
guard
|
||||
let key = key,
|
||||
let key,
|
||||
let string = keyToKeyEquivalentString[key]
|
||||
else {
|
||||
return ""
|
||||
|
|
|
@ -74,7 +74,7 @@ final class LocalEventMonitor {
|
|||
}
|
||||
|
||||
func stop() {
|
||||
guard let monitor = monitor else {
|
||||
guard let monitor else {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ extension NSAlert {
|
|||
self.alertStyle = style
|
||||
self.icon = icon
|
||||
|
||||
if let message = message {
|
||||
if let message {
|
||||
self.informativeText = message
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ extension NSAlert {
|
|||
*/
|
||||
@discardableResult
|
||||
func runModal(for window: NSWindow? = nil) -> NSApplication.ModalResponse {
|
||||
guard let window = window else {
|
||||
guard let window else {
|
||||
return runModal()
|
||||
}
|
||||
|
||||
|
@ -391,7 +391,7 @@ extension HorizontalAlignment {
|
|||
|
||||
@available(macOS 10.15, *)
|
||||
extension View {
|
||||
func formLabel<Label: View>(@ViewBuilder _ label: () -> Label) -> some View {
|
||||
func formLabel(@ViewBuilder _ label: () -> some View) -> some View {
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
label()
|
||||
labelsHidden()
|
||||
|
|
33
readme.md
33
readme.md
|
@ -10,35 +10,6 @@ I'm happy to accept more configurability and features. PR welcome! What you see
|
|||
|
||||
<img src="https://github.com/sindresorhus/KeyboardShortcuts/raw/main/screenshot.png" width="532">
|
||||
|
||||
<br>
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<p>
|
||||
<p>
|
||||
<sup>
|
||||
<a href="https://github.com/sponsors/sindresorhus">Sindre's open source work is supported by the community</a>
|
||||
</sup>
|
||||
</p>
|
||||
<sup>Special thanks to:</sup>
|
||||
<br>
|
||||
<br>
|
||||
<a href="https://keygen.sh">
|
||||
<div>
|
||||
<img src="https://sindresorhus.com/assets/thanks/keygen-logo.svg" width="210" alt="Keygen">
|
||||
</div>
|
||||
<b>A dead-simple software licensing and distribution API built for developers</b>
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
---
|
||||
|
||||
<br>
|
||||
|
||||
## Requirements
|
||||
|
||||
macOS 10.11+
|
||||
|
@ -132,7 +103,7 @@ Using [`KeyboardShortcuts.RecorderCocoa`](Sources/KeyboardShortcuts/RecorderCoco
|
|||
import Cocoa
|
||||
import KeyboardShortcuts
|
||||
|
||||
final class PreferencesViewController: NSViewController {
|
||||
final class SettingsViewController: NSViewController {
|
||||
override func loadView() {
|
||||
view = NSView()
|
||||
|
||||
|
@ -255,6 +226,6 @@ No. However, there is nothing stopping you from using Swift Package Manager for
|
|||
|
||||
- [Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults
|
||||
- [Regex](https://github.com/sindresorhus/Regex) - Swifty regular expressions
|
||||
- [Preferences](https://github.com/sindresorhus/Preferences) - Add a preferences window to your macOS app in minutes
|
||||
- [Preferences](https://github.com/sindresorhus/Preferences) - Add a settings window to your macOS app in minutes
|
||||
- [LaunchAtLogin](https://github.com/sindresorhus/LaunchAtLogin) - Add "Launch at Login" functionality to your macOS app
|
||||
- [More…](https://github.com/search?q=user%3Asindresorhus+language%3Aswift)
|
||||
|
|
Loading…
Reference in New Issue