Component: Make filter public to everyone

This commit is contained in:
zt515 2017-12-26 23:57:20 +08:00
parent 8445254e0d
commit 2ca2a47049
4 changed files with 27 additions and 26 deletions

View File

@ -52,14 +52,14 @@ class ColorSchemeComponent : ConfigFileBasedComponent<NeoColorScheme>(NeoTermPat
fun reloadColorSchemes(): Boolean { fun reloadColorSchemes(): Boolean {
colors.clear() colors.clear()
File(NeoTermPath.COLORS_PATH).listFiles { pathname -> File(baseDir)
pathname.name.endsWith(".color") || pathname.name.endsWith(".nl") .listFiles(NEOLANG_FILTER)
}.forEach { .forEach {
val colorScheme = this.loadConfigure(it) val colorScheme = this.loadConfigure(it)
if (colorScheme != null) { if (colorScheme != null) {
colors.put(colorScheme.colorName, colorScheme) colors.put(colorScheme.colorName, colorScheme)
} }
} }
if (colors.containsKey(DefaultColorScheme.colorName)) { if (colors.containsKey(DefaultColorScheme.colorName)) {
DEFAULT_COLOR = colors[DefaultColorScheme.colorName]!! DEFAULT_COLOR = colors[DefaultColorScheme.colorName]!!
@ -105,7 +105,7 @@ class ColorSchemeComponent : ConfigFileBasedComponent<NeoColorScheme>(NeoTermPat
private fun extractDefaultColor(context: Context): Boolean { private fun extractDefaultColor(context: Context): Boolean {
try { try {
AssetsUtils.extractAssetsDir(context, "colors", NeoTermPath.COLORS_PATH) AssetsUtils.extractAssetsDir(context, "colors", baseDir)
return true return true
} catch (e: Exception) { } catch (e: Exception) {
NLog.e("ColorScheme", "Failed to extract default colors: ${e.localizedMessage}") NLog.e("ColorScheme", "Failed to extract default colors: ${e.localizedMessage}")

View File

@ -9,18 +9,11 @@ import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.terminal.extrakey.ExtraKeysView import io.neoterm.frontend.terminal.extrakey.ExtraKeysView
import io.neoterm.utils.AssetsUtils import io.neoterm.utils.AssetsUtils
import java.io.File import java.io.File
import java.io.FileFilter
/** /**
* @author kiva * @author kiva
*/ */
class ExtraKeyComponent : ConfigFileBasedComponent<NeoExtraKey>(NeoTermPath.EKS_PATH) { class ExtraKeyComponent : ConfigFileBasedComponent<NeoExtraKey>(NeoTermPath.EKS_PATH) {
companion object {
private val FILTER = FileFilter {
it.extension == "nl"
}
}
override val checkComponentFileWhenObtained = true override val checkComponentFileWhenObtained = true
private val extraKeys: MutableMap<String, NeoExtraKey> = mutableMapOf() private val extraKeys: MutableMap<String, NeoExtraKey> = mutableMapOf()
@ -59,22 +52,23 @@ class ExtraKeyComponent : ConfigFileBasedComponent<NeoExtraKey>(NeoTermPath.EKS_
private fun extractDefaultConfig(context: Context) { private fun extractDefaultConfig(context: Context) {
try { try {
AssetsUtils.extractAssetsDir(context, "eks", NeoTermPath.EKS_PATH) AssetsUtils.extractAssetsDir(context, "eks", baseDir)
} catch (e: Exception) { } catch (e: Exception) {
NLog.e("ExtraKey", "Failed to extract configure: ${e.localizedMessage}") NLog.e("ExtraKey", "Failed to extract configure: ${e.localizedMessage}")
} }
} }
private fun reloadExtraKeyConfig() { private fun reloadExtraKeyConfig() {
val configDir = File(NeoTermPath.EKS_PATH) extraKeys.clear()
File(baseDir)
configDir.listFiles(FILTER).forEach { .listFiles(NEOLANG_FILTER)
if (it.absolutePath != NeoTermPath.EKS_DEFAULT_FILE) { .forEach {
val extraKey = this.loadConfigure(it) if (it.absolutePath != NeoTermPath.EKS_DEFAULT_FILE) {
if (extraKey != null) { val extraKey = this.loadConfigure(it)
registerShortcutKeys(extraKey) if (extraKey != null) {
registerShortcutKeys(extraKey)
}
}
} }
}
}
} }
} }

View File

@ -3,6 +3,7 @@ package io.neoterm.component.profile
import io.neolang.visitor.ConfigVisitor import io.neolang.visitor.ConfigVisitor
import io.neoterm.frontend.component.helper.ConfigFileBasedComponent import io.neoterm.frontend.component.helper.ConfigFileBasedComponent
import io.neoterm.frontend.config.NeoTermPath import io.neoterm.frontend.config.NeoTermPath
import java.io.File
/** /**
* @author kiva * @author kiva
@ -31,6 +32,7 @@ class ProfileComponent : ConfigFileBasedComponent<NeoProfile>(NeoTermPath.PROFIL
fun reloadProfiles() { fun reloadProfiles() {
profileList.clear() profileList.clear()
} }
fun registerProfile(metaName: String, prototype: Class<out NeoProfile>) { fun registerProfile(metaName: String, prototype: Class<out NeoProfile>) {

View File

@ -6,6 +6,7 @@ import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.component.NeoComponent import io.neoterm.frontend.component.NeoComponent
import io.neoterm.frontend.logging.NLog import io.neoterm.frontend.logging.NLog
import java.io.File import java.io.File
import java.io.FileFilter
/** /**
* @author kiva * @author kiva
@ -13,6 +14,10 @@ import java.io.File
abstract class ConfigFileBasedComponent<out T : ConfigFileBasedObject>(protected val baseDir: String) : NeoComponent { abstract class ConfigFileBasedComponent<out T : ConfigFileBasedObject>(protected val baseDir: String) : NeoComponent {
companion object { companion object {
private val TAG = ConfigFileBasedComponent::class.java.simpleName private val TAG = ConfigFileBasedComponent::class.java.simpleName
val NEOLANG_FILTER = FileFilter {
it.extension == "nl"
}
} }
open val checkComponentFileWhenObtained = false open val checkComponentFileWhenObtained = false