Profile: Generify NeoProfile

This commit is contained in:
zt515 2017-12-12 23:51:23 +08:00
parent d8c6ff82e3
commit 8f493d907f
4 changed files with 23 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import io.neoterm.component.script.UserScriptComponent
import io.neoterm.component.session.SessionComponent
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.component.ComponentManager
import io.neoterm.frontend.session.shell.ShellProfile
/**
* @author kiva
@ -30,5 +31,8 @@ object NeoInitializer {
ComponentManager.registerComponent(PackageComponent::class.java)
ComponentManager.registerComponent(SessionComponent::class.java)
ComponentManager.registerComponent(ProfileComponent::class.java)
val profileComp = ComponentManager.getComponent<ProfileComponent>()
profileComp.registerProfile(ShellProfile.PROFILE_META_NAME, ShellProfile::class.java)
}
}

View File

@ -3,4 +3,6 @@ package io.neoterm.component.profile
/**
* @author kiva
*/
abstract class NeoProfile
abstract class NeoProfile {
abstract val profileMetaName: String
}

View File

@ -9,7 +9,16 @@ import java.io.File
* @author kiva
*/
class ProfileComponent : NeoComponent {
private val profileList = mutableListOf<ShellProfile>()
private val profileRegistry = mutableMapOf<String, Class<out NeoProfile>>()
private val profileList = mutableListOf<NeoProfile>()
fun registerProfile(metaName: String, prototype: Class<out NeoProfile>) {
profileRegistry[metaName] = prototype
}
fun unregisterProfile(metaName: String) {
profileRegistry.remove(metaName)
}
private fun checkForFiles() {
val profileDir = File(NeoTermPath.PROFILE_PATH)

View File

@ -11,6 +11,12 @@ import io.neoterm.frontend.config.NeoPreference
* @author kiva
*/
class ShellProfile : NeoProfile() {
companion object {
const val PROFILE_META_NAME = "profile-shell"
}
override val profileMetaName = PROFILE_META_NAME
var loginShell = DefaultValues.loginShell
var initialCommand = DefaultValues.initialCommand