Skip to content

Commit

Permalink
Added: a button to delete the current drawing
Browse files Browse the repository at this point in the history
Added: a button to go to the DB folder where the current drawing is saved.
  • Loading branch information
fjossinet committed Oct 19, 2023
1 parent 0cb8b99 commit 90f0d7b
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 11 deletions.
101 changes: 98 additions & 3 deletions src/main/kotlin/RNArtist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class RNArtist : Application() {
val verticalSplitPane: SplitPane
val upperPanel: UpperPanel
val lowerPanel: LowerPanel
private val manageCurrent2DBar:ManageCurrentDrawing
private val navigationBar: NavigationBar
private val undoredoThemeBar: UndoRedoThemeBar
private val undoredoLayoutBar: UndoRedoLayoutBar
Expand All @@ -83,7 +84,7 @@ class RNArtist : Application() {
lateinit var stage: Stage
private val root: BorderPane

var currentThumbnail: Thumbnail? = null
var currentThumbnail: SimpleObjectProperty<Thumbnail?> = SimpleObjectProperty(null)
//we explicitly create the observable list of thumbnails to link it to an extractor that will automatically update the picture when the layout and/or theme of the current drawing is saved back in the DSL script.
private val thumbnailsList: ObservableList<Thumbnail> =
FXCollections.observableArrayList { thumbnail: Thumbnail ->
Expand Down Expand Up @@ -123,6 +124,7 @@ class RNArtist : Application() {
fun blinkUINode(name:String) {
this.upperPanel.blinkUINode(name)
this.lowerPanel.blinkUINode(name)
this.manageCurrent2DBar.blinkUINode(name)
this.navigationBar.blinkUINode(name)
this.undoredoThemeBar.blinkUINode(name)
this.undoredoLayoutBar.blinkUINode(name)
Expand Down Expand Up @@ -205,6 +207,15 @@ class RNArtist : Application() {
thumbnails.items.clear()
}

fun searchFolder(path:String, start:TreeItem<DBFolder> = lowerPanel.dbExplorerPanel.dbExplorerSubPanel.dbTreeView.root):TreeItem<DBFolder>? {
return if (start.value.absPath.equals(path))
start
else if (start.children.isNotEmpty())
start.children.map { searchFolder(path, it) }.filter { it != null }.firstOrNull()
else
null
}

fun addFolderToTreeView(invariantSeparatorsPath2StructuralFiles: String): TreeItem<DBFolder>? {
currentDB.get()?.let { currentDB ->
val inBetweenDirs = invariantSeparatorsPath2StructuralFiles.split(currentDB.rootInvariantSeparatorsPath).last().removePrefix("/").removeSuffix("/")
Expand Down Expand Up @@ -662,6 +673,7 @@ class RNArtist : Application() {
this.add(vBox, 1, 0, 1, 1)
val hBox = HBox()
hBox.alignment = Pos.CENTER
hBox.children.add(manageCurrent2DBar)
hBox.children.add(navigationBar)
hBox.children.add(undoredoThemeBar)
hBox.children.add(undoredoLayoutBar)
Expand Down Expand Up @@ -2828,7 +2840,7 @@ class RNArtist : Application() {

init {
this.onMouseClicked = EventHandler { event ->
currentThumbnail = this.item
currentThumbnail.set(this.item)
val w = TaskDialog(mediator)
w.task = LoadStructure(mediator, item.dslScriptInvariantSeparatorsPath)
}
Expand Down Expand Up @@ -4767,6 +4779,88 @@ class RNArtist : Application() {

}

private inner class ManageCurrentDrawing : Canvas2DToolBars() {

val trashCurrentDrawingButton:RNArtistButton
val showDBFolderForCurrentDrawingButton:RNArtistButton

init {
this.showDBFolderForCurrentDrawingButton = addButton("fas-folder") {
mediator.currentDrawing.get()?.let {
searchFolder(File(it.dslScriptInvariantSeparatorsPath).parentFile.invariantSeparatorsPath)?.let {
mediator.rnartist.expandTreeView(it)
mediator.rnartist.selectInTreeView(it)
}
}
}

//this button is enables if the currentThumnail is not null. The current thumbnail becomes not null if:
// it has been clicked, meaning that its 2D is now the current drawing
// a 2D has been saved in the current folder
currentThumbnail.addListener { _,_,newValue ->
showDBFolderForCurrentDrawingButton.isDisable = newValue == null
}

//this button is enable if we have a currentDB, a currentDrawing and if the currentDrawing dsl script path starts with the root DB path
mediator.currentDrawing.addListener { _, _, newValue ->
this.showDBFolderForCurrentDrawingButton.isDisable = mediator.currentDB?.let { currentDB ->
newValue?.let { current2D ->
!current2D.dslScriptInvariantSeparatorsPath.startsWith(currentDB.rootInvariantSeparatorsPath)
} ?: run {
true
}
} ?: run {
true
}
}

mediator.rnartist.currentDB.addListener { _, _, newValue ->
this.showDBFolderForCurrentDrawingButton.isDisable = mediator.currentDrawing.get()?.let { current2D ->
newValue?.let { currentDB ->
!current2D.dslScriptInvariantSeparatorsPath.startsWith(currentDB.rootInvariantSeparatorsPath)
} ?: run {
true
}
} ?: run {
true
}
}

this.showDBFolderForCurrentDrawingButton.isDisable = true

this.trashCurrentDrawingButton = addButton("fas-trash") {
val alert =
Alert(Alert.AlertType.CONFIRMATION)
alert.initStyle(StageStyle.TRANSPARENT);
alert.initOwner(stage)
alert.initModality(Modality.WINDOW_MODAL)
alert.dialogPane.background =
Background(BackgroundFill(RNArtistGUIColor, CornerRadii(10.0), Insets.EMPTY))
alert.title = "Need Confirmation"
alert.headerText = null
alert.contentText = "Are you sure to delete your current 2D?"

val alerttStage = alert.dialogPane.scene.window as Stage
alerttStage.isAlwaysOnTop = true
alerttStage.toFront()
val result = alert.showAndWait()
if (result.get() == ButtonType.OK) {
mediator.currentDrawing.set(null)
}
}

mediator.currentDrawing.addListener { _, _, newValue ->
trashCurrentDrawingButton.isDisable = newValue == null
}

this.trashCurrentDrawingButton.isDisable = true
}

override fun blinkUINode(name: String) {
}

}

private inner class NavigationBar : Canvas2DToolBars() {

val zoomInButton:RNArtistButton
Expand Down Expand Up @@ -5381,6 +5475,7 @@ class RNArtist : Application() {
load()
this.mediator = Mediator(this)

this.manageCurrent2DBar = ManageCurrentDrawing()
this.navigationBar = NavigationBar()
this.undoredoThemeBar = UndoRedoThemeBar()
this.undoredoLayoutBar = UndoRedoLayoutBar()
Expand Down Expand Up @@ -5481,7 +5576,7 @@ class RNArtist : Application() {
scene.window.y = 0.0
scene.stylesheets.add("io/github/fjossinet/rnartist/gui/css/main.css")

this.displayDocPage("quickstart.html")
//this.displayDocPage("quickstart.html")
SplashWindow(this.mediator)
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/io/github/fjossinet/rnartist/io/tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Save2D(mediator: Mediator) : RNArtistTask<File?>(mediator) {
this.rnartistDialog.displayException(exception)
} ?: run {
this.resultNow().first?.let { scriptFile ->
//it was a copy of the current 2D in the current folder
mediator.rnartist.currentThumbnail = mediator.rnartist.addThumbnail(File(mediator.currentDB!!.getDrawingsDirForDataDir(File(mediator.rnartist.currentDBFolderAbsPath.get())), "${scriptFile.name.split(".kts").first()}.png"),
scriptFile.invariantSeparatorsPath)
//it is a copy of the current 2D in the current folder
mediator.rnartist.currentThumbnail.set(mediator.rnartist.addThumbnail(File(mediator.currentDB!!.getDrawingsDirForDataDir(File(mediator.rnartist.currentDBFolderAbsPath.get())), "${scriptFile.name.split(".kts").first()}.png"),
scriptFile.invariantSeparatorsPath))
} ?: run {
//it xas an update of the current 2D in the current folder
//it is an update of the current 2D in the current folder
mediator.rnartist.thumbnails.items.forEach {
if (it.dslScriptInvariantSeparatorsPath.equals(mediator.currentDrawing.get()?.dslScriptInvariantSeparatorsPath)) {
it.layoutAndThemeUpdated.value = !it.layoutAndThemeUpdated.value
Expand Down Expand Up @@ -87,13 +87,13 @@ class Save2DSelection(mediator: Mediator) : RNArtistTask<File?>(mediator) {
this.rnartistDialog.displayException(exception)
} ?: run {
this.resultNow().first?.let { scriptFile ->
mediator.rnartist.currentThumbnail = mediator.rnartist.addThumbnail(
mediator.rnartist.currentThumbnail.set(mediator.rnartist.addThumbnail(
File(
mediator.currentDB!!.getDrawingsDirForDataDir(File(mediator.rnartist.currentDBFolderAbsPath.get())),
"${scriptFile.name.split(".kts").first()}.png"
),
scriptFile.invariantSeparatorsPath
)
))
}
this.rnartistDialog.stage.close()
}
Expand Down Expand Up @@ -478,7 +478,7 @@ class UpdateAll2Ds(mediator: Mediator) : RNArtistTask<Any?>(mediator) {
this.rnartistDialog.displayException(exception)
} ?: run {
mediator.rnartist.thumbnails.items.forEach { item ->
if (item != mediator.rnartist.currentThumbnail) {
if (item != mediator.rnartist.currentThumbnail.get()) {
item.layoutAndThemeUpdated.value = !item.layoutAndThemeUpdated.value
}
}
Expand All @@ -497,7 +497,7 @@ class UpdateAll2Ds(mediator: Mediator) : RNArtistTask<Any?>(mediator) {

//then the other thumbnails
mediator.rnartist.thumbnails.items.forEach { item ->
if (item != mediator.rnartist.currentThumbnail) {
if (item != mediator.rnartist.currentThumbnail.get()) {
updateMessage(
"Updating 2D for ${
item.dslScriptInvariantSeparatorsPath.removeSuffix(".kts").split(
Expand Down

0 comments on commit 90f0d7b

Please sign in to comment.