Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dkandalov committed Mar 11, 2022
1 parent 9e4ca07 commit 3e46a02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ijkl/keymap-modifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun initCurrentKeymapModifier(
"Switched keymap from '$oldKeymap' to '$newKeymap'. Shortcuts: " +
"added - ${shortcuts.added.size}; " +
"already existed - ${shortcuts.alreadyExisted.size}; " +
"conflicts - ${shortcuts.conflicts.values.sumBy { it.size }}"
"conflicts - ${shortcuts.conflicts.values.sumOf { it.size }}"
)
if (shortcuts.conflicts.isNotEmpty()) {
val conflictsDescription = shortcuts
Expand Down
8 changes: 5 additions & 3 deletions src/ijkl/osx-key-layout-installer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun initOsxKeyLayoutInstaller(
"<a href=''>Click here</a> to install bundle with 'U.S. - IJKL' and 'British - IJKL' input sources. "
application.showNotification(message) { notification, _ ->
try {
copyKeyLayoutTo(bundleName, userPathToBundle)
copyKeyLayout(bundleName, userPathToBundle)
notification.expire()
application.showNotification(
"The bundle with input sources was copied to '$userPathToBundle'. " +
Expand All @@ -36,17 +36,19 @@ fun initOsxKeyLayoutInstaller(
}
}

fun copyKeyLayoutTo(fromResource: String, toDir: String) {
fun copyKeyLayout(fromResource: String, toDir: String) {
// List directories and files manually because there seems to be no easy way to list files/dirs in classloader resources.
FileUtil.createDirectory(File("$toDir/Contents/Resources/en.lproj"))
FileUtil.createDirectory(File("$toDir/Contents/Resources/English.lproj"))
listOf(
"Contents/Info.plist",
"Contents/version.plist",
"Contents/Resources/British - IJKL.icns",
"Contents/Resources/British - IJKL.keylayout",
"Contents/Resources/U.S. - IJKL.icns",
"Contents/Resources/U.S. - IJKL.keylayout",
"Contents/Resources/en.lproj/InfoPlist.strings"
"Contents/Resources/en.lproj/InfoPlist.strings",
"Contents/Resources/English.lproj/InfoPlist.strings",
).forEach { fileName ->
FileUtil.copy(
resourceInputStream("$fromResource/$fileName"),
Expand Down
12 changes: 5 additions & 7 deletions test/ijkl/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.hamcrest.core.IsEqual.equalTo
import org.junit.Assert.assertThat
import org.junit.Test
import java.io.File
import java.util.regex.Pattern
import java.util.TreeSet

class Tests {
@Test fun `win, linux keymap xml`() {
Expand All @@ -24,7 +24,7 @@ class Tests {

private fun List<ShortcutData>.validate(amountOfActions: Int, amountOfShortcuts: Int) {
size shouldEqual amountOfActions
sumBy { it.shortcuts.size } shouldEqual amountOfShortcuts
sumOf { it.shortcuts.size } shouldEqual amountOfShortcuts
first().apply {
actionId shouldEqual "\$Delete"
shortcuts shouldEqual listOf("alt semicolon").map { it.toKeyboardShortcut() }
Expand All @@ -38,15 +38,13 @@ class Tests {
@Test fun `copy layout from resources to a folder`() {
val tempDir = FileUtil.createTempDirectory("", "", true)

copyKeyLayoutTo(fromResource = "ijkl-keys.bundle", toDir = tempDir.absolutePath)
copyKeyLayout(fromResource = "ijkl-keys.bundle", toDir = tempDir.absolutePath)

tempDir.allFiles() shouldEqual File("resources/ijkl-keys.bundle").allFiles()
}

private fun File.allFiles() = FileUtil
.findFilesOrDirsByMask(Pattern.compile(".*"), this)
.map { it.toRelativeString(this) }
.sorted()
private fun File.allFiles() = walkTopDown()
.mapTo(TreeSet()) { it.toRelativeString(this) }

private infix fun <T> T.shouldEqual(that: T) {
assertThat(this, equalTo(that))
Expand Down

0 comments on commit 3e46a02

Please sign in to comment.