Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Sources/PalmierPro/App/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ final class AppState {
openProject(at: url, register: false, options: options)
}

func duplicateProject(at url: URL) {
let panel = NSSavePanel()
panel.allowedContentTypes = [Self.projectContentType]
panel.nameFieldStringValue = "\(url.deletingPathExtension().lastPathComponent) Copy"
panel.directoryURL = url.deletingLastPathComponent()
panel.title = "Duplicate Project"
panel.begin { response in
guard response == .OK, let dest = panel.url else { return }
do {
try FileManager.default.copyItem(at: url, to: dest)
AppState.shared.openProject(at: dest)
} catch {
NSAlert(error: error).runModal()
}
}
}

func openProjectFromPanel() {
let panel = NSOpenPanel()
panel.allowedContentTypes = [Self.projectContentType]
Expand Down
1 change: 1 addition & 0 deletions Sources/PalmierPro/Project/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct HomeView: View {
ProjectCard(
entry: entry,
onOpen: { AppState.shared.openProject(at: $0) },
onDuplicate: { AppState.shared.duplicateProject(at: $0) },
onRemove: { ProjectRegistry.shared.remove($0) }
)
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/PalmierPro/Project/ProjectCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
struct ProjectCard: View {
let entry: ProjectEntry
let onOpen: (URL) -> Void
let onDuplicate: (URL) -> Void
let onRemove: (URL) -> Void

@State private var isHovered = false
Expand Down Expand Up @@ -101,6 +102,7 @@ struct ProjectCard: View {
.contextMenu {
if entry.isAccessible {
Button("Open") { onOpen(entry.url) }
Button("Duplicate") { onDuplicate(entry.url) }
Button("Reveal in Finder") {
NSWorkspace.shared.selectFile(entry.url.path, inFileViewerRootedAtPath: entry.url.deletingLastPathComponent().path)
}
Expand Down