parent
4469c208f7
commit
38481b3a34
@ -32,6 +32,7 @@ private const val PREF_UI_SCALE = "ui_scale"
|
||||
private const val PREF_DIFF_TYPE = "diffType"
|
||||
private const val PREF_DIFF_FULL_FILE = "diffFullFile"
|
||||
private const val PREF_SWAP_UNCOMMITED_CHANGES = "inverseUncommitedChanges"
|
||||
private const val PREF_TERMINAL_PATH = "terminalPath"
|
||||
|
||||
|
||||
private const val PREF_GIT_FF_MERGE = "gitFFMerge"
|
||||
@ -76,6 +77,9 @@ class AppSettings @Inject constructor() {
|
||||
private val _textDiffFullFileFlow = MutableStateFlow(diffDisplayFullFile)
|
||||
val diffDisplayFullFileFlow = _textDiffFullFileFlow.asStateFlow()
|
||||
|
||||
private val _terminalPathFlow = MutableStateFlow(terminalPath)
|
||||
val terminalPathFlow = _terminalPathFlow.asStateFlow()
|
||||
|
||||
var latestTabsOpened: String
|
||||
get() = preferences.get(PREF_LATEST_REPOSITORIES_TABS_OPENED, "")
|
||||
set(value) {
|
||||
@ -202,6 +206,14 @@ class AppSettings @Inject constructor() {
|
||||
_textDiffFullFileFlow.value = newValue
|
||||
}
|
||||
|
||||
var terminalPath: String
|
||||
get() = preferences.get(PREF_TERMINAL_PATH, "")
|
||||
set(value) {
|
||||
preferences.put(PREF_TERMINAL_PATH, value)
|
||||
|
||||
_terminalPathFlow.value = value
|
||||
}
|
||||
|
||||
fun saveCustomTheme(filePath: String) {
|
||||
val file = File(filePath)
|
||||
val content = file.readText()
|
||||
@ -222,10 +234,10 @@ class AppSettings @Inject constructor() {
|
||||
|
||||
// TODO migrate old prefs path to new one?
|
||||
fun initPreferencesPath() {
|
||||
if(getCurrentOs() == OS.LINUX) {
|
||||
if (getCurrentOs() == OS.LINUX) {
|
||||
val xdgConfigHome: String? = System.getenv("XDG_CONFIG_HOME")
|
||||
|
||||
val settingsPath = if(xdgConfigHome.isNullOrBlank()) {
|
||||
val settingsPath = if (xdgConfigHome.isNullOrBlank()) {
|
||||
val home = System.getProperty("user.home").orEmpty()
|
||||
"$home/.config/gitnuro"
|
||||
} else {
|
||||
|
@ -1,20 +1,26 @@
|
||||
package com.jetpackduba.gitnuro.terminal
|
||||
|
||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||
import javax.inject.Inject
|
||||
|
||||
// For flatpak: https://github.com/flathub/com.visualstudio.code#use-host-shell-in-the-integrated-terminal
|
||||
|
||||
class OpenRepositoryInTerminalUseCase @Inject constructor(
|
||||
private val terminalProvider: ITerminalProvider
|
||||
private val terminalProvider: ITerminalProvider,
|
||||
private val settings: AppSettings,
|
||||
) {
|
||||
operator fun invoke(path: String) {
|
||||
val terminalEmulators = terminalProvider.getTerminalEmulators()
|
||||
|
||||
for (terminal in terminalEmulators) {
|
||||
val isTerminalEmulatorInstalled = terminalProvider.isTerminalInstalled(terminal)
|
||||
if (isTerminalEmulatorInstalled) {
|
||||
terminalProvider.startTerminal(terminal, path)
|
||||
break
|
||||
if (settings.terminalPath.isNotEmpty()) {
|
||||
terminalProvider.startTerminal(TerminalEmulator("CUSTOM_TERMINAL", settings.terminalPath), path)
|
||||
} else {
|
||||
for (terminal in terminalEmulators) {
|
||||
val isTerminalEmulatorInstalled = terminalProvider.isTerminalInstalled(terminal)
|
||||
if (isTerminalEmulatorInstalled) {
|
||||
terminalProvider.startTerminal(terminal, path)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,8 +50,10 @@ val settings = listOf(
|
||||
|
||||
SettingsEntry.Section("Network"),
|
||||
SettingsEntry.Entry(AppIcons.NETWORK, "Proxy") { },
|
||||
)
|
||||
|
||||
SettingsEntry.Section("Tools"),
|
||||
SettingsEntry.Entry(AppIcons.TERMINAL, "Terminal") { Terminal(it) },
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun SettingsDialog(
|
||||
@ -229,6 +231,23 @@ private fun RemoteActions(settingsViewModel: SettingsViewModel) {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Terminal(settingsViewModel: SettingsViewModel) {
|
||||
var commitsLimit by remember { mutableStateOf(settingsViewModel.terminalPath) }
|
||||
|
||||
SettingTextInput(
|
||||
title = "Custom terminal path",
|
||||
subtitle = "If empty, Gitnuro will try to open the default terminal emulator",
|
||||
value = commitsLimit,
|
||||
onValueChanged = { value ->
|
||||
commitsLimit = value
|
||||
settingsViewModel.terminalPath = value
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun Branches(settingsViewModel: SettingsViewModel) {
|
||||
val ffMerge by settingsViewModel.ffMergeFlow.collectAsState()
|
||||
@ -505,6 +524,41 @@ fun SettingIntInput(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingTextInput(
|
||||
title: String,
|
||||
subtitle: String,
|
||||
value: String,
|
||||
enabled: Boolean = true,
|
||||
onValueChanged: (String) -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
FieldTitles(title, subtitle)
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
var text by remember {
|
||||
mutableStateOf(value)
|
||||
}
|
||||
|
||||
AdjustableOutlinedTextField(
|
||||
value = text,
|
||||
modifier = Modifier.width(240.dp),
|
||||
isError = false,
|
||||
enabled = enabled,
|
||||
onValueChange = {
|
||||
text = it
|
||||
onValueChanged(it)
|
||||
},
|
||||
colors = outlinedTextFieldColors(),
|
||||
singleLine = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FieldTitles(
|
||||
title: String,
|
||||
|
@ -26,6 +26,7 @@ class SettingsViewModel @Inject constructor(
|
||||
val pullRebaseFlow = appSettings.pullRebaseFlow
|
||||
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
|
||||
val swapUncommitedChangesFlow = appSettings.swapUncommitedChangesFlow
|
||||
val terminalPathFlow = appSettings.terminalPathFlow
|
||||
|
||||
var scaleUi: Float
|
||||
get() = appSettings.scaleUi
|
||||
@ -63,6 +64,12 @@ class SettingsViewModel @Inject constructor(
|
||||
appSettings.theme = value
|
||||
}
|
||||
|
||||
var terminalPath: String
|
||||
get() = appSettings.terminalPath
|
||||
set(value) {
|
||||
appSettings.terminalPath = value
|
||||
}
|
||||
|
||||
fun saveCustomTheme(filePath: String): Error? {
|
||||
return try {
|
||||
appSettings.saveCustomTheme(filePath)
|
||||
|
Loading…
Reference in New Issue
Block a user