diff --git a/commander/pom.xml b/commander/pom.xml
index 42bb88f3..a0c21390 100644
--- a/commander/pom.xml
+++ b/commander/pom.xml
@@ -13,9 +13,9 @@
UTF-8
- 25
- 25
- 21.0.6
+ 21
+ 21
+ 21
5.12.1
3.2.5
@@ -42,8 +42,25 @@
testfx-junit5
4.0.18
test
+
+
+ org.testfx
+ openjfx-monocle
+ jdk-12.0.1+2
+ test
+
+
+
+
+
+
+
+
+
+
+
diff --git a/commander/src/main/java/hse/java/commander/CommanderApplication.java b/commander/src/main/java/hse/java/commander/CommanderApplication.java
index 471f6fd5..d5928f87 100644
--- a/commander/src/main/java/hse/java/commander/CommanderApplication.java
+++ b/commander/src/main/java/hse/java/commander/CommanderApplication.java
@@ -21,6 +21,5 @@ public void start(Stage stage) throws IOException {
stage.setTitle("Commander");
stage.setScene(scene);
stage.show();
- System.out.println("Hello world");
}
}
diff --git a/commander/src/main/java/hse/java/commander/MainController.java b/commander/src/main/java/hse/java/commander/MainController.java
index 5de3b66d..c1004f3c 100644
--- a/commander/src/main/java/hse/java/commander/MainController.java
+++ b/commander/src/main/java/hse/java/commander/MainController.java
@@ -2,44 +2,130 @@
import javafx.fxml.FXML;
import javafx.scene.control.Button;
+import javafx.scene.control.Label;
import javafx.scene.control.ListView;
-import java.nio.file.Path;
+import java.nio.file.*;
+import java.util.stream.Stream;
public class MainController {
- @FXML
- public ListView left;
-
- @FXML
- public ListView right;
-
- @FXML
- public Button move;
+ @FXML public ListView left;
+ @FXML public ListView right;
+ @FXML public Label leftLabel;
+ @FXML public Label rightLabel;
+ @FXML public Button copy;
+ @FXML public Button move;
+ @FXML public Button delete;
- private Path leftDir;
- private Path rightDir;
+ private Path leftPath;
+ private Path rightPath;
+ private ListView activePanel;
- // for testing
public void setInitialDirs(Path leftStart, Path rightStart) {
- this.leftDir = leftStart;
- this.rightDir = rightStart;
+ leftPath = leftStart;
+ rightPath = rightStart;
+ update();
}
public void initialize() {
- move.setOnMouseClicked(event -> {
+ activePanel = left;
+ left.setOnMouseClicked(e -> {
+ activePanel = left;
+ if (e.getClickCount() == 2) open(left);
});
- System.out.println(System.getProperty("user.home"));
- left.getItems().add("Kek");
-
- left.setOnMouseClicked(event -> {
- if (event.getClickCount() == 2) {
- int index = left.getSelectionModel().getSelectedIndex();
- if (index >= 0) {
- left.getItems().set(index, "clicked");
- }
- }
+
+ right.setOnMouseClicked(e -> {
+ activePanel = right;
+ if (e.getClickCount() == 2) open(right);
});
+
+ copy.setOnAction(e -> copy());
+ move.setOnAction(e -> move());
+ delete.setOnAction(e -> delete());
+ }
+
+ private void dir(ListView panel, Path path) {
+ panel.getItems().clear();
+ panel.getItems().add("...");
+ try (Stream f = Files.list(path)) {
+ f.map(p -> p.getFileName().toString()).sorted().forEach(panel.getItems()::add);
+ } catch (Exception e) {}
+ Label label = panel == left ? leftLabel : rightLabel;
+ if (label != null) label.setText(path.toString());
+ }
+
+ private void update() {
+ dir(left, leftPath);
+ dir(right, rightPath);
+ }
+
+ private void open(ListView panel) {
+ String name = panel.getSelectionModel().getSelectedItem();
+ if (name == null) return;
+
+ Path curr = panel == left ? leftPath : rightPath;
+
+ if (name.equals("...")) {
+ Path parent = curr.getParent();
+ if (parent != null) {
+ if (panel == left) leftPath = parent;
+ else rightPath = parent;
+ update();
+ }
+ return;
+ }
+
+ Path next = curr.resolve(name);
+ if (Files.isDirectory(next)) {
+ if (panel == left) leftPath = next;
+ else rightPath = next;
+ update();
+ }
+ }
+
+ @FXML
+ public void copy() {
+ if (activePanel == null) return;
+ String name = activePanel.getSelectionModel().getSelectedItem();
+ if (name == null || name.equals("...")) return;
+
+ Path src = (activePanel == left ? leftPath : rightPath).resolve(name);
+ Path dst = (activePanel == left ? rightPath : leftPath).resolve(name);
+
+ try {
+ Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING);
+ } catch (Exception e) {}
+ update();
+ }
+
+ @FXML
+ public void move() {
+ if (activePanel == null) return;
+ String name = activePanel.getSelectionModel().getSelectedItem();
+ if (name == null || name.equals("...")) return;
+
+ Path src = (activePanel == left ? leftPath : rightPath).resolve(name);
+ Path dst = (activePanel == left ? rightPath : leftPath).resolve(name);
+
+ try {
+ Files.move(src, dst, StandardCopyOption.REPLACE_EXISTING);
+ } catch (Exception e) {}
+ update();
+ }
+
+ @FXML
+ public void delete() {
+ if (activePanel == null) return;
+ String name = activePanel.getSelectionModel().getSelectedItem();
+ if (name == null || name.equals("...")) return;
+
+ Path file = (activePanel == left ? leftPath : rightPath).resolve(name);
+
+ try {
+ Files.deleteIfExists(file);
+ } catch (Exception e) {}
+ update();
}
}
diff --git a/commander/src/main/resources/hse/java/commander/commander-ui.fxml b/commander/src/main/resources/hse/java/commander/commander-ui.fxml
index 724bbc8a..8537de50 100644
--- a/commander/src/main/resources/hse/java/commander/commander-ui.fxml
+++ b/commander/src/main/resources/hse/java/commander/commander-ui.fxml
@@ -5,10 +5,16 @@
-
-
+
+
+
+
+
+
+
+
-
+