Skip to content

Commit

Permalink
"copy" and "cut" can now process directories
Browse files Browse the repository at this point in the history
  • Loading branch information
spacebanana420 committed Sep 9, 2024
1 parent 176dbd2 commit b15234d
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/parasolib/commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,32 @@ public static void runCommand(String cmd_str, String parent, String[][] paths) {
if (old_path.equals(new_path)) {return;}
Path source = Path.of(old_path);
Path target = Path.of(new_path);

String path_type = ""; String operation_type = "";
try {
if (browserdata.clipboard_cut) {
Files.move(source, target);
userinput.pressToContinue("File " + browserdata.file_clipboard[1] + " has been cut!");
operation_type = "cut!";
if (new File(old_path).isDirectory()) {
path_type = "Directory ";
fileops.moveDirectory(old_path, new_path);
}
else {
path_type = "File ";
Files.move(source, target);
}
}
else {
Files.copy(source, target);
userinput.pressToContinue("File " + browserdata.file_clipboard[1] + " has been pasted!");
operation_type = "pasted!";
if (new File(old_path).isDirectory()) {
path_type = "Directory ";
fileops.copyDirectory(old_path, new_path);
}
else {
path_type = "File ";
Files.copy(source, target);
}
}
userinput.pressToContinue(path_type + browserdata.file_clipboard[1] + " has been " + operation_type);
}
catch (IOException e) {
String message =
Expand Down Expand Up @@ -443,8 +460,18 @@ private static void changeTab(String parent) {

private static void copyToClipboard(String[] args, String[][] paths, String parent, boolean cut) {
int i = browser.answerToIndex(args[1]);
if (!browser.indexLeadsToFile(i, paths)) {return;}
String file_name = browser.returnFile(i, paths);
String file_name = "";
boolean path_valid = false;
if (browser.indexLeadsToFile(i, paths)) {
path_valid = true;
file_name = browser.returnFile(i, paths);
}
else if (browser.indexLeadsToDir(i, paths)) {
path_valid = true;
file_name = browser.returnDir(i, paths);
}
if (!path_valid) {return;}

String file_path = parent;
browserdata.file_clipboard = new String[]{file_path, file_name};
browserdata.clipboard_cut = cut;
Expand Down

0 comments on commit b15234d

Please sign in to comment.