Skip to content

Commit

Permalink
Implemented "copy feed URL" on context menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdoe committed Jan 6, 2024
1 parent 0e01bbb commit 6679223
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
14 changes: 2 additions & 12 deletions CCMenu/Source/Pipeline Window/PipelineListToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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: {
Expand All @@ -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
}

}
28 changes: 26 additions & 2 deletions CCMenu/Source/Pipeline Window/PipelineListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ final class ListViewState: ObservableObject {
@Published var sheetType: Pipeline.FeedType = .cctray
@Published var editIndex: Int?
@Published var selection: Set<String> = 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
}

}


Expand Down Expand Up @@ -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")!)
Expand Down

0 comments on commit 6679223

Please sign in to comment.