Skip to content

Commit

Permalink
Big refactoring: extracted model and ui component code from Update.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashev committed Oct 14, 2024
1 parent 0629748 commit 11200c8
Show file tree
Hide file tree
Showing 16 changed files with 877 additions and 458 deletions.
2 changes: 1 addition & 1 deletion biz.ganttproject.app.localization
15 changes: 14 additions & 1 deletion ganttproject/src/main/java/biz/ganttproject/FXUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import javafx.scene.control.Button
import javafx.scene.control.ContentDisplay
import javafx.scene.control.Labeled
import javafx.scene.control.ScrollPane
import javafx.scene.control.TitledPane
import javafx.scene.layout.BorderPane
import javafx.scene.paint.Color
import javafx.stage.Window
import javafx.util.Duration
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -76,6 +78,12 @@ object FXUtil {
}
}

fun launchFx(code: suspend ()->Unit) {
GlobalScope.launch(Dispatchers.JavaFx) {
code()
}
}

fun startup(code: () -> Unit) {
val javafxOk = isJavaFxAvailable ?: run {
try {
Expand Down Expand Up @@ -274,7 +282,7 @@ object FXUtil {

fun Node.printCss() {
println("class=${styleClass} pseudoclass=${pseudoClassStates} scene=${this.scene}")
parent?.printCss()
//parent?.printCss()
}

fun Parent.walkTree(code: (Node)->Unit) {
Expand All @@ -286,6 +294,11 @@ fun Parent.walkTree(code: (Node)->Unit) {
it.walkTree(code)
}
}
it is TitledPane -> it.content.let {
if (it is Parent) {
it.walkTree(code)
}
}
it is Parent -> it.walkTree(code)
else -> code(this)
}
Expand Down
3 changes: 2 additions & 1 deletion ganttproject/src/main/java/biz/ganttproject/app/Dialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ class DialogControllerPane(private val root: BorderPane) : DialogController {
}

override fun resize() {

this.buttonBar.layout()
this.root.layout()
}

override fun setEscCloseEnabled(value: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class PropertySheetBuilder(private val localizer: Localizer) {
if (item.label != null) {
val label = createLabel(item)
gridPane.add(label, 0, idx)
GridPane.setHgrow(label, Priority.SOMETIMES)
GridPane.setHgrow(label, Priority.NEVER)
GridPane.setHalignment(label, HPos.RIGHT)
item.editor.also {editor ->
if (editor is Region) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2024 BarD Software s.r.o., Dmitry Barashev.
*
* This file is part of GanttProject, an opensource project management tool.
*
* GanttProject 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.
*
* GanttProject is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GanttProject. If not, see <http://www.gnu.org/licenses/>.
*/
package biz.ganttproject.platform

import biz.ganttproject.app.RootLocalizer
import biz.ganttproject.lib.fx.vbox
import biz.ganttproject.walkTree
import com.bardsoftware.eclipsito.update.UpdateMetadata
import com.sandec.mdfx.MarkdownView
import javafx.event.EventHandler
import javafx.scene.Parent
import javafx.scene.control.Button
import javafx.scene.control.Label

/**
* User interface for the major update record.
*/
internal class MajorUpdateUi(update: UpdateMetadata) {
val title = Label(ourLocalizer.formatText("majorUpdate.title", update.version)).apply {
styleClass.add("title")
}
val subtitle = Label(ourLocalizer.formatText("majorUpdate.subtitle", update.version)).apply {
styleClass.setAll("subtitle")
}
val text: MarkdownView = MarkdownView().also { l ->
l.stylesheets.add("/biz/ganttproject/app/mdfx.css")
l.styleClass.add("par")
l.mdString = ourLocalizer.formatText("majorUpdate.description", update.description)
// l.children.forEach {
// if (it is Parent) {
// it.walkTree { println(it.styleClass) }
// }
// }
}
// val btnMinorUpdates = Button(ourLocalizer.formatText("majorUpdate.showBugfixUpdates")).also {
// it.styleClass.addAll("btn", "btn-attention", "secondary")
// it.onAction = EventHandler {
// this.onShowMinorUpdates()
// }
// }
val component = vbox {
addClasses("major-update")
addStylesheets("/biz/ganttproject/platform/Update.css")
add(title)
add(subtitle)
add(text)
// if (hasMinorUpdates) {
// add(Label("Minor updates are also available"))
// add(btnMinorUpdates)
// }
}
}
private val ourLocalizer = RootLocalizer.createWithRootKey("platform.update", baseLocalizer = RootLocalizer)
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class PlatformOptionPageProvider : OptionPageProviderBase("platform") {
if (ex != null) {
updatesFetchErrorDialog(ex, dialogBuildApi)
} else {
updatesAvailableDialog(filteredUpdates, filteredUpdates, { uiFacade.quitApplication(false) }, dialogBuildApi)
val updateModel = UpdateDialogModel(filteredUpdates, filteredUpdates, restarter = { uiFacade.quitApplication(false) })
updatesAvailableDialog(updateModel, dialogBuildApi)
}
return Scene(group)
}
Expand Down
Loading

0 comments on commit 11200c8

Please sign in to comment.