Fixes duplicated code and typos.
This commit is contained in:
parent
11d33c0b42
commit
f339948219
|
@ -1,4 +1,5 @@
|
||||||
build
|
build
|
||||||
|
.build
|
||||||
*.pbxuser
|
*.pbxuser
|
||||||
*.mode1v3
|
*.mode1v3
|
||||||
*.tm_build_errors
|
*.tm_build_errors
|
||||||
|
|
|
@ -34,14 +34,14 @@
|
||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
@objc(VTCandidateControllerDelegate)
|
@objc (VTCandidateControllerDelegate)
|
||||||
public protocol CandidateControllerDelegate: AnyObject {
|
public protocol CandidateControllerDelegate: AnyObject {
|
||||||
func candidateCountForController(_ controller: CandidateController) -> UInt
|
func candidateCountForController(_ controller: CandidateController) -> UInt
|
||||||
func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt) -> String
|
func candidateController(_ controller: CandidateController, candidateAtIndex index: UInt) -> String
|
||||||
func candidateController(_ controller: CandidateController, didSelectCandidateAtIndex index: UInt)
|
func candidateController(_ controller: CandidateController, didSelectCandidateAtIndex index: UInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(VTCandidateController)
|
@objc (VTCandidateController)
|
||||||
public class CandidateController: NSWindowController {
|
public class CandidateController: NSWindowController {
|
||||||
@objc public weak var delegate: CandidateControllerDelegate?
|
@objc public weak var delegate: CandidateControllerDelegate?
|
||||||
@objc public var selectedCandidateIndex: UInt = UInt.max
|
@objc public var selectedCandidateIndex: UInt = UInt.max
|
||||||
|
@ -95,7 +95,7 @@ public class CandidateController: NSWindowController {
|
||||||
UInt.max
|
UInt.max
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:)
|
@objc (setWindowTopLeftPoint:bottomOutOfScreenAdjustmentHeight:)
|
||||||
public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) {
|
public func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: CGFloat) {
|
||||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
|
||||||
self.doSet(windowTopLeftPoint: windowTopLeftPoint, bottomOutOfScreenAdjustmentHeight: height)
|
self.doSet(windowTopLeftPoint: windowTopLeftPoint, bottomOutOfScreenAdjustmentHeight: height)
|
||||||
|
|
|
@ -44,8 +44,8 @@ fileprivate class HorizontalCandidateView: NSView {
|
||||||
private var keyLabelHeight: CGFloat = 0
|
private var keyLabelHeight: CGFloat = 0
|
||||||
private var candidateTextHeight: CGFloat = 0
|
private var candidateTextHeight: CGFloat = 0
|
||||||
private var cellPadding: CGFloat = 0
|
private var cellPadding: CGFloat = 0
|
||||||
private var keyLabelAttrDict: [NSAttributedString.Key:AnyObject] = [:]
|
private var keyLabelAttrDict: [NSAttributedString.Key: AnyObject] = [:]
|
||||||
private var candidateAttrDict: [NSAttributedString.Key:AnyObject] = [:]
|
private var candidateAttrDict: [NSAttributedString.Key: AnyObject] = [:]
|
||||||
private var elementWidths: [CGFloat] = []
|
private var elementWidths: [CGFloat] = []
|
||||||
private var trackingHighlightedIndex: UInt = UInt.max
|
private var trackingHighlightedIndex: UInt = UInt.max
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ fileprivate class HorizontalCandidateView: NSView {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(setKeyLabels:displayedCandidates:)
|
@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])
|
||||||
|
@ -81,7 +81,7 @@ fileprivate class HorizontalCandidateView: NSView {
|
||||||
elementWidths = newWidths
|
elementWidths = newWidths
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(setKeyLabelFont:candidateFont:)
|
@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)
|
||||||
|
@ -192,8 +192,8 @@ fileprivate class HorizontalCandidateView: NSView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(VTHorizontalCandidateController)
|
@objc (VTHorizontalCandidateController)
|
||||||
public class HorizontalCandidateController : CandidateController {
|
public class HorizontalCandidateController: CandidateController {
|
||||||
private var candidateView: HorizontalCandidateView
|
private var candidateView: HorizontalCandidateView
|
||||||
private var prevPageButton: NSButton
|
private var prevPageButton: NSButton
|
||||||
private var nextPageButton: NSButton
|
private var nextPageButton: NSButton
|
||||||
|
@ -312,9 +312,9 @@ public class HorizontalCandidateController : CandidateController {
|
||||||
return result < delegate.candidateCountForController(self) ? result : UInt.max
|
return result < delegate.candidateCountForController(self) ? result : UInt.max
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public override var selectedCandidateIndex: UInt {
|
public override var selectedCandidateIndex: UInt {
|
||||||
get {
|
get {
|
||||||
return currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex
|
currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
guard let delegate = delegate else {
|
guard let delegate = delegate else {
|
||||||
|
@ -362,7 +362,7 @@ extension HorizontalCandidateController {
|
||||||
frameRect.size = newSize
|
frameRect.size = newSize
|
||||||
candidateView.frame = frameRect
|
candidateView.frame = frameRect
|
||||||
|
|
||||||
if self.pageCount > 1 {
|
if pageCount > 1 {
|
||||||
var buttonRect = nextPageButton.frame
|
var buttonRect = nextPageButton.frame
|
||||||
var spacing = 0.0
|
var spacing = 0.0
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ extension HorizontalCandidateController {
|
||||||
frameRect.size = newSize
|
frameRect.size = newSize
|
||||||
frameRect.origin = NSMakePoint(topLeftPoint.x, topLeftPoint.y - frameRect.size.height)
|
frameRect.origin = NSMakePoint(topLeftPoint.x, topLeftPoint.y - frameRect.size.height)
|
||||||
self.window?.setFrame(frameRect, display: false)
|
self.window?.setFrame(frameRect, display: false)
|
||||||
self.candidateView.setNeedsDisplay(candidateView.bounds)
|
candidateView.setNeedsDisplay(candidateView.bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc fileprivate func pageButtonAction(_ sender: Any) {
|
@objc fileprivate func pageButtonAction(_ sender: Any) {
|
||||||
|
@ -412,7 +412,7 @@ extension HorizontalCandidateController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc fileprivate func candidateViewMouseDidClick(_ sender: Any) {
|
@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.setParagraphStyle(NSParagraphStyle.default)
|
||||||
paraStyle.alignment = .center
|
paraStyle.alignment = .center
|
||||||
|
|
||||||
let textAttr: [NSAttributedString.Key:AnyObject] = [
|
let textAttr: [NSAttributedString.Key: AnyObject] = [
|
||||||
.font: keyLabelFont,
|
.font: keyLabelFont,
|
||||||
.foregroundColor: black,
|
.foregroundColor: black,
|
||||||
.paragraphStyle: paraStyle]
|
.paragraphStyle: paraStyle]
|
||||||
|
@ -97,7 +97,7 @@ private let kCandidateTextPaddingWithMandatedTableViewPadding = 18.0
|
||||||
private let kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0
|
private let kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0
|
||||||
|
|
||||||
|
|
||||||
@objc(VTVerticalCandidateController)
|
@objc (VTVerticalCandidateController)
|
||||||
public class VerticalCandidateController: CandidateController {
|
public class VerticalCandidateController: CandidateController {
|
||||||
private var keyLabelStripView: VerticalKeyLabelStripView
|
private var keyLabelStripView: VerticalKeyLabelStripView
|
||||||
private var scrollView: NSScrollView
|
private var scrollView: NSScrollView
|
||||||
|
@ -172,7 +172,7 @@ public class VerticalCandidateController: CandidateController {
|
||||||
public override func reloadData() {
|
public override func reloadData() {
|
||||||
maxCandidateAttrStringWidth = ceil(candidateFont.pointSize * 2.0 + candidateTextPadding)
|
maxCandidateAttrStringWidth = ceil(candidateFont.pointSize * 2.0 + candidateTextPadding)
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
self.layoutCandidateView()
|
layoutCandidateView()
|
||||||
if delegate?.candidateCountForController(self) ?? 0 > 0 {
|
if delegate?.candidateCountForController(self) ?? 0 > 0 {
|
||||||
selectedCandidateIndex = 0
|
selectedCandidateIndex = 0
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ public class VerticalCandidateController: CandidateController {
|
||||||
return UInt.max
|
return UInt.max
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public override var selectedCandidateIndex: UInt {
|
public override var selectedCandidateIndex: UInt {
|
||||||
get {
|
get {
|
||||||
let selectedRow = tableView.selectedRow
|
let selectedRow = tableView.selectedRow
|
||||||
return selectedRow == -1 ? UInt.max : UInt(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
|
// 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
|
// 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
|
let textWidth = boundingRect.size.width + candidateTextPadding
|
||||||
if textWidth > maxCandidateAttrStringWidth {
|
if textWidth > maxCandidateAttrStringWidth {
|
||||||
maxCandidateAttrStringWidth = textWidth
|
maxCandidateAttrStringWidth = textWidth
|
||||||
|
@ -390,11 +390,11 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
||||||
|
|
||||||
private func layoutCandidateView() {
|
private func layoutCandidateView() {
|
||||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { [self] in
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) { [self] in
|
||||||
self.doLayoutCanaditeView()
|
doLayoutCandidateView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func doLayoutCanaditeView() {
|
private func doLayoutCandidateView() {
|
||||||
guard let delegate = delegate else {
|
guard let delegate = delegate else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
|
||||||
tableView.rowHeight = rowHeight
|
tableView.rowHeight = rowHeight
|
||||||
|
|
||||||
var maxKeyLabelWidth = keyLabelFontSize
|
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)
|
let boundingBox = NSSize(width: 1600.0, height: 1600.0)
|
||||||
|
|
||||||
for label in keyLabels {
|
for label in keyLabels {
|
||||||
|
|
|
@ -42,7 +42,7 @@ private let kUpdateInfoSiteKey = "UpdateInfoSite"
|
||||||
private let kNextCheckInterval: TimeInterval = 86400.0
|
private let kNextCheckInterval: TimeInterval = 86400.0
|
||||||
private let kTimeoutInterval: TimeInterval = 60.0
|
private let kTimeoutInterval: TimeInterval = 60.0
|
||||||
|
|
||||||
@objc(AppDelegate)
|
@objc (AppDelegate)
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControllerDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControllerDelegate {
|
||||||
|
|
||||||
@IBOutlet weak var window: NSWindow?
|
@IBOutlet weak var window: NSWindow?
|
||||||
|
@ -69,12 +69,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
||||||
preferencesWindowController?.window?.orderFront(self)
|
preferencesWindowController?.window?.orderFront(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(checkForUpdate)
|
@objc (checkForUpdate)
|
||||||
func checkForUpdate() {
|
func checkForUpdate() {
|
||||||
checkForUpdate(forced: false)
|
checkForUpdate(forced: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(checkForUpdateForced:)
|
@objc (checkForUpdateForced:)
|
||||||
func checkForUpdate(forced: Bool) {
|
func checkForUpdate(forced: Bool) {
|
||||||
|
|
||||||
if checkTask != nil {
|
if checkTask != nil {
|
||||||
|
@ -106,7 +106,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
||||||
let request = URLRequest(url: updateInfoURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: kTimeoutInterval)
|
let request = URLRequest(url: updateInfoURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: kTimeoutInterval)
|
||||||
|
|
||||||
func showNoUpdateAvailableAlert() {
|
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
|
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: "")
|
let buttonTitle = NSLocalizedString("Dismiss", comment: "")
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
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
|
return
|
||||||
|
@ -189,7 +189,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
|
||||||
remoteVersion,
|
remoteVersion,
|
||||||
versionDescription)
|
versionDescription)
|
||||||
DispatchQueue.main.async {
|
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 {
|
} catch {
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
// a special deferred client for Terminal.app fix
|
// a special deferred client for Terminal.app fix
|
||||||
id _currentDeferredClient;
|
id _currentDeferredClient;
|
||||||
|
|
||||||
// currently available candidates
|
// current available candidates
|
||||||
NSMutableArray *_candidates;
|
NSMutableArray *_candidates;
|
||||||
|
|
||||||
// current input mode
|
// current input mode
|
||||||
|
|
|
@ -1140,6 +1140,31 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
string layout = [self currentLayout];
|
string layout = [self currentLayout];
|
||||||
string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode);
|
string customPunctuation = string("_punctuation_") + layout + string(1, (char)charCode);
|
||||||
if (_languageModel->hasUnigramsForKey(customPunctuation)) {
|
if (_languageModel->hasUnigramsForKey(customPunctuation)) {
|
||||||
|
[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)) {
|
||||||
|
[self handlePunctuation:punctuation usingVerticalMode:useVerticalMode client:client];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// still nothing, then we update the composing buffer (some app has
|
||||||
|
// strange behavior if we don't do this, "thinking" the key is not
|
||||||
|
// actually consumed)
|
||||||
|
if ([_composingBuffer length] || !_bpmfReadingBuffer->isEmpty()) {
|
||||||
|
[self beep];
|
||||||
|
[self updateClientComposingBuffer:client];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)handlePunctuation:(string)customPunctuation usingVerticalMode:(BOOL)useVerticalMode client:(id)client
|
||||||
|
{
|
||||||
if (_bpmfReadingBuffer->isEmpty()) {
|
if (_bpmfReadingBuffer->isEmpty()) {
|
||||||
_builder->insertReadingAtCursor(customPunctuation);
|
_builder->insertReadingAtCursor(customPunctuation);
|
||||||
[self popOverflowComposingTextAndWalk:client];
|
[self popOverflowComposingTextAndWalk:client];
|
||||||
|
@ -1158,45 +1183,6 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; }
|
||||||
[self _showCandidateWindowUsingVerticalMode:useVerticalMode client:client];
|
[self _showCandidateWindowUsingVerticalMode: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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// still nothing, then we update the composing buffer (some app has
|
|
||||||
// strange behavior if we don't do this, "thinking" the key is not
|
|
||||||
// actually consumed)
|
|
||||||
if ([_composingBuffer length] || !_bpmfReadingBuffer->isEmpty()) {
|
|
||||||
[self beep];
|
|
||||||
[self updateClientComposingBuffer:client];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode
|
- (BOOL)handleCandidateEventWithInputText:(NSString *)inputText charCode:(UniChar)charCode keyCode:(NSUInteger)keyCode
|
||||||
|
|
|
@ -46,12 +46,12 @@ public class InputSourceHelper: NSObject {
|
||||||
TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource]
|
TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource]
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(inputSourceForProperty:stringValue:)
|
@objc (inputSourceForProperty:stringValue:)
|
||||||
public static func inputSource(for propertyKey: CFString, stringValue: String) -> TISInputSource? {
|
public static func inputSource(for propertyKey: CFString, stringValue: String) -> TISInputSource? {
|
||||||
let stringID = CFStringGetTypeID()
|
let stringID = CFStringGetTypeID()
|
||||||
for source in allInstalledInputSources() {
|
for source in allInstalledInputSources() {
|
||||||
if let proprtyPtr = TISGetInputSourceProperty(source, propertyKey) {
|
if let propertyPtr = TISGetInputSourceProperty(source, propertyKey) {
|
||||||
let property = Unmanaged<CFTypeRef>.fromOpaque(proprtyPtr).takeUnretainedValue()
|
let property = Unmanaged<CFTypeRef>.fromOpaque(propertyPtr).takeUnretainedValue()
|
||||||
let typeID = CFGetTypeID(property)
|
let typeID = CFGetTypeID(property)
|
||||||
if typeID != stringID {
|
if typeID != stringID {
|
||||||
continue
|
continue
|
||||||
|
@ -64,12 +64,12 @@ public class InputSourceHelper: NSObject {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(inputSourceForInputSourceID:)
|
@objc (inputSourceForInputSourceID:)
|
||||||
public static func inputSource(for sourceID: String) -> TISInputSource? {
|
public static func inputSource(for sourceID: String) -> TISInputSource? {
|
||||||
inputSource(for: kTISPropertyInputSourceID, stringValue: sourceID)
|
inputSource(for: kTISPropertyInputSourceID, stringValue: sourceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(inputSourceEnabled:)
|
@objc (inputSourceEnabled:)
|
||||||
public static func inputSourceEnabled(for source: TISInputSource) -> Bool {
|
public static func inputSourceEnabled(for source: TISInputSource) -> Bool {
|
||||||
if let valuePts = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsEnabled) {
|
if let valuePts = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsEnabled) {
|
||||||
let value = Unmanaged<CFBoolean>.fromOpaque(valuePts).takeUnretainedValue()
|
let value = Unmanaged<CFBoolean>.fromOpaque(valuePts).takeUnretainedValue()
|
||||||
|
@ -78,13 +78,13 @@ public class InputSourceHelper: NSObject {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(enableInputSource:)
|
@objc (enableInputSource:)
|
||||||
public static func enable(inputSource: TISInputSource) -> Bool {
|
public static func enable(inputSource: TISInputSource) -> Bool {
|
||||||
let status = TISEnableInputSource(inputSource)
|
let status = TISEnableInputSource(inputSource)
|
||||||
return status == noErr
|
return status == noErr
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(enableAllInputModesForInputSourceBundleID:)
|
@objc (enableAllInputModesForInputSourceBundleID:)
|
||||||
public static func enableAllInputMode(for inputSourceBundleD: String) -> Bool {
|
public static func enableAllInputMode(for inputSourceBundleD: String) -> Bool {
|
||||||
var enabled = false
|
var enabled = false
|
||||||
for source in allInstalledInputSources() {
|
for source in allInstalledInputSources() {
|
||||||
|
@ -105,7 +105,7 @@ public class InputSourceHelper: NSObject {
|
||||||
return enabled
|
return enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(enableInputMode:forInputSourceBundleID:)
|
@objc (enableInputMode:forInputSourceBundleID:)
|
||||||
public static func enable(inputMode modeID: String, for bundleID: String) -> Bool {
|
public static func enable(inputMode modeID: String, for bundleID: String) -> Bool {
|
||||||
for source in allInstalledInputSources() {
|
for source in allInstalledInputSources() {
|
||||||
guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID),
|
guard let bundleIDPtr = TISGetInputSourceProperty(source, kTISPropertyBundleID),
|
||||||
|
@ -126,13 +126,13 @@ public class InputSourceHelper: NSObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(disableInputSource:)
|
@objc (disableInputSource:)
|
||||||
public static func disable(inputSource: TISInputSource) -> Bool {
|
public static func disable(inputSource: TISInputSource) -> Bool {
|
||||||
let status = TISDisableInputSource(inputSource)
|
let status = TISDisableInputSource(inputSource)
|
||||||
return status == noErr
|
return status == noErr
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(registerInputSource:)
|
@objc (registerInputSource:)
|
||||||
public static func registerTnputSource(at url: URL) -> Bool {
|
public static func registerTnputSource(at url: URL) -> Bool {
|
||||||
let status = TISRegisterInputSource(url as CFURL)
|
let status = TISRegisterInputSource(url as CFURL)
|
||||||
return status == noErr
|
return status == noErr
|
||||||
|
|
|
@ -40,7 +40,8 @@ import Cocoa
|
||||||
}
|
}
|
||||||
|
|
||||||
class NonModalAlertWindowController: NSWindowController {
|
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 titleTextField: NSTextField!
|
||||||
@IBOutlet weak var contentTextField: NSTextField!
|
@IBOutlet weak var contentTextField: NSTextField!
|
||||||
|
@ -62,7 +63,7 @@ class NonModalAlertWindowController: NSWindowController {
|
||||||
var newFrame = confirmButton.frame
|
var newFrame = confirmButton.frame
|
||||||
newFrame.size.width = max(90, newFrame.size.width + 10)
|
newFrame.size.width = max(90, newFrame.size.width + 10)
|
||||||
newFrame.origin.x += oldFrame.size.width - newFrame.size.width
|
newFrame.origin.x += oldFrame.size.width - newFrame.size.width
|
||||||
self.confirmButton.frame = newFrame
|
confirmButton.frame = newFrame
|
||||||
|
|
||||||
if let cancelButtonTitle = cancelButtonTitle {
|
if let cancelButtonTitle = cancelButtonTitle {
|
||||||
cancelButton.title = cancelButtonTitle
|
cancelButton.title = cancelButtonTitle
|
||||||
|
@ -70,10 +71,10 @@ class NonModalAlertWindowController: NSWindowController {
|
||||||
var adjustFrame = cancelButton.frame
|
var adjustFrame = cancelButton.frame
|
||||||
adjustFrame.size.width = max(90, adjustFrame.size.width + 10)
|
adjustFrame.size.width = max(90, adjustFrame.size.width + 10)
|
||||||
adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width
|
adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width
|
||||||
self.confirmButton.frame = adjustFrame
|
confirmButton.frame = adjustFrame
|
||||||
self.cancelButton.isHidden = false
|
cancelButton.isHidden = false
|
||||||
} else {
|
} else {
|
||||||
self.cancelButton.isHidden = true
|
cancelButton.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelButton.nextKeyView = confirmButton
|
cancelButton.nextKeyView = confirmButton
|
||||||
|
|
|
@ -12,11 +12,11 @@ class OpenCCBridge: NSObject {
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc static func convert(_ string:String) -> String? {
|
@objc static func convert(_ string: String) -> String? {
|
||||||
return shared.converter?.convert(string)
|
shared.converter?.convert(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func convert(_ string:String) -> String? {
|
private func convert(_ string: String) -> String? {
|
||||||
return converter?.convert(string)
|
converter?.convert(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ private let kDefaultKeys = "123456789"
|
||||||
// Please note that the class should be exposed as "PreferencesWindowController"
|
// 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
|
// in Objective-C in order to let IMK to see the same class name as
|
||||||
// the "InputMethodServerPreferencesWindowControllerClass" in Info.plist.
|
// the "InputMethodServerPreferencesWindowControllerClass" in Info.plist.
|
||||||
@objc(PreferencesWindowController) class PreferencesWindowController: NSWindowController {
|
@objc (PreferencesWindowController) class PreferencesWindowController: NSWindowController {
|
||||||
@IBOutlet weak var fontSizePopUpButton: NSPopUpButton!
|
@IBOutlet weak var fontSizePopUpButton: NSPopUpButton!
|
||||||
@IBOutlet weak var basisKeyboardLayoutButton: NSPopUpButton!
|
@IBOutlet weak var basisKeyboardLayoutButton: NSPopUpButton!
|
||||||
@IBOutlet weak var selectionKeyComboBox: NSComboBox!
|
@IBOutlet weak var selectionKeyComboBox: NSComboBox!
|
||||||
|
@ -117,7 +117,7 @@ private let kDefaultKeys = "123456789"
|
||||||
selectionKeyComboBox.stringValue = candidateSelectionKeys
|
selectionKeyComboBox.stringValue = candidateSelectionKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func updateBasisKeyboardLayoutAction(_ sender:Any) {
|
@IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) {
|
||||||
if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject {
|
if let sourceID = basisKeyboardLayoutButton.selectedItem?.representedObject {
|
||||||
UserDefaults.standard.set(sourceID, forKey: kBasisKeyboardLayoutPreferenceKey)
|
UserDefaults.standard.set(sourceID, forKey: kBasisKeyboardLayoutPreferenceKey)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue