Add FileTreeOperationTest
This commit is contained in:
@@ -7,6 +7,7 @@ import javafx.scene.control.TreeView;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -83,10 +84,14 @@ public class FiletreeController implements Initializable, Controller {
|
||||
if (event.getClickCount() == 2) {
|
||||
TreeItem<String> item = filetree.getSelectionModel().getSelectedItem();
|
||||
|
||||
Path path = FiletreeOperations.getPathOfTreeItem(item);
|
||||
try {
|
||||
Path path = FiletreeOperations.getPathOfTreeItem(item);
|
||||
|
||||
if (!Files.isDirectory(path)) {
|
||||
this.eventBus.post(new OpenFileEvent(Optional.ofNullable(path)));
|
||||
if (!Files.isDirectory(path)) {
|
||||
this.eventBus.post(new OpenFileEvent(Optional.ofNullable(path)));
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("[ERROR]: Could not find filepath from filetree");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package app.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
@@ -19,7 +20,6 @@ public class FiletreeOperations {
|
||||
|
||||
private static int iconSize = 20;
|
||||
|
||||
// FIXME: File specific icons not working properly
|
||||
// TODO: Clean up code that is not in use
|
||||
// TODO: Error check for recursiveness, and files without icons
|
||||
|
||||
@@ -111,11 +111,14 @@ public class FiletreeOperations {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static Path getPathOfTreeItem(TreeItem<String> item) {
|
||||
final String rootFolderName =
|
||||
public static Path getPathOfTreeItem(TreeItem<String> item) throws FileNotFoundException {
|
||||
Path projectPath =
|
||||
Model
|
||||
.getProjectPath()
|
||||
.orElseThrow()
|
||||
.orElseThrow(() -> new IllegalStateException());
|
||||
|
||||
final String rootFolderName =
|
||||
projectPath
|
||||
.getFileName()
|
||||
.toString();
|
||||
|
||||
@@ -123,9 +126,11 @@ public class FiletreeOperations {
|
||||
while (!rootFolderName.equals(item.getValue())) {
|
||||
path = File.separator + item.getValue() + path;
|
||||
item = item.getParent();
|
||||
if (item == null)
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
path = Model.getProjectPath().orElseThrow().toString() + path;
|
||||
path = projectPath.toString() + path;
|
||||
|
||||
Path pathToString = Paths.get(path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user