Skip to content

Commit

Permalink
fix: do not react to shortcuts when fragment is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph5610 committed Feb 25, 2024
1 parent 2e1e672 commit 6e9538a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import online.hudacek.fxradio.ui.util.keyCombination
import online.hudacek.fxradio.ui.util.make
import online.hudacek.fxradio.ui.util.requestFocusOnSceneAvailable
import online.hudacek.fxradio.ui.util.searchField
import online.hudacek.fxradio.util.Modal
import online.hudacek.fxradio.viewmodel.LibraryState
import online.hudacek.fxradio.viewmodel.LibraryViewModel
import online.hudacek.fxradio.viewmodel.SearchViewModel
Expand Down Expand Up @@ -65,8 +66,10 @@ class LibrarySearchView : BaseView() {
}

shortcut(keyCombination(KeyCode.F)) {
requestFocusOnSceneAvailable()
setSearchState(text)
if (!Modal.isAnyFragmentOpen()) {
requestFocusOnSceneAvailable()
setSearchState(text)
}
}

validator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class PlayerView : BaseView() {
}

shortcut(keyCombination(KeyCode.I)) {
if (selectedStationViewModel.stationProperty.value.isValid()) {
isSelected = !isSelected
if (!Modal.isAnyFragmentOpen()) {
if (selectedStationViewModel.stationProperty.value.isValid()) {
isSelected = !isSelected
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/online/hudacek/fxradio/util/Modal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ sealed class Modal<out T : Fragment>(
data object Preferences : Modal<PreferencesFragment>()
data object OpenStream : Modal<OpenStreamFragment>()
data object Countries : Modal<CountriesSearchFragment>()

companion object {
/**
* Returns true if any [Fragment] is currently present in the scene
*/
fun isAnyFragmentOpen() = FX.primaryStage.scene.findUIComponents().any { it is Fragment }
}
}

/**
Expand Down

0 comments on commit 6e9538a

Please sign in to comment.