TDKCandidates // Add context menu support.

This commit is contained in:
ShikiSuen 2022-11-27 21:17:42 +08:00
parent 1d593b490f
commit 5db19f854e
4 changed files with 100 additions and 0 deletions

View File

@ -51,6 +51,12 @@ public struct VwrCandidateHorizontal: View {
}
}
private func didRightClickCandidateAt(_ pos: Int, action: CandidateContextMenuAction) {
if let delegate = controller?.delegate {
delegate.candidatePairRightClicked(at: pos, action: action)
}
}
public var body: some View {
VStack(alignment: .leading, spacing: 0) {
ScrollView(.vertical, showsIndicators: false) {
@ -65,6 +71,25 @@ public struct VwrCandidateHorizontal: View {
)
.contentShape(Rectangle())
.onTapGesture { didSelectCandidateAt(currentCandidate.index) }
.contextMenu {
if controller?.delegate?.isCandidateContextMenuEnabled ?? false {
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toBoost)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toNerf)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toFilter)
} label: {
Text("✖︎ " + currentCandidate.displayedText)
}
}
}
}
Spacer()
}.frame(

View File

@ -50,6 +50,12 @@ public struct VwrCandidateVertical: View {
}
}
private func didRightClickCandidateAt(_ pos: Int, action: CandidateContextMenuAction) {
if let delegate = controller?.delegate {
delegate.candidatePairRightClicked(at: pos, action: action)
}
}
public var body: some View {
VStack(alignment: .leading, spacing: 0) {
ScrollView(.horizontal, showsIndicators: false) {
@ -65,6 +71,25 @@ public struct VwrCandidateVertical: View {
)
.contentShape(Rectangle())
.onTapGesture { didSelectCandidateAt(currentCandidate.index) }
.contextMenu {
if controller?.delegate?.isCandidateContextMenuEnabled ?? false {
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toBoost)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toNerf)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toFilter)
} label: {
Text("✖︎ " + currentCandidate.displayedText)
}
}
}
}
}
}.frame(

View File

@ -52,6 +52,12 @@ public struct VwrCandidateHorizontalBackports: View {
}
}
private func didRightClickCandidateAt(_ pos: Int, action: CandidateContextMenuAction) {
if let delegate = controller?.delegate {
delegate.candidatePairRightClicked(at: pos, action: action)
}
}
public var body: some View {
VStack(alignment: .leading, spacing: 0) {
ScrollView(.vertical, showsIndicators: false) {
@ -66,6 +72,25 @@ public struct VwrCandidateHorizontalBackports: View {
)
.contentShape(Rectangle())
.onTapGesture { didSelectCandidateAt(currentCandidate.index) }
.contextMenu {
if controller?.delegate?.isCandidateContextMenuEnabled ?? false {
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toBoost)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toNerf)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toFilter)
} label: {
Text("✖︎ " + currentCandidate.displayedText)
}
}
}
}
Spacer()
}.frame(

View File

@ -51,6 +51,12 @@ public struct VwrCandidateVerticalBackports: View {
}
}
private func didRightClickCandidateAt(_ pos: Int, action: CandidateContextMenuAction) {
if let delegate = controller?.delegate {
delegate.candidatePairRightClicked(at: pos, action: action)
}
}
public var body: some View {
VStack(alignment: .leading, spacing: 0) {
ScrollView(.horizontal, showsIndicators: false) {
@ -66,6 +72,25 @@ public struct VwrCandidateVerticalBackports: View {
)
.contentShape(Rectangle())
.onTapGesture { didSelectCandidateAt(currentCandidate.index) }
.contextMenu {
if controller?.delegate?.isCandidateContextMenuEnabled ?? false {
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toBoost)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toNerf)
} label: {
Text("" + currentCandidate.displayedText)
}
Button {
didRightClickCandidateAt(currentCandidate.index, action: .toFilter)
} label: {
Text("✖︎ " + currentCandidate.displayedText)
}
}
}
}
}
}.frame(