mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-23 18:01:14 +01:00
feat: add redo and undo commands
This commit is contained in:
@@ -15,15 +15,11 @@ final class Application: NSObject, ObservableObject {
|
||||
|
||||
extension Application {
|
||||
func openMemo(_ memoObject: MemoObject?) {
|
||||
withAnimation(.easeOut) {
|
||||
self.memoObject = memoObject
|
||||
}
|
||||
self.memoObject = memoObject
|
||||
}
|
||||
|
||||
func closeMemo() {
|
||||
withAnimation(.easeOut) {
|
||||
self.memoObject = nil
|
||||
}
|
||||
self.memoObject = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,32 +19,40 @@ struct DashboardView: View {
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
NavigationSplitView(columnVisibility: $columnVisibility) {
|
||||
Sidebar(sidebarItem: $sidebarItem, horizontalSizeClass: horizontalSizeClass)
|
||||
} detail: {
|
||||
switch sidebarItem {
|
||||
case .memos:
|
||||
MemosView()
|
||||
case .trash:
|
||||
TrashView(sidebarItem: $sidebarItem)
|
||||
default:
|
||||
MemosView()
|
||||
ZStack {
|
||||
if let memo = application.memoObject {
|
||||
NavigationStack {
|
||||
MemoView(memo: memo)
|
||||
.onDisappear {
|
||||
withPersistence(\.viewContext) { context in
|
||||
try context.saveIfNeeded()
|
||||
context.refreshAllObjects()
|
||||
}
|
||||
}
|
||||
.navigationTitle("")
|
||||
}
|
||||
.transition(.opacity)
|
||||
.matchedGeometryEffect(id: "pop-up", in: namespace)
|
||||
} else {
|
||||
NavigationSplitView(columnVisibility: $columnVisibility) {
|
||||
Sidebar(sidebarItem: $sidebarItem, horizontalSizeClass: horizontalSizeClass)
|
||||
} detail: {
|
||||
switch sidebarItem {
|
||||
case .memos:
|
||||
MemosView()
|
||||
case .trash:
|
||||
TrashView(sidebarItem: $sidebarItem)
|
||||
default:
|
||||
MemosView()
|
||||
}
|
||||
}
|
||||
.transition(.opacity)
|
||||
.matchedGeometryEffect(id: "pop-up", in: namespace)
|
||||
}
|
||||
}
|
||||
.animation(.easeIn, value: application.memoObject)
|
||||
.toolbar(application.memoObject == nil ? .visible : .hidden, for: .windowToolbar)
|
||||
.toolbarBackground(application.memoObject == nil ? .clear : Color(nsColor: .windowBackgroundColor), for: .windowToolbar)
|
||||
.overlay {
|
||||
if let memo = application.memoObject {
|
||||
MemoView(memo: memo)
|
||||
.onDisappear {
|
||||
withPersistence(\.viewContext) { context in
|
||||
try context.saveIfNeeded()
|
||||
context.refreshAllObjects()
|
||||
}
|
||||
}
|
||||
.transition(.move(edge: .bottom))
|
||||
}
|
||||
}
|
||||
.onChange(of: columnVisibility) { oldValue, newValue in
|
||||
application.changeSidebarVisibility(newValue == .all ? .shown : .hidden)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ struct MemoView: View {
|
||||
loadingIndicator("Loading photo...")
|
||||
}
|
||||
}
|
||||
.focusedSceneObject(history)
|
||||
.focusedSceneValue(\.activeSceneKey, .memo)
|
||||
}
|
||||
|
||||
private var canvasView: some View {
|
||||
|
||||
@@ -8,21 +8,28 @@
|
||||
import SwiftUI
|
||||
|
||||
struct EditCommands: Commands {
|
||||
@FocusedValue(\.activeSceneKey) private var appScene
|
||||
|
||||
@FocusedObject var history: History?
|
||||
|
||||
var body: some Commands {
|
||||
CommandGroup(replacing: .undoRedo) {
|
||||
// memo view
|
||||
Button {
|
||||
|
||||
} label: {
|
||||
Text("Undo")
|
||||
if appScene == .memo, 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])
|
||||
Button {
|
||||
|
||||
} label: {
|
||||
Text("Redo")
|
||||
}
|
||||
.keyboardShortcut("z", modifiers: [.command, .shift])
|
||||
}
|
||||
CommandGroup(replacing: .pasteboard) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user