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