From 5db19f854ee8641460f2fbf0d751da81d1e8db85 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sun, 27 Nov 2022 21:17:42 +0800 Subject: [PATCH] TDKCandidates // Add context menu support. --- .../VwrCandidateHorizontal.swift | 25 +++++++++++++++++++ .../VwrCandidateVertical.swift | 25 +++++++++++++++++++ .../VwrCandidateHorizontalBackports.swift | 25 +++++++++++++++++++ .../VwrCandidateVerticalBackports.swift | 25 +++++++++++++++++++ 4 files changed, 100 insertions(+) diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateHorizontal.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateHorizontal.swift index 8c0882ab..5f86f054 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateHorizontal.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateHorizontal.swift @@ -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( diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateVertical.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateVertical.swift index efbdf792..1b2c441a 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateVertical.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK/VwrCandidateVertical.swift @@ -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( diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateHorizontalBackports.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateHorizontalBackports.swift index b8029593..fa603180 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateHorizontalBackports.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateHorizontalBackports.swift @@ -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( diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateVerticalBackports.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateVerticalBackports.swift index 5c6f1643..46098aec 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateVerticalBackports.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/VwrCandidateTDK_Backports/VwrCandidateVerticalBackports.swift @@ -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(