generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate LanguageCheckStrategy another file
- Loading branch information
Showing
2 changed files
with
30 additions
and
25 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/github/lauvsong/langcursor/core/LanguageCheckStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.lauvsong.langcursor.core | ||
|
||
import com.github.lauvsong.langcursor.utils.WindowsLanguageUtil | ||
import com.jcraft.jsch.agentproxy.connector.PageantConnector | ||
import java.awt.im.InputContext | ||
import java.util.* | ||
|
||
fun interface LanguageCheckStrategy { | ||
fun isEnglishInput(): Boolean | ||
} | ||
|
||
val defaultLanguageCheckStrategy = LanguageCheckStrategy { | ||
val locale = InputContext.getInstance().locale | ||
val language = locale.language | ||
val country = locale.country | ||
|
||
language == Locale.ENGLISH.language | ||
|| country == Locale.US.country | ||
|| country == Locale.UK.country | ||
} | ||
|
||
val windowsLanguageCheckStrategy = LanguageCheckStrategy { | ||
PageantConnector.User32.INSTANCE.GetForegroundWindow() | ||
?.let { hwnd -> | ||
WindowsLanguageUtil.INSTANCE.isEnglish(hwnd.pointer) | ||
} ?: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters