UI: Create session with profile
This commit is contained in:
@ -27,6 +27,10 @@ class ShellProfile : NeoProfile() {
|
|||||||
private const val FONT = "font"
|
private const val FONT = "font"
|
||||||
private const val COLOR_SCHEME = "color-scheme"
|
private const val COLOR_SCHEME = "color-scheme"
|
||||||
private const val WORD_BASED_IME = "word-based-ime"
|
private const val WORD_BASED_IME = "word-based-ime"
|
||||||
|
|
||||||
|
fun create() : ShellProfile {
|
||||||
|
return ShellProfile()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val profileMetaName = PROFILE_META_NAME
|
override val profileMetaName = PROFILE_META_NAME
|
||||||
|
@ -20,9 +20,12 @@ import de.mrapp.android.tabswitcher.*
|
|||||||
import io.neoterm.App
|
import io.neoterm.App
|
||||||
import io.neoterm.R
|
import io.neoterm.R
|
||||||
import io.neoterm.backend.TerminalSession
|
import io.neoterm.backend.TerminalSession
|
||||||
|
import io.neoterm.component.profile.ProfileComponent
|
||||||
|
import io.neoterm.frontend.component.ComponentManager
|
||||||
import io.neoterm.frontend.config.NeoPermission
|
import io.neoterm.frontend.config.NeoPermission
|
||||||
import io.neoterm.frontend.config.NeoPreference
|
import io.neoterm.frontend.config.NeoPreference
|
||||||
import io.neoterm.frontend.session.shell.ShellParameter
|
import io.neoterm.frontend.session.shell.ShellParameter
|
||||||
|
import io.neoterm.frontend.session.shell.ShellProfile
|
||||||
import io.neoterm.frontend.session.shell.client.TermSessionCallback
|
import io.neoterm.frontend.session.shell.client.TermSessionCallback
|
||||||
import io.neoterm.frontend.session.shell.client.TermViewClient
|
import io.neoterm.frontend.session.shell.client.TermViewClient
|
||||||
import io.neoterm.frontend.session.shell.client.event.*
|
import io.neoterm.frontend.session.shell.client.event.*
|
||||||
@ -151,6 +154,10 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
addNewSession()
|
addNewSession()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
R.id.menu_item_new_session_with_profile -> {
|
||||||
|
showProfileDialog()
|
||||||
|
true
|
||||||
|
}
|
||||||
R.id.menu_item_new_system_session -> {
|
R.id.menu_item_new_system_session -> {
|
||||||
forceAddSystemSession()
|
forceAddSystemSession()
|
||||||
true
|
true
|
||||||
@ -370,7 +377,7 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
val lastSession = getStoredCurrentSessionOrLast()
|
val lastSession = getStoredCurrentSessionOrLast()
|
||||||
|
|
||||||
for (session in termService!!.sessions) {
|
for (session in termService!!.sessions) {
|
||||||
addNewSession(session)
|
addNewSessionFromExisting(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (session in termService!!.xSessions) {
|
for (session in termService!!.xSessions) {
|
||||||
@ -425,14 +432,55 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
this@NeoTermActivity.recreate()
|
this@NeoTermActivity.recreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewSession() {
|
private fun showProfileDialog() {
|
||||||
|
val profileComponent = ComponentManager.getComponent<ProfileComponent>()
|
||||||
|
val profiles = profileComponent.getProfiles(ShellProfile.PROFILE_META_NAME)
|
||||||
|
.filterIsInstance<ShellProfile>()
|
||||||
|
|
||||||
|
AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.new_session_with_profile)
|
||||||
|
.setItems(profiles.map { it.profileName }.toTypedArray(), { dialog, which ->
|
||||||
|
val selectedProfile = profiles[which]
|
||||||
|
addNewSessionWithProfile(selectedProfile)
|
||||||
|
})
|
||||||
|
.setPositiveButton(android.R.string.no, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addNewSession() = addNewSessionWithProfile(ShellProfile.create())
|
||||||
|
|
||||||
|
private fun addNewSession(sessionName: String?, systemShell: Boolean, animation: Animation)
|
||||||
|
= addNewSessionWithProfile(sessionName, systemShell, animation, ShellProfile.create())
|
||||||
|
|
||||||
|
private fun addNewSessionWithProfile(profile: ShellProfile) {
|
||||||
if (!tabSwitcher.isSwitcherShown) {
|
if (!tabSwitcher.isSwitcherShown) {
|
||||||
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
||||||
}
|
}
|
||||||
addNewSession(null, getSystemShellMode(), createRevealAnimation())
|
addNewSessionWithProfile(null, getSystemShellMode(),
|
||||||
|
createRevealAnimation(), profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewSession(session: TerminalSession?) {
|
private fun addNewSessionWithProfile(sessionName: String?, systemShell: Boolean,
|
||||||
|
animation: Animation, profile: ShellProfile) {
|
||||||
|
val sessionCallback = TermSessionCallback()
|
||||||
|
val viewClient = TermViewClient(this)
|
||||||
|
|
||||||
|
val parameter = ShellParameter()
|
||||||
|
.callback(sessionCallback)
|
||||||
|
.systemShell(systemShell)
|
||||||
|
.profile(profile)
|
||||||
|
val session = termService!!.createTermSession(parameter)
|
||||||
|
|
||||||
|
session.mSessionName = sessionName ?: generateSessionName("NeoTerm")
|
||||||
|
|
||||||
|
val tab = createTab(session.mSessionName) as TermTab
|
||||||
|
tab.termData.initializeSessionWith(session, sessionCallback, viewClient)
|
||||||
|
|
||||||
|
addNewTab(tab, animation)
|
||||||
|
switchToSession(tab)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addNewSessionFromExisting(session: TerminalSession?) {
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -455,24 +503,6 @@ class NeoTermActivity : AppCompatActivity(), ServiceConnection, SharedPreference
|
|||||||
switchToSession(tab)
|
switchToSession(tab)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewSession(sessionName: String?, systemShell: Boolean, animation: Animation) {
|
|
||||||
val sessionCallback = TermSessionCallback()
|
|
||||||
val viewClient = TermViewClient(this)
|
|
||||||
|
|
||||||
val parameter = ShellParameter()
|
|
||||||
.callback(sessionCallback)
|
|
||||||
.systemShell(systemShell)
|
|
||||||
val session = termService!!.createTermSession(parameter)
|
|
||||||
|
|
||||||
session.mSessionName = sessionName ?: generateSessionName("NeoTerm")
|
|
||||||
|
|
||||||
val tab = createTab(session.mSessionName) as TermTab
|
|
||||||
tab.termData.initializeSessionWith(session, sessionCallback, viewClient)
|
|
||||||
|
|
||||||
addNewTab(tab, animation)
|
|
||||||
switchToSession(tab)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addXSession() {
|
private fun addXSession() {
|
||||||
if (!tabSwitcher.isSwitcherShown) {
|
if (!tabSwitcher.isSwitcherShown) {
|
||||||
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
toggleSwitcher(showSwitcher = true, easterEgg = false)
|
||||||
|
@ -13,6 +13,11 @@
|
|||||||
android:title="@string/new_session"
|
android:title="@string/new_session"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_item_new_session_with_profile"
|
||||||
|
android:title="@string/new_session_with_profile"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_item_new_system_session"
|
android:id="@+id/menu_item_new_system_session"
|
||||||
android:title="@string/new_system_session"
|
android:title="@string/new_system_session"
|
||||||
|
@ -152,6 +152,8 @@
|
|||||||
<string name="select_new_value">选择</string>
|
<string name="select_new_value">选择</string>
|
||||||
<string name="input_new_value">输入新颜色</string>
|
<string name="input_new_value">输入新颜色</string>
|
||||||
<string name="toggle_eks">切换拓展键</string>
|
<string name="toggle_eks">切换拓展键</string>
|
||||||
|
<string name="new_x_session">新建图形会话</string>
|
||||||
|
<string name="new_session_with_profile">新建个性化会话</string>
|
||||||
|
|
||||||
<string-array name="color_item_names">
|
<string-array name="color_item_names">
|
||||||
<item>背景色</item>
|
<item>背景色</item>
|
||||||
|
@ -157,6 +157,7 @@
|
|||||||
<string name="input_new_value">Enter new color</string>
|
<string name="input_new_value">Enter new color</string>
|
||||||
<string name="toggle_eks">Toggle extra keys</string>
|
<string name="toggle_eks">Toggle extra keys</string>
|
||||||
<string name="new_x_session">New X Session</string>
|
<string name="new_x_session">New X Session</string>
|
||||||
|
<string name="new_session_with_profile">New Session With Profile</string>
|
||||||
|
|
||||||
<string name="default_source_url">http://neoterm.studio</string>
|
<string name="default_source_url">http://neoterm.studio</string>
|
||||||
<string name="lnpo_source_url">http://lnpo.top:81/neoterm</string>
|
<string name="lnpo_source_url">http://lnpo.top:81/neoterm</string>
|
||||||
|
Reference in New Issue
Block a user