Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions commander/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<javafx.version>21.0.6</javafx.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<javafx.version>21</javafx.version>
<junit.version>5.12.1</junit.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
</properties>
Expand All @@ -42,8 +42,25 @@
<artifactId>testfx-junit5</artifactId>
<version>4.0.18</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>openjfx-monocle</artifactId>
<version>jdk-12.0.1+2</version>
<scope>test</scope>
</dependency>
</dependencies>












<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ public void start(Stage stage) throws IOException {
stage.setTitle("Commander");
stage.setScene(scene);
stage.show();
System.out.println("Hello world");
}
}
136 changes: 111 additions & 25 deletions commander/src/main/java/hse/java/commander/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> left;

@FXML
public ListView<String> right;

@FXML
public Button move;
@FXML public ListView<String> left;
@FXML public ListView<String> 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<String> 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<String> panel, Path path) {
panel.getItems().clear();
panel.getItems().add("...");
try (Stream<Path> 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<String> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="421.0" prefWidth="627.0" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hse.java.commander.MainController">
<HBox prefHeight="370.0" prefWidth="627.0">
<ListView fx:id="left" id="left" prefHeight="318.0" prefWidth="311.0" />
<ListView fx:id="right" id="right" prefHeight="318.0" prefWidth="321.0" />
<VBox prefWidth="313.0">
<Label fx:id="leftLabel" maxWidth="Infinity" style="-fx-background-color: #e8e8e8; -fx-padding: 2 4;" />
<ListView fx:id="left" prefHeight="350.0" prefWidth="313.0" VBox.vgrow="ALWAYS" />
</VBox>
<VBox prefWidth="314.0">
<Label fx:id="rightLabel" maxWidth="Infinity" style="-fx-background-color: #e8e8e8; -fx-padding: 2 4;" />
<ListView fx:id="right" prefHeight="350.0" prefWidth="314.0" VBox.vgrow="ALWAYS" />
</VBox>
</HBox>
<HBox spacing="10.0">
<HBox spacing="10.0" style="-fx-padding: 6;">
<Button fx:id="copy" mnemonicParsing="false" text="Copy" />
<Button fx:id="move" mnemonicParsing="false" text="Move" />
<Button fx:id="delete" mnemonicParsing="false" text="Delete" />
Expand Down
Loading