mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-07-04 20:11:36 +02:00
refactor: remove memo manager
This commit is contained in:
@@ -37,7 +37,6 @@
|
|||||||
EC2BEBF82C0F601A005DB0AF /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC2BEBF72C0F601A005DB0AF /* Node.swift */; };
|
EC2BEBF82C0F601A005DB0AF /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC2BEBF72C0F601A005DB0AF /* Node.swift */; };
|
||||||
EC35655A2BF060D900A4E0BF /* Quad.metal in Sources */ = {isa = PBXBuildFile; fileRef = EC3565592BF060D900A4E0BF /* Quad.metal */; };
|
EC35655A2BF060D900A4E0BF /* Quad.metal in Sources */ = {isa = PBXBuildFile; fileRef = EC3565592BF060D900A4E0BF /* Quad.metal */; };
|
||||||
EC37FB122C1B2DD90008D976 /* ToolSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC37FB112C1B2DD90008D976 /* ToolSelection.swift */; };
|
EC37FB122C1B2DD90008D976 /* ToolSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC37FB112C1B2DD90008D976 /* ToolSelection.swift */; };
|
||||||
EC3D67CC2C3AAD5E00359400 /* MemoManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC3D67CB2C3AAD5E00359400 /* MemoManager.swift */; };
|
|
||||||
EC42F7852C25267000E86E96 /* ElementGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC42F7842C25267000E86E96 /* ElementGroup.swift */; };
|
EC42F7852C25267000E86E96 /* ElementGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC42F7842C25267000E86E96 /* ElementGroup.swift */; };
|
||||||
EC4538892BEBCAE000A86FEC /* Quad.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC4538882BEBCAE000A86FEC /* Quad.swift */; };
|
EC4538892BEBCAE000A86FEC /* Quad.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC4538882BEBCAE000A86FEC /* Quad.swift */; };
|
||||||
EC5050072BF65CED00B4D86E /* PenDropDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC5050062BF65CED00B4D86E /* PenDropDelegate.swift */; };
|
EC5050072BF65CED00B4D86E /* PenDropDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC5050062BF65CED00B4D86E /* PenDropDelegate.swift */; };
|
||||||
@@ -175,7 +174,6 @@
|
|||||||
EC2BEBF72C0F601A005DB0AF /* Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = "<group>"; };
|
EC2BEBF72C0F601A005DB0AF /* Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = "<group>"; };
|
||||||
EC3565592BF060D900A4E0BF /* Quad.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Quad.metal; sourceTree = "<group>"; };
|
EC3565592BF060D900A4E0BF /* Quad.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Quad.metal; sourceTree = "<group>"; };
|
||||||
EC37FB112C1B2DD90008D976 /* ToolSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolSelection.swift; sourceTree = "<group>"; };
|
EC37FB112C1B2DD90008D976 /* ToolSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolSelection.swift; sourceTree = "<group>"; };
|
||||||
EC3D67CB2C3AAD5E00359400 /* MemoManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MemoManager.swift; sourceTree = "<group>"; };
|
|
||||||
EC42F7842C25267000E86E96 /* ElementGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementGroup.swift; sourceTree = "<group>"; };
|
EC42F7842C25267000E86E96 /* ElementGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementGroup.swift; sourceTree = "<group>"; };
|
||||||
EC4538882BEBCAE000A86FEC /* Quad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Quad.swift; sourceTree = "<group>"; };
|
EC4538882BEBCAE000A86FEC /* Quad.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Quad.swift; sourceTree = "<group>"; };
|
||||||
EC5050062BF65CED00B4D86E /* PenDropDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PenDropDelegate.swift; sourceTree = "<group>"; };
|
EC5050062BF65CED00B4D86E /* PenDropDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PenDropDelegate.swift; sourceTree = "<group>"; };
|
||||||
@@ -309,7 +307,6 @@
|
|||||||
EC01511C2C305C99008A115E /* Dashboard */ = {
|
EC01511C2C305C99008A115E /* Dashboard */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
EC3D67CB2C3AAD5E00359400 /* MemoManager.swift */,
|
|
||||||
EC01511D2C305CA9008A115E /* DashboardView.swift */,
|
EC01511D2C305CA9008A115E /* DashboardView.swift */,
|
||||||
);
|
);
|
||||||
path = Dashboard;
|
path = Dashboard;
|
||||||
@@ -1123,7 +1120,6 @@
|
|||||||
EC01511E2C305CA9008A115E /* DashboardView.swift in Sources */,
|
EC01511E2C305CA9008A115E /* DashboardView.swift in Sources */,
|
||||||
EC8F54AE2C2AF5A4001C7C74 /* LineGridVertex.swift in Sources */,
|
EC8F54AE2C2AF5A4001C7C74 /* LineGridVertex.swift in Sources */,
|
||||||
EC2002F02C417BF1002EBD5F /* ActiveSceneKey.swift in Sources */,
|
EC2002F02C417BF1002EBD5F /* ActiveSceneKey.swift in Sources */,
|
||||||
EC3D67CC2C3AAD5E00359400 /* MemoManager.swift in Sources */,
|
|
||||||
EC2002E12C416470002EBD5F /* Shortcut.swift in Sources */,
|
EC2002E12C416470002EBD5F /* Shortcut.swift in Sources */,
|
||||||
EC5E83902BFDB69C00261D9C /* MovingAverage.swift in Sources */,
|
EC5E83902BFDB69C00261D9C /* MovingAverage.swift in Sources */,
|
||||||
ECFA15262BEF224900455818 /* StrokeObject.swift in Sources */,
|
ECFA15262BEF224900455818 /* StrokeObject.swift in Sources */,
|
||||||
|
|||||||
@@ -9,9 +9,24 @@ import Combine
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
final class Application: NSObject, ObservableObject {
|
final class Application: NSObject, ObservableObject {
|
||||||
|
@Published var memoObject: MemoObject?
|
||||||
@Published private(set) var sidebarVisibility: SidebarVisibility = .shown
|
@Published private(set) var sidebarVisibility: SidebarVisibility = .shown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Application {
|
||||||
|
func openMemo(_ memoObject: MemoObject?) {
|
||||||
|
withAnimation(.easeOut) {
|
||||||
|
self.memoObject = memoObject
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func closeMemo() {
|
||||||
|
withAnimation(.easeOut) {
|
||||||
|
self.memoObject = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension Application {
|
extension Application {
|
||||||
func activateSearchBar() {
|
func activateSearchBar() {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import SwiftUI
|
|||||||
struct DashboardView: View {
|
struct DashboardView: View {
|
||||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||||
|
|
||||||
@StateObject private var memoManager: MemoManager = .shared
|
|
||||||
@EnvironmentObject private var application: Application
|
@EnvironmentObject private var application: Application
|
||||||
|
|
||||||
@State private var sidebarItem: SidebarItem? = .memos
|
@State private var sidebarItem: SidebarItem? = .memos
|
||||||
@@ -32,10 +31,10 @@ struct DashboardView: View {
|
|||||||
MemosView()
|
MemosView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.toolbar(memoManager.memoObject == nil ? .visible : .hidden, for: .windowToolbar)
|
.toolbar(application.memoObject == nil ? .visible : .hidden, for: .windowToolbar)
|
||||||
.toolbarBackground(memoManager.memoObject == nil ? .clear : Color(nsColor: .windowBackgroundColor), for: .windowToolbar)
|
.toolbarBackground(application.memoObject == nil ? .clear : Color(nsColor: .windowBackgroundColor), for: .windowToolbar)
|
||||||
.overlay {
|
.overlay {
|
||||||
if let memo = memoManager.memoObject {
|
if let memo = application.memoObject {
|
||||||
MemoView(memo: memo)
|
MemoView(memo: memo)
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
withPersistence(\.viewContext) { context in
|
withPersistence(\.viewContext) { context in
|
||||||
@@ -62,7 +61,7 @@ struct DashboardView: View {
|
|||||||
MemosView()
|
MemosView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.fullScreenCover(item: $memoManager.memoObject) { memo in
|
.fullScreenCover(item: $application.memoObject) { memo in
|
||||||
MemoView(memo: memo)
|
MemoView(memo: memo)
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
withPersistence(\.viewContext) { context in
|
withPersistence(\.viewContext) { context in
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
//
|
|
||||||
// MemoManager.swift
|
|
||||||
// Memola
|
|
||||||
//
|
|
||||||
// Created by Dscyre Scotti on 7/7/24.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
#warning("TODO: use environmnet instead of singleton")
|
|
||||||
class MemoManager: ObservableObject {
|
|
||||||
static let shared: MemoManager = .init()
|
|
||||||
|
|
||||||
@Published var memoObject: MemoObject?
|
|
||||||
|
|
||||||
private init() { }
|
|
||||||
|
|
||||||
func openMemo(_ memoObject: MemoObject?) {
|
|
||||||
#if os(macOS)
|
|
||||||
withAnimation(.easeOut) {
|
|
||||||
self.memoObject = memoObject
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
self.memoObject = memoObject
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
func closeMemo() {
|
|
||||||
#if os(macOS)
|
|
||||||
withAnimation(.easeOut) {
|
|
||||||
self.memoObject = nil
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
self.memoObject = nil
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,8 @@ struct MemosView: View {
|
|||||||
@Environment(\.shortcut) private var shortcut
|
@Environment(\.shortcut) private var shortcut
|
||||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||||
|
|
||||||
|
@EnvironmentObject private var application: Application
|
||||||
|
|
||||||
@FetchRequest private var memoObjects: FetchedResults<MemoObject>
|
@FetchRequest private var memoObjects: FetchedResults<MemoObject>
|
||||||
|
|
||||||
@State private var query: String = ""
|
@State private var query: String = ""
|
||||||
@@ -259,7 +261,7 @@ struct MemosView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func openMemo(for memo: MemoObject) {
|
private func openMemo(for memo: MemoObject) {
|
||||||
MemoManager.shared.openMemo(memo)
|
application.openMemo(memo)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updatePredicate() {
|
private func updatePredicate() {
|
||||||
@@ -291,7 +293,7 @@ struct MemosView: View {
|
|||||||
private func handleShortcut(for shortcut: Shortcuts) {
|
private func handleShortcut(for shortcut: Shortcuts) {
|
||||||
switch shortcut {
|
switch shortcut {
|
||||||
case .newMemo:
|
case .newMemo:
|
||||||
if MemoManager.shared.memoObject == nil {
|
if application.memoObject == nil {
|
||||||
createMemo(title: "Untitled")
|
createMemo(title: "Untitled")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ struct TrashView: View {
|
|||||||
@Environment(\.shortcut) private var shortcut
|
@Environment(\.shortcut) private var shortcut
|
||||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||||
|
|
||||||
|
@EnvironmentObject private var application: Application
|
||||||
|
|
||||||
@FetchRequest private var memoObjects: FetchedResults<MemoObject>
|
@FetchRequest private var memoObjects: FetchedResults<MemoObject>
|
||||||
|
|
||||||
@State private var query: String = ""
|
@State private var query: String = ""
|
||||||
@@ -152,7 +154,7 @@ struct TrashView: View {
|
|||||||
restoreMemo(for: memo)
|
restoreMemo(for: memo)
|
||||||
self.sidebarItem = .memos
|
self.sidebarItem = .memos
|
||||||
if let memo {
|
if let memo {
|
||||||
MemoManager.shared.openMemo(memo)
|
application.openMemo(memo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ struct Toolbar: View {
|
|||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
@EnvironmentObject private var application: Application
|
||||||
|
#endif
|
||||||
|
|
||||||
@ObservedObject private var tool: Tool
|
@ObservedObject private var tool: Tool
|
||||||
@ObservedObject private var canvas: Canvas
|
@ObservedObject private var canvas: Canvas
|
||||||
@ObservedObject private var history: History
|
@ObservedObject private var history: History
|
||||||
@@ -186,7 +190,7 @@ struct Toolbar: View {
|
|||||||
private func closeMemo() {
|
private func closeMemo() {
|
||||||
canvas.save(for: memo) {
|
canvas.save(for: memo) {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
MemoManager.shared.closeMemo()
|
application.closeMemo()
|
||||||
#else
|
#else
|
||||||
dismiss()
|
dismiss()
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user