Clément Espeute пре 11 месеци
родитељ
комит
1083ac7db8
3 измењених фајлова са 119 додато и 71 уклоњено
  1. 71 27
      hide/Ide.hx
  2. 43 44
      hide/comp/cdb/Editor.hx
  3. 5 0
      hide/view/FileTree.hx

+ 71 - 27
hide/Ide.hx

@@ -802,9 +802,23 @@ class Ide extends hide.tools.IdeData {
 		}).appendTo(window.window.document.body).click();
 		}).appendTo(window.window.document.body).click();
 
 
 		// remove comments
 		// remove comments
+	}
+
+	public function findPathRefs(path: String) {
+		var refs : Array<{str: String, ?goto: () -> Void}> = [];
 
 
+		function filter(ctx: FilterPathContext) {
+			if (ctx.valueCurrent == path) {
+				refs.push(ctx.getRef());
+			}
+		}
 
 
+		filterPaths(filter);
 
 
+		open("hide.view.RefViewer", null, function(view) {
+			var refViewer : hide.view.RefViewer = cast view;
+			refViewer.showRefs(refs, 'Number of references to "$path"');
+		});
 	}
 	}
 
 
 	/**
 	/**
@@ -853,44 +867,75 @@ class Ide extends hide.tools.IdeData {
 			}
 			}
 		}
 		}
 
 
-		filterPrefabs(function(p:hrt.prefab.Prefab, path: String) {
-			context.changed = false;
-			context.contextPath = path;
-			context.openFunc = () -> openFile(context.contextPath);
-			p.source = context.filter(p.source);
-			var h = p.getHideProps();
-			if( h.onResourceRenamed != null )
-				h.onResourceRenamed(adaptedFilter);
-			else {
-				filterContent(p);
+		{
+			var currentPath : String = null;
+			context.getRef = () -> {
+				var p = currentPath; // Make capture
+				return {str: p, goto: () -> openFile(getPath(p))};
+			};
+
+			filterPrefabs(function(p:hrt.prefab.Prefab, path: String) {
+				context.changed = false;
+				currentPath = path;
+				p.source = context.filter(p.source);
+				var h = p.getHideProps();
+				if( h.onResourceRenamed != null )
+					h.onResourceRenamed(adaptedFilter);
+				else {
+					filterContent(p);
+				}
+				return context.changed;
+			});
+		}
+
+		{
+			var currentPath : String = null;
+			context.getRef = () -> {
+				var p = currentPath;
+				return {str: p, goto : Ide.showFileInExplorer.bind(getPath(p))};
 			}
 			}
-			return context.changed;
-		});
 
 
-		filterProps(function(content:Dynamic, path: String) {
-			context.changed = false;
-			context.contextPath = path;
-			context.openFunc = Ide.showFileInExplorer.bind(path);
-			filterContent(content);
-			return context.changed;
-		});
+			filterProps(function(content:Dynamic, path: String) {
+				context.changed = false;
+				currentPath = path;
+				filterContent(content);
+				return context.changed;
+			});
+		}
+
 
 
 		context.changed = false;
 		context.changed = false;
 		var tmpSheets = [];
 		var tmpSheets = [];
+
+		var currentSheet : cdb.Sheet = null;
+		var currentColumn : String = null;
+		var currentObject : Dynamic = null;
+		context.getRef = () -> {
+			var cs = currentSheet;
+			var cc = currentColumn;
+			var sheets = cdb.Sheet.getSheetPath(cs, cc);
+
+			var path = hide.comp.cdb.Editor.splitPath({s: sheets, o: currentObject});
+			return {str: sheets[0].s.name+"."+path.pathNames.join("."), goto: hide.comp.cdb.Editor.openReference2.bind(sheets[0].s, path.pathParts)};
+		};
+
 		for( sheet in database.sheets ) {
 		for( sheet in database.sheets ) {
 			if( sheet.props.dataFiles != null && sheet.lines == null ) {
 			if( sheet.props.dataFiles != null && sheet.lines == null ) {
 				// we already updated prefabs, no need to load data files
 				// we already updated prefabs, no need to load data files
 				tmpSheets.push(sheet);
 				tmpSheets.push(sheet);
 				@:privateAccess sheet.sheet.lines = [];
 				@:privateAccess sheet.sheet.lines = [];
 			}
 			}
-			context.contextPath = 'cdb:${sheet.getPath()}';
-			context.openFunc = () -> {throw "Todo";};
 			for( c in sheet.columns ) {
 			for( c in sheet.columns ) {
 				switch( c.type ) {
 				switch( c.type ) {
 				case TFile:
 				case TFile:
-					for( o in sheet.getLines() ) {
-						var v : Dynamic = context.filter(Reflect.field(o, c.name));
-						if( v != null ) Reflect.setField(o, c.name, v);
+					var sheets = cdb.Sheet.getSheetPath(sheet, c.name);
+					for( obj in sheet.getObjects() ) {
+						currentSheet = sheet;
+						currentColumn = c.name;
+						currentObject = obj;
+						var path = Reflect.field(obj.path[obj.path.length - 1], c.name);
+						var v : Dynamic = context.filter(path);
+						if( v != null ) Reflect.setField(obj.path[obj.path.length - 1], c.name, v);
 					}
 					}
 				default:
 				default:
 				}
 				}
@@ -1465,9 +1510,6 @@ class FilterPathContext {
 	public var valueCurrent: String;
 	public var valueCurrent: String;
 	var valueChanged: String;
 	var valueChanged: String;
 
 
-	public var contextPath: String;
-	public var openFunc: () -> Void;
-
 	public var filterFn: (FilterPathContext) -> Void;
 	public var filterFn: (FilterPathContext) -> Void;
 
 
 	var changed = false;
 	var changed = false;
@@ -1486,4 +1528,6 @@ class FilterPathContext {
 		filterFn(this);
 		filterFn(this);
 		return valueChanged;
 		return valueChanged;
 	}
 	}
+
+	public var getRef : () -> {str: String, ?goto: () -> Void};
 }
 }

+ 43 - 44
hide/comp/cdb/Editor.hx

@@ -1111,55 +1111,54 @@ class Editor extends Component {
 		return id;
 		return id;
 	}
 	}
 
 
-	public function getReferences(id: String, withCodePaths = true, returnAtFirstRef = false, sheet: cdb.Sheet, ?codeFileCache: Array<{path: String, data:String}>, ?prefabFileCache: Array<{path: String, data:String}>) : Array<{str:String, ?goto:Void->Void}> {
-		#if hl
-		return [];
-		#else
-		if( id == null )
-			return [];
-
-		function splitPath(rs: {s:Array<{s:cdb.Sheet, c:String, id:Null<String>}>, o:{path:Array<Dynamic>, indexes:Array<Int>}}) {
-			var path = [];
-			var coords = [];
-			for( i in 0...rs.s.length ) {
-				var s = rs.s[i];
-				var oid = Reflect.field(rs.o.path[i], s.id);
-				var idx = rs.o.indexes[i];
-				if( oid == null || oid == "" )
-					path.push(s.s.name.split("@").pop() + (idx < 0 ? "" : "[" + idx +"]"));
-				else {
-					path.push(oid);
-				}
-				if (i == rs.s.length - 1 && s.c != "" && s.c != null) {
-					path.push(s.c);
-				}
-			}
-
-			var coords = [];
-			var curIdx = 0;
-			while(curIdx < rs.o.indexes.length) {
-				var sheet = rs.s[curIdx];
-				var isSheet = !sheet.s.props.isProps;
-				if (isSheet) {
-					var oid = Reflect.field(rs.o.path[curIdx], sheet.id);
-					var next = sheet.c;
-					if (oid != null) {
-						coords.push(Id(sheet.id, oid, next));
-					}
-					else {
-						coords.push(Line(rs.o.indexes[curIdx], next));
-					}
+	public static function splitPath(rs: {s:Array<{s:cdb.Sheet, c:String, id:Null<String>}>, o:{path:Array<Dynamic>, indexes:Array<Int>}}) {
+		var path = [];
+		var coords = [];
+		for( i in 0...rs.s.length ) {
+			var s = rs.s[i];
+			var oid = Reflect.field(rs.o.path[i], s.id);
+			var idx = rs.o.indexes[i];
+			if( oid == null || oid == "" )
+				path.push(s.s.name.split("@").pop() + (idx < 0 ? "" : "[" + idx +"]"));
+			else {
+				path.push(oid);
+			}
+			if (i == rs.s.length - 1 && s.c != "" && s.c != null) {
+				path.push(s.c);
+			}
+		}
+		var coords = [];
+		var curIdx = 0;
+		while(curIdx < rs.o.indexes.length) {
+			var sheet = rs.s[curIdx];
+			var isSheet = !sheet.s.props.isProps;
+			if (isSheet) {
+				var oid = Reflect.field(rs.o.path[curIdx], sheet.id);
+				var next = sheet.c;
+				if (oid != null) {
+					coords.push(Id(sheet.id, oid, next));
 				}
 				}
 				else {
 				else {
-					coords.push(Prop(rs.s[curIdx].c));
+					coords.push(Line(rs.o.indexes[curIdx], next));
 				}
 				}
-
-				curIdx += 1;
+			}
+			else {
+				coords.push(Prop(rs.s[curIdx].c));
 			}
 			}
 
 
-			return {pathNames: path, pathParts: coords};
+			curIdx += 1;
 		}
 		}
 
 
+		return {pathNames: path, pathParts: coords};
+	}
+
+	public function getReferences(id: String, withCodePaths = true, returnAtFirstRef = false, sheet: cdb.Sheet, ?codeFileCache: Array<{path: String, data:String}>, ?prefabFileCache: Array<{path: String, data:String}>) : Array<{str:String, ?goto:Void->Void}> {
+		#if hl
+		return [];
+		#else
+		if( id == null )
+			return [];
+
 		var results = sheet.getReferencesFromId(id);
 		var results = sheet.getReferencesFromId(id);
 		var message = new Array<{str:String, ?goto:Void->Void}>();
 		var message = new Array<{str:String, ?goto:Void->Void}>();
 		if( results != null ) {
 		if( results != null ) {
@@ -1433,8 +1432,8 @@ class Editor extends Component {
 		}
 		}
 	}
 	}
 
 
-	function openReference2(rootSheet : cdb.Sheet, path: Path) {
-		ide.open("hide.view.CdbTable", {}, function(view) Std.downcast(view,hide.view.CdbTable).goto2(rootSheet,path));
+	public static function openReference2(rootSheet : cdb.Sheet, path: Path) {
+		hide.Ide.inst.open("hide.view.CdbTable", {}, function(view) Std.downcast(view,hide.view.CdbTable).goto2(rootSheet,path));
 	}
 	}
 
 
 	function openReference( s : cdb.Sheet, line : Int, column : Int, ?scriptLine: Int ) {
 	function openReference( s : cdb.Sheet, line : Int, column : Int, ?scriptLine: Int ) {

+ 5 - 0
hide/view/FileTree.hx

@@ -129,6 +129,7 @@ class FileTree extends FileView {
 				{ label : "Copy Path", enabled : current != null, click : function() { ide.setClipboard(current); } },
 				{ label : "Copy Path", enabled : current != null, click : function() { ide.setClipboard(current); } },
 				{ label : "Copy Absolute Path", enabled : current != null, click : function() { ide.setClipboard(Ide.inst.getPath(current)); } },
 				{ label : "Copy Absolute Path", enabled : current != null, click : function() { ide.setClipboard(Ide.inst.getPath(current)); } },
 				{ label : "Open in Explorer", enabled : current != null, click : function() { onExploreFile(current); } },
 				{ label : "Open in Explorer", enabled : current != null, click : function() { onExploreFile(current); } },
+				{ label : "Find References", enabled : current != null, click : onFindPathRef.bind(current)},
 				{ label : "", isSeparator: true },
 				{ label : "", isSeparator: true },
 				{ label : "Clone", enabled : current != null, click : function() {
 				{ label : "Clone", enabled : current != null, click : function() {
 						try {
 						try {
@@ -187,6 +188,10 @@ class FileTree extends FileView {
 		return ret;
 		return ret;
 	}
 	}
 
 
+	function onFindPathRef(path: String) {
+		ide.findPathRefs(path);
+	}
+
 	function onRenameRec(path:String, name:String) {
 	function onRenameRec(path:String, name:String) {
 
 
 		var parts = path.split("/");
 		var parts = path.split("/");