Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Jan 18, 2019
1 parent bc3833e commit 3d178e1
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 662 deletions.
74 changes: 37 additions & 37 deletions Gureum.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions GureumTests/GureumTests.swift
Expand Up @@ -55,7 +55,7 @@ class GureumTests: XCTestCase {
for app in apps { for app in apps {
app.client.string = "" app.client.string = ""
app.controller.setValue("org.youknowone.inputmethod.Gureum.qwerty", forTag: kTextServiceInputModePropertyTag, client: app.client) app.controller.setValue("org.youknowone.inputmethod.Gureum.qwerty", forTag: kTextServiceInputModePropertyTag, client: app.client)
app.inputText(nil, key: -1, modifiers: NSEvent.ModifierFlags.capsLock) app.inputFlags(NSEvent.ModifierFlags.capsLock)


app.inputText(" ", key: Int(kVK_Space), modifiers: NSEvent.ModifierFlags.shift) app.inputText(" ", key: Int(kVK_Space), modifiers: NSEvent.ModifierFlags.shift)
app.inputText(" ", key: Int(kVK_Space), modifiers: NSEvent.ModifierFlags.shift) app.inputText(" ", key: Int(kVK_Space), modifiers: NSEvent.ModifierFlags.shift)
Expand Down Expand Up @@ -426,7 +426,7 @@ class GureumTests: XCTestCase {
app.client.string = "" app.client.string = ""
app.controller.setValue(GureumInputSourceIdentifier.qwerty.rawValue, forTag: kTextServiceInputModePropertyTag, client: app.client) app.controller.setValue(GureumInputSourceIdentifier.qwerty.rawValue, forTag: kTextServiceInputModePropertyTag, client: app.client)


let composer = app.controller.composer as! GureumComposer let composer = app.controller.receiver.composer as! GureumComposer
let emoticonComposer = composer.emoticonComposer let emoticonComposer = composer.emoticonComposer
emoticonComposer.delegate = composer.delegate // roman? emoticonComposer.delegate = composer.delegate // roman?
composer.delegate = emoticonComposer composer.delegate = emoticonComposer
Expand Down
10 changes: 8 additions & 2 deletions GureumTests/MockApp.swift
Expand Up @@ -10,14 +10,20 @@ import Foundation
@testable import GureumCore @testable import GureumCore


class VirtualApp: NSObject { class VirtualApp: NSObject {
let controller: CIMInputController let controller: MockInputController
let client = MockInputClient() let client = MockInputClient()


override init() { override init() {
controller = CIMMockInputController(server: InputMethodServer.shared.server, delegate: client, client: client) controller = MockInputController(server: InputMethodServer.shared.server, delegate: client, client: client)
super.init() super.init()
} }


func inputFlags(_ flags: NSEvent.ModifierFlags) -> Bool {
let processed = controller.inputFlags(Int(flags.rawValue), client: client)
controller.updateComposition()
return processed
}

func inputText(_ string: String!, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags) -> Bool { func inputText(_ string: String!, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags) -> Bool {
let processed = controller.inputText(string, key: keyCode, modifiers: Int(flags.rawValue), client: client) let processed = controller.inputText(string, key: keyCode, modifiers: Int(flags.rawValue), client: client)
controller.updateComposition() controller.updateComposition()
Expand Down
2 changes: 1 addition & 1 deletion OSX/CIMInputController.m
@@ -1,5 +1,5 @@
// //
// CIMInputController.m // InputController.m
// Gureum // Gureum
// //
// Created by youknowone on 11. 8. 31.. // Created by youknowone on 11. 8. 31..
Expand Down
7 changes: 3 additions & 4 deletions OSX/GureumAppDelegate.swift
Expand Up @@ -34,10 +34,10 @@ class NotificationCenterDelegate: NSObject, NSUserNotificationCenterDelegate {
} }
} }


class GureumAppDelegate: NSObject, NSApplicationDelegate, CIMApplicationDelegate { class GureumAppDelegate: NSObject, NSApplicationDelegate, GureumApplicationDelegate {
@IBOutlet @objc var menu: NSMenu! @IBOutlet @objc var menu: NSMenu!


let configuration = GureumConfiguration.shared let configuration = Configuration.shared
let notificationCenterDelegate = NotificationCenterDelegate() let notificationCenterDelegate = NotificationCenterDelegate()


func applicationDidFinishLaunching(_ notification: Notification) { func applicationDidFinishLaunching(_ notification: Notification) {
Expand All @@ -55,8 +55,7 @@ class GureumAppDelegate: NSObject, NSApplicationDelegate, CIMApplicationDelegate
Fabric.with([Crashlytics.self]) Fabric.with([Crashlytics.self])
#endif #endif


let updateManager = UpdateManager.shared UpdateManager.shared.notifyUpdateIfNeeded()
updateManager.notifyUpdateIfNeeded()


// IMKServer를 띄워야만 입력기가 동작한다 // IMKServer를 띄워야만 입력기가 동작한다
_ = InputMethodServer.shared _ = InputMethodServer.shared
Expand Down
4 changes: 2 additions & 2 deletions OSX/CIMInputControllerGureum.swift → OSX/GureumMenu.swift
@@ -1,5 +1,5 @@
// //
// CIMInputControllerGureum.swift // InputControllerGureum.swift
// Gureum // Gureum
// //
// Created by KMLee on 2018. 8. 24.. // Created by KMLee on 2018. 8. 24..
Expand All @@ -10,7 +10,7 @@ import Cocoa
import Foundation import Foundation
import GureumCore import GureumCore


extension CIMInputController { extension GureumAppDelegate {
@IBAction func checkRecentVersion(_: Any) { @IBAction func checkRecentVersion(_: Any) {
guard let info = UpdateManager.shared.requestRecentVersion() else { guard let info = UpdateManager.shared.requestRecentVersion() else {
return return
Expand Down
4 changes: 2 additions & 2 deletions OSX/Info.plist
Expand Up @@ -442,9 +442,9 @@
<key>InputMethodConnectionName</key> <key>InputMethodConnectionName</key>
<string>GureumInputMethod_1_Connection</string> <string>GureumInputMethod_1_Connection</string>
<key>InputMethodServerControllerClass</key> <key>InputMethodServerControllerClass</key>
<string>CIMInputController</string> <string>GureumInputController</string>
<key>InputMethodServerDelegateClass</key> <key>InputMethodServerDelegateClass</key>
<string>CIMInputController</string> <string>GureumInputController</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
Expand Down
18 changes: 7 additions & 11 deletions OSX/MainMenu.xib
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"/> <customObject id="-2" userLabel="File's Owner" customClass="NSApplication"/>
Expand All @@ -17,44 +17,40 @@
<outlet property="menu" destination="538" id="544"/> <outlet property="menu" destination="538" id="544"/>
</connections> </connections>
</customObject> </customObject>
<customObject id="550" customClass="CIMInputController"/>
<menu id="538"> <menu id="538">
<items> <items>
<menuItem title="구름 입력기에 관하여" id="539"> <menuItem title="구름 입력기에 관하여" id="539">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showStandardAboutPanel:" target="550" id="552"/>
</connections>
</menuItem> </menuItem>
<menuItem title="업데이트 확인" id="557"> <menuItem title="업데이트 확인" id="557">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="checkRecentVersion:" target="550" id="566"/> <action selector="checkRecentVersion:" target="494" id="iAc-Fb-XKV"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="561"/> <menuItem isSeparatorItem="YES" id="561"/>
<menuItem title="웹사이트..." id="555"> <menuItem title="웹사이트..." id="555">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="openWebsite:" target="550" id="567"/> <action selector="openWebsite:" target="494" id="qXD-LJ-2eV"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title=" 도움말..." id="553"> <menuItem title=" 도움말..." id="553">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="openWebsiteHelp:" target="550" id="568"/> <action selector="openWebsiteHelp:" target="494" id="3GP-kp-Nx0"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title=" 버그 알리기..." id="564"> <menuItem title=" 버그 알리기..." id="564">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="openWebsiteIssues:" target="550" id="569"/> <action selector="openWebsiteIssues:" target="494" id="eEb-ZD-TRB"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title=" 소스 코드..." id="562"> <menuItem title=" 소스 코드..." id="562">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="openWebsiteSource:" target="550" id="570"/> <action selector="openWebsiteSource:" target="494" id="9e7-Ql-FjA"/>
</connections> </connections>
</menuItem> </menuItem>
</items> </items>
Expand Down
10 changes: 5 additions & 5 deletions OSXCore/CIMBaseComposer.swift → OSXCore/BaseComposer.swift
@@ -1,5 +1,5 @@
// //
// CIMBaseComposer.swift // BaseComposer.swift
// Gureum // Gureum
// //
// Created by 김민주 on 2018. 9. 1.. // Created by 김민주 on 2018. 9. 1..
Expand All @@ -9,7 +9,7 @@
import Cocoa import Cocoa
import Foundation import Foundation


class CIMBaseComposer { class BaseComposer {
func composedString() -> NSString { func composedString() -> NSString {
return "" return ""
} }
Expand All @@ -22,7 +22,7 @@ class CIMBaseComposer {
return "" return ""
} }


func dequeueCommitString() -> NSString { func dequeueCommitString() -> String {
return "" return ""
} }


Expand All @@ -36,7 +36,7 @@ class CIMBaseComposer {
return nil return nil
} }


func input(controller _: CIMInputController!, command _: String!, key _: Int, modifier _: NSEvent.ModifierFlags, client _: Any) -> CIMInputTextProcessResult { func input(controller _: InputController!, command _: String!, key _: Int, modifier _: NSEvent.ModifierFlags, client _: Any) -> InputResult {
return CIMInputTextProcessResult.notProcessed return .notProcessed
} }
} }
31 changes: 11 additions & 20 deletions OSXCore/CIMComposer.swift → OSXCore/ComposerDelegate.swift
@@ -1,5 +1,5 @@
// //
// CIMComposer.swift // DelegatedComposer.swift
// OSX // OSX
// //
// Created by Jeong YunWon on 20/10/2018. // Created by Jeong YunWon on 20/10/2018.
Expand All @@ -12,9 +12,9 @@ import Foundation
/*! /*!
@protocol @protocol
@brief 입력을 처리하는 클래스의 관한 공통 형식 @brief 입력을 처리하는 클래스의 관한 공통 형식
@discussion TextData형식으로 @ref IMKServerInput 을 처리할 클래스의 공통 인터페이스. CharmIM에서 입력 값을 보고 처리하는 모든 클래스는 이 프로토콜을 구현한다. @discussion TextData형식으로 @ref IMKServerInput 을 처리할 클래스의 공통 인터페이스. 입력 값을 보고 처리하는 모든 클래스는 이 프로토콜을 구현한다.
*/ */
protocol CIMInputTextDelegate { protocol InputTextDelegate {
/*! /*!
@method @method
@param controller 서버에서 입력을 받은 컨트롤러 @param controller 서버에서 입력을 받은 컨트롤러
Expand All @@ -25,15 +25,15 @@ protocol CIMInputTextDelegate {
@return 입력 처리 여부. YES를 반환하면 이미 처리된 입력으로 보고 NO를 반환하면 외부에서 입력을 다시 처리한다. @return 입력 처리 여부. YES를 반환하면 이미 처리된 입력으로 보고 NO를 반환하면 외부에서 입력을 다시 처리한다.
@see IMKServerInput @see IMKServerInput
*/ */
func input(controller: CIMInputController, inputText: String?, key: Int, modifiers: NSEvent.ModifierFlags, client: Any) -> CIMInputTextProcessResult func input(text: String?, key: Int, modifiers: NSEvent.ModifierFlags, client: Any) -> InputResult
} }


/*! /*!
@brief 실제로 문자를 합성하는 합성기의 프로토콜 @brief 실제로 문자를 합성하는 합성기의 프로토콜
@discussion 입력기 전체의 상태에 영향을 끼치는 처리를 마친 후 출력할 글자를 조합하기 위해 CIMComposer로 입력을 전달한다. 기본적으로 자판마다 하나씩 구현하게 된다. @discussion 입력기 전체의 상태에 영향을 끼치는 처리를 마친 후 출력할 글자를 조합하기 위해 DelegatedComposer로 입력을 전달한다. 기본적으로 자판마다 하나씩 구현하게 된다.
*/ */


protocol CIMComposerDelegate: CIMInputTextDelegate { protocol ComposerDelegate: InputTextDelegate {
//! @brief 입력기가 선택 됨 //! @brief 입력기가 선택 됨
func composerSelected(_ sender: Any!) func composerSelected(_ sender: Any!)


Expand All @@ -59,23 +59,18 @@ protocol CIMComposerDelegate: CIMInputTextDelegate {
func candidateSelected(_ candidateString: NSAttributedString) func candidateSelected(_ candidateString: NSAttributedString)
//! @brief 변환 후보 문자열 변경 //! @brief 변환 후보 문자열 변경
func candidateSelectionChanged(_ candidateString: NSAttributedString) func candidateSelectionChanged(_ candidateString: NSAttributedString)

func input(controller: CIMInputController, command string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client: Any) -> CIMInputTextProcessResult
} }


/*! /*!
@brief 일반적인 합성기 구조 @brief 일반적인 합성기 구조
@warning 이 자체로는 동작하지 않는다. 상속하여 동작을 구현하거나 @ref CIMBaseComposer 를 사용한다. @warning 이 자체로는 동작하지 않는다. 상속하여 동작을 구현하거나 @ref BaseComposer 를 사용한다.
*/ */
class CIMComposer: NSObject, CIMComposerDelegate { class DelegatedComposer: ComposerDelegate {
func composerSelected(_: Any!) {} func composerSelected(_: Any!) {}


var delegate: CIMComposerDelegate! var delegate: ComposerDelegate!
var inputMode: String = "" var inputMode: String = ""
var server: InputMethodServer {
return InputMethodServer.shared
}


var composedString: String { var composedString: String {
return delegate.composedString return delegate.composedString
Expand Down Expand Up @@ -117,11 +112,7 @@ class CIMComposer: NSObject, CIMComposerDelegate {
return delegate.candidateSelectionChanged(candidateString) return delegate.candidateSelectionChanged(candidateString)
} }


func input(controller: CIMInputController, inputText string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any) -> CIMInputTextProcessResult { func input(text string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any) -> InputResult {
return delegate.input(controller: controller, inputText: string, key: keyCode, modifiers: flags, client: sender) return delegate.input(text: string, key: keyCode, modifiers: flags, client: sender)
}

func input(controller: CIMInputController, command string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any) -> CIMInputTextProcessResult {
return delegate.input(controller: controller, command: string, key: keyCode, modifiers: flags, client: sender)
} }
} }

0 comments on commit 3d178e1

Please sign in to comment.