Skip to content

Commit

Permalink
Merge pull request #220 from rladstaetter/218-if-you-drop-a-directory…
Browse files Browse the repository at this point in the history
…-with-zip-files-those-should-be-unpacked-and-displayed

#218: opens zip files in dropped directory
  • Loading branch information
rladstaetter authored Apr 23, 2024
2 parents 485520f + d380e58 commit 5bc00cc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package app.logorrr.usecases.dnd

import app.logorrr.io.FileId
import app.logorrr.steps.{CheckTabPaneActions, VisibleItemActions}
import app.logorrr.usecases.StartEmptyApplicationTest
import app.logorrr.views.UiNodes
import app.logorrr.{LogoRRRApp, TestFiles}
import javafx.scene.Scene
import javafx.scene.control.ToolBar
import javafx.scene.input.MouseButton
import javafx.stage.Stage
import org.junit.jupiter.api.{BeforeAll, Test}

object DndDropDirectoryTest {

@BeforeAll
def setUp(): Unit = {
// necessary for https://github.com/TestFX/TestFX/issues/33
System.setProperty("testfx.robot", "awt")
}

}

class DndDropDirectoryTest extends StartEmptyApplicationTest
with VisibleItemActions
with CheckTabPaneActions {

@throws[Exception]
override def start(stage: Stage): Unit = {
LogoRRRApp.start(stage, services)
stage.toFront()

val dndStage = new Stage()
val dropBox = new ToolBar(Seq(new DragSourceButton(TestFiles.baseDir)): _*)
dndStage.setScene(new Scene(dropBox))
dndStage.show()

}

@Test def testOpeningDirectoryWith5FilesAndAZipContaining10Files(): Unit = {
checkForEmptyTabPane()
drag(DragSourceButton.uiNode(FileId(TestFiles.baseDir)).ref, MouseButton.PRIMARY).dropTo(UiNodes.MainTabPane.ref)
expectCountOfOpenFiles(15)
}

}



8 changes: 7 additions & 1 deletion app/src/main/scala/app/logorrr/views/main/MainTabPane.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import javafx.scene.control.{Tab, TabPane}
import javafx.scene.input.{DragEvent, TransferMode}

import java.nio.file.{Files, Path}
import java.util.stream.Collectors
import java.{lang, util}
import scala.collection.mutable
import scala.jdk.CollectionConverters._

Expand Down Expand Up @@ -90,7 +92,11 @@ class MainTabPane extends TabPane with CanLog {
}

private def dropDirectory(path: Path): Unit = {
Files.list(path).filter((p: Path) => Files.isRegularFile(p)).forEach((t: Path) => openFile(FileId(t)))
val files = Files.list(path).filter((p: Path) => Files.isRegularFile(p))
// diff between regular files and zip files, try to open zip files as container
val collectorResults: util.Map[lang.Boolean, util.List[Path]] = files.collect(Collectors.partitioningBy((p: Path) => p.getFileName.toString.endsWith(".zip")))
collectorResults.get(false).forEach(p => openFile(FileId(p)))
collectorResults.get(true).forEach(p => openZipFile(p))
}

/**
Expand Down

0 comments on commit 5bc00cc

Please sign in to comment.