mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-21 17:09:21 +01:00
feat: add tool and grid commands
This commit is contained in:
@@ -181,6 +181,19 @@ extension Canvas {
|
||||
try context.saveIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
func toggleGridMode() {
|
||||
let _gridMode: GridMode
|
||||
switch gridMode {
|
||||
case .none:
|
||||
_gridMode = .point
|
||||
case .point:
|
||||
_gridMode = .line
|
||||
case .line:
|
||||
_gridMode = .none
|
||||
}
|
||||
setGridMode(_gridMode)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Stroke
|
||||
|
||||
@@ -35,6 +35,7 @@ final class Tool: NSObject, ObservableObject {
|
||||
}
|
||||
|
||||
func selectTool(_ selection: ToolSelection) {
|
||||
guard self.selection != selection else { return }
|
||||
self.selection = selection
|
||||
withPersistence(\.viewContext) { [weak object] context in
|
||||
object?.selection = selection.rawValue
|
||||
|
||||
@@ -61,6 +61,8 @@ struct MemoView: View {
|
||||
loadingIndicator("Loading photo...")
|
||||
}
|
||||
}
|
||||
.focusedSceneObject(tool)
|
||||
.focusedSceneObject(canvas)
|
||||
.focusedSceneObject(history)
|
||||
.focusedSceneValue(\.activeSceneKey, .memo)
|
||||
}
|
||||
|
||||
@@ -142,14 +142,7 @@ struct Toolbar: View {
|
||||
private var gridModeControl: some View {
|
||||
#if os(macOS)
|
||||
Button {
|
||||
switch canvas.gridMode {
|
||||
case .none:
|
||||
canvas.gridMode = .point
|
||||
case .point:
|
||||
canvas.gridMode = .line
|
||||
case .line:
|
||||
canvas.gridMode = .none
|
||||
}
|
||||
canvas.toggleGridMode()
|
||||
} label: {
|
||||
Image(systemName: canvas.gridMode.icon)
|
||||
.frame(width: size, height: size)
|
||||
|
||||
@@ -10,25 +10,49 @@ import SwiftUI
|
||||
struct EditCommands: Commands {
|
||||
@FocusedValue(\.activeSceneKey) private var appScene
|
||||
|
||||
@FocusedObject var tool: Tool?
|
||||
@FocusedObject var history: History?
|
||||
|
||||
var body: some Commands {
|
||||
CommandGroup(replacing: .undoRedo) {
|
||||
if appScene == .memo, let history {
|
||||
Button {
|
||||
history.historyPublisher.send(.undo)
|
||||
} label: {
|
||||
Text("Undo")
|
||||
if appScene == .memo {
|
||||
if let history {
|
||||
Button {
|
||||
history.historyPublisher.send(.undo)
|
||||
} label: {
|
||||
Text("Undo")
|
||||
}
|
||||
.keyboardShortcut("z", modifiers: [.command])
|
||||
.disabled(history.undoDisabled)
|
||||
Button {
|
||||
history.historyPublisher.send(.redo)
|
||||
} label: {
|
||||
Text("Redo")
|
||||
}
|
||||
.keyboardShortcut("z", modifiers: [.command, .shift])
|
||||
.disabled(history.redoDisabled)
|
||||
}
|
||||
.keyboardShortcut("z", modifiers: [.command])
|
||||
.disabled(history.undoDisabled)
|
||||
Button {
|
||||
history.historyPublisher.send(.redo)
|
||||
} label: {
|
||||
Text("Redo")
|
||||
Divider()
|
||||
if let tool {
|
||||
Button {
|
||||
tool.selectTool(.hand)
|
||||
} label: {
|
||||
Text("Hand Tool")
|
||||
}
|
||||
.keyboardShortcut("h", modifiers: [.option])
|
||||
Button {
|
||||
tool.selectTool(.pen)
|
||||
} label: {
|
||||
Text("Pen Tool")
|
||||
}
|
||||
.keyboardShortcut("p", modifiers: [.option])
|
||||
Button {
|
||||
tool.selectTool(.photo)
|
||||
} label: {
|
||||
Text("Photo Tool")
|
||||
}
|
||||
.keyboardShortcut("p", modifiers: [.option, .shift])
|
||||
}
|
||||
.keyboardShortcut("z", modifiers: [.command, .shift])
|
||||
.disabled(history.redoDisabled)
|
||||
}
|
||||
}
|
||||
CommandGroup(replacing: .pasteboard) { }
|
||||
|
||||
@@ -9,23 +9,25 @@ import SwiftUI
|
||||
|
||||
struct ViewCommands: Commands {
|
||||
@ObservedObject private var application: Application
|
||||
|
||||
@FocusedValue(\.activeSceneKey) private var appScene
|
||||
|
||||
@FocusedObject var canvas: Canvas?
|
||||
|
||||
init(application: Application) {
|
||||
self.application = application
|
||||
}
|
||||
|
||||
var body: some Commands {
|
||||
CommandGroup(replacing: .toolbar) {
|
||||
if appScene == .memos || appScene == .trash {
|
||||
switch appScene {
|
||||
case .memos, .trash:
|
||||
Button {
|
||||
application.activateSearchBar()
|
||||
} label: {
|
||||
Text("Find Memo")
|
||||
}
|
||||
.keyboardShortcut("f", modifiers: [.command])
|
||||
}
|
||||
if appScene == .memos || appScene == .trash {
|
||||
Button {
|
||||
application.toggleSidebar()
|
||||
} label: {
|
||||
@@ -37,6 +39,15 @@ struct ViewCommands: Commands {
|
||||
}
|
||||
}
|
||||
.keyboardShortcut("o", modifiers: [.command])
|
||||
case .memo:
|
||||
Button {
|
||||
canvas?.toggleGridMode()
|
||||
} label: {
|
||||
Text("Change Grid Layout")
|
||||
}
|
||||
.keyboardShortcut("g", modifiers: [.option])
|
||||
default:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user