From c72f1c10a7fdd8d5f4537b690e26f4d98d0444da Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 4 Apr 2022 13:21:27 +0800 Subject: [PATCH] Proj // Shorten the naming of Candidate Controllers. --- Source/Modules/ControllerModules/KeyHandler.h | 6 +- .../Modules/ControllerModules/KeyHandler.mm | 78 +++++++++---------- .../Modules/IMEModules/ctlInputMethod.swift | 70 ++++++++--------- ...ateController.swift => ctlCandidate.swift} | 18 ++--- ...ler.swift => ctlCandidateHorizontal.swift} | 9 +-- ...oller.swift => ctlCandidateVertical.swift} | 9 +-- vChewing.xcodeproj/project.pbxproj | 24 +++--- 7 files changed, 103 insertions(+), 111 deletions(-) rename Source/UI/CandidateUI/{CandidateController.swift => ctlCandidate.swift} (91%) rename Source/UI/CandidateUI/{HorizontalCandidateController.swift => ctlCandidateHorizontal.swift} (98%) rename Source/UI/CandidateUI/{VerticalCandidateController.swift => ctlCandidateVertical.swift} (98%) diff --git a/Source/Modules/ControllerModules/KeyHandler.h b/Source/Modules/ControllerModules/KeyHandler.h index 6b6116d0..9e1db717 100644 --- a/Source/Modules/ControllerModules/KeyHandler.h +++ b/Source/Modules/ControllerModules/KeyHandler.h @@ -39,10 +39,8 @@ extern InputMode imeModeNULL; @class KeyHandler; @protocol KeyHandlerDelegate -- (id)candidateControllerForKeyHandler:(KeyHandler *)keyHandler; -- (void)keyHandler:(KeyHandler *)keyHandler - didSelectCandidateAtIndex:(NSInteger)index - candidateController:(id)controller; +- (id)ctlCandidateForKeyHandler:(KeyHandler *)keyHandler; +- (void)keyHandler:(KeyHandler *)keyHandler didSelectCandidateAtIndex:(NSInteger)index ctlCandidate:(id)controller; - (BOOL)keyHandler:(KeyHandler *)keyHandler didRequestWriteUserPhraseWithState:(InputState *)state; @end diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index c2eb3b12..0f638936 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -1261,7 +1261,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; { NSString *inputText = input.inputText; UniChar charCode = input.charCode; - VTCandidateController *gCurrentCandidateController = [self.delegate candidateControllerForKeyHandler:self]; + ctlCandidate *ctlCandidateCurrent = [self.delegate ctlCandidateForKeyHandler:self]; BOOL cancelCandidateKey = [input isBackSpace] || [input isESC] || [input isDelete] || (([input isCursorBackward] || [input isCursorForward]) && [input isShiftHold]); @@ -1306,18 +1306,18 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; return YES; } [self.delegate keyHandler:self - didSelectCandidateAtIndex:gCurrentCandidateController.selectedCandidateIndex - candidateController:gCurrentCandidateController]; + didSelectCandidateAtIndex:ctlCandidateCurrent.selectedCandidateIndex + ctlCandidate:ctlCandidateCurrent]; return YES; } if ([input isTab]) { - BOOL updated = mgrPrefs.specifyTabKeyBehavior - ? ([input isShiftHold] ? [gCurrentCandidateController showPreviousPage] - : [gCurrentCandidateController showNextPage]) - : ([input isShiftHold] ? [gCurrentCandidateController highlightPreviousCandidate] - : [gCurrentCandidateController highlightNextCandidate]); + BOOL updated = + mgrPrefs.specifyTabKeyBehavior + ? ([input isShiftHold] ? [ctlCandidateCurrent showPreviousPage] : [ctlCandidateCurrent showNextPage]) + : ([input isShiftHold] ? [ctlCandidateCurrent highlightPreviousCandidate] + : [ctlCandidateCurrent highlightNextCandidate]); if (!updated) { [IME prtDebugIntel:@"9B691919"]; @@ -1329,10 +1329,10 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isSpace]) { BOOL updated = mgrPrefs.specifySpaceKeyBehavior - ? ([input isShiftHold] ? [gCurrentCandidateController highlightNextCandidate] - : [gCurrentCandidateController showNextPage]) - : ([input isShiftHold] ? [gCurrentCandidateController showNextPage] - : [gCurrentCandidateController highlightNextCandidate]); + ? ([input isShiftHold] ? [ctlCandidateCurrent highlightNextCandidate] + : [ctlCandidateCurrent showNextPage]) + : ([input isShiftHold] ? [ctlCandidateCurrent showNextPage] + : [ctlCandidateCurrent highlightNextCandidate]); if (!updated) { [IME prtDebugIntel:@"A11C781F"]; @@ -1343,7 +1343,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isPageDown] || input.emacsKey == vChewingEmacsKeyNextPage) { - BOOL updated = [gCurrentCandidateController showNextPage]; + BOOL updated = [ctlCandidateCurrent showNextPage]; if (!updated) { [IME prtDebugIntel:@"9B691919"]; @@ -1354,7 +1354,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isPageUp]) { - BOOL updated = [gCurrentCandidateController showPreviousPage]; + BOOL updated = [ctlCandidateCurrent showPreviousPage]; if (!updated) { [IME prtDebugIntel:@"9569955D"]; @@ -1365,9 +1365,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isLeft]) { - if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) + if ([ctlCandidateCurrent isKindOfClass:[ctlCandidateHorizontal class]]) { - BOOL updated = [gCurrentCandidateController highlightPreviousCandidate]; + BOOL updated = [ctlCandidateCurrent highlightPreviousCandidate]; if (!updated) { [IME prtDebugIntel:@"1145148D"]; @@ -1376,7 +1376,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } else { - BOOL updated = [gCurrentCandidateController showPreviousPage]; + BOOL updated = [ctlCandidateCurrent showPreviousPage]; if (!updated) { [IME prtDebugIntel:@"1919810D"]; @@ -1388,7 +1388,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (input.emacsKey == vChewingEmacsKeyBackward) { - BOOL updated = [gCurrentCandidateController highlightPreviousCandidate]; + BOOL updated = [ctlCandidateCurrent highlightPreviousCandidate]; if (!updated) { [IME prtDebugIntel:@"9B89308D"]; @@ -1399,9 +1399,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isRight]) { - if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) + if ([ctlCandidateCurrent isKindOfClass:[ctlCandidateHorizontal class]]) { - BOOL updated = [gCurrentCandidateController highlightNextCandidate]; + BOOL updated = [ctlCandidateCurrent highlightNextCandidate]; if (!updated) { [IME prtDebugIntel:@"9B65138D"]; @@ -1410,7 +1410,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } else { - BOOL updated = [gCurrentCandidateController showNextPage]; + BOOL updated = [ctlCandidateCurrent showNextPage]; if (!updated) { [IME prtDebugIntel:@"9244908D"]; @@ -1422,7 +1422,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (input.emacsKey == vChewingEmacsKeyForward) { - BOOL updated = [gCurrentCandidateController highlightNextCandidate]; + BOOL updated = [ctlCandidateCurrent highlightNextCandidate]; if (!updated) { [IME prtDebugIntel:@"9B2428D"]; @@ -1433,9 +1433,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isUp]) { - if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) + if ([ctlCandidateCurrent isKindOfClass:[ctlCandidateHorizontal class]]) { - BOOL updated = [gCurrentCandidateController showPreviousPage]; + BOOL updated = [ctlCandidateCurrent showPreviousPage]; if (!updated) { [IME prtDebugIntel:@"9B614524"]; @@ -1444,7 +1444,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } else { - BOOL updated = [gCurrentCandidateController highlightPreviousCandidate]; + BOOL updated = [ctlCandidateCurrent highlightPreviousCandidate]; if (!updated) { [IME prtDebugIntel:@"ASD9908D"]; @@ -1456,9 +1456,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isDown]) { - if ([gCurrentCandidateController isKindOfClass:[VTHorizontalCandidateController class]]) + if ([ctlCandidateCurrent isKindOfClass:[ctlCandidateHorizontal class]]) { - BOOL updated = [gCurrentCandidateController showNextPage]; + BOOL updated = [ctlCandidateCurrent showNextPage]; if (!updated) { [IME prtDebugIntel:@"92B990DD"]; @@ -1467,7 +1467,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } else { - BOOL updated = [gCurrentCandidateController highlightNextCandidate]; + BOOL updated = [ctlCandidateCurrent highlightNextCandidate]; if (!updated) { [IME prtDebugIntel:@"6B99908D"]; @@ -1479,14 +1479,14 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if ([input isHome] || input.emacsKey == vChewingEmacsKeyHome) { - if (gCurrentCandidateController.selectedCandidateIndex == 0) + if (ctlCandidateCurrent.selectedCandidateIndex == 0) { [IME prtDebugIntel:@"9B6EDE8D"]; errorCallback(); } else { - gCurrentCandidateController.selectedCandidateIndex = 0; + ctlCandidateCurrent.selectedCandidateIndex = 0; } return YES; @@ -1510,14 +1510,14 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (([input isEnd] || input.emacsKey == vChewingEmacsKeyEnd) && candidates.count > 0) { - if (gCurrentCandidateController.selectedCandidateIndex == candidates.count - 1) + if (ctlCandidateCurrent.selectedCandidateIndex == candidates.count - 1) { [IME prtDebugIntel:@"9B69AAAD"]; errorCallback(); } else { - gCurrentCandidateController.selectedCandidateIndex = candidates.count - 1; + ctlCandidateCurrent.selectedCandidateIndex = candidates.count - 1; } return YES; } @@ -1541,9 +1541,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; match = inputText; } - for (NSUInteger j = 0, c = [gCurrentCandidateController.keyLabels count]; j < c; j++) + for (NSUInteger j = 0, c = [ctlCandidateCurrent.keyLabels count]; j < c; j++) { - VTCandidateKeyLabel *label = gCurrentCandidateController.keyLabels[j]; + VTCandidateKeyLabel *label = ctlCandidateCurrent.keyLabels[j]; if ([match compare:label.key options:NSCaseInsensitiveSearch] == NSOrderedSame) { index = j; @@ -1553,12 +1553,10 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (index != NSNotFound) { - NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:index]; + NSUInteger candidateIndex = [ctlCandidateCurrent candidateIndexAtKeyLabelIndex:index]; if (candidateIndex != NSUIntegerMax) { - [self.delegate keyHandler:self - didSelectCandidateAtIndex:candidateIndex - candidateController:gCurrentCandidateController]; + [self.delegate keyHandler:self didSelectCandidateAtIndex:candidateIndex ctlCandidate:ctlCandidateCurrent]; return YES; } } @@ -1606,12 +1604,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (shouldAutoSelectCandidate) { - NSUInteger candidateIndex = [gCurrentCandidateController candidateIndexAtKeyLabelIndex:0]; + NSUInteger candidateIndex = [ctlCandidateCurrent candidateIndexAtKeyLabelIndex:0]; if (candidateIndex != NSUIntegerMax) { [self.delegate keyHandler:self didSelectCandidateAtIndex:candidateIndex - candidateController:gCurrentCandidateController]; + ctlCandidate:ctlCandidateCurrent]; [self clear]; InputStateEmptyIgnoringPreviousState *empty = [[InputStateEmptyIgnoringPreviousState alloc] init]; stateCallback(empty); diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index 4bfc6675..73f2c310 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -35,11 +35,11 @@ extension Bool { private let kMinKeyLabelSize: CGFloat = 10 -private var gCurrentCandidateController: CandidateController? +private var ctlCandidateCurrent: ctlCandidate? -extension CandidateController { - fileprivate static let horizontal = HorizontalCandidateController() - fileprivate static let vertical = VerticalCandidateController() +extension ctlCandidate { + fileprivate static let horizontal = ctlCandidateHorizontal() + fileprivate static let vertical = ctlCandidateVertical() } @objc(ctlInputMethod) @@ -500,8 +500,8 @@ extension ctlInputMethod { private func handle(state: InputState.Deactivated, previous: InputState, client: Any?) { currentCandidateClient = nil - gCurrentCandidateController?.delegate = nil - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.delegate = nil + ctlCandidateCurrent?.visible = false hideTooltip() if let previous = previous as? InputState.NotEmpty { @@ -513,7 +513,7 @@ extension ctlInputMethod { } private func handle(state: InputState.Empty, previous: InputState, client: Any?) { - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.visible = false hideTooltip() guard let client = client as? IMKTextInput else { @@ -531,7 +531,7 @@ extension ctlInputMethod { private func handle( state: InputState.EmptyIgnoringPreviousState, previous: InputState, client: Any! ) { - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.visible = false hideTooltip() guard let client = client as? IMKTextInput else { @@ -544,7 +544,7 @@ extension ctlInputMethod { } private func handle(state: InputState.Committing, previous: InputState, client: Any?) { - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.visible = false hideTooltip() guard let client = client as? IMKTextInput else { @@ -561,7 +561,7 @@ extension ctlInputMethod { } private func handle(state: InputState.Inputting, previous: InputState, client: Any?) { - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.visible = false hideTooltip() guard let client = client as? IMKTextInput else { @@ -586,7 +586,7 @@ extension ctlInputMethod { } private func handle(state: InputState.Marking, previous: InputState, client: Any?) { - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.visible = false guard let client = client as? IMKTextInput else { hideTooltip() return @@ -610,7 +610,7 @@ extension ctlInputMethod { private func handle(state: InputState.ChoosingCandidate, previous: InputState, client: Any?) { hideTooltip() guard let client = client as? IMKTextInput else { - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.visible = false return } @@ -625,7 +625,7 @@ extension ctlInputMethod { private func handle(state: InputState.AssociatedPhrases, previous: InputState, client: Any?) { hideTooltip() guard let client = client as? IMKTextInput else { - gCurrentCandidateController?.visible = false + ctlCandidateCurrent?.visible = false return } client.setMarkedText( @@ -664,14 +664,14 @@ extension ctlInputMethod { return false }() - gCurrentCandidateController?.delegate = nil + ctlCandidateCurrent?.delegate = nil if useVerticalMode { - gCurrentCandidateController = .vertical + ctlCandidateCurrent = .vertical } else if mgrPrefs.useHorizontalCandidateList { - gCurrentCandidateController = .horizontal + ctlCandidateCurrent = .horizontal } else { - gCurrentCandidateController = .vertical + ctlCandidateCurrent = .vertical } // set the attributes for the candidate panel (which uses NSAttributedString) @@ -699,24 +699,24 @@ extension ctlInputMethod { return finalReturnFont } - gCurrentCandidateController?.keyLabelFont = labelFont( + ctlCandidateCurrent?.keyLabelFont = labelFont( name: mgrPrefs.candidateKeyLabelFontName, size: keyLabelSize) - gCurrentCandidateController?.candidateFont = candidateFont( + ctlCandidateCurrent?.candidateFont = candidateFont( name: mgrPrefs.candidateTextFontName, size: textSize) let candidateKeys = mgrPrefs.candidateKeys let keyLabels = candidateKeys.count > 4 ? Array(candidateKeys) : Array(mgrPrefs.defaultCandidateKeys) let keyLabelSuffix = state is InputState.AssociatedPhrases ? "^" : "" - gCurrentCandidateController?.keyLabels = keyLabels.map { + ctlCandidateCurrent?.keyLabels = keyLabels.map { CandidateKeyLabel(key: String($0), displayedText: String($0) + keyLabelSuffix) } - gCurrentCandidateController?.delegate = self - gCurrentCandidateController?.reloadData() + ctlCandidateCurrent?.delegate = self + ctlCandidateCurrent?.reloadData() currentCandidateClient = client - gCurrentCandidateController?.visible = true + ctlCandidateCurrent?.visible = true var lineHeightRect = NSMakeRect(0.0, 0.0, 16.0, 16.0) var cursor: Int = 0 @@ -735,13 +735,13 @@ extension ctlInputMethod { } if useVerticalMode { - gCurrentCandidateController?.set( + ctlCandidateCurrent?.set( windowTopLeftPoint: NSMakePoint( lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, lineHeightRect.origin.y - 4.0), bottomOutOfScreenAdjustmentHeight: lineHeightRect.size.height + 4.0) } else { - gCurrentCandidateController?.set( + ctlCandidateCurrent?.set( windowTopLeftPoint: NSMakePoint( lineHeightRect.origin.x, lineHeightRect.origin.y - 4.0), bottomOutOfScreenAdjustmentHeight: lineHeightRect.size.height + 4.0) @@ -776,16 +776,16 @@ extension ctlInputMethod { // MARK: - extension ctlInputMethod: KeyHandlerDelegate { - func candidateController(for keyHandler: KeyHandler) -> Any { - gCurrentCandidateController ?? .vertical + func ctlCandidate(for keyHandler: KeyHandler) -> Any { + ctlCandidateCurrent ?? .vertical } func keyHandler( _ keyHandler: KeyHandler, didSelectCandidateAt index: Int, - candidateController controller: Any + ctlCandidate controller: Any ) { - if let controller = controller as? CandidateController { - self.candidateController(controller, didSelectCandidateAtIndex: UInt(index)) + if let controller = controller as? ctlCandidate { + self.ctlCandidate(controller, didSelectCandidateAtIndex: UInt(index)) } } @@ -815,8 +815,8 @@ extension ctlInputMethod: KeyHandlerDelegate { // MARK: - -extension ctlInputMethod: CandidateControllerDelegate { - func candidateCountForController(_ controller: CandidateController) -> UInt { +extension ctlInputMethod: ctlCandidateDelegate { + func candidateCountForController(_ controller: ctlCandidate) -> UInt { if let state = state as? InputState.ChoosingCandidate { return UInt(state.candidates.count) } else if let state = state as? InputState.AssociatedPhrases { @@ -825,7 +825,7 @@ extension ctlInputMethod: CandidateControllerDelegate { return 0 } - func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt) + func ctlCandidate(_ controller: ctlCandidate, candidateAtIndex index: UInt) -> String { if let state = state as? InputState.ChoosingCandidate { @@ -836,9 +836,7 @@ extension ctlInputMethod: CandidateControllerDelegate { return "" } - func candidateController( - _ controller: CandidateController, didSelectCandidateAtIndex index: UInt - ) { + func ctlCandidate(_ controller: ctlCandidate, didSelectCandidateAtIndex index: UInt) { let client = currentCandidateClient if let state = state as? InputState.SymbolTable, diff --git a/Source/UI/CandidateUI/CandidateController.swift b/Source/UI/CandidateUI/ctlCandidate.swift similarity index 91% rename from Source/UI/CandidateUI/CandidateController.swift rename to Source/UI/CandidateUI/ctlCandidate.swift index 2ef1ce09..3ec8337f 100644 --- a/Source/UI/CandidateUI/CandidateController.swift +++ b/Source/UI/CandidateUI/ctlCandidate.swift @@ -38,18 +38,18 @@ public class CandidateKeyLabel: NSObject { } } -@objc(VTCandidateControllerDelegate) -public protocol CandidateControllerDelegate: AnyObject { - func candidateCountForController(_ controller: CandidateController) -> UInt - func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt) +@objc(ctlCandidateDelegate) +public protocol ctlCandidateDelegate: AnyObject { + func candidateCountForController(_ controller: ctlCandidate) -> UInt + func ctlCandidate(_ controller: ctlCandidate, candidateAtIndex index: UInt) -> String - func candidateController( - _ controller: CandidateController, didSelectCandidateAtIndex index: UInt) + func ctlCandidate( + _ controller: ctlCandidate, didSelectCandidateAtIndex index: UInt) } -@objc(VTCandidateController) -public class CandidateController: NSWindowController { - @objc public weak var delegate: CandidateControllerDelegate? { +@objc(ctlCandidate) +public class ctlCandidate: NSWindowController { + @objc public weak var delegate: ctlCandidateDelegate? { didSet { reloadData() } diff --git a/Source/UI/CandidateUI/HorizontalCandidateController.swift b/Source/UI/CandidateUI/ctlCandidateHorizontal.swift similarity index 98% rename from Source/UI/CandidateUI/HorizontalCandidateController.swift rename to Source/UI/CandidateUI/ctlCandidateHorizontal.swift index d6f2be0a..027703e9 100644 --- a/Source/UI/CandidateUI/HorizontalCandidateController.swift +++ b/Source/UI/CandidateUI/ctlCandidateHorizontal.swift @@ -236,8 +236,7 @@ private class HorizontalCandidateView: NSView { } } -@objc(VTHorizontalCandidateController) -public class HorizontalCandidateController: CandidateController { +@objc public class ctlCandidateHorizontal: ctlCandidate { private var candidateView: HorizontalCandidateView private var prevPageButton: NSButton private var nextPageButton: NSButton @@ -379,7 +378,7 @@ public class HorizontalCandidateController: CandidateController { } } -extension HorizontalCandidateController { +extension ctlCandidateHorizontal { private var pageCount: UInt { guard let delegate = delegate else { @@ -402,7 +401,7 @@ extension HorizontalCandidateController { let begin = currentPage * keyLabelCount for index in begin..