saalfeldlab / paintera

GNU General Public License v2.0
100 stars 17 forks source link

Make project directory mutable #304

Closed hanslovsky closed 5 years ago

hanslovsky commented 5 years ago

This is WIP with multiple targets:

This will most likely be merged only after #267

Fixes #190 Fixes #245 Fixes #256

hanslovsky commented 5 years ago

I checked the side bar and all the preference nodes seem to be present after refactoring.

hanslovsky commented 5 years ago

As far as I can tell, all key bindings that do not include any mouse event handling are now converted into KeyCombination style matching and are documented in the F1 help window in the UI.

This is pretty much ready for merge but the mouse event handling needs some work, which should happen in a separate PR once this is merged.

hanslovsky commented 5 years ago

I think I found a way to ship the readme with Paintera:

  1. convert README.md to src/main/resources/README.html, e.g. with pandoc
  2. ln -s $(realpath img) src/main/resources (relative link is better but you get the idea, can even be done permanently on GH)
  3. Inside Paintera, do something like this:
import javafx.application.Application
import javafx.scene.Scene
import javafx.scene.web.WebView
import javafx.stage.Stage

class WebViewIssue : Application() {
    override fun start(primaryStage: Stage) {
        val url = javaClass.getResource("README.html")
        val wv = WebView().also { it.engine.load(url.toString()) }
        primaryStage.scene = Scene(wv)
        primaryStage.show()
    }
}

fun main() = Application.launch(WebViewIssue::class.java)
hanslovsky commented 5 years ago

Relevant for the rendering of resources: https://community.oracle.com/thread/2332194

hanslovsky commented 5 years ago

README Rendering works now if classes are loaded from .class files, i.e. when run from Intellij IDE but images are not rendered when run from .jar file. This might be good enough for now but should be investigated further. I will test on my other machine and then probably merge soon.

hanslovsky commented 5 years ago

FWIW, this is how I render the README.md from md into html at runtime:

val vs = Version.VERSION_STRING
val tag = if (vs.endsWith("SNAPSHOT"))
    "master"
else
    "^.*-SNAPSHOT-([A-Za-z0-9]+)$"
            .toRegex()
            .find(vs)
            ?.let { it.groupValues[1] }
            ?: "paintera-$vs"
val ghurl = "https://github.com/saalfeldlab/paintera/blob/$tag/README.md"
val jarPath = javaClass.protectionDomain.codeSource.location.let { URLDecoder.decode(it.file, "UTF-8") }
// TODO what is the correct prefix when loading from jar?
val prefix = if (jarPath.endsWith(".jar")) "jar:file:$jarPath!" else "file://$jarPath"
val extensions = listOf(TablesExtension.create())
val parser = Parser.builder().extensions(extensions).build()
val renderer = HtmlRenderer.builder().extensions(extensions).build()
val document = javaClass.getResource("/README.md").openStream().use { parser.parseReader(it.reader()) }
val readmeHtml = renderer.render(document).replace("img src=\"img", "img src=\"${prefix}/img")
val dialog = PainteraAlerts.information("_Close", true).also { it.initModality(Modality.NONE) }
val wv = WebView()
        .also { it.engine.loadContent(readmeHtml) }
        .also { it.maxHeight = Double.POSITIVE_INFINITY }
hanslovsky commented 5 years ago

I will go ahead and merge. I will work with @igorpisarev to fix any merge issues with #267 once that PR is ready to merge. I will add a new paintera-experimental command to saalfeldlab/paintera-cmd