Move save functionality to File menu
- Remove save button from application toolbar - Add Save (⌘S) and Save As (⌘⇧S) menu items to File menu - Implement notification-based communication between menu and document views - Add unsaved changes indicator in window titles - Support both saving existing files and creating new files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,11 @@ import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
import AppKit
|
||||
|
||||
extension Notification.Name {
|
||||
static let saveDocument = Notification.Name("saveDocument")
|
||||
static let saveDocumentAs = Notification.Name("saveDocumentAs")
|
||||
}
|
||||
|
||||
@main
|
||||
struct MarkdownViewerApp: App {
|
||||
@StateObject private var recentFilesManager = RecentFilesManager.shared
|
||||
@@ -19,6 +24,18 @@ struct MarkdownViewerApp: App {
|
||||
|
||||
Divider()
|
||||
|
||||
Button("Save") {
|
||||
NotificationCenter.default.post(name: .saveDocument, object: nil)
|
||||
}
|
||||
.keyboardShortcut("s", modifiers: .command)
|
||||
|
||||
Button("Save As...") {
|
||||
NotificationCenter.default.post(name: .saveDocumentAs, object: nil)
|
||||
}
|
||||
.keyboardShortcut("s", modifiers: [.command, .shift])
|
||||
|
||||
Divider()
|
||||
|
||||
Menu("Recent Files") {
|
||||
if recentFilesManager.recentFiles.isEmpty {
|
||||
Text("No Recent Files")
|
||||
@@ -91,7 +108,8 @@ struct MarkdownViewerApp: App {
|
||||
newWindow.contentView = NSHostingView(
|
||||
rootView: MarkdownDocumentView(
|
||||
content: content,
|
||||
fileName: url.lastPathComponent
|
||||
fileName: url.lastPathComponent,
|
||||
fileURL: url
|
||||
)
|
||||
)
|
||||
newWindow.center()
|
||||
|
||||
Reference in New Issue
Block a user