Improve: extract common method

This commit is contained in:
zt515
2017-12-04 23:44:14 +08:00
parent 3251bd8a40
commit a631a24ccf
5 changed files with 24 additions and 13 deletions

View File

@ -46,7 +46,7 @@ class ConfigVisitor : IVisitorCallback {
override fun onExitContext() {
val context = currentContext
if (context != null && context.parent != null) {
if (context?.parent != null) {
this.currentContext = context.parent
}
}
@ -54,4 +54,9 @@ class ConfigVisitor : IVisitorCallback {
override fun getCurrentContext(): NeoLangContext {
return currentContext!!
}
fun getStringValue(path: Array<String>, name: String): String? {
val value = this.getAttribute(path, name)
return if (value.isValid()) value.asString() else null
}
}

View File

@ -183,12 +183,10 @@ open class NeoColorScheme : CodeGenObject {
}
private fun getMetaByVisitor(visitor: ConfigVisitor, metaName: String): String? {
val value = visitor.getAttribute(COLOR_META_PATH, metaName)
return if (value.isValid()) value.asString() else null
return visitor.getStringValue(COLOR_META_PATH, metaName)
}
private fun getColorByVisitor(visitor: ConfigVisitor, colorName: String): String? {
val value = visitor.getAttribute(COLOR_PATH, colorName)
return if (value.isValid()) value.asString() else null
return visitor.getStringValue(COLOR_PATH, colorName)
}
}

View File

@ -101,7 +101,6 @@ class NeoExtraKey {
}
private fun getMetaByVisitor(visitor: ConfigVisitor, metaName: String): String? {
val value = visitor.getAttribute(EKS_META_CONTEXT_PATH, metaName)
return if (value.isValid()) value.asString() else null
return visitor.getStringValue(EKS_META_CONTEXT_PATH, metaName)
}
}

View File

@ -55,9 +55,9 @@ class FontComponent : NeoComponent {
fun reloadFonts(): Boolean {
fonts.clear()
fonts.put("Android Monospace", NeoFont(Typeface.MONOSPACE))
fonts.put("Android Sans Serif", NeoFont(Typeface.SANS_SERIF))
fonts.put("Android Serif", NeoFont(Typeface.SERIF))
fonts.put("Monospace", NeoFont(Typeface.MONOSPACE))
fonts.put("Sans Serif", NeoFont(Typeface.SANS_SERIF))
fonts.put("Serif", NeoFont(Typeface.SERIF))
val fontDir = File(NeoTermPath.FONT_PATH)
for (file in fontDir.listFiles({ pathname -> pathname.name.endsWith(".ttf") })) {
val fontName = fontName(file)

View File

@ -0,0 +1,9 @@
package io.neoterm.component.profile
/**
* @author kiva
*/
class Profile {
lateinit var profileFont: String
lateinit var profileColorScheme: String
}