Minor changes on the associated phrases.
1. Removes the tooltip on the candidate window to make the exprience looks like OpenVanilla. 2. Adds a Shift key symbol on the key label.
This commit is contained in:
parent
2ebc789030
commit
169d03ab9b
|
@ -23,6 +23,18 @@
|
||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
|
@objc(VTCandidateKeyLabel)
|
||||||
|
public class CandidateKeyLabel: NSObject {
|
||||||
|
@objc public private(set) var key: String
|
||||||
|
@objc public private(set) var displayedText: String
|
||||||
|
|
||||||
|
public init(key: String, displayedText: String) {
|
||||||
|
self.key = key
|
||||||
|
self.displayedText = displayedText
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc(VTCandidateControllerDelegate)
|
@objc(VTCandidateControllerDelegate)
|
||||||
public protocol CandidateControllerDelegate: AnyObject {
|
public protocol CandidateControllerDelegate: AnyObject {
|
||||||
func candidateCountForController(_ controller: CandidateController) -> UInt
|
func candidateCountForController(_ controller: CandidateController) -> UInt
|
||||||
|
@ -62,7 +74,9 @@ public class CandidateController: NSWindowController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public var keyLabels: [String] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
|
@objc public var keyLabels: [CandidateKeyLabel] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"].map {
|
||||||
|
CandidateKeyLabel(key: $0, displayedText: $0)
|
||||||
|
}
|
||||||
@objc public var keyLabelFont: NSFont = NSFont.systemFont(ofSize: 14)
|
@objc public var keyLabelFont: NSFont = NSFont.systemFont(ofSize: 14)
|
||||||
@objc public var candidateFont: NSFont = NSFont.systemFont(ofSize: 18)
|
@objc public var candidateFont: NSFont = NSFont.systemFont(ofSize: 18)
|
||||||
@objc public var tooltip: String = ""
|
@objc public var tooltip: String = ""
|
||||||
|
|
|
@ -73,7 +73,6 @@ fileprivate class HorizontalCandidateView: NSView {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(setKeyLabels:displayedCandidates:)
|
|
||||||
func set(keyLabels labels: [String], displayedCandidates candidates: [String]) {
|
func set(keyLabels labels: [String], displayedCandidates candidates: [String]) {
|
||||||
let count = min(labels.count, candidates.count)
|
let count = min(labels.count, candidates.count)
|
||||||
keyLabels = Array(labels[0..<count])
|
keyLabels = Array(labels[0..<count])
|
||||||
|
@ -91,7 +90,6 @@ fileprivate class HorizontalCandidateView: NSView {
|
||||||
elementWidths = newWidths
|
elementWidths = newWidths
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(setKeyLabelFont:candidateFont:)
|
|
||||||
func set(keyLabelFont labelFont: NSFont, candidateFont: NSFont) {
|
func set(keyLabelFont labelFont: NSFont, candidateFont: NSFont) {
|
||||||
let paraStyle = NSMutableParagraphStyle()
|
let paraStyle = NSMutableParagraphStyle()
|
||||||
paraStyle.setParagraphStyle(NSParagraphStyle.default)
|
paraStyle.setParagraphStyle(NSParagraphStyle.default)
|
||||||
|
@ -374,7 +372,7 @@ extension HorizontalCandidateController {
|
||||||
let candidate = delegate.candidateController(self, candidateAtIndex: index)
|
let candidate = delegate.candidateController(self, candidateAtIndex: index)
|
||||||
candidates.append(candidate)
|
candidates.append(candidate)
|
||||||
}
|
}
|
||||||
candidateView.set(keyLabels: keyLabels, displayedCandidates: candidates)
|
candidateView.set(keyLabels: keyLabels.map { $0.displayedText}, displayedCandidates: candidates)
|
||||||
candidateView.toolTip = tooltip
|
candidateView.toolTip = tooltip
|
||||||
var newSize = candidateView.sizeForView
|
var newSize = candidateView.sizeForView
|
||||||
var frameRect = candidateView.frame
|
var frameRect = candidateView.frame
|
||||||
|
|
|
@ -450,7 +450,8 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
||||||
}
|
}
|
||||||
|
|
||||||
keyLabelStripView.keyLabelFont = keyLabelFont
|
keyLabelStripView.keyLabelFont = keyLabelFont
|
||||||
keyLabelStripView.keyLabels = Array(keyLabels[0..<Int(keyLabelCount)])
|
let keyLabels = keyLabels[0..<Int(keyLabelCount)].map { $0.displayedText }
|
||||||
|
keyLabelStripView.keyLabels = keyLabels
|
||||||
keyLabelStripView.labelOffsetY = (keyLabelFontSize >= candidateFontSize) ? 0.0 : floor((candidateFontSize - keyLabelFontSize) / 2.0)
|
keyLabelStripView.labelOffsetY = (keyLabelFontSize >= candidateFontSize) ? 0.0 : floor((candidateFontSize - keyLabelFontSize) / 2.0)
|
||||||
|
|
||||||
let rowHeight = ceil(fontSize * 1.25)
|
let rowHeight = ceil(fontSize * 1.25)
|
||||||
|
|
|
@ -248,7 +248,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AppDelegate : FSEventStreamHelperDelegate {
|
extension AppDelegate: FSEventStreamHelperDelegate {
|
||||||
func helper(_ helper: FSEventStreamHelper, didReceive events: [FSEventStreamHelper.Event]) {
|
func helper(_ helper: FSEventStreamHelper, didReceive events: [FSEventStreamHelper.Event]) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
LanguageModelManager.loadUserPhrases()
|
LanguageModelManager.loadUserPhrases()
|
||||||
|
|
|
@ -437,11 +437,10 @@ extension McBopomofoInputMethodController {
|
||||||
extension McBopomofoInputMethodController {
|
extension McBopomofoInputMethodController {
|
||||||
|
|
||||||
private func show(candidateWindowWith state: InputState, client: Any!) {
|
private func show(candidateWindowWith state: InputState, client: Any!) {
|
||||||
let useVerticalMode:Bool = {
|
let useVerticalMode: Bool = {
|
||||||
if let state = state as? InputState.ChoosingCandidate {
|
if let state = state as? InputState.ChoosingCandidate {
|
||||||
return state.useVerticalMode
|
return state.useVerticalMode
|
||||||
}
|
} else if let state = state as? InputState.AssociatedPhrases {
|
||||||
else if let state = state as? InputState.AssociatedPhrases {
|
|
||||||
return state.useVerticalMode
|
return state.useVerticalMode
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -455,12 +454,6 @@ extension McBopomofoInputMethodController {
|
||||||
gCurrentCandidateController = McBopomofoInputMethodController.verticalCandidateController
|
gCurrentCandidateController = McBopomofoInputMethodController.verticalCandidateController
|
||||||
}
|
}
|
||||||
|
|
||||||
if state is InputState.AssociatedPhrases {
|
|
||||||
gCurrentCandidateController?.tooltip = NSLocalizedString("Associated Phrases", comment: "")
|
|
||||||
} else {
|
|
||||||
gCurrentCandidateController?.tooltip = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the attributes for the candidate panel (which uses NSAttributedString)
|
// set the attributes for the candidate panel (which uses NSAttributedString)
|
||||||
let textSize = Preferences.candidateListTextSize
|
let textSize = Preferences.candidateListTextSize
|
||||||
let keyLabelSize = max(textSize / 2, kMinKeyLabelSize)
|
let keyLabelSize = max(textSize / 2, kMinKeyLabelSize)
|
||||||
|
@ -477,10 +470,11 @@ extension McBopomofoInputMethodController {
|
||||||
|
|
||||||
let candidateKeys = Preferences.candidateKeys
|
let candidateKeys = Preferences.candidateKeys
|
||||||
let keyLabels = candidateKeys.count > 4 ? Array(candidateKeys) : Array(Preferences.defaultCandidateKeys)
|
let keyLabels = candidateKeys.count > 4 ? Array(candidateKeys) : Array(Preferences.defaultCandidateKeys)
|
||||||
|
let keyLabelPrefix = state is InputState.AssociatedPhrases ? "⇧ " : ""
|
||||||
|
gCurrentCandidateController?.keyLabels = keyLabels.map {
|
||||||
|
CandidateKeyLabel(key: String($0), displayedText: keyLabelPrefix + String($0))
|
||||||
|
}
|
||||||
|
|
||||||
gCurrentCandidateController?.keyLabels = Array(keyLabels.map {
|
|
||||||
String($0)
|
|
||||||
})
|
|
||||||
gCurrentCandidateController?.delegate = self
|
gCurrentCandidateController?.delegate = self
|
||||||
gCurrentCandidateController?.reloadData()
|
gCurrentCandidateController?.reloadData()
|
||||||
currentCandidateClient = client
|
currentCandidateClient = client
|
||||||
|
@ -488,7 +482,7 @@ extension McBopomofoInputMethodController {
|
||||||
gCurrentCandidateController?.visible = true
|
gCurrentCandidateController?.visible = true
|
||||||
|
|
||||||
var lineHeightRect = NSMakeRect(0.0, 0.0, 16.0, 16.0)
|
var lineHeightRect = NSMakeRect(0.0, 0.0, 16.0, 16.0)
|
||||||
var cursor:UInt = 0
|
var cursor: UInt = 0
|
||||||
|
|
||||||
if let state = state as? InputState.ChoosingCandidate {
|
if let state = state as? InputState.ChoosingCandidate {
|
||||||
cursor = state.cursorIndex
|
cursor = state.cursorIndex
|
||||||
|
@ -579,10 +573,10 @@ extension McBopomofoInputMethodController: CandidateControllerDelegate {
|
||||||
|
|
||||||
if keyHandler.inputMode == .plainBopomofo {
|
if keyHandler.inputMode == .plainBopomofo {
|
||||||
keyHandler.clear()
|
keyHandler.clear()
|
||||||
let text = inputting.composingBuffer
|
let composingBuffer = inputting.composingBuffer
|
||||||
handle(state: .Committing(poppedText: text), client: currentCandidateClient)
|
handle(state: .Committing(poppedText: composingBuffer), client: currentCandidateClient)
|
||||||
if Preferences.associatedPhrasesEnabled,
|
if Preferences.associatedPhrasesEnabled,
|
||||||
let associatePhrases = keyHandler.buildAssociatePhraseState(withKey: text, useVerticalMode: state.useVerticalMode) as? InputState.AssociatedPhrases {
|
let associatePhrases = keyHandler.buildAssociatePhraseState(withKey: composingBuffer, useVerticalMode: state.useVerticalMode) as? InputState.AssociatedPhrases {
|
||||||
self.handle(state: associatePhrases, client: self.currentCandidateClient)
|
self.handle(state: associatePhrases, client: self.currentCandidateClient)
|
||||||
} else {
|
} else {
|
||||||
handle(state: .Empty(), client: currentDeferredClient)
|
handle(state: .Empty(), client: currentDeferredClient)
|
||||||
|
@ -593,7 +587,12 @@ extension McBopomofoInputMethodController: CandidateControllerDelegate {
|
||||||
} else if let state = state as? InputState.AssociatedPhrases {
|
} else if let state = state as? InputState.AssociatedPhrases {
|
||||||
let selectedValue = state.candidates[Int(index)]
|
let selectedValue = state.candidates[Int(index)]
|
||||||
handle(state: .Committing(poppedText: selectedValue), client: currentCandidateClient)
|
handle(state: .Committing(poppedText: selectedValue), client: currentCandidateClient)
|
||||||
handle(state: .Empty(), client: currentDeferredClient)
|
if Preferences.associatedPhrasesEnabled,
|
||||||
|
let associatePhrases = keyHandler.buildAssociatePhraseState(withKey: selectedValue, useVerticalMode: state.useVerticalMode) as? InputState.AssociatedPhrases {
|
||||||
|
self.handle(state: associatePhrases, client: self.currentCandidateClient)
|
||||||
|
} else {
|
||||||
|
handle(state: .Empty(), client: currentDeferredClient)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -890,8 +890,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
}
|
}
|
||||||
|
|
||||||
if (charCode == 13 || [input isEnter]) {
|
if (charCode == 13 || [input isEnter]) {
|
||||||
if ([state isKindOfClass: [InputStateAssociatedPhrases class]] && ![input isShiftHold]) {
|
if ([state isKindOfClass: [InputStateAssociatedPhrases class]]) {
|
||||||
return NO;
|
[self clear];
|
||||||
|
InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init];
|
||||||
|
stateCallback(empty);
|
||||||
|
return YES;
|
||||||
}
|
}
|
||||||
[self.delegate keyHandler:self didSelectCandidateAtIndex:gCurrentCandidateController.selectedCandidateIndex candidateController:gCurrentCandidateController];
|
[self.delegate keyHandler:self didSelectCandidateAtIndex:gCurrentCandidateController.selectedCandidateIndex candidateController:gCurrentCandidateController];
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -1012,10 +1015,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
|
|
||||||
if ([state isKindOfClass: [InputStateChoosingCandidate class]]) {
|
if ([state isKindOfClass: [InputStateChoosingCandidate class]]) {
|
||||||
candidates = [(InputStateChoosingCandidate *)state candidates];
|
candidates = [(InputStateChoosingCandidate *)state candidates];
|
||||||
|
} else if ([state isKindOfClass: [InputStateAssociatedPhrases class]]) {
|
||||||
|
candidates = [(InputStateAssociatedPhrases *)state candidates];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([state isKindOfClass: [InputStateAssociatedPhrases class]]) {
|
if (!candidates) {
|
||||||
candidates = [(InputStateAssociatedPhrases *)state candidates];
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (([input isEnd] || input.emacsKey == McBopomofoEmacsKeyEnd) && candidates.count > 0) {
|
if (([input isEnd] || input.emacsKey == McBopomofoEmacsKeyEnd) && candidates.count > 0) {
|
||||||
|
@ -1029,21 +1034,23 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([state isKindOfClass: [InputStateAssociatedPhrases class]]) {
|
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) {
|
||||||
if (![input isShiftHold]) {
|
if (![input isShiftHold]) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSInteger index = NSNotFound;
|
NSInteger index = NSNotFound;
|
||||||
NSString *match = inputText;
|
NSString *match;
|
||||||
|
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) {
|
||||||
if ([state isKindOfClass: [InputStateAssociatedPhrases class]]) {
|
|
||||||
match = input.inputTextIgnoringModifiers;
|
match = input.inputTextIgnoringModifiers;
|
||||||
|
} else {
|
||||||
|
match = inputText;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NSUInteger j = 0, c = [gCurrentCandidateController.keyLabels count]; j < c; j++) {
|
for (NSUInteger j = 0, c = [gCurrentCandidateController.keyLabels count]; j < c; j++) {
|
||||||
if ([match compare:[gCurrentCandidateController.keyLabels objectAtIndex:j] options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
VTCandidateKeyLabel *label = gCurrentCandidateController.keyLabels[j];
|
||||||
|
if ([match compare:label.key options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
index = j;
|
index = j;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1057,7 +1064,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([state isKindOfClass: [InputStateAssociatedPhrases class]]) {
|
if ([state isKindOfClass:[InputStateAssociatedPhrases class]]) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,9 @@ import Carbon
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func changeSelectionKeyAction(_ sender: Any) {
|
@IBAction func changeSelectionKeyAction(_ sender: Any) {
|
||||||
guard let keys = (sender as AnyObject).stringValue?.trimmingCharacters(in: .whitespacesAndNewlines) else {
|
guard let keys = (sender as AnyObject).stringValue?
|
||||||
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
.lowercased() else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in New Issue