From 391dfe4282627eef2def054e3694f244ff962472 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Thu, 13 Jun 2019 21:22:42 +0200 Subject: [PATCH] don't open export if nothing is selected & clean up --- .../controller/RootController.kt | 15 ++++++--------- .../org/hso/texturesyncclient/model/GUIModel.kt | 10 ++-------- .../texturesyncclient/model/GUIModelController.kt | 4 ++-- .../view/mainView/MainViewController.kt | 6 ++---- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt index a7171b8..c122b53 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/controller/RootController.kt @@ -32,16 +32,11 @@ import javax.imageio.ImageIO class RootController : Controller() { private val mvc: MainViewController by inject() - private val svc: StartupViewController by inject() private lateinit var con: Connection - private lateinit var selectedTextureModel: GUIModel - private var lastExportDir: String = System.getProperty("user.home") - lateinit var selectedTexture: Texture - fun isSelectedTextureInitialized() = ::selectedTexture.isInitialized /** * calculate the resolution, get today's date -> upload to server @@ -54,7 +49,7 @@ class RootController : Controller() { val uuid = UUID.randomUUID() val format = if (File(path).extension.toLowerCase() == "png") TextureFormat.PNG else TextureFormat.JPEG - var bimg = ImageIO.read(File(path)) //image for obtaining resolution + val bimg = ImageIO.read(File(path)) //image for obtaining resolution val resolution = Pair(bimg.height, bimg.width) val cal = Calendar.getInstance() //calendar obj with current time val hash = Sha256(data) @@ -228,9 +223,8 @@ class RootController : Controller() { /** * remove a texture from the FolderView and the server - * @param data the texture as meta element */ - fun deleteTexture(data: Texture) { + fun deleteTexture() { val dialogDelete = JFXOkayCancelAlert( "Löschen", "Textur ${selectedTextureModel.data.name} wirklich löschen?", @@ -257,7 +251,6 @@ class RootController : Controller() { newTexture, con.getTextureFile(selectedTextureModel.data.textureHash) ) - selectedTextureModel.setTexture(newTexture) selectedTextureModel.data = newTexture } catch (e: Exception) { println(e) @@ -278,9 +271,13 @@ class RootController : Controller() { */ fun setSelectedTexture(model: GUIModel) { selectedTextureModel = model + selectedTexture = model.data } companion object { + + var selectedTexture: Texture? = null + fun switchStartupToMain() { Platform.runLater { find(StartupView::class).replaceWith(MainView::class, sizeToScene = true, centerOnScreen = true) diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt index 3418598..0f59082 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModel.kt @@ -12,6 +12,7 @@ import javafx.scene.layout.BackgroundFill import javafx.scene.layout.CornerRadii import javafx.scene.layout.VBox import javafx.scene.paint.Paint +import org.hso.texturesyncclient.controller.RootController import tornadofx.addClass import tornadofx.find import tornadofx.paddingTop @@ -24,12 +25,9 @@ class GUIModel constructor(var data: Texture, img: Image) : VBox() { private var exportItem = MenuItem("exportiern") private var deleteItem = MenuItem("löschen") - private lateinit var texture: Texture - private val gmc = find(GUIModelController::class) init { - texture = data super.setPadding(Insets(5.0, 5.0, 5.0, 5.0)) super.getChildren().addAll(image, label) super.setOnContextMenuRequested { p0 -> contextMenu.show(this@GUIModel, p0.screenX, p0.screenY) } @@ -69,15 +67,11 @@ class GUIModel constructor(var data: Texture, img: Image) : VBox() { } deleteItem.setOnAction { - gmc.delete(data) + gmc.delete() } contextMenu.items.add(exportItem) contextMenu.items.add(deleteItem) } - fun setTexture(data: Texture) { - texture = data - } - } \ No newline at end of file diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt index 07651f4..a0c4d06 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/model/GUIModelController.kt @@ -14,8 +14,8 @@ class GUIModelController : Controller() { rootc.exportTexture(data) } - fun delete(data: Texture) { - rootc.deleteTexture(data) + fun delete() { + rootc.deleteTexture() } fun previewSelectedAction(data: Texture) { diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt index 87c07fb..a91afc3 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/mainView/MainViewController.kt @@ -67,7 +67,7 @@ class MainViewController : Controller() { folderView.children.clear() mv.cvSearch.isDisable = true setPreview3DTexture(Image("icons/TextureSync_Icon_256x256.jpeg")) // reset the 3DPreview to the logo - // TODO should we clear the selectedTexture? + RootController.selectedTexture = null runAsync { rootc.queryElements(tags) @@ -100,9 +100,7 @@ class MainViewController : Controller() { } fun scExport() { - if (rootc.isSelectedTextureInitialized()) { - rootc.exportTexture(rootc.selectedTexture) - } + RootController.selectedTexture?.let { rootc.exportTexture(RootController.selectedTexture!!) } } } \ No newline at end of file