mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-13 20:02:57 +08:00
Closable tab and export logs
This commit is contained in:
parent
4b17c58de0
commit
c196e36f9b
@ -6,6 +6,7 @@ import javafx.scene.control.Tab
|
||||
import javafx.scene.control.TabPane
|
||||
import javafx.scene.image.Image
|
||||
import javafx.scene.input.KeyCode
|
||||
import javafx.stage.FileChooser
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||
import net.mamoe.mirai.console.graphical.model.BotModel
|
||||
@ -16,7 +17,7 @@ import tornadofx.*
|
||||
class PrimaryView : View() {
|
||||
|
||||
private val controller = find<MiraiGraphicalUIController>()
|
||||
private lateinit var mainTabPane : TabPane
|
||||
private lateinit var mainTabPane: TabPane
|
||||
|
||||
override val root = borderpane {
|
||||
|
||||
@ -72,7 +73,7 @@ class PrimaryView : View() {
|
||||
|
||||
center = jfxTabPane {
|
||||
|
||||
logTab("Main", controller.mainLog)
|
||||
logTab("Main", controller.mainLog, closeable = false)
|
||||
|
||||
tab("Plugins").content = find<PluginsView>().root
|
||||
|
||||
@ -93,13 +94,35 @@ class PrimaryView : View() {
|
||||
private fun TabPane.logTab(
|
||||
text: String? = null,
|
||||
logs: ObservableList<String>,
|
||||
closeable: Boolean = true,
|
||||
op: Tab.() -> Unit = {}
|
||||
) = tab(text) {
|
||||
|
||||
vbox {
|
||||
buttonbar {
|
||||
button("导出日志").action { }
|
||||
button("关闭").action { close() }
|
||||
|
||||
button("导出日志").action {
|
||||
val path = chooseFile(
|
||||
"选择保存路径",
|
||||
arrayOf(FileChooser.ExtensionFilter("日志", "txt")),
|
||||
FileChooserMode.Save
|
||||
) {
|
||||
initialFileName = "$text.txt"
|
||||
}
|
||||
runAsyncWithOverlay {
|
||||
path.firstOrNull()?.run {
|
||||
if (!exists()) createNewFile()
|
||||
writer().use {
|
||||
logs.forEach { log -> it.appendln(log) }
|
||||
}
|
||||
true
|
||||
} ?: false
|
||||
}.ui {// isSucceed: Boolean ->
|
||||
// notify something
|
||||
}
|
||||
|
||||
if (closeable) button("关闭").action { close() }
|
||||
}
|
||||
}
|
||||
|
||||
listview(logs) {
|
||||
|
Loading…
Reference in New Issue
Block a user