You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
4 years ago
|
import androidx.compose.runtime.Composable
|
||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||
|
import androidx.compose.ui.window.MenuScope
|
||
|
import androidx.compose.ui.window.Tray
|
||
|
import common.LocalAppResources
|
||
|
import kotlinx.coroutines.launch
|
||
|
import window.NotepadWindow
|
||
|
|
||
|
@Composable
|
||
|
fun NotepadApplication(state: NotepadApplicationState) {
|
||
|
if (state.settings.isTrayEnabled && state.windows.isNotEmpty()) {
|
||
|
ApplicationTray(state)
|
||
|
}
|
||
|
|
||
|
for (window in state.windows) {
|
||
|
NotepadWindow(window)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@OptIn(ExperimentalComposeUiApi::class)
|
||
|
@Composable
|
||
|
private fun ApplicationTray(state: NotepadApplicationState) {
|
||
|
Tray(
|
||
|
LocalAppResources.current.icon ?: return,
|
||
|
state = state.tray,
|
||
|
hint = "Notepad",
|
||
|
menu = { ApplicationMenu(state) }
|
||
|
)
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
|
private fun MenuScope.ApplicationMenu(state: NotepadApplicationState) {
|
||
|
val scope = rememberCoroutineScope()
|
||
|
fun exit() = scope.launch { state.exit() }
|
||
|
|
||
|
Item("New", onClick = state::newWindow)
|
||
|
Separator()
|
||
|
Item("Exit", onClick = { exit() })
|
||
|
}
|