Added tabs management keybindings
This commit is contained in:
parent
1b4b75d75b
commit
4423e47019
@ -12,6 +12,7 @@ import androidx.compose.runtime.*
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.Density
|
import androidx.compose.ui.unit.Density
|
||||||
@ -25,6 +26,8 @@ import com.jetpackduba.gitnuro.di.DaggerAppComponent
|
|||||||
import com.jetpackduba.gitnuro.extensions.preferenceValue
|
import com.jetpackduba.gitnuro.extensions.preferenceValue
|
||||||
import com.jetpackduba.gitnuro.extensions.toWindowPlacement
|
import com.jetpackduba.gitnuro.extensions.toWindowPlacement
|
||||||
import com.jetpackduba.gitnuro.git.AppGpgSigner
|
import com.jetpackduba.gitnuro.git.AppGpgSigner
|
||||||
|
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
||||||
|
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
||||||
import com.jetpackduba.gitnuro.logging.printError
|
import com.jetpackduba.gitnuro.logging.printError
|
||||||
import com.jetpackduba.gitnuro.managers.AppStateManager
|
import com.jetpackduba.gitnuro.managers.AppStateManager
|
||||||
import com.jetpackduba.gitnuro.managers.TempFilesManager
|
import com.jetpackduba.gitnuro.managers.TempFilesManager
|
||||||
@ -271,7 +274,38 @@ class App {
|
|||||||
|
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.background(MaterialTheme.colors.background)
|
modifier = Modifier
|
||||||
|
.background(MaterialTheme.colors.background)
|
||||||
|
.onPreviewKeyEvent {
|
||||||
|
when {
|
||||||
|
it.matchesBinding(KeybindingOption.OPEN_NEW_TAB) -> {
|
||||||
|
tabsManager.addNewEmptyTab()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
it.matchesBinding(KeybindingOption.CLOSE_CURRENT_TAB) -> {
|
||||||
|
tabsManager.closeTab(currentTab)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
it.matchesBinding(KeybindingOption.CHANGE_CURRENT_TAB_LEFT) -> {
|
||||||
|
val tabToSelect = tabs.getOrNull(tabs.indexOf(currentTab) - 1)
|
||||||
|
if (tabToSelect != null) {
|
||||||
|
tabsManager.selectTab(tabToSelect)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
it.matchesBinding(KeybindingOption.CHANGE_CURRENT_TAB_RIGHT) -> {
|
||||||
|
val tabToSelect = tabs.getOrNull(tabs.indexOf(currentTab) + 1)
|
||||||
|
if (tabToSelect != null) {
|
||||||
|
tabsManager.selectTab(tabToSelect)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
Tabs(
|
Tabs(
|
||||||
tabsInformationList = tabs,
|
tabsInformationList = tabs,
|
||||||
|
@ -72,6 +72,26 @@ enum class KeybindingOption {
|
|||||||
* Used to pop stash changes to workspace
|
* Used to pop stash changes to workspace
|
||||||
*/
|
*/
|
||||||
OPEN_ANOTHER_REPOSITORY,
|
OPEN_ANOTHER_REPOSITORY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to open a new tab
|
||||||
|
*/
|
||||||
|
OPEN_NEW_TAB,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to close current tab
|
||||||
|
*/
|
||||||
|
CLOSE_CURRENT_TAB,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to change current tab to the one in the left
|
||||||
|
*/
|
||||||
|
CHANGE_CURRENT_TAB_LEFT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to change current tab to the one in the right
|
||||||
|
*/
|
||||||
|
CHANGE_CURRENT_TAB_RIGHT,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,6 +134,18 @@ private fun baseKeybindings() = mapOf(
|
|||||||
KeybindingOption.OPEN_ANOTHER_REPOSITORY to listOf(
|
KeybindingOption.OPEN_ANOTHER_REPOSITORY to listOf(
|
||||||
Keybinding(key = Key.O, control = true),
|
Keybinding(key = Key.O, control = true),
|
||||||
),
|
),
|
||||||
|
KeybindingOption.OPEN_NEW_TAB to listOf(
|
||||||
|
Keybinding(key = Key.T, control = true),
|
||||||
|
),
|
||||||
|
KeybindingOption.CLOSE_CURRENT_TAB to listOf(
|
||||||
|
Keybinding(key = Key.W, control = true),
|
||||||
|
),
|
||||||
|
KeybindingOption.CHANGE_CURRENT_TAB_LEFT to listOf(
|
||||||
|
Keybinding(key = Key.DirectionLeft, alt = true),
|
||||||
|
),
|
||||||
|
KeybindingOption.CHANGE_CURRENT_TAB_RIGHT to listOf(
|
||||||
|
Keybinding(key = Key.DirectionRight, alt = true),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun linuxKeybindings(): Map<KeybindingOption, List<Keybinding>> = baseKeybindings()
|
private fun linuxKeybindings(): Map<KeybindingOption, List<Keybinding>> = baseKeybindings()
|
||||||
|
@ -22,6 +22,7 @@ import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
|||||||
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
||||||
import com.jetpackduba.gitnuro.models.AuthorInfoSimple
|
import com.jetpackduba.gitnuro.models.AuthorInfoSimple
|
||||||
import com.jetpackduba.gitnuro.ui.components.SecondaryButton
|
import com.jetpackduba.gitnuro.ui.components.SecondaryButton
|
||||||
|
import com.jetpackduba.gitnuro.ui.components.TabInformation
|
||||||
import com.jetpackduba.gitnuro.ui.components.TripleVerticalSplitPanel
|
import com.jetpackduba.gitnuro.ui.components.TripleVerticalSplitPanel
|
||||||
import com.jetpackduba.gitnuro.ui.dialogs.*
|
import com.jetpackduba.gitnuro.ui.dialogs.*
|
||||||
import com.jetpackduba.gitnuro.ui.diff.Diff
|
import com.jetpackduba.gitnuro.ui.diff.Diff
|
||||||
|
@ -25,7 +25,9 @@ import androidx.compose.ui.focus.onFocusChanged
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.input.key.*
|
import androidx.compose.ui.input.key.KeyEventType
|
||||||
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
|
import androidx.compose.ui.input.key.type
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
@ -119,10 +121,12 @@ fun WelcomeView(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
var showAdditionalInfo by remember { mutableStateOf(false) }
|
var showAdditionalInfo by remember { mutableStateOf(false) }
|
||||||
|
val searchFocusRequester = remember { FocusRequester() }
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
.focusable(true)
|
||||||
.background(MaterialTheme.colors.surface),
|
.background(MaterialTheme.colors.surface),
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -156,6 +160,7 @@ fun WelcomeView(
|
|||||||
canRepositoriesBeRemoved = true,
|
canRepositoriesBeRemoved = true,
|
||||||
onOpenKnownRepository = onOpenKnownRepository,
|
onOpenKnownRepository = onOpenKnownRepository,
|
||||||
onRemoveRepositoryFromRecent = onRemoveRepositoryFromRecent,
|
onRemoveRepositoryFromRecent = onRemoveRepositoryFromRecent,
|
||||||
|
searchFieldFocusRequester = searchFocusRequester,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,6 +178,10 @@ fun WelcomeView(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
searchFocusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
|
||||||
if (showAdditionalInfo) {
|
if (showAdditionalInfo) {
|
||||||
AppInfoDialog(
|
AppInfoDialog(
|
||||||
onClose = { showAdditionalInfo = false },
|
onClose = { showAdditionalInfo = false },
|
||||||
@ -287,6 +296,7 @@ fun RecentRepositories(
|
|||||||
canRepositoriesBeRemoved: Boolean,
|
canRepositoriesBeRemoved: Boolean,
|
||||||
onRemoveRepositoryFromRecent: (String) -> Unit,
|
onRemoveRepositoryFromRecent: (String) -> Unit,
|
||||||
onOpenKnownRepository: (String) -> Unit,
|
onOpenKnownRepository: (String) -> Unit,
|
||||||
|
searchFieldFocusRequester: FocusRequester,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -307,6 +317,7 @@ fun RecentRepositories(
|
|||||||
canRepositoriesBeRemoved = canRepositoriesBeRemoved,
|
canRepositoriesBeRemoved = canRepositoriesBeRemoved,
|
||||||
onRemoveRepositoryFromRecent = onRemoveRepositoryFromRecent,
|
onRemoveRepositoryFromRecent = onRemoveRepositoryFromRecent,
|
||||||
onOpenKnownRepository = onOpenKnownRepository,
|
onOpenKnownRepository = onOpenKnownRepository,
|
||||||
|
searchFieldFocusRequester = searchFieldFocusRequester,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,7 +327,7 @@ fun RecentRepositories(
|
|||||||
fun RecentRepositoriesList(
|
fun RecentRepositoriesList(
|
||||||
recentlyOpenedRepositories: List<String>,
|
recentlyOpenedRepositories: List<String>,
|
||||||
canRepositoriesBeRemoved: Boolean,
|
canRepositoriesBeRemoved: Boolean,
|
||||||
searchFieldFocusRequester: FocusRequester = remember { FocusRequester() },
|
searchFieldFocusRequester: FocusRequester,
|
||||||
onRemoveRepositoryFromRecent: (String) -> Unit,
|
onRemoveRepositoryFromRecent: (String) -> Unit,
|
||||||
onOpenKnownRepository: (String) -> Unit,
|
onOpenKnownRepository: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
@ -21,7 +21,6 @@ import androidx.compose.ui.draw.alpha
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.Dp
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.jetpackduba.gitnuro.AppIcons
|
import com.jetpackduba.gitnuro.AppIcons
|
||||||
import com.jetpackduba.gitnuro.di.AppComponent
|
import com.jetpackduba.gitnuro.di.AppComponent
|
||||||
|
Loading…
Reference in New Issue
Block a user