-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor application life cycle and other UI related improvements
### Code changes - Remove `AppDelegate` and leverage from the new SwiftUI app life cycle - Remove `AppDelegateLaunchController` - Refactor the UI components into smaller more manageable parts - Move context menus and commands into their own structs - Add new `Saloon` store which acts as the application delegate in the new SwiftUI life cycle - Store group and workflow selection in user defaults - Remove Introspect framework dependency ### Features - Commands can now be focused, supports navigation and supports deletion - Improve group and workflow selections
- Loading branch information
Showing
75 changed files
with
1,617 additions
and
1,352 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import SwiftUI | ||
import ModelKit | ||
import ViewKit | ||
|
||
struct KeyboardCowboyCommands: Commands { | ||
let store: Saloon | ||
let keyInputSubject: KeyInputSubjectWrapper | ||
|
||
private var firstResponder: NSResponder? { NSApp.keyWindow?.firstResponder } | ||
|
||
var body: some Commands { | ||
CommandGroup(replacing: CommandGroupPlacement.pasteboard, addition: { | ||
Button("Copy") { | ||
firstResponder?.tryToPerform(#selector(NSText.copy(_:)), with: nil) | ||
}.keyboardShortcut("c", modifiers: [.command]) | ||
|
||
Button("Paste") { | ||
firstResponder?.tryToPerform(#selector(NSText.paste(_:)), with: nil) | ||
}.keyboardShortcut("v", modifiers: [.command]) | ||
|
||
keyInput(.delete, name: "Delete") { | ||
firstResponder?.tryToPerform(#selector(NSText.delete(_:)), with: nil) | ||
} | ||
|
||
Button("Select All") { | ||
firstResponder?.tryToPerform(#selector(NSText.selectAll(_:)), with: nil) | ||
}.keyboardShortcut("a", modifiers: [.command]) | ||
}) | ||
|
||
CommandMenu("Navigation") { | ||
keyInput(.upArrow, name: "Select Previous") { | ||
guard let cgEvent = CGEvent(keyboardEventSource: nil, virtualKey: 126, keyDown: false) else { | ||
return | ||
} | ||
let event = NSEvent.init(cgEvent: cgEvent) | ||
firstResponder?.tryToPerform(#selector(NSApplication.keyDown(with:)), with: event) | ||
} | ||
|
||
keyInput(.downArrow, name: "Select Next") { | ||
guard let cgEvent = CGEvent(keyboardEventSource: nil, virtualKey: 125, keyDown: false) else { | ||
return | ||
} | ||
let event = NSEvent.init(cgEvent: cgEvent) | ||
firstResponder?.tryToPerform(#selector(NSApplication.keyDown(with:)), with: event) | ||
} | ||
} | ||
|
||
CommandGroup(replacing: CommandGroupPlacement.newItem, addition: { | ||
if let group = store.selectedGroup { | ||
Button("New Workflow") { | ||
store.context.workflow.perform(.create(groupId: group.id)) | ||
}.keyboardShortcut("n", modifiers: [.command]) | ||
} | ||
|
||
if store.selectedWorkflow != nil { | ||
Button("New Keyboard shortcut") { | ||
store.context.keyboardsShortcuts.perform( | ||
.create(ModelKit.KeyboardShortcut.empty(), offset: 999, in: store.context.workflow.state)) | ||
}.keyboardShortcut("k", modifiers: [.command]) | ||
|
||
Button("New Command") { | ||
store.context.commands.perform(.create(Command.application(.empty()), in: store.context.workflow.state)) | ||
}.keyboardShortcut("n", modifiers: [.control, .option, .command]) | ||
} | ||
Button("New Group") { | ||
store.context.groups.perform(.createGroup) | ||
}.keyboardShortcut("N", modifiers: [.command]) | ||
}) | ||
|
||
CommandGroup(after: CommandGroupPlacement.toolbar, addition: { | ||
Button("Toggle Sidebar") { | ||
firstResponder?.tryToPerform( | ||
#selector(NSSplitViewController.toggleSidebar(_:)), with: nil) | ||
}.keyboardShortcut("S") | ||
}) | ||
} | ||
|
||
func keyInput(_ key: KeyEquivalent, name: String, modifiers: EventModifiers = [], | ||
fallbackEvent: @escaping () -> Void) -> some View { | ||
return keyboardShortcut(key, name: name, sender: keyInputSubject, | ||
modifiers: modifiers, | ||
fallbackEvent: fallbackEvent) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.