diff --git a/CCMenu/Source/Pipeline Window/PipelineListToolbar.swift b/CCMenu/Source/Pipeline Window/PipelineListToolbar.swift index 8b08473..571a5ae 100644 --- a/CCMenu/Source/Pipeline Window/PipelineListToolbar.swift +++ b/CCMenu/Source/Pipeline Window/PipelineListToolbar.swift @@ -82,7 +82,7 @@ struct PipelineListToolbar: ToolbarContent { .help("Add a pipeline") Button() { - viewState.editIndex = selectionIndexSet().first + viewState.editIndex = viewState.selectionIndexSet(pipelines: model.pipelines).first viewState.isShowingSheet = true } label: { Label("Edit", systemImage: "gearshape") @@ -93,7 +93,7 @@ struct PipelineListToolbar: ToolbarContent { Button() { withAnimation { - model.pipelines.remove(atOffsets: selectionIndexSet()) + model.pipelines.remove(atOffsets: viewState.selectionIndexSet(pipelines: model.pipelines)) viewState.selection.removeAll() } } label: { @@ -114,14 +114,4 @@ struct PipelineListToolbar: ToolbarContent { // } } - private func selectionIndexSet() -> IndexSet { - var indexSet = IndexSet() - for (i, p) in model.pipelines.enumerated() { - if viewState.selection.contains(p.id) { - indexSet.insert(i) - } - } - return indexSet - } - } diff --git a/CCMenu/Source/Pipeline Window/PipelineListView.swift b/CCMenu/Source/Pipeline Window/PipelineListView.swift index 3535817..5419470 100644 --- a/CCMenu/Source/Pipeline Window/PipelineListView.swift +++ b/CCMenu/Source/Pipeline Window/PipelineListView.swift @@ -12,6 +12,18 @@ final class ListViewState: ObservableObject { @Published var sheetType: Pipeline.FeedType = .cctray @Published var editIndex: Int? @Published var selection: Set = Set() + + // TODO: Improve API + func selectionIndexSet(pipelines: [Pipeline]) -> IndexSet { + var indexSet = IndexSet() + for (i, p) in pipelines.enumerated() { + if selection.contains(p.id) { + indexSet.insert(i) + } + } + return indexSet + } + } @@ -39,8 +51,20 @@ struct PipelineListView: View { } } .frame(minWidth: 500) - .contextMenu(forSelectionType: String.self) {_ in - Text("Copy URL") // TODO: add functionality + .contextMenu(forSelectionType: String.self) { selection in + Button("Copy Feed URL") { + let value = model.pipelines + .filter({ selection.contains($0.id) }) + .map({ $0.feed.url }) + .joined(separator: "\n") + NSPasteboard.general.prepareForNewContents() + NSPasteboard.general.setString(value, forType: .string) + } + Divider() + Button("Open Web Page") { + // TODO: see primary action + } + .disabled(true) } primaryAction: { _ in // TODO: figure out what to open (same logic as in menu?) openUrl(URL(string: "http://ccmenu.org")!)