Skip to content

Commit

Permalink
Fix feedback from alpha testers
Browse files Browse the repository at this point in the history
- Don't default to Safari when adding url commands
- Refactor GroupListCell to remove unused `UserSelection` and rewrite
  icon to use Circle with overlay instead of a ZStack
- Remove `RoundOutlinedButton` view
- Refactor AddButton to use Label for rendering
- Implement backspace for deleting groups and workflows
- Add confirmation when trying to remove an entire group
- Add keyboard command for adding new workflow
  • Loading branch information
zenangst committed Dec 7, 2020
1 parent d8c0431 commit bdb17c7
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 58 deletions.
19 changes: 16 additions & 3 deletions App/Sources/Application/KeyboardCowboyApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct KeyboardCowboyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@Environment(\.scenePhase) var scenePhase
@State var content: MainView?
private var firstResponder: NSResponder? { NSApp.keyWindow?.firstResponder }

var body: some Scene {
WindowGroup {
Expand All @@ -27,15 +28,27 @@ struct KeyboardCowboyApp: App {
}
.windowToolbarStyle(UnifiedWindowToolbarStyle())
.commands {
CommandGroup(after: CommandGroupPlacement.newItem, addition: {
CommandGroup(replacing: CommandGroupPlacement.pasteboard, addition: {
Button("Delete") {
firstResponder?.tryToPerform(#selector(NSText.delete(_:)), with: nil)
}.keyboardShortcut(.delete, modifiers: [])
})

CommandGroup(replacing: CommandGroupPlacement.newItem, addition: {
Button("New Workflow") {
if let group = appDelegate.userSelection.group {
appDelegate.workflowFeatureController?.perform(.createWorkflow(in: group))
}
}.keyboardShortcut("n", modifiers: [.command])

Button("New Group") {
appDelegate.groupFeatureController?.perform(.createGroup)
}.keyboardShortcut("N")
}.keyboardShortcut("N", modifiers: [.command, .shift])
})

CommandGroup(after: CommandGroupPlacement.toolbar, addition: {
Button("Toggle Sidebar") {
NSApp.keyWindow?.firstResponder?.tryToPerform(
firstResponder?.tryToPerform(
#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
}.keyboardShortcut("S")
})
Expand Down
6 changes: 3 additions & 3 deletions ViewKit/Sources/Factories/ModelFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ModelFactory {
shellScriptCommand(id: id),
keyboardCommand(id: id),
openCommand(id: id),
urlCommand(id: id)
urlCommand(id: id, application: nil)
]

return result
Expand Down Expand Up @@ -159,9 +159,9 @@ class ModelFactory {
path: "~/Developer/Xcode.project"))
}

func urlCommand(id: String) -> Command {
func urlCommand(id: String, application: Application?) -> Command {
Command.open(.init(id: id,
application: Application.safari(),
application: application,
path: "https://github.com"))
}

Expand Down
40 changes: 34 additions & 6 deletions ViewKit/Sources/Views/GroupList/GroupList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public struct GroupList: View {
let workflowController: WorkflowController
@State private var editGroup: ModelKit.Group?
@State private var selection: ModelKit.Group?
@State var isDropping: Bool = false
@State private var isDropping: Bool = false
@State private var deleteGroup: ModelKit.Group?

public var body: some View {
List {
Expand Down Expand Up @@ -51,13 +52,12 @@ public struct GroupList: View {
.contextMenu {
Button("Show Info") { editGroup = group }
Divider()
Button("Delete") {
groupController.action(.deleteGroup(group))()
}
Button("Delete", action: onDelete)
}

}
.onInsert(of: []) { _, _ in }
.onInsert(of: []) { _, _ in
Swift.print("foo")
}
.onMove { indices, newOffset in
for i in indices {
groupController.action(.moveGroup(from: i, to: newOffset))()
Expand All @@ -67,6 +67,24 @@ public struct GroupList: View {
.onDrop($isDropping) { groupController.perform(.dropFile($0)) }
.border(Color.accentColor, width: isDropping ? 5 : 0)
.sheet(item: $editGroup, content: editGroup)
.sheet(item: $deleteGroup, content: { group in
VStack(spacing: 0) {
Text("Are you sure you want to delete the group “\(group.name)”?")
.padding()
Divider()
HStack {
Button("Cancel", action: {
deleteGroup = nil
}).keyboardShortcut(.cancelAction)
Button("Delete", action: {
deleteGroup = nil
groupController.perform(.deleteGroup(group))
}).keyboardShortcut(.defaultAction)
}.padding()
}
})
.onDeleteCommand(perform: onDelete)

AddButton(text: "Add Group", action: {
groupController.perform(.createGroup)
})
Expand Down Expand Up @@ -103,6 +121,16 @@ private extension GroupList {
},
cancelAction: { editGroup = nil })
}

func onDelete() {
if let group = userSelection.group {
if group.workflows.isEmpty {
groupController.perform(.deleteGroup(group))
} else {
deleteGroup = group
}
}
}
}

// MARK: - Previews
Expand Down
22 changes: 10 additions & 12 deletions ViewKit/Sources/Views/GroupList/GroupListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ struct GroupListCell: View {
let count: Int
let editAction: () -> Void
@State private var isHovering: Bool = false
@EnvironmentObject var userSelection: UserSelection

var body: some View {
HStack {
icon
textField
text
Spacer()
if isHovering {
editButton(editAction)
Expand All @@ -33,17 +32,17 @@ struct GroupListCell: View {

private extension GroupListCell {
var icon: some View {
ZStack {
Circle().fill(Color(hex: color))
.frame(width: 24, height: 24)
Image(systemName: symbol)
.renderingMode(.template)
.foregroundColor(.white)
.frame(width: 14, height: 12)
}
Circle()
.fill(Color(hex: color))
.frame(width: 24, height: 24, alignment: .center)
.overlay(
Image(systemName: symbol)
.renderingMode(.template)
.foregroundColor(.white)
)
}

var textField: some View {
var text: some View {
Text(name)
.foregroundColor(.primary)
.lineSpacing(-2.0)
Expand Down Expand Up @@ -78,7 +77,6 @@ struct GroupListCell_Previews: PreviewProvider, TestPreviewProvider {
symbol: group.symbol,
count: group.workflows.count,
editAction: {})
.environmentObject(UserSelection())
.frame(width: 300)
}
}
10 changes: 6 additions & 4 deletions ViewKit/Sources/Views/Shared/AddButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ struct AddButton: View {
var body: some View {
HStack(spacing: 4) {
if alignment == .center || alignment == .right { Spacer() }
RoundOutlinedButton(title: "+", color: Color(.secondaryLabelColor))
.onTapGesture(perform: action)
Button(text, action: action)
.buttonStyle(PlainButtonStyle())
Button(action: action, label: {
Label(
title: { Text(text) },
icon: { Image(systemName: "plus.circle") }
)
}).buttonStyle(PlainButtonStyle())
if alignment == .center || alignment == .left { Spacer() }
}.padding(8)
}
Expand Down
28 changes: 0 additions & 28 deletions ViewKit/Sources/Views/Shared/RoundOutlinedButton.swift

This file was deleted.

5 changes: 5 additions & 0 deletions ViewKit/Sources/Views/WorkflowList/WorkflowList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public struct WorkflowList: View {
.navigationTitle("\(group.name)")
.navigationSubtitle("Workflows: \(group.workflows.count)")
.environment(\.defaultMinListRowHeight, 1)
.onDeleteCommand(perform: {
if let workflow = selection {
workflowController.perform(.deleteWorkflow(workflow, in: group))
}
})
} else {
SearchView(searchController: searchController)
}
Expand Down
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ targets:
base:
ASSETCATALOG_COMPILER_APPICON_NAME: "AppIcon"
CODE_SIGN_IDENTITY: "-"
CURRENT_PROJECT_VERSION: 8
CURRENT_PROJECT_VERSION: 9
INFOPLIST_FILE: "App/Resources/Info.plist"
MARKETING_VERSION: 0.0.8
MARKETING_VERSION: 0.0.9
PRODUCT_BUNDLE_IDENTIFIER: "com.zenangst.Keyboard-Cowboy"
PRODUCT_NAME: "Keyboard Cowboy"
ENABLE_HARDENED_RUNTIME: true
Expand Down

0 comments on commit bdb17c7

Please sign in to comment.