diff --git a/Memola/App/Application.swift b/Memola/App/Application.swift index 84a91f9..8f473e9 100644 --- a/Memola/App/Application.swift +++ b/Memola/App/Application.swift @@ -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 } } diff --git a/Memola/Features/Dashboard/Dashboard/DashboardView.swift b/Memola/Features/Dashboard/Dashboard/DashboardView.swift index a007ab7..48cc22c 100644 --- a/Memola/Features/Dashboard/Dashboard/DashboardView.swift +++ b/Memola/Features/Dashboard/Dashboard/DashboardView.swift @@ -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) } diff --git a/Memola/Features/Memo/Memo/MemoView.swift b/Memola/Features/Memo/Memo/MemoView.swift index 3d28666..2f6385d 100644 --- a/Memola/Features/Memo/Memo/MemoView.swift +++ b/Memola/Features/Memo/Memo/MemoView.swift @@ -61,6 +61,8 @@ struct MemoView: View { loadingIndicator("Loading photo...") } } + .focusedSceneObject(history) + .focusedSceneValue(\.activeSceneKey, .memo) } private var canvasView: some View { diff --git a/Memola/Shortcut/Commands/EditCommands.swift b/Memola/Shortcut/Commands/EditCommands.swift index 159dce9..12d00d1 100644 --- a/Memola/Shortcut/Commands/EditCommands.swift +++ b/Memola/Shortcut/Commands/EditCommands.swift @@ -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) { } }