can now double click on directory without error

This commit is contained in:
Oystein 2021-04-07 04:53:36 +02:00
parent 2ecda54d7f
commit 382ae5cbbc
2 changed files with 9 additions and 3 deletions

View File

@ -4,6 +4,8 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection; import java.util.Collection;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Scanner; import java.util.Scanner;
@ -144,6 +146,7 @@ public class EditorController implements Initializable, Controller {
private void setEditorContent(String filePath) { private void setEditorContent(String filePath) {
if (filePath == null) { if (filePath == null) {
editor.clear(); editor.clear();
editor.appendText("// New File");
return; return;
} }
try (Scanner sc = new Scanner(new File(filePath))) { try (Scanner sc = new Scanner(new File(filePath))) {

View File

@ -10,6 +10,7 @@ import javafx.scene.input.MouseEvent;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
@ -136,7 +137,6 @@ public class FiletreeController implements Initializable, Controller {
private void handleMouseClick(MouseEvent event) { private void handleMouseClick(MouseEvent event) {
if (event.getClickCount() == 2) { if (event.getClickCount() == 2) {
TreeItem<String> item = filetree.getSelectionModel().getSelectedItem(); TreeItem<String> item = filetree.getSelectionModel().getSelectedItem();
String root = Model.getProjectPath().getFileName().toString(); String root = Model.getProjectPath().getFileName().toString();
String path = ""; String path = "";
while (!root.equals(item.getValue())) { while (!root.equals(item.getValue())) {
@ -146,8 +146,11 @@ public class FiletreeController implements Initializable, Controller {
path = Model.getProjectPath() + path; path = Model.getProjectPath() + path;
Path pathToString = Paths.get(path); Path pathToString = Paths.get(path);
Model.setActiveFilePath(pathToString); if (!Files.isDirectory(pathToString)) {
this.eventBus.post(new FileSelectedEvent(path)); Model.setActiveFilePath(pathToString);
this.eventBus.post(new FileSelectedEvent(path));
}
} }
} }