From b15234d0540c53813101838b987a7146734d27ef Mon Sep 17 00:00:00 2001 From: Space Banana Date: Mon, 9 Sep 2024 14:47:15 +0100 Subject: [PATCH] "copy" and "cut" can now process directories --- src/parasolib/commands.java | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/parasolib/commands.java b/src/parasolib/commands.java index 0be98c3..c68c047 100644 --- a/src/parasolib/commands.java +++ b/src/parasolib/commands.java @@ -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 = @@ -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;