mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 14:52:03 +01:00
Add ability to set hotkeys to window dialogs
This commit is contained in:
@@ -23,6 +23,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.key.Key
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.KeysSet
|
||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.IntSize
|
import androidx.compose.ui.unit.IntSize
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -40,6 +41,7 @@ fun WindowDialog(
|
|||||||
onNegativeButton: (() -> Unit)? = null,
|
onNegativeButton: (() -> Unit)? = null,
|
||||||
positiveButtonText: String = "OK",
|
positiveButtonText: String = "OK",
|
||||||
onPositiveButton: (() -> Unit)? = null,
|
onPositiveButton: (() -> Unit)? = null,
|
||||||
|
keyboardShortcuts: List<KeyboardShortcut> = emptyList(),
|
||||||
row: @Composable (RowScope.() -> Unit)
|
row: @Composable (RowScope.() -> Unit)
|
||||||
) = SwingUtilities.invokeLater {
|
) = SwingUtilities.invokeLater {
|
||||||
val window = AppWindow(
|
val window = AppWindow(
|
||||||
@@ -68,6 +70,10 @@ fun WindowDialog(
|
|||||||
window.keyboard.setShortcut(Key.Enter, onPositiveButton.plusClose())
|
window.keyboard.setShortcut(Key.Enter, onPositiveButton.plusClose())
|
||||||
window.keyboard.setShortcut(Key.Escape, onNegativeButton.plusClose())
|
window.keyboard.setShortcut(Key.Escape, onNegativeButton.plusClose())
|
||||||
|
|
||||||
|
keyboardShortcuts.forEach {
|
||||||
|
window.keyboard.setShortcut(it.key) { it.shortcut(window) }
|
||||||
|
}
|
||||||
|
|
||||||
window.show {
|
window.show {
|
||||||
AppTheme {
|
AppTheme {
|
||||||
Surface {
|
Surface {
|
||||||
@@ -95,6 +101,7 @@ fun WindowDialog(
|
|||||||
size: IntSize = IntSize(400, 200),
|
size: IntSize = IntSize(400, 200),
|
||||||
onDismissRequest: (() -> Unit)? = null,
|
onDismissRequest: (() -> Unit)? = null,
|
||||||
forceFocus: Boolean = true,
|
forceFocus: Boolean = true,
|
||||||
|
keyboardShortcuts: List<KeyboardShortcut> = emptyList(),
|
||||||
buttons: @Composable (AppWindow) -> Unit,
|
buttons: @Composable (AppWindow) -> Unit,
|
||||||
content: @Composable (AppWindow) -> Unit
|
content: @Composable (AppWindow) -> Unit
|
||||||
) = SwingUtilities.invokeLater {
|
) = SwingUtilities.invokeLater {
|
||||||
@@ -116,6 +123,10 @@ fun WindowDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyboardShortcuts.forEach {
|
||||||
|
window.keyboard.setShortcut(it.key) { it.shortcut(window) }
|
||||||
|
}
|
||||||
|
|
||||||
window.show {
|
window.show {
|
||||||
AppTheme {
|
AppTheme {
|
||||||
Surface {
|
Surface {
|
||||||
@@ -129,3 +140,8 @@ fun WindowDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class KeyboardShortcut(val key: KeysSet, val shortcut: (AppWindow) -> Unit) {
|
||||||
|
constructor(key: Key, shortcut: (AppWindow) -> Unit) :
|
||||||
|
this(KeysSet(key), shortcut)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user