Browse Source

[ide] Remove filewatch pause when renaming dirs

- Also batch updating the references to the renamed files to further improve performance gains.
- Removing the pause lead to big perf increase (1 min) because with the new filebrowser all the files are watched and the pause compute the hash of all the files. Could potentially lead to frezzes but none were found during testing.
Clément Espeute 1 week ago
parent
commit
8b36995318
2 changed files with 33 additions and 44 deletions
  1. 22 18
      hide/tools/FileManager.hx
  2. 11 26
      hide/view/FileBrowser.hx

+ 22 - 18
hide/tools/FileManager.hx

@@ -600,12 +600,12 @@ class FileManager {
 		queueProcessPendingMessages();
 	}
 
-	public static function doRename(path:String, name:String) {
-		var isDir = sys.FileSystem.isDirectory(hide.Ide.inst.getPath(path));
-		if( isDir ) hide.Ide.inst.fileWatcher.pause();
-		var ret = onRenameRec(path, name);
-		if( isDir ) hide.Ide.inst.fileWatcher.resume();
-		return ret;
+	public static function doRename(operations: Array<{from: String, to: String}>) {
+		for (op in operations) {
+			onRenameRec(op.from, "/" + op.to);
+		}
+
+		replacePathInFiles(operations);
 	}
 
 	public static function onRenameRec(path:String, name:String) {
@@ -623,6 +623,9 @@ class FileManager {
 		if( newPath == path )
 			return false;
 
+		if (!sys.FileSystem.exists(ide.getPath(path)))
+			return false;
+
 		if( sys.FileSystem.exists(ide.getPath(newPath)) ) {
 			function addPath(path:String,rand:String) {
 				var p = path.split(".");
@@ -679,8 +682,6 @@ class FileManager {
 		if( !wasRenamed )
 			sys.FileSystem.rename(ide.getPath(path), ide.getPath(newPath));
 
-		replacePathInFiles(path, newPath, isDir);
-
 		var dataDir = new haxe.io.Path(path);
 		if( dataDir.ext != "dat" ) {
 			dataDir.ext = "dat";
@@ -782,20 +783,23 @@ class FileManager {
 		return true;
 	}
 
-	public static function replacePathInFiles(oldPath: String, newPath: String, isDir: Bool = false) {
+	public static function replacePathInFiles(operations: Array<{from: String, to: String}>) {
 		function filter(ctx: hide.Ide.FilterPathContext) {
 			var p = ctx.valueCurrent;
 			if( p == null )
 				return;
-			if( p == oldPath ) {
-				ctx.change(newPath);
-				return;
-			}
-			if( p == "/"+oldPath ) {
-				ctx.change(newPath);
-				return;
-			}
-			if( isDir ) {
+			for (op in operations) {
+				var oldPath = op.from;
+				var newPath = op.to;
+
+				if( p == oldPath ) {
+					ctx.change(newPath);
+					return;
+				}
+				if( p == "/"+oldPath ) {
+					ctx.change(newPath);
+					return;
+				}
 				if( StringTools.startsWith(p,oldPath+"/") ) {
 					ctx.change(newPath + p.substr(oldPath.length));
 					return;

+ 11 - 26
hide/view/FileBrowser.hx

@@ -665,7 +665,7 @@ class FileBrowser extends hide.ui.View<FileBrowserState> {
 
 		if (this.favorites.length == 0)
 			this.favoritesTree.element.parent().hide();
-			
+
 		// Ressources tree
 		fancyTree = new hide.comp.FancyTree<FileEntry>(browserLayout.find(".left").find(".bot"), { saveDisplayKey: "fileBrowserTree_Main", search: true, customScroll: element.find("fancy-scroll").get(0) } );
 		fancyTree.getChildren = (file: FileEntry) -> {
@@ -965,27 +965,13 @@ class FileBrowser extends hide.ui.View<FileBrowserState> {
 
 	static function execMoveFiles(operations: Array<{from: String, to: String}>, isUndo: Bool) : Void {
 		if (!isUndo) {
-			for (file in operations) {
-				// File could have been removed by the system in between our undo/redo operations
-				if (sys.FileSystem.exists(hide.Ide.inst.getPath(file.from))) {
-					try {
-						FileManager.doRename(file.from, "/" + file.to);
-					} catch (e) {
-						hide.Ide.inst.quickError('move file ${file.from} -> ${file.to} failed : $e');
-					}
-				}
-			}
+			FileManager.doRename(operations);
 		} else {
-			for (file in operations) {
-				// File could have been removed by the system in between our undo/redo operations
-				if (sys.FileSystem.exists(hide.Ide.inst.getPath(file.to))) {
-					try {
-						FileManager.doRename(file.to, "/" + file.from);
-					} catch (e) {
-						hide.Ide.inst.quickError('move file ${file.from} -> ${file.to} failed : $e');
-					}
-				}
+			var rev = [];
+			for (op in operations) {
+				rev.push({from: op.to, to: op.from});
 			}
+			FileManager.doRename(rev);
 		}
 	}
 
@@ -1250,12 +1236,11 @@ class FileBrowser extends hide.ui.View<FileBrowserState> {
 
 			options.push({ label: "Replace Refs With", click : function() {
 				ide.chooseFile(["*"], (newPath: String) -> {
-					var selection = [for (file in getItemAndSelection(item, isGallery)) file.getRelPath()];
-					if(ide.confirm('Replace all refs of $selection with $newPath ? This action can not be undone')) {
-						for (oldPath in selection) {
-							FileManager.replacePathInFiles(oldPath, newPath, false);
-						}
-						ide.message("Done");
+					var files = [for (file in getItemAndSelection(item, isGallery)) file.getRelPath()];
+					if(ide.confirm('Replace all refs of $files with $newPath ? This action can not be undone')) {
+						var selection = [for (file in files) {from: file, to: newPath}];
+						FileManager.replacePathInFiles(selection);
+						ide.message("All references replaced");
 					}
 				});
 			}});