mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 12:25:12 -04:00
desktop util: open files in system editor
This commit is contained in:
parent
7145de8229
commit
fd4e55e552
@ -17,6 +17,7 @@ import com.sun.javafx.util.WeakReferenceQueue
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.reflection.ReflectionUtil.setValue
|
||||
import de.bixilon.kutil.url.URLUtil.toURL
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.profile.delegate.watcher.SimpleProfileDelegateWatcher.Companion.profileWatchFX
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
@ -24,6 +25,7 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.eros.controller.EmbeddedJavaFXController
|
||||
import de.bixilon.minosoft.gui.eros.controller.JavaFXController
|
||||
import de.bixilon.minosoft.gui.eros.controller.JavaFXWindowController
|
||||
import de.bixilon.minosoft.util.DesktopUtil
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import javafx.application.HostServices
|
||||
import javafx.application.Platform
|
||||
@ -39,8 +41,6 @@ import javafx.scene.text.Text
|
||||
import javafx.scene.text.TextFlow
|
||||
import javafx.stage.Modality
|
||||
import javafx.stage.Stage
|
||||
import java.net.CookieHandler
|
||||
import java.net.CookieManager
|
||||
import kotlin.reflect.jvm.javaField
|
||||
|
||||
object JavaFXUtil {
|
||||
@ -161,14 +161,15 @@ object JavaFXUtil {
|
||||
}
|
||||
|
||||
fun Text.hyperlink(link: String) {
|
||||
this.setOnMouseClicked { HOST_SERVICES.showDocument(link) }
|
||||
val url = link.toURL()
|
||||
this.setOnMouseClicked { DefaultThreadPool += { DesktopUtil.openURL(url) } }
|
||||
this.accessibleRole = AccessibleRole.HYPERLINK
|
||||
this.styleClass.setAll("hyperlink")
|
||||
this.clickable()
|
||||
}
|
||||
|
||||
fun Text.file(path: String) {
|
||||
// ToDo: Open in file browser/default program
|
||||
this.setOnMouseClicked { DefaultThreadPool += { DesktopUtil.openFile(path) } }
|
||||
this.accessibleRole = AccessibleRole.HYPERLINK
|
||||
this.styleClass.setAll("hyperlink")
|
||||
this.clickable()
|
||||
@ -179,14 +180,6 @@ object JavaFXUtil {
|
||||
this.cursorProperty().unsafeCast<StyleableProperty<Cursor>>().applyStyle(null, Cursor.HAND)
|
||||
}
|
||||
|
||||
fun resetWebView() {
|
||||
// ToDo
|
||||
CookieManager().apply {
|
||||
CookieHandler.setDefault(this)
|
||||
this.cookieStore.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
fun runLater(runnable: Runnable) {
|
||||
if (Thread.currentThread() === JAVA_FX_THREAD) {
|
||||
runnable.run()
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2022 Moritz Zwerger
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
@ -18,13 +18,14 @@ import de.bixilon.minosoft.terminal.RunConfiguration
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
||||
object DesktopUtil {
|
||||
|
||||
fun openURL(url: URL) {
|
||||
if (RunConfiguration.DISABLE_EROS) {
|
||||
Log.log(LogMessageType.GENERAL, LogLevels.INFO) { "Can not open url: $url" }
|
||||
Log.log(LogMessageType.GENERAL, LogLevels.WARN) { "Can not open url: $url: Eros is disabled!" }
|
||||
return
|
||||
}
|
||||
try {
|
||||
@ -35,6 +36,22 @@ object DesktopUtil {
|
||||
}
|
||||
|
||||
fun openFile(path: String) {
|
||||
println("ToDo: Can not open file: $path")
|
||||
val file = File(path)
|
||||
if (!file.exists()) {
|
||||
Log.log(LogMessageType.GENERAL, LogLevels.WARN) { "Can not open file $file: File does not exist!" }
|
||||
return
|
||||
}
|
||||
|
||||
if (RunConfiguration.DISABLE_EROS) {
|
||||
Log.log(LogMessageType.GENERAL, LogLevels.INFO) { "Can not open file: $file: Eros is disabled!" }
|
||||
return
|
||||
}
|
||||
// Desktop.getDesktop().open(File(path))
|
||||
|
||||
try {
|
||||
JavaFXUtil.HOST_SERVICES.showDocument(File(path).absolutePath)
|
||||
} catch (exception: Throwable) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user