Skip to content

Commit

Permalink
Removed workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Aug 11, 2024
1 parent 799b9c4 commit 50357c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
17 changes: 9 additions & 8 deletions app/src/main/scala/tripaint/MainStage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import java.io.File
import scala.language.implicitConversions
import scala.util.Try

class MainStage(controls: TriPaintViewListener, model: TriPaintModel)
extends Stage
with TriPaintView {
class MainStage(controls: TriPaintViewListener, model: TriPaintModel, stage: Stage)
extends TriPaintView {
private val (currentEditMode, setCurrentEditMode) = createResource(EditMode.Draw)

private val imageDisplay: ImageGridPane = new ImageGridPane(model.imageGrid, currentEditMode)
Expand All @@ -49,8 +48,8 @@ class MainStage(controls: TriPaintViewListener, model: TriPaintModel)
private var currentFolder: Option[File] = None

{
this.setTitle("TriPaint")
this.setOnCloseRequest(e => {
stage.setTitle("TriPaint")
stage.setOnCloseRequest(e => {
if (!controls.requestExit()) e.consume()
})

Expand Down Expand Up @@ -84,7 +83,7 @@ class MainStage(controls: TriPaintViewListener, model: TriPaintModel)
}
}

this.setScene(scene)
stage.setScene(scene)
}

private def makeColorBox() = {
Expand Down Expand Up @@ -119,7 +118,7 @@ class MainStage(controls: TriPaintViewListener, model: TriPaintModel)
currentFolder.foreach(chooser.setInitialDirectory)
chooser.setTitle("Save file")
chooser.getExtensionFilters.add(new ExtensionFilter("PNG", "*.png"))
val result = Option(chooser.showSaveDialog(this))
val result = Option(chooser.showSaveDialog(stage))
result.foreach(r => currentFolder = Some(r.getParentFile))
result
}
Expand All @@ -139,7 +138,7 @@ class MainStage(controls: TriPaintViewListener, model: TriPaintModel)
override def askForFileToOpen(): Option[File] = {
val chooser = new FileChooser
chooser.setTitle("Open file")
val result = Option(chooser.showOpenDialog(this))
val result = Option(chooser.showOpenDialog(stage))
result.foreach(r => currentFolder = Some(r.getParentFile))
result
}
Expand Down Expand Up @@ -300,4 +299,6 @@ class MainStage(controls: TriPaintViewListener, model: TriPaintModel)
val sizeStr = dialog.showAndWait().toScala
sizeStr.map(str => Try(str.toInt).toOption.filter(_ > 0).getOrElse(32))
}

override def close(): Unit = stage.close()
}
8 changes: 1 addition & 7 deletions app/src/main/scala/tripaint/TriPaint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ object TriPaint {
class App extends Application {
override def start(stage: Stage): Unit = {
val model: TriPaintModel = TriPaintModel.create()
val controller = new TriPaintController(model, new MainStage(_, _))
val s = controller.view.asInstanceOf[Stage]

// TODO: send stage to the UI instead of copying over the data
stage.setTitle(s.getTitle)
stage.setScene(s.getScene)
stage.setOnCloseRequest(s.getOnCloseRequest)
val controller = new TriPaintController(model, new MainStage(_, _, stage))

Platform.runLater(() =>
model.imageGrid.setImageSizeIfEmpty(controller.view.askForImageSize().getOrElse(32))
Expand Down

0 comments on commit 50357c1

Please sign in to comment.