diff --git a/app/src/main/java/io/neoterm/component/colorscheme/ColorSchemeComponent.kt b/app/src/main/java/io/neoterm/component/colorscheme/ColorSchemeComponent.kt index a09ca21..1056eec 100644 --- a/app/src/main/java/io/neoterm/component/colorscheme/ColorSchemeComponent.kt +++ b/app/src/main/java/io/neoterm/component/colorscheme/ColorSchemeComponent.kt @@ -52,14 +52,14 @@ class ColorSchemeComponent : ConfigFileBasedComponent(NeoTermPat fun reloadColorSchemes(): Boolean { colors.clear() - File(NeoTermPath.COLORS_PATH).listFiles { pathname -> - pathname.name.endsWith(".color") || pathname.name.endsWith(".nl") - }.forEach { - val colorScheme = this.loadConfigure(it) - if (colorScheme != null) { - colors.put(colorScheme.colorName, colorScheme) - } - } + File(baseDir) + .listFiles(NEOLANG_FILTER) + .forEach { + val colorScheme = this.loadConfigure(it) + if (colorScheme != null) { + colors.put(colorScheme.colorName, colorScheme) + } + } if (colors.containsKey(DefaultColorScheme.colorName)) { DEFAULT_COLOR = colors[DefaultColorScheme.colorName]!! @@ -105,7 +105,7 @@ class ColorSchemeComponent : ConfigFileBasedComponent(NeoTermPat private fun extractDefaultColor(context: Context): Boolean { try { - AssetsUtils.extractAssetsDir(context, "colors", NeoTermPath.COLORS_PATH) + AssetsUtils.extractAssetsDir(context, "colors", baseDir) return true } catch (e: Exception) { NLog.e("ColorScheme", "Failed to extract default colors: ${e.localizedMessage}") diff --git a/app/src/main/java/io/neoterm/component/extrakey/ExtraKeyComponent.kt b/app/src/main/java/io/neoterm/component/extrakey/ExtraKeyComponent.kt index 1a853fe..3a16cab 100644 --- a/app/src/main/java/io/neoterm/component/extrakey/ExtraKeyComponent.kt +++ b/app/src/main/java/io/neoterm/component/extrakey/ExtraKeyComponent.kt @@ -9,18 +9,11 @@ import io.neoterm.frontend.logging.NLog import io.neoterm.frontend.terminal.extrakey.ExtraKeysView import io.neoterm.utils.AssetsUtils import java.io.File -import java.io.FileFilter /** * @author kiva */ class ExtraKeyComponent : ConfigFileBasedComponent(NeoTermPath.EKS_PATH) { - companion object { - private val FILTER = FileFilter { - it.extension == "nl" - } - } - override val checkComponentFileWhenObtained = true private val extraKeys: MutableMap = mutableMapOf() @@ -59,22 +52,23 @@ class ExtraKeyComponent : ConfigFileBasedComponent(NeoTermPath.EKS_ private fun extractDefaultConfig(context: Context) { try { - AssetsUtils.extractAssetsDir(context, "eks", NeoTermPath.EKS_PATH) + AssetsUtils.extractAssetsDir(context, "eks", baseDir) } catch (e: Exception) { NLog.e("ExtraKey", "Failed to extract configure: ${e.localizedMessage}") } } private fun reloadExtraKeyConfig() { - val configDir = File(NeoTermPath.EKS_PATH) - - configDir.listFiles(FILTER).forEach { - if (it.absolutePath != NeoTermPath.EKS_DEFAULT_FILE) { - val extraKey = this.loadConfigure(it) - if (extraKey != null) { - registerShortcutKeys(extraKey) + extraKeys.clear() + File(baseDir) + .listFiles(NEOLANG_FILTER) + .forEach { + if (it.absolutePath != NeoTermPath.EKS_DEFAULT_FILE) { + val extraKey = this.loadConfigure(it) + if (extraKey != null) { + registerShortcutKeys(extraKey) + } + } } - } - } } } \ No newline at end of file diff --git a/app/src/main/java/io/neoterm/component/profile/ProfileComponent.kt b/app/src/main/java/io/neoterm/component/profile/ProfileComponent.kt index 49fdf00..aa1f8db 100644 --- a/app/src/main/java/io/neoterm/component/profile/ProfileComponent.kt +++ b/app/src/main/java/io/neoterm/component/profile/ProfileComponent.kt @@ -3,6 +3,7 @@ package io.neoterm.component.profile import io.neolang.visitor.ConfigVisitor import io.neoterm.frontend.component.helper.ConfigFileBasedComponent import io.neoterm.frontend.config.NeoTermPath +import java.io.File /** * @author kiva @@ -31,6 +32,7 @@ class ProfileComponent : ConfigFileBasedComponent(NeoTermPath.PROFIL fun reloadProfiles() { profileList.clear() + } fun registerProfile(metaName: String, prototype: Class) { diff --git a/app/src/main/java/io/neoterm/frontend/component/helper/ConfigFileBasedComponent.kt b/app/src/main/java/io/neoterm/frontend/component/helper/ConfigFileBasedComponent.kt index 1a85a2a..527c9cb 100644 --- a/app/src/main/java/io/neoterm/frontend/component/helper/ConfigFileBasedComponent.kt +++ b/app/src/main/java/io/neoterm/frontend/component/helper/ConfigFileBasedComponent.kt @@ -6,6 +6,7 @@ import io.neoterm.frontend.component.ComponentManager import io.neoterm.frontend.component.NeoComponent import io.neoterm.frontend.logging.NLog import java.io.File +import java.io.FileFilter /** * @author kiva @@ -13,6 +14,10 @@ import java.io.File abstract class ConfigFileBasedComponent(protected val baseDir: String) : NeoComponent { companion object { private val TAG = ConfigFileBasedComponent::class.java.simpleName + + val NEOLANG_FILTER = FileFilter { + it.extension == "nl" + } } open val checkComponentFileWhenObtained = false