don't open export if nothing is selected & clean up

This commit is contained in:
Jannik 2019-06-13 21:22:42 +02:00
parent 225316abb9
commit 391dfe4282
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
4 changed files with 12 additions and 23 deletions

View File

@ -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)

View File

@ -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
}
}

View File

@ -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) {

View File

@ -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!!) }
}
}