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_TYPE = "diffType"
|
||||||
private const val PREF_DIFF_FULL_FILE = "diffFullFile"
|
private const val PREF_DIFF_FULL_FILE = "diffFullFile"
|
||||||
private const val PREF_SWAP_UNCOMMITED_CHANGES = "inverseUncommitedChanges"
|
private const val PREF_SWAP_UNCOMMITED_CHANGES = "inverseUncommitedChanges"
|
||||||
|
private const val PREF_TERMINAL_PATH = "terminalPath"
|
||||||
|
|
||||||
|
|
||||||
private const val PREF_GIT_FF_MERGE = "gitFFMerge"
|
private const val PREF_GIT_FF_MERGE = "gitFFMerge"
|
||||||
@ -76,6 +77,9 @@ class AppSettings @Inject constructor() {
|
|||||||
private val _textDiffFullFileFlow = MutableStateFlow(diffDisplayFullFile)
|
private val _textDiffFullFileFlow = MutableStateFlow(diffDisplayFullFile)
|
||||||
val diffDisplayFullFileFlow = _textDiffFullFileFlow.asStateFlow()
|
val diffDisplayFullFileFlow = _textDiffFullFileFlow.asStateFlow()
|
||||||
|
|
||||||
|
private val _terminalPathFlow = MutableStateFlow(terminalPath)
|
||||||
|
val terminalPathFlow = _terminalPathFlow.asStateFlow()
|
||||||
|
|
||||||
var latestTabsOpened: String
|
var latestTabsOpened: String
|
||||||
get() = preferences.get(PREF_LATEST_REPOSITORIES_TABS_OPENED, "")
|
get() = preferences.get(PREF_LATEST_REPOSITORIES_TABS_OPENED, "")
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -202,6 +206,14 @@ class AppSettings @Inject constructor() {
|
|||||||
_textDiffFullFileFlow.value = newValue
|
_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) {
|
fun saveCustomTheme(filePath: String) {
|
||||||
val file = File(filePath)
|
val file = File(filePath)
|
||||||
val content = file.readText()
|
val content = file.readText()
|
||||||
@ -222,10 +234,10 @@ class AppSettings @Inject constructor() {
|
|||||||
|
|
||||||
// TODO migrate old prefs path to new one?
|
// TODO migrate old prefs path to new one?
|
||||||
fun initPreferencesPath() {
|
fun initPreferencesPath() {
|
||||||
if(getCurrentOs() == OS.LINUX) {
|
if (getCurrentOs() == OS.LINUX) {
|
||||||
val xdgConfigHome: String? = System.getenv("XDG_CONFIG_HOME")
|
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()
|
val home = System.getProperty("user.home").orEmpty()
|
||||||
"$home/.config/gitnuro"
|
"$home/.config/gitnuro"
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,20 +1,26 @@
|
|||||||
package com.jetpackduba.gitnuro.terminal
|
package com.jetpackduba.gitnuro.terminal
|
||||||
|
|
||||||
|
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
// For flatpak: https://github.com/flathub/com.visualstudio.code#use-host-shell-in-the-integrated-terminal
|
// For flatpak: https://github.com/flathub/com.visualstudio.code#use-host-shell-in-the-integrated-terminal
|
||||||
|
|
||||||
class OpenRepositoryInTerminalUseCase @Inject constructor(
|
class OpenRepositoryInTerminalUseCase @Inject constructor(
|
||||||
private val terminalProvider: ITerminalProvider
|
private val terminalProvider: ITerminalProvider,
|
||||||
|
private val settings: AppSettings,
|
||||||
) {
|
) {
|
||||||
operator fun invoke(path: String) {
|
operator fun invoke(path: String) {
|
||||||
val terminalEmulators = terminalProvider.getTerminalEmulators()
|
val terminalEmulators = terminalProvider.getTerminalEmulators()
|
||||||
|
|
||||||
for (terminal in terminalEmulators) {
|
if (settings.terminalPath.isNotEmpty()) {
|
||||||
val isTerminalEmulatorInstalled = terminalProvider.isTerminalInstalled(terminal)
|
terminalProvider.startTerminal(TerminalEmulator("CUSTOM_TERMINAL", settings.terminalPath), path)
|
||||||
if (isTerminalEmulatorInstalled) {
|
} else {
|
||||||
terminalProvider.startTerminal(terminal, path)
|
for (terminal in terminalEmulators) {
|
||||||
break
|
val isTerminalEmulatorInstalled = terminalProvider.isTerminalInstalled(terminal)
|
||||||
|
if (isTerminalEmulatorInstalled) {
|
||||||
|
terminalProvider.startTerminal(terminal, path)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,10 @@ val settings = listOf(
|
|||||||
|
|
||||||
SettingsEntry.Section("Network"),
|
SettingsEntry.Section("Network"),
|
||||||
SettingsEntry.Entry(AppIcons.NETWORK, "Proxy") { },
|
SettingsEntry.Entry(AppIcons.NETWORK, "Proxy") { },
|
||||||
)
|
|
||||||
|
|
||||||
|
SettingsEntry.Section("Tools"),
|
||||||
|
SettingsEntry.Entry(AppIcons.TERMINAL, "Terminal") { Terminal(it) },
|
||||||
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsDialog(
|
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
|
@Composable
|
||||||
private fun Branches(settingsViewModel: SettingsViewModel) {
|
private fun Branches(settingsViewModel: SettingsViewModel) {
|
||||||
val ffMerge by settingsViewModel.ffMergeFlow.collectAsState()
|
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
|
@Composable
|
||||||
private fun FieldTitles(
|
private fun FieldTitles(
|
||||||
title: String,
|
title: String,
|
||||||
|
@ -26,6 +26,7 @@ class SettingsViewModel @Inject constructor(
|
|||||||
val pullRebaseFlow = appSettings.pullRebaseFlow
|
val pullRebaseFlow = appSettings.pullRebaseFlow
|
||||||
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
|
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
|
||||||
val swapUncommitedChangesFlow = appSettings.swapUncommitedChangesFlow
|
val swapUncommitedChangesFlow = appSettings.swapUncommitedChangesFlow
|
||||||
|
val terminalPathFlow = appSettings.terminalPathFlow
|
||||||
|
|
||||||
var scaleUi: Float
|
var scaleUi: Float
|
||||||
get() = appSettings.scaleUi
|
get() = appSettings.scaleUi
|
||||||
@ -63,6 +64,12 @@ class SettingsViewModel @Inject constructor(
|
|||||||
appSettings.theme = value
|
appSettings.theme = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var terminalPath: String
|
||||||
|
get() = appSettings.terminalPath
|
||||||
|
set(value) {
|
||||||
|
appSettings.terminalPath = value
|
||||||
|
}
|
||||||
|
|
||||||
fun saveCustomTheme(filePath: String): Error? {
|
fun saveCustomTheme(filePath: String): Error? {
|
||||||
return try {
|
return try {
|
||||||
appSettings.saveCustomTheme(filePath)
|
appSettings.saveCustomTheme(filePath)
|
||||||
|
Loading…
Reference in New Issue
Block a user