diff --git a/main/src/Data/File.java b/main/src/Data/File.java index 5e1ec8acf4c0cacc49a21e782ca13c54075b75b0..131e713801e2b1a0aeaa20e860c8b76aaa51a954 100644 --- a/main/src/Data/File.java +++ b/main/src/Data/File.java @@ -10,7 +10,6 @@ public class File implements Serializable { boolean isSystemFile; //是否系统文件 boolean isNormalFile; //是否普通文件 boolean isFolder; //是否文件夹 - private String absolutePath;//文件的绝对路径 private String fileName;//文件名 private int diskStartNum;//磁盘起始地址 private File parent;//父目录 @@ -22,16 +21,14 @@ public class File implements Serializable { private String content;//文件内容; List childrenFile;//子文件或子目录 - public File(boolean isReadOnly, boolean isSystemFile, boolean isNormalFile, boolean isFolder, String absolutePath, String fileName, File parent,Path path) { + public File(boolean isReadOnly, boolean isSystemFile, boolean isNormalFile, boolean isFolder, String fileName, File parent) { this.isReadOnly = isReadOnly; this.isSystemFile = isSystemFile; this.isNormalFile = isNormalFile; this.isFolder = isFolder; - this.absolutePath = absolutePath; this.fileName = fileName; this.parent = parent; isOpen = false; - this.path = path; if(isFolder == true){ childrenFile = new ArrayList<>(); } @@ -69,14 +66,6 @@ public class File implements Serializable { isFolder = folder; } - public String getAbsolutePath() { - return absolutePath; - } - - public void setAbsolutePath(String absolutePath) { - this.absolutePath = absolutePath; - } - public String getFileName() { return fileName; } diff --git a/main/src/controller/MainController.java b/main/src/controller/MainController.java index f28ec78c482dbe454b535c04d22b5aaeb4948130..5cc6c22220eb23060eb3135fc1e4876ad4721a81 100644 --- a/main/src/controller/MainController.java +++ b/main/src/controller/MainController.java @@ -127,7 +127,7 @@ public class MainController { currentPath = rootPath; contextMenuInit(); menuItemAction(); - rootFile = new File(false,true,false,true,"c:","c:",null,rootPath); + rootFile = new File(false,true,false,true,"c:",null); currentFile = rootFile; fileExplorer.setAlignment(Pos.TOP_LEFT); fileExplorer.setHgap(15); diff --git a/main/src/operations/createFileOperations.java b/main/src/operations/createFileOperations.java index f85b3defcd2c51cfcc2194f6fea2cf9ed49066e0..39fb3501a6f7a3d4d18792cfcf5d81a6527da6c5 100644 --- a/main/src/operations/createFileOperations.java +++ b/main/src/operations/createFileOperations.java @@ -13,6 +13,7 @@ import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import javafx.scene.layout.FlowPane; import util.FindLabelToFile; +import util.GetFileAbsolutePath; import util.RandomStr; @@ -25,10 +26,9 @@ import static controller.MainController.rootFile; public class createFileOperations { public static void createFile(FlowPane flowPane, Map icons, ContextMenu actionContextMenu){ String rdStr = RandomStr.getRandomString(5); - Path newPath = new Path(currentFile.getAbsolutePath()+"新建文件"+rdStr,currentFile.getPath()); - File file = new File(true,false,true,false,currentFile.getAbsolutePath()+"\\新建文件"+rdStr,"新建文件"+rdStr,currentFile,newPath); +// Path newPath = new Path(currentFile.getAbsolutePath()+"新建文件"+rdStr,currentFile.getPath()); + File file = new File(true,false,true,false,"新建文件"+rdStr,currentFile); System.out.println("创建文件"); - Label icon = new Label(file.getFileName(),new ImageView("icon/文本文件.png")); icon.setContentDisplay(ContentDisplay.TOP); icon.setWrapText(false); @@ -57,7 +57,7 @@ public class createFileOperations { flowPane.getChildren().add(icon); currentFile.getChildrenFile().add(file); - currentFile.getPath().getChildren().add(newPath); +// currentFile.getPath().getChildren().add(newPath); icon.setOnMouseEntered(new EventHandler() { @@ -102,6 +102,10 @@ public class createFileOperations { } deleteOperations.deleteFile(flowPane, icons, deleteFile); }); + actionContextMenu.getItems().get(2).setOnAction(ActionEvent -> { + currentFile = FindLabelToFile.findFile(icons, src); + + }); actionContextMenu.show(src, event.getScreenX(), event.getScreenY()); } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { System.out.println("打开文件"); @@ -117,8 +121,8 @@ public class createFileOperations { public static void createFolder(FlowPane flowPane, /*File currentFile,*/ Map icons, ContextMenu actionContextMenu){ String rdStr = RandomStr.getRandomString(5); - Path newPath = new Path(currentFile.getAbsolutePath()+"新建文件夹" + rdStr,currentFile.getPath()); - File file = new File(false,false,true,true,currentFile.getAbsolutePath()+"\\新建文件夹"+rdStr,"新建文件夹"+rdStr,currentFile,newPath); +// Path newPath = new Path(currentFile.getAbsolutePath()+"新建文件夹" + rdStr,currentFile.getPath()); + File file = new File(false,false,true,true,"新建文件夹"+rdStr,currentFile); System.out.println("创建文件夹"); Label icon = new Label(file.getFileName(),new ImageView("icon/文件夹.png")); icon.setContentDisplay(ContentDisplay.TOP); @@ -150,7 +154,7 @@ public class createFileOperations { } } currentFile.getChildrenFile().add(file); - currentFile.getPath().getChildren().add(newPath); +// currentFile.getPath().getChildren().add(newPath); icon.setOnMouseEntered(new EventHandler() { @Override public void handle(MouseEvent event) { diff --git a/main/src/operations/renameOperations.java b/main/src/operations/renameOperations.java new file mode 100644 index 0000000000000000000000000000000000000000..fe8be97c0744f6bc013d3cb331b9287b36817caa --- /dev/null +++ b/main/src/operations/renameOperations.java @@ -0,0 +1,5 @@ +package operations; + +public class renameOperations { + +} diff --git a/main/src/util/GetFileAbsolutePath.java b/main/src/util/GetFileAbsolutePath.java new file mode 100644 index 0000000000000000000000000000000000000000..0e145e9e7cef7a8cbbda0c394790404376fb5459 --- /dev/null +++ b/main/src/util/GetFileAbsolutePath.java @@ -0,0 +1,32 @@ +package util; + +import Data.File; + +import java.util.Stack; + +import static controller.MainController.rootFile; + +public class GetFileAbsolutePath { + public static String getAbsPath(File file) { + if (file != null) { + Stack filePath = new Stack<>(); + if (file != rootFile) { + File tmpFile = file; + while (tmpFile != rootFile) { + filePath.push(tmpFile.getFileName()); + tmpFile = tmpFile.getParent(); + } + } + String fileAbsPath = "C:\\"; + while (!filePath.isEmpty()) { + if (filePath.size() == 1) { + fileAbsPath = fileAbsPath + filePath.peek(); + } else { + fileAbsPath = fileAbsPath + filePath.peek() + "\\"; + } + filePath.pop(); + } + return fileAbsPath; + } else return null; + } +} \ No newline at end of file