Bläddra i källkod

[hide] Added repalce refs with, added extension point for custom file filters in search&replace

Clément Espeute 8 månader sedan
förälder
incheckning
ea25dd9275
2 ändrade filer med 45 tillägg och 26 borttagningar
  1. 6 0
      hide/Ide.hx
  2. 39 26
      hide/view/FileTree.hx

+ 6 - 0
hide/Ide.hx

@@ -1085,8 +1085,14 @@ class Ide extends hide.tools.IdeData {
 		}
 		for( sheet in tmpSheets )
 			@:privateAccess sheet.sheet.lines = null;
+
+		for (customFilter in customFilepathRefFilters) {
+			customFilter(context);
+		}
 	}
 
+	public var customFilepathRefFilters : Array<(ctx : FilterPathContext) -> Void> = [];
+
 	public function refreshFont() {
 		var font = ideConfig.useAlternateFont ? "Verdana" : "Inter";
 		var size = ideConfig.useAlternateFont ? "9pt" : "9.5pt";

+ 39 - 26
hide/view/FileTree.hx

@@ -163,6 +163,16 @@ class FileTree extends FileView {
 						tree.refresh();
 					}
 				}},
+				{ label: "Replace Refs With", enabled: selection.length > 0, click : function() {
+					ide.chooseFile(["*"], (newPath: String) -> {
+						if(ide.confirm('Replace all refs of $selection with $newPath ? This action can not be undone')) {
+							for (oldPath in selection) {
+								replacePathInFiles(oldPath, newPath, false);
+							}
+							ide.message("Done");
+						}
+					});
+				}},
 			]);
 		});
 		tree.onDblClick = onOpenFile;
@@ -264,32 +274,7 @@ class FileTree extends FileView {
 		if( !wasRenamed )
 			sys.FileSystem.rename(ide.getPath(path), ide.getPath(newPath));
 
-		var changed = false;
-		function filter(ctx: hide.Ide.FilterPathContext) {
-			var p = ctx.valueCurrent;
-			if( p == null )
-				return;
-			if( p == path ) {
-				ctx.change(newPath);
-				return;
-			}
-			if( p == "/"+path ) {
-				ctx.change(newPath);
-				return;
-			}
-			if( isDir ) {
-				if( StringTools.startsWith(p,path+"/") ) {
-					ctx.change(newPath + p.substr(path.length));
-					return;
-				}
-				if( StringTools.startsWith(p,"/"+path+"/") ) {
-					ctx.change("/"+newPath + p.substr(path.length+1));
-					return;
-				}
-			}
-		}
-
-		ide.filterPaths(filter);
+		replacePathInFiles(path, newPath, isDir);
 
 		var dataDir = new haxe.io.Path(path);
 		if( dataDir.ext != "dat" ) {
@@ -392,6 +377,34 @@ class FileTree extends FileView {
 		return true;
 	}
 
+	function replacePathInFiles(oldPath: String, newPath: String, isDir: Bool = false) {
+		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 ) {
+				if( StringTools.startsWith(p,oldPath+"/") ) {
+					ctx.change(newPath + p.substr(oldPath.length));
+					return;
+				}
+				if( StringTools.startsWith(p,"/"+oldPath+"/") ) {
+					ctx.change("/"+newPath + p.substr(oldPath.length+1));
+					return;
+				}
+			}
+		}
+
+		ide.filterPaths(filter);
+	}
+
 	function onAllowMove(e: String, to : String) {
 		var destAbsPath = Ide.inst.getPath(to);
 		return sys.FileSystem.isDirectory(destAbsPath);