From e01eb46c9f2f8861547cf7658f2406b10097bcdc Mon Sep 17 00:00:00 2001 From: zonble Date: Fri, 14 Jan 2022 00:43:21 +0800 Subject: [PATCH] Wraps InputSourceHelper to a SPM package. --- McBopomofo.xcodeproj/project.pbxproj | 48 +++--- Packages/InputSourceHelper/.gitignore | 7 + Packages/InputSourceHelper/Package.swift | 25 +++ Packages/InputSourceHelper/README.md | 3 + .../InputSourceHelper.swift | 0 Packages/NonModalAlertWindow/.gitignore | 7 + Packages/NonModalAlertWindow/Package.swift | 25 +++ Packages/NonModalAlertWindow/README.md | 3 + .../NonModalAlertWindowController.swift | 147 ++++++++++++++++++ .../NonModalAlertWindowController.xib | 85 ++++++++++ Source/InputMethodController.mm | 1 - Source/Installer/AppDelegate.m | 3 +- Source/OpenCCBridge.swift | 8 +- Source/main.m | 2 +- 14 files changed, 337 insertions(+), 27 deletions(-) create mode 100644 Packages/InputSourceHelper/.gitignore create mode 100644 Packages/InputSourceHelper/Package.swift create mode 100644 Packages/InputSourceHelper/README.md rename {Source => Packages/InputSourceHelper/Sources/InputSourceHelper}/InputSourceHelper.swift (100%) create mode 100644 Packages/NonModalAlertWindow/.gitignore create mode 100644 Packages/NonModalAlertWindow/Package.swift create mode 100644 Packages/NonModalAlertWindow/README.md create mode 100644 Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/NonModalAlertWindowController.swift create mode 100644 Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/Resources/NonModalAlertWindowController.xib diff --git a/McBopomofo.xcodeproj/project.pbxproj b/McBopomofo.xcodeproj/project.pbxproj index bd96b94c..af6e167a 100644 --- a/McBopomofo.xcodeproj/project.pbxproj +++ b/McBopomofo.xcodeproj/project.pbxproj @@ -39,17 +39,17 @@ D41355D8278D74B5005E5CBD /* LanguageModelManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = D41355D7278D7409005E5CBD /* LanguageModelManager.mm */; }; D41355DB278E6D17005E5CBD /* McBopomofoLM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D41355D9278E6D17005E5CBD /* McBopomofoLM.cpp */; }; D41355DE278EA3ED005E5CBD /* UserPhrasesLM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D41355DC278EA3ED005E5CBD /* UserPhrasesLM.cpp */; }; - D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */; }; D427F76A278C9E29004A2160 /* CandidateUI in Frameworks */ = {isa = PBXBuildFile; productRef = D427F769278C9E29004A2160 /* CandidateUI */; }; D427F76C278CA2B0004A2160 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D427F76B278CA1BA004A2160 /* AppDelegate.swift */; }; D427F7A927905E90004A2160 /* TooltipUI in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7A827905E90004A2160 /* TooltipUI */; }; D427F7AE27907B8A004A2160 /* NotifierUI in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7AD27907B8A004A2160 /* NotifierUI */; }; + D427F7B4279086DC004A2160 /* InputSourceHelper in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7B3279086DC004A2160 /* InputSourceHelper */; }; + D427F7B6279086F6004A2160 /* InputSourceHelper in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7B5279086F6004A2160 /* InputSourceHelper */; }; + D427F7BB27908D78004A2160 /* OpenCCBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = D427F7BA27908D78004A2160 /* OpenCCBridge.swift */; }; + D427F7BE27908DD7004A2160 /* OpenCC in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7BD27908DD7004A2160 /* OpenCC */; }; D47F7DCE278BFB57002F9DD7 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DCD278BFB57002F9DD7 /* PreferencesWindowController.swift */; }; D47F7DD0278C0897002F9DD7 /* NonModalAlertWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DCF278C0897002F9DD7 /* NonModalAlertWindowController.swift */; }; D47F7DD3278C1263002F9DD7 /* UserOverrideModel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DD2278C1263002F9DD7 /* UserOverrideModel.cpp */; }; - D47F7DD5278C25A0002F9DD7 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DD4278C25A0002F9DD7 /* InputSourceHelper.swift */; }; - D47F7DD6278C3075002F9DD7 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D47F7DD4278C25A0002F9DD7 /* InputSourceHelper.swift */; }; - D48550A325EBE689006A204C /* OpenCC in Frameworks */ = {isa = PBXBuildFile; productRef = D48550A225EBE689006A204C /* OpenCC */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -167,16 +167,16 @@ D41355DC278EA3ED005E5CBD /* UserPhrasesLM.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UserPhrasesLM.cpp; sourceTree = ""; }; D41355DD278EA3ED005E5CBD /* UserPhrasesLM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserPhrasesLM.h; sourceTree = ""; }; D427A9BF25ED28CC005D43E0 /* McBopomofo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "McBopomofo-Bridging-Header.h"; sourceTree = ""; }; - D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenCCBridge.swift; sourceTree = ""; }; D427F768278C9D0D004A2160 /* CandidateUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = CandidateUI; path = Packages/CandidateUI; sourceTree = ""; }; D427F76B278CA1BA004A2160 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; D427F7A727905E43004A2160 /* TooltipUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = TooltipUI; path = Packages/TooltipUI; sourceTree = ""; }; D427F7AC27907B7E004A2160 /* NotifierUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = NotifierUI; path = Packages/NotifierUI; sourceTree = ""; }; + D427F7B2279086B5004A2160 /* InputSourceHelper */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = InputSourceHelper; path = Packages/InputSourceHelper; sourceTree = ""; }; + D427F7BA27908D78004A2160 /* OpenCCBridge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenCCBridge.swift; sourceTree = ""; }; D47F7DCD278BFB57002F9DD7 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = ""; }; D47F7DCF278C0897002F9DD7 /* NonModalAlertWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonModalAlertWindowController.swift; sourceTree = ""; }; D47F7DD1278C1263002F9DD7 /* UserOverrideModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserOverrideModel.h; sourceTree = ""; }; D47F7DD2278C1263002F9DD7 /* UserOverrideModel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserOverrideModel.cpp; sourceTree = ""; }; - D47F7DD4278C25A0002F9DD7 /* InputSourceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceHelper.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -184,11 +184,12 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D427F7B4279086DC004A2160 /* InputSourceHelper in Frameworks */, 6A38BC2815FC158A00A8A51F /* InputMethodKit.framework in Frameworks */, - D48550A325EBE689006A204C /* OpenCC in Frameworks */, D427F7A927905E90004A2160 /* TooltipUI in Frameworks */, D427F76A278C9E29004A2160 /* CandidateUI in Frameworks */, D427F7AE27907B8A004A2160 /* NotifierUI in Frameworks */, + D427F7BE27908DD7004A2160 /* OpenCC in Frameworks */, 6A0D4EA715FC0D2D00ABF4B3 /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -197,6 +198,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D427F7B6279086F6004A2160 /* InputSourceHelper in Frameworks */, 6ACA41CD15FC1D7500935EF6 /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -247,10 +249,9 @@ D41355D7278D7409005E5CBD /* LanguageModelManager.mm */, 6A0D4EC815FC0D6400ABF4B3 /* main.m */, D427F76B278CA1BA004A2160 /* AppDelegate.swift */, - D47F7DD4278C25A0002F9DD7 /* InputSourceHelper.swift */, D47F7DCF278C0897002F9DD7 /* NonModalAlertWindowController.swift */, D47F7DCD278BFB57002F9DD7 /* PreferencesWindowController.swift */, - D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */, + D427F7BA27908D78004A2160 /* OpenCCBridge.swift */, 6A0D4EF615FC0DA600ABF4B3 /* McBopomofo-Prefix.pch */, D427A9BF25ED28CC005D43E0 /* McBopomofo-Bridging-Header.h */, ); @@ -401,6 +402,7 @@ D427F768278C9D0D004A2160 /* CandidateUI */, D427F7A727905E43004A2160 /* TooltipUI */, D427F7AC27907B7E004A2160 /* NotifierUI */, + D427F7B2279086B5004A2160 /* InputSourceHelper */, ); name = Packages; sourceTree = ""; @@ -440,10 +442,11 @@ ); name = McBopomofo; packageProductDependencies = ( - D48550A225EBE689006A204C /* OpenCC */, D427F769278C9E29004A2160 /* CandidateUI */, D427F7A827905E90004A2160 /* TooltipUI */, D427F7AD27907B8A004A2160 /* NotifierUI */, + D427F7B3279086DC004A2160 /* InputSourceHelper */, + D427F7BD27908DD7004A2160 /* OpenCC */, ); productName = McBopomofo; productReference = 6A0D4EA215FC0D2D00ABF4B3 /* McBopomofo.app */; @@ -464,6 +467,9 @@ 6ACA420115FC1DCC00935EF6 /* PBXTargetDependency */, ); name = McBopomofoInstaller; + packageProductDependencies = ( + D427F7B5279086F6004A2160 /* InputSourceHelper */, + ); productName = McBopomofoInstaller; productReference = 6ACA41CB15FC1D7500935EF6 /* McBopomofoInstaller.app */; productType = "com.apple.product-type.application"; @@ -492,7 +498,7 @@ ); mainGroup = 6A0D4E9215FC0CFA00ABF4B3; packageReferences = ( - D48550A125EBE689006A204C /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */, + D427F7BC27908DD7004A2160 /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */, ); productRefGroup = 6A0D4EA315FC0D2D00ABF4B3 /* Products */; projectDirPath = ""; @@ -568,12 +574,11 @@ files = ( D427F76C278CA2B0004A2160 /* AppDelegate.swift in Sources */, 6A0D4ED315FC0D6400ABF4B3 /* main.m in Sources */, - D47F7DD5278C25A0002F9DD7 /* InputSourceHelper.swift in Sources */, D47F7DD0278C0897002F9DD7 /* NonModalAlertWindowController.swift in Sources */, - D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */, D47F7DCE278BFB57002F9DD7 /* PreferencesWindowController.swift in Sources */, 6A0D4ED215FC0D6400ABF4B3 /* InputMethodController.mm in Sources */, D41355DB278E6D17005E5CBD /* McBopomofoLM.cpp in Sources */, + D427F7BB27908D78004A2160 /* OpenCCBridge.swift in Sources */, D47F7DD3278C1263002F9DD7 /* UserOverrideModel.cpp in Sources */, 6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */, D41355DE278EA3ED005E5CBD /* UserPhrasesLM.cpp in Sources */, @@ -589,7 +594,6 @@ 6ACA41F915FC1D9000935EF6 /* AppDelegate.m in Sources */, 6A225A232367A1D700F685C6 /* ArchiveUtil.m in Sources */, 6ACA41FF15FC1D9000935EF6 /* main.m in Sources */, - D47F7DD6278C3075002F9DD7 /* InputSourceHelper.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1054,12 +1058,12 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - D48550A125EBE689006A204C /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */ = { + D427F7BC27908DD7004A2160 /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/ddddxxx/SwiftyOpenCC.git"; requirement = { kind = revision; - revision = 1d8105a0f7199c90af722bff62728050c858e777; + revision = a802c02cbf1c6fcd529575f11a9876d94fc813f4; }; }; /* End XCRemoteSwiftPackageReference section */ @@ -1077,9 +1081,17 @@ isa = XCSwiftPackageProductDependency; productName = NotifierUI; }; - D48550A225EBE689006A204C /* OpenCC */ = { + D427F7B3279086DC004A2160 /* InputSourceHelper */ = { isa = XCSwiftPackageProductDependency; - package = D48550A125EBE689006A204C /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */; + productName = InputSourceHelper; + }; + D427F7B5279086F6004A2160 /* InputSourceHelper */ = { + isa = XCSwiftPackageProductDependency; + productName = InputSourceHelper; + }; + D427F7BD27908DD7004A2160 /* OpenCC */ = { + isa = XCSwiftPackageProductDependency; + package = D427F7BC27908DD7004A2160 /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */; productName = OpenCC; }; /* End XCSwiftPackageProductDependency section */ diff --git a/Packages/InputSourceHelper/.gitignore b/Packages/InputSourceHelper/.gitignore new file mode 100644 index 00000000..bb460e7b --- /dev/null +++ b/Packages/InputSourceHelper/.gitignore @@ -0,0 +1,7 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata diff --git a/Packages/InputSourceHelper/Package.swift b/Packages/InputSourceHelper/Package.swift new file mode 100644 index 00000000..4543d050 --- /dev/null +++ b/Packages/InputSourceHelper/Package.swift @@ -0,0 +1,25 @@ +// swift-tools-version:5.5 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "InputSourceHelper", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "InputSourceHelper", + targets: ["InputSourceHelper"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "InputSourceHelper", + dependencies: []), + ] +) diff --git a/Packages/InputSourceHelper/README.md b/Packages/InputSourceHelper/README.md new file mode 100644 index 00000000..cc27cfb9 --- /dev/null +++ b/Packages/InputSourceHelper/README.md @@ -0,0 +1,3 @@ +# InputSourceHelper + +A description of this package. diff --git a/Source/InputSourceHelper.swift b/Packages/InputSourceHelper/Sources/InputSourceHelper/InputSourceHelper.swift similarity index 100% rename from Source/InputSourceHelper.swift rename to Packages/InputSourceHelper/Sources/InputSourceHelper/InputSourceHelper.swift diff --git a/Packages/NonModalAlertWindow/.gitignore b/Packages/NonModalAlertWindow/.gitignore new file mode 100644 index 00000000..bb460e7b --- /dev/null +++ b/Packages/NonModalAlertWindow/.gitignore @@ -0,0 +1,7 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata diff --git a/Packages/NonModalAlertWindow/Package.swift b/Packages/NonModalAlertWindow/Package.swift new file mode 100644 index 00000000..7e9a84ed --- /dev/null +++ b/Packages/NonModalAlertWindow/Package.swift @@ -0,0 +1,25 @@ +// swift-tools-version:5.5 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "NonModalAlertWindow", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "NonModalAlertWindow", + targets: ["NonModalAlertWindow"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "NonModalAlertWindow", + dependencies: []), + ] +) diff --git a/Packages/NonModalAlertWindow/README.md b/Packages/NonModalAlertWindow/README.md new file mode 100644 index 00000000..93b2b884 --- /dev/null +++ b/Packages/NonModalAlertWindow/README.md @@ -0,0 +1,3 @@ +# NonModalAlertWindow + +A description of this package. diff --git a/Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/NonModalAlertWindowController.swift b/Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/NonModalAlertWindowController.swift new file mode 100644 index 00000000..936250e9 --- /dev/null +++ b/Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/NonModalAlertWindowController.swift @@ -0,0 +1,147 @@ +// +// NonModalAlertWindowController.swift +// +// Copyright (c) 2011 The McBopomofo Project. +// +// Contributors: +// Mengjuei Hsieh (@mjhsieh) +// Weizhong Yang (@zonble) +// +// Based on the Syrup Project and the Formosana Library +// by Lukhnos Liu (@lukhnos). +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +import Cocoa + +@objc public protocol NonModalAlertWindowControllerDelegate: AnyObject { + func nonModalAlertWindowControllerDidConfirm(_ controller: NonModalAlertWindowController) + func nonModalAlertWindowControllerDidCancel(_ controller: NonModalAlertWindowController) +} + +@objc public class NonModalAlertWindowController: NSWindowController { + @objc (sharedInstance) + public static let shared: NonModalAlertWindowController = { + NSLog("shaerd???") + guard let path = Bundle.main.path(forResource: "NonModalAlertWindow_NonModalAlertWindow", ofType: "bundle"), + let modelBudle = Bundle(path: path), + let xibPath = modelBudle.path(forResource: "NonModalAlertWindowController", ofType: "nib") + else { + let controller = NonModalAlertWindowController(windowNibName: "NonModalAlertWindowController") + return controller + } + NSLog("shared path \(path)") + NSLog("shared modelBudle \(modelBudle)") + NSLog("shared xibPath \(xibPath)") + let controller = NonModalAlertWindowController(windowNibPath: xibPath, owner: self) + return controller + }() + + @IBOutlet weak var titleTextField: NSTextField! + @IBOutlet weak var contentTextField: NSTextField! + @IBOutlet weak var confirmButton: NSButton! + @IBOutlet weak var cancelButton: NSButton! + weak var delegate: NonModalAlertWindowControllerDelegate? + + @objc public func show(title: String, content: String, confirmButtonTitle: String, cancelButtonTitle: String?, cancelAsDefault: Bool, delegate: NonModalAlertWindowControllerDelegate?) { + if window?.isVisible == true { + self.delegate?.nonModalAlertWindowControllerDidCancel(self) + } + + self.delegate = delegate + + var oldFrame = confirmButton.frame + confirmButton.title = confirmButtonTitle + confirmButton.sizeToFit() + + var newFrame = confirmButton.frame + newFrame.size.width = max(90, newFrame.size.width + 10) + newFrame.origin.x += oldFrame.size.width - newFrame.size.width + confirmButton.frame = newFrame + + if let cancelButtonTitle = cancelButtonTitle { + cancelButton.title = cancelButtonTitle + cancelButton.sizeToFit() + var adjustFrame = cancelButton.frame + adjustFrame.size.width = max(90, adjustFrame.size.width + 10) + adjustFrame.origin.x = newFrame.origin.x - adjustFrame.size.width + confirmButton.frame = adjustFrame + cancelButton.isHidden = false + } else { + cancelButton.isHidden = true + } + + cancelButton.nextKeyView = confirmButton + confirmButton.nextKeyView = cancelButton + + if cancelButtonTitle != nil { + if cancelAsDefault { + window?.defaultButtonCell = cancelButton.cell as? NSButtonCell + } else { + cancelButton.keyEquivalent = " " + window?.defaultButtonCell = confirmButton.cell as? NSButtonCell + } + } else { + window?.defaultButtonCell = confirmButton.cell as? NSButtonCell + } + + titleTextField.stringValue = title + + oldFrame = contentTextField.frame + contentTextField.stringValue = content + + var infiniteHeightFrame = oldFrame + infiniteHeightFrame.size.width -= 4.0 + infiniteHeightFrame.size.height = 10240 + newFrame = (content as NSString).boundingRect(with: infiniteHeightFrame.size, options: [.usesLineFragmentOrigin], attributes: [.font: contentTextField.font!]) + newFrame.size.width = max(newFrame.size.width, oldFrame.size.width) + newFrame.size.height += 4.0 + newFrame.origin = oldFrame.origin + newFrame.origin.y -= (newFrame.size.height - oldFrame.size.height) + contentTextField.frame = newFrame + + var windowFrame = window?.frame ?? NSRect.zero + windowFrame.size.height += (newFrame.size.height - oldFrame.size.height) + window?.level = NSWindow.Level(Int(CGShieldingWindowLevel()) + 1) + window?.setFrame(windowFrame, display: true) + window?.center() + window?.makeKeyAndOrderFront(self) + NSApp.activate(ignoringOtherApps: true) + } + + @IBAction func confirmButtonAction(_ sender: Any) { + delegate?.nonModalAlertWindowControllerDidConfirm(self) + window?.orderOut(self) + } + + @IBAction func cancelButtonAction(_ sender: Any) { + cancel(sender) + } + + @objc public func cancel(_ sender: Any) { + delegate?.nonModalAlertWindowControllerDidCancel(self) + delegate = nil + window?.orderOut(self) + } + +} diff --git a/Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/Resources/NonModalAlertWindowController.xib b/Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/Resources/NonModalAlertWindowController.xib new file mode 100644 index 00000000..8c378007 --- /dev/null +++ b/Packages/NonModalAlertWindow/Sources/NonModalAlertWindow/Resources/NonModalAlertWindowController.xib @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 1b02accd..9d4cfb11 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -44,7 +44,6 @@ @import CandidateUI; @import NotifierUI; @import TooltipUI; -@import OpenCC; // C++ namespace usages using namespace std; diff --git a/Source/Installer/AppDelegate.m b/Source/Installer/AppDelegate.m index 62f7acc5..84dbd224 100644 --- a/Source/Installer/AppDelegate.m +++ b/Source/Installer/AppDelegate.m @@ -27,7 +27,8 @@ #import "AppDelegate.h" #import -#import "McBopomofoInstaller-Swift.h" +//#import "McBopomofoInstaller-Swift.h" +@import InputSourceHelper; static NSString *const kTargetBin = @"McBopomofo"; static NSString *const kTargetType = @"app"; diff --git a/Source/OpenCCBridge.swift b/Source/OpenCCBridge.swift index f63a2726..43bc6a35 100644 --- a/Source/OpenCCBridge.swift +++ b/Source/OpenCCBridge.swift @@ -3,7 +3,7 @@ import OpenCC // Since SwiftyOpenCC only provide Swift classes, we create an NSObject subclass // in Swift in order to bridge the Swift classes into our Objective-C++ project. -class OpenCCBridge: NSObject { +public class OpenCCBridge: NSObject { private static let shared = OpenCCBridge() private var converter: ChineseConverter? @@ -12,11 +12,7 @@ class OpenCCBridge: NSObject { super.init() } - @objc static func convert(_ string: String) -> String? { + @objc public static func convert(_ string: String) -> String? { shared.converter?.convert(string) } - - private func convert(_ string: String) -> String? { - converter?.convert(string) - } } diff --git a/Source/main.m b/Source/main.m index a98863b0..f65d13a7 100644 --- a/Source/main.m +++ b/Source/main.m @@ -34,7 +34,7 @@ #import #import -#import "McBopomofo-Swift.h" +@import InputSourceHelper; static NSString *const kConnectionName = @"McBopomofo_1_Connection";