Fixes duplicated code and typos.
This commit is contained in:
parent
11d33c0b42
commit
f339948219
|
@ -1,4 +1,5 @@
|
|||
build
|
||||
.build
|
||||
*.pbxuser
|
||||
*.mode1v3
|
||||
*.tm_build_errors
|
||||
|
|
|
@ -34,14 +34,14 @@
|
|||
|
||||
import Cocoa
|
||||
|
||||
@objc(VTCandidateControllerDelegate)
|
||||
@objc (VTCandidateControllerDelegate)
|
||||
public protocol CandidateControllerDelegate: AnyObject {
|
||||
func candidateCountForController(_ controller: CandidateController) -> UInt
|
||||
func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt) -> String
|
||||
func candidateController(_ controller: CandidateController, didSelectCandidateAtIndex index: UInt)
|
||||
}
|
||||
|
||||
@objc(VTCandidateController)
|
||||
@objc (VTCandidateController)
|
||||
public class CandidateController: NSWindowController {
|
||||
@objc public weak var delegate: CandidateControllerDelegate?
|
||||
@objc public var selectedCandidateIndex: UInt = UInt.max
|
||||
|
@ -95,7 +95,7 @@ public class CandidateController: NSWindowController {
|
|||
UInt.max
|
||||
}
|
||||
|
||||
@objc(setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:)
|
||||
@objc (setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:)
|
||||
public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) {
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
|
||||
self.doSet(windowTopLeftPoint: windowTopLeftPoint, bottomOutOfScreenAdjustmentHeight: height)
|
||||
|
@ -110,9 +110,9 @@ public class CandidateController: NSWindowController {
|
|||
for screen in NSScreen.screens {
|
||||
let frame = screen.visibleFrame
|
||||
if windowTopLeftPoint.x >= frame.minX &&
|
||||
windowTopLeftPoint.x <= frame.maxX &&
|
||||
windowTopLeftPoint.y >= frame.minY &&
|
||||
windowTopLeftPoint.y <= frame.maxY {
|
||||
windowTopLeftPoint.x <= frame.maxX &&
|
||||
windowTopLeftPoint.y >= frame.minY &&
|
||||
windowTopLeftPoint.y <= frame.maxY {
|
||||
screenFrame = frame
|
||||
break
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ fileprivate class HorizontalCandidateView: NSView {
|
|||
private var keyLabelHeight: CGFloat = 0
|
||||
private var candidateTextHeight: CGFloat = 0
|
||||
private var cellPadding: CGFloat = 0
|
||||
private var keyLabelAttrDict: [NSAttributedString.Key:AnyObject] = [:]
|
||||
private var candidateAttrDict: [NSAttributedString.Key:AnyObject] = [:]
|
||||
private var keyLabelAttrDict: [NSAttributedString.Key: AnyObject] = [:]
|
||||
private var candidateAttrDict: [NSAttributedString.Key: AnyObject] = [:]
|
||||
private var elementWidths: [CGFloat] = []
|
||||
private var trackingHighlightedIndex: UInt = UInt.max
|
||||
|
||||
|
@ -64,7 +64,7 @@ fileprivate class HorizontalCandidateView: NSView {
|
|||
return result
|
||||
}
|
||||
|
||||
@objc(setKeyLabels:displayedCandidates:)
|
||||
@objc (setKeyLabels:displayedCandidates:)
|
||||
func set(keyLabels labels: [String], displayedCandidates candidates: [String]) {
|
||||
let count = min(labels.count, candidates.count)
|
||||
keyLabels = Array(labels[0..<count])
|
||||
|
@ -81,7 +81,7 @@ fileprivate class HorizontalCandidateView: NSView {
|
|||
elementWidths = newWidths
|
||||
}
|
||||
|
||||
@objc(setKeyLabelFont:candidateFont:)
|
||||
@objc (setKeyLabelFont:candidateFont:)
|
||||
func set(keyLabelFont labelFont: NSFont, candidateFont: NSFont) {
|
||||
let paraStyle = NSMutableParagraphStyle()
|
||||
paraStyle.setParagraphStyle(NSParagraphStyle.default)
|
||||
|
@ -192,8 +192,8 @@ fileprivate class HorizontalCandidateView: NSView {
|
|||
}
|
||||
}
|
||||
|
||||
@objc(VTHorizontalCandidateController)
|
||||
public class HorizontalCandidateController : CandidateController {
|
||||
@objc (VTHorizontalCandidateController)
|
||||
public class HorizontalCandidateController: CandidateController {
|
||||
private var candidateView: HorizontalCandidateView
|
||||
private var prevPageButton: NSButton
|
||||
private var nextPageButton: NSButton
|
||||
|
@ -312,9 +312,9 @@ public class HorizontalCandidateController : CandidateController {
|
|||
return result < delegate.candidateCountForController(self) ? result : UInt.max
|
||||
}
|
||||
|
||||
@objc public override var selectedCandidateIndex: UInt {
|
||||
public override var selectedCandidateIndex: UInt {
|
||||
get {
|
||||
return currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex
|
||||
currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex
|
||||
}
|
||||
set {
|
||||
guard let delegate = delegate else {
|
||||
|
@ -362,7 +362,7 @@ extension HorizontalCandidateController {
|
|||
frameRect.size = newSize
|
||||
candidateView.frame = frameRect
|
||||
|
||||
if self.pageCount > 1 {
|
||||
if pageCount > 1 {
|
||||
var buttonRect = nextPageButton.frame
|
||||
var spacing = 0.0
|
||||
|
||||
|
@ -397,7 +397,7 @@ extension HorizontalCandidateController {
|
|||
frameRect.size = newSize
|
||||
frameRect.origin = NSMakePoint(topLeftPoint.x, topLeftPoint.y - frameRect.size.height)
|
||||
self.window?.setFrame(frameRect, display: false)
|
||||
self.candidateView.setNeedsDisplay(candidateView.bounds)
|
||||
candidateView.setNeedsDisplay(candidateView.bounds)
|
||||
}
|
||||
|
||||
@objc fileprivate func pageButtonAction(_ sender: Any) {
|
||||
|
@ -407,12 +407,12 @@ extension HorizontalCandidateController {
|
|||
if sender == nextPageButton {
|
||||
_ = showNextPage()
|
||||
} else if sender == prevPageButton {
|
||||
_ = showPreviousPage()
|
||||
_ = showPreviousPage()
|
||||
}
|
||||
}
|
||||
|
||||
@objc fileprivate func candidateViewMouseDidClick(_ sender: Any) {
|
||||
delegate?.candidateController(self, didSelectCandidateAtIndex: self.selectedCandidateIndex)
|
||||
delegate?.candidateController(self, didSelectCandidateAtIndex: selectedCandidateIndex)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ fileprivate class VerticalKeyLabelStripView: NSView {
|
|||
paraStyle.setParagraphStyle(NSParagraphStyle.default)
|
||||
paraStyle.alignment = .center
|
||||
|
||||
let textAttr: [NSAttributedString.Key:AnyObject] = [
|
||||
let textAttr: [NSAttributedString.Key: AnyObject] = [
|
||||
.font: keyLabelFont,
|
||||
.foregroundColor: black,
|
||||
.paragraphStyle: paraStyle]
|
||||
|
@ -97,7 +97,7 @@ private let kCandidateTextPaddingWithMandatedTableViewPadding = 18.0
|
|||
private let kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0
|
||||
|
||||
|
||||
@objc(VTVerticalCandidateController)
|
||||
@objc (VTVerticalCandidateController)
|
||||
public class VerticalCandidateController: CandidateController {
|
||||
private var keyLabelStripView: VerticalKeyLabelStripView
|
||||
private var scrollView: NSScrollView
|
||||
|
@ -172,7 +172,7 @@ public class VerticalCandidateController: CandidateController {
|
|||
public override func reloadData() {
|
||||
maxCandidateAttrStringWidth = ceil(candidateFont.pointSize * 2.0 + candidateTextPadding)
|
||||
tableView.reloadData()
|
||||
self.layoutCandidateView()
|
||||
layoutCandidateView()
|
||||
if delegate?.candidateCountForController(self) ?? 0 > 0 {
|
||||
selectedCandidateIndex = 0
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class VerticalCandidateController: CandidateController {
|
|||
return UInt.max
|
||||
}
|
||||
|
||||
@objc public override var selectedCandidateIndex: UInt {
|
||||
public override var selectedCandidateIndex: UInt {
|
||||
get {
|
||||
let selectedRow = tableView.selectedRow
|
||||
return selectedRow == -1 ? UInt.max : UInt(selectedRow)
|
||||
|
@ -272,7 +272,7 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
|||
// we do more work than what this method is expected to; normally not a good practice, but for the amount of data (9 to 10 rows max), we can afford the overhead
|
||||
|
||||
// expand the window width if text overflows
|
||||
let boundingRect = attrString.boundingRect(with: NSSize(width: 10240.0, height: 10240.0) , options: .usesLineFragmentOrigin)
|
||||
let boundingRect = attrString.boundingRect(with: NSSize(width: 10240.0, height: 10240.0), options: .usesLineFragmentOrigin)
|
||||
let textWidth = boundingRect.size.width + candidateTextPadding
|
||||
if textWidth > maxCandidateAttrStringWidth {
|
||||
maxCandidateAttrStringWidth = textWidth
|
||||
|
@ -287,7 +287,7 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
|||
var newHilightIndex = 0
|
||||
|
||||
if keyLabelStripView.highlightedIndex != -1 &&
|
||||
(row >= selectedRow + Int(count) || (selectedRow > count && row <= selectedRow - Int(count))) {
|
||||
(row >= selectedRow + Int(count) || (selectedRow > count && row <= selectedRow - Int(count))) {
|
||||
newHilightIndex = -1
|
||||
} else {
|
||||
let firstVisibleRow = tableView.row(at: scrollView.documentVisibleRect.origin)
|
||||
|
@ -390,11 +390,11 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
|||
|
||||
private func layoutCandidateView() {
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { [self] in
|
||||
self.doLayoutCanaditeView()
|
||||
doLayoutCandidateView()
|
||||
}
|
||||
}
|
||||
|
||||
private func doLayoutCanaditeView() {
|
||||
private func doLayoutCandidateView() {
|
||||
guard let delegate = delegate else {
|
||||
return
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
|||
tableView.rowHeight = rowHeight
|
||||
|
||||
var maxKeyLabelWidth = keyLabelFontSize
|
||||
let textAttr: [NSAttributedString.Key:AnyObject] = [.font: keyLabelFont]
|
||||
let textAttr: [NSAttributedString.Key: AnyObject] = [.font: keyLabelFont]
|
||||
let boundingBox = NSSize(width: 1600.0, height: 1600.0)
|
||||
|
||||
for label in keyLabels {
|
||||
|
|
|
@ -42,7 +42,7 @@ private let kUpdateInfoSiteKey = "UpdateInfoSite"
|
|||
private let kNextCheckInterval: TimeInterval = 86400.0
|
||||
private let kTimeoutInterval: TimeInterval = 60.0
|
||||
|
||||
@objc(AppDelegate)
|
||||
@objc (AppDelegate)
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControllerDelegate {
|
||||
|
||||
@IBOutlet weak var window: NSWindow?
|
||||
|
@ -69,12 +69,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
|||
preferencesWindowController?.window?.orderFront(self)
|
||||
}
|
||||
|
||||
@objc(checkForUpdate)
|
||||
@objc (checkForUpdate)
|
||||
func checkForUpdate() {
|
||||
checkForUpdate(forced: false)
|
||||
}
|
||||
|
||||
@objc(checkForUpdateForced:)
|
||||
@objc (checkForUpdateForced:)
|
||||
func checkForUpdate(forced: Bool) {
|
||||
|
||||
if checkTask != nil {
|
||||
|
@ -98,15 +98,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
|||
UserDefaults.standard.set(nextUpdateDate, forKey: kNextUpdateCheckDateKey)
|
||||
|
||||
guard let infoDict = Bundle.main.infoDictionary,
|
||||
let updateInfoURLString = infoDict[kUpdateInfoEndpointKey] as? String,
|
||||
let updateInfoURL = URL(string: updateInfoURLString) else {
|
||||
let updateInfoURLString = infoDict[kUpdateInfoEndpointKey] as? String,
|
||||
let updateInfoURL = URL(string: updateInfoURLString) else {
|
||||
return
|
||||
}
|
||||
|
||||
let request = URLRequest(url: updateInfoURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: kTimeoutInterval)
|
||||
|
||||
func showNoUpdateAvailableAlert() {
|
||||
NonModalAlertWindowController.shared.show(title: NSLocalizedString("Check for Update Completed", comment: ""), content: NSLocalizedString("You are already using the latest version of McBopomofo.", comment: ""), confirmButtonTitle: NSLocalizedString("OK", comment: "") , cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
|
||||
NonModalAlertWindowController.shared.show(title: NSLocalizedString("Check for Update Completed", comment: ""), content: NSLocalizedString("You are already using the latest version of McBopomofo.", comment: ""), confirmButtonTitle: NSLocalizedString("OK", comment: ""), cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
|
||||
}
|
||||
|
||||
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||
|
@ -121,7 +121,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
|||
let buttonTitle = NSLocalizedString("Dismiss", comment: "")
|
||||
|
||||
DispatchQueue.main.async {
|
||||
NonModalAlertWindowController.shared.show(title:title , content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
|
||||
NonModalAlertWindowController.shared.show(title: title, content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -131,7 +131,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
|||
guard let plist = try PropertyListSerialization.propertyList(from: data ?? Data(), options: [], format: nil) as? [AnyHashable: Any],
|
||||
let remoteVersion = plist[kCFBundleVersionKey] as? String,
|
||||
let infoDict = Bundle.main.infoDictionary
|
||||
else {
|
||||
else {
|
||||
if forced {
|
||||
DispatchQueue.main.async {
|
||||
showNoUpdateAvailableAlert()
|
||||
|
@ -156,7 +156,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
|||
}
|
||||
|
||||
guard let siteInfoURLString = plist[kUpdateInfoSiteKey] as? String,
|
||||
let siteInfoURL = URL(string: siteInfoURLString) else {
|
||||
let siteInfoURL = URL(string: siteInfoURLString) else {
|
||||
if forced {
|
||||
DispatchQueue.main.async {
|
||||
showNoUpdateAvailableAlert()
|
||||
|
@ -189,7 +189,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
|||
remoteVersion,
|
||||
versionDescription)
|
||||
DispatchQueue.main.async {
|
||||
NonModalAlertWindowController.shared.show(title: NSLocalizedString("New Version Available", comment: "") , content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self)
|
||||
NonModalAlertWindowController.shared.show(title: NSLocalizedString("New Version Available", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self)
|
||||
}
|
||||
|
||||
} catch {
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
// a special deferred client for Terminal.app fix
|
||||
id _currentDeferredClient;
|
||||
|
||||
// currently available candidates
|
||||
// current available candidates
|
||||
NSMutableArray *_candidates;
|
||||
|
||||
// current input mode
|
||||
|
|
|
@ -1140,50 +1140,14 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
|||
string layout = [self currentLayout];
|
||||
string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode);
|
||||
if (_languageModel->hasUnigramsForKey(customPunctuation)) {
|
||||
if (_bpmfReadingBuffer->isEmpty()) {
|
||||
_builder->insertReadingAtCursor(customPunctuation);
|
||||
[self popOverflowComposingTextAndWalk:client];
|
||||
}
|
||||
else { // If there is still unfinished bpmf reading, ignore the punctuation
|
||||
[self beep];
|
||||
}
|
||||
[self updateClientComposingBuffer:client];
|
||||
|
||||
if (_inputMode == kPlainBopomofoModeIdentifier && _bpmfReadingBuffer->isEmpty()) {
|
||||
[self collectCandidates];
|
||||
if ([_candidates count] == 1) {
|
||||
[self commitComposition:client];
|
||||
}
|
||||
else {
|
||||
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
|
||||
}
|
||||
}
|
||||
|
||||
[self handlePunctuation:customPunctuation usingVerticalMode:useVerticalMode client:client];
|
||||
return YES;
|
||||
}
|
||||
|
||||
// if nothing is matched, see if it's a punctuation key
|
||||
string punctuation = string("_punctuation_") + string(1, (char)charCode);
|
||||
if (_languageModel->hasUnigramsForKey(punctuation)) {
|
||||
if (_bpmfReadingBuffer->isEmpty()) {
|
||||
_builder->insertReadingAtCursor(punctuation);
|
||||
[self popOverflowComposingTextAndWalk:client];
|
||||
}
|
||||
else { // If there is still unfinished bpmf reading, ignore the punctuation
|
||||
[self beep];
|
||||
}
|
||||
[self updateClientComposingBuffer:client];
|
||||
|
||||
if (_inputMode == kPlainBopomofoModeIdentifier && _bpmfReadingBuffer->isEmpty()) {
|
||||
[self collectCandidates];
|
||||
if ([_candidates count] == 1) {
|
||||
[self commitComposition:client];
|
||||
}
|
||||
else {
|
||||
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
|
||||
}
|
||||
}
|
||||
|
||||
[self handlePunctuation:punctuation usingVerticalMode:useVerticalMode client:client];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -1199,6 +1163,28 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (void)handlePunctuation:(string)customPunctuation usingVerticalMode:(BOOL)useVerticalMode client:(id)client
|
||||
{
|
||||
if (_bpmfReadingBuffer->isEmpty()) {
|
||||
_builder->insertReadingAtCursor(customPunctuation);
|
||||
[self popOverflowComposingTextAndWalk:client];
|
||||
}
|
||||
else { // If there is still unfinished bpmf reading, ignore the punctuation
|
||||
[self beep];
|
||||
}
|
||||
[self updateClientComposingBuffer:client];
|
||||
|
||||
if (_inputMode == kPlainBopomofoModeIdentifier && _bpmfReadingBuffer->isEmpty()) {
|
||||
[self collectCandidates];
|
||||
if ([_candidates count] == 1) {
|
||||
[self commitComposition:client];
|
||||
}
|
||||
else {
|
||||
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode
|
||||
{
|
||||
BOOL cancelCandidateKey =
|
||||
|
|
|
@ -46,12 +46,12 @@ public class InputSourceHelper: NSObject {
|
|||
TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource]
|
||||
}
|
||||
|
||||
@objc(inputSourceForProperty:stringValue:)
|
||||
@objc (inputSourceForProperty:stringValue:)
|
||||
public static func inputSource(for propertyKey: CFString, stringValue: String) -> TISInputSource? {
|
||||
let stringID = CFStringGetTypeID()
|
||||
for source in allInstalledInputSources() {
|
||||
if let proprtyPtr = TISGetInputSourceProperty(source, propertyKey) {
|
||||
let property = Unmanaged<CFTypeRef>.fromOpaque(proprtyPtr).takeUnretainedValue()
|
||||
if let propertyPtr = TISGetInputSourceProperty(source, propertyKey) {
|
||||
let property = Unmanaged<CFTypeRef>.fromOpaque(propertyPtr).takeUnretainedValue()
|
||||
let typeID = CFGetTypeID(property)
|
||||
if typeID != stringID {
|
||||
continue
|
||||
|
@ -64,12 +64,12 @@ public class InputSourceHelper: NSObject {
|
|||
return nil
|
||||
}
|
||||
|
||||
@objc(inputSourceForInputSourceID:)
|
||||
@objc (inputSourceForInputSourceID:)
|
||||
public static func inputSource(for sourceID: String) -> TISInputSource? {
|
||||
inputSource(for: kTISPropertyInputSourceID, stringValue: sourceID)
|
||||
}
|
||||
|
||||
@objc(inputSourceEnabled:)
|
||||
@objc (inputSourceEnabled:)
|
||||
public static func inputSourceEnabled(for source: TISInputSource) -> Bool {
|
||||
if let valuePts = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsEnabled) {
|
||||
let value = Unmanaged<CFBoolean>.fromOpaque(valuePts).takeUnretainedValue()
|
||||
|
@ -78,20 +78,20 @@ public class InputSourceHelper: NSObject {
|
|||
return false
|
||||
}
|
||||
|
||||
@objc(enableInputSource:)
|
||||
@objc (enableInputSource:)
|
||||
public static func enable(inputSource: TISInputSource) -> Bool {
|
||||
let status = TISEnableInputSource(inputSource)
|
||||
return status == noErr
|
||||
}
|
||||
|
||||
@objc(enableAllInputModesForInputSourceBundleID:)
|
||||
@objc (enableAllInputModesForInputSourceBundleID:)
|
||||
public static func enableAllInputMode(for inputSourceBundleD: String) -> Bool {
|
||||
var enabled = false
|
||||
for source in allInstalledInputSources() {
|
||||
guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID),
|
||||
let _ = TISGetInputSourceProperty(source, kTISPropertyInputModeID) else {
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
let bundleID = Unmanaged<CFString>.fromOpaque(bundleIDPtr).takeUnretainedValue()
|
||||
if String(bundleID) == inputSourceBundleD {
|
||||
let modeEnabled = self.enable(inputSource: source)
|
||||
|
@ -105,13 +105,13 @@ public class InputSourceHelper: NSObject {
|
|||
return enabled
|
||||
}
|
||||
|
||||
@objc(enableInputMode:forInputSourceBundleID:)
|
||||
@objc (enableInputMode:forInputSourceBundleID:)
|
||||
public static func enable(inputMode modeID: String, for bundleID: String) -> Bool {
|
||||
for source in allInstalledInputSources() {
|
||||
guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID),
|
||||
let modePtr = TISGetInputSourceProperty(source, kTISPropertyInputModeID) else {
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
let inputsSourceBundleID = Unmanaged<CFString>.fromOpaque(bundleIDPtr).takeUnretainedValue()
|
||||
let inputsSourceModeID = Unmanaged<CFString>.fromOpaque(modePtr).takeUnretainedValue()
|
||||
if modeID == String(inputsSourceModeID) && bundleID == String(inputsSourceBundleID) {
|
||||
|
@ -126,13 +126,13 @@ public class InputSourceHelper: NSObject {
|
|||
|
||||
}
|
||||
|
||||
@objc(disableInputSource:)
|
||||
@objc (disableInputSource:)
|
||||
public static func disable(inputSource: TISInputSource) -> Bool {
|
||||
let status = TISDisableInputSource(inputSource)
|
||||
return status == noErr
|
||||
}
|
||||
|
||||
@objc(registerInputSource:)
|
||||
@objc (registerInputSource:)
|
||||
public static func registerTnputSource(at url: URL) -> Bool {
|
||||
let status = TISRegisterInputSource(url as CFURL)
|
||||
return status == noErr
|
||||
|
|
|
@ -40,7 +40,8 @@ import Cocoa
|
|||
}
|
||||
|
||||
class NonModalAlertWindowController: NSWindowController {
|
||||
@objc(sharedInstance) static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController")
|
||||
@objc (sharedInstance)
|
||||
static let shared = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController")
|
||||
|
||||
@IBOutlet weak var titleTextField: NSTextField!
|
||||
@IBOutlet weak var contentTextField: NSTextField!
|
||||
|
@ -62,7 +63,7 @@ class NonModalAlertWindowController: NSWindowController {
|
|||
var newFrame = confirmButton.frame
|
||||
newFrame.size.width = max(90, newFrame.size.width + 10)
|
||||
newFrame.origin.x += oldFrame.size.width - newFrame.size.width
|
||||
self.confirmButton.frame = newFrame
|
||||
confirmButton.frame = newFrame
|
||||
|
||||
if let cancelButtonTitle = cancelButtonTitle {
|
||||
cancelButton.title = cancelButtonTitle
|
||||
|
@ -70,10 +71,10 @@ class NonModalAlertWindowController: NSWindowController {
|
|||
var adjustFrame = cancelButton.frame
|
||||
adjustFrame.size.width = max(90, adjustFrame.size.width + 10)
|
||||
adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width
|
||||
self.confirmButton.frame = adjustFrame
|
||||
self.cancelButton.isHidden = false
|
||||
confirmButton.frame = adjustFrame
|
||||
cancelButton.isHidden = false
|
||||
} else {
|
||||
self.cancelButton.isHidden = true
|
||||
cancelButton.isHidden = true
|
||||
}
|
||||
|
||||
cancelButton.nextKeyView = confirmButton
|
||||
|
|
|
@ -12,11 +12,11 @@ class OpenCCBridge: NSObject {
|
|||
super.init()
|
||||
}
|
||||
|
||||
@objc static func convert(_ string:String) -> String? {
|
||||
return shared.converter?.convert(string)
|
||||
@objc static func convert(_ string: String) -> String? {
|
||||
shared.converter?.convert(string)
|
||||
}
|
||||
|
||||
private func convert(_ string:String) -> String? {
|
||||
return converter?.convert(string)
|
||||
private func convert(_ string: String) -> String? {
|
||||
converter?.convert(string)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ private let kDefaultKeys = "123456789"
|
|||
// Please note that the class should be exposed as "PreferencesWindowController"
|
||||
// in Objective-C in order to let IMK to see the same class name as
|
||||
// the "InputMethodServerPreferencesWindowControllerClass" in Info.plist.
|
||||
@objc(PreferencesWindowController) class PreferencesWindowController: NSWindowController {
|
||||
@objc (PreferencesWindowController) class PreferencesWindowController: NSWindowController {
|
||||
@IBOutlet weak var fontSizePopUpButton: NSPopUpButton!
|
||||
@IBOutlet weak var basisKeyboardLayoutButton: NSPopUpButton!
|
||||
@IBOutlet weak var selectionKeyComboBox: NSComboBox!
|
||||
|
@ -85,8 +85,8 @@ private let kDefaultKeys = "123456789"
|
|||
|
||||
guard let sourceIDPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceID),
|
||||
let localizedNamePtr = TISGetInputSourceProperty(source, kTISPropertyLocalizedName) else {
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
let sourceID = String(Unmanaged<CFString>.fromOpaque(sourceIDPtr).takeUnretainedValue())
|
||||
let localizedName = String(Unmanaged<CFString>.fromOpaque(localizedNamePtr).takeUnretainedValue())
|
||||
|
@ -109,7 +109,7 @@ private let kDefaultKeys = "123456789"
|
|||
selectionKeyComboBox.addItems(withObjectValues: [kDefaultKeys, "asdfghjkl", "asdfzxcvb"])
|
||||
|
||||
var candidateSelectionKeys = (UserDefaults.standard.string(forKey: kCandidateKeys) ?? kDefaultKeys)
|
||||
.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
||||
.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
||||
if candidateSelectionKeys.isEmpty {
|
||||
candidateSelectionKeys = kDefaultKeys
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ private let kDefaultKeys = "123456789"
|
|||
selectionKeyComboBox.stringValue = candidateSelectionKeys
|
||||
}
|
||||
|
||||
@IBAction func updateBasisKeyboardLayoutAction(_ sender:Any) {
|
||||
@IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) {
|
||||
if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject {
|
||||
UserDefaults.standard.set(sourceID, forKey: kBasisKeyboardLayoutPreferenceKey)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue