فهرست منبع

Find Ref -> Goto prefab now selects the prefabs that holds the ref, fixed crash in goto ref cdb

Clément Espeute 11 ماه پیش
والد
کامیت
d9622a5dbc
6فایلهای تغییر یافته به همراه101 افزوده شده و 11 حذف شده
  1. 19 3
      hide/Ide.hx
  2. 36 2
      hide/comp/SceneEditor.hx
  3. 1 1
      hide/comp/cdb/Editor.hx
  4. 7 2
      hide/view/CdbTable.hx
  5. 20 0
      hide/view/FXEditor.hx
  6. 18 3
      hide/view/Prefab.hx

+ 19 - 3
hide/Ide.hx

@@ -815,7 +815,7 @@ class Ide extends hide.tools.IdeData {
 
 		filterPaths(filter);
 
-		open("hide.view.RefViewer", null, function(view) {
+		open("hide.view.RefViewer", null, null, function(view) {
 			var refViewer : hide.view.RefViewer = cast view;
 			refViewer.showRefs(refs, 'Number of references to "$path"');
 		});
@@ -869,14 +869,30 @@ class Ide extends hide.tools.IdeData {
 
 		{
 			var currentPath : String = null;
+			var currentPrefab: hrt.prefab.Prefab = null;
 			context.getRef = () -> {
-				var p = currentPath; // Make capture
-				return {str: p, goto: () -> openFile(getPath(p))};
+				var p = currentPath; // needed capture
+				var cp = currentPrefab; // needed capture
+				return {str: '$p:${cp.getAbsPath()}', goto: () -> openFile(getPath(p), null, (view) -> {
+					var pref = Std.downcast(view, hide.view.Prefab);
+					if (pref != null) {
+						pref.delaySceneEditor(() -> {
+							pref.sceneEditor.selectElementsIndirect([cp]);
+						});
+					}
+					else {
+						var fx = Std.downcast(view, hide.view.FXEditor);
+						fx.delaySceneEditor(() -> {
+							@:privateAccess fx.sceneEditor.selectElementsIndirect([cp]);
+						});
+					}
+				})};
 			};
 
 			filterPrefabs(function(p:hrt.prefab.Prefab, path: String) {
 				context.changed = false;
 				currentPath = path;
+				currentPrefab = p;
 				p.source = context.filter(p.source);
 				var h = p.getHideProps();
 				if( h.onResourceRenamed != null )

+ 36 - 2
hide/comp/SceneEditor.hx

@@ -880,6 +880,7 @@ class SceneEditor {
 	public var scene : hide.comp.Scene;
 	public var properties : hide.comp.PropsEditor;
 
+
 	//public var context(default,null) : hrt.prefab.Context;
 	public var curEdit(default, null) : SceneEditorContext;
 	public var snapToGround = false;
@@ -922,6 +923,8 @@ class SceneEditor {
 	public var showGrid = false;
 
 	var statusText : h2d.Text;
+	var ready = false;
+	var readyDelayed : Array<() -> Void> = [];
 
 	function getRootObjects3d() : Array<Object> {
 		var arr = [];
@@ -969,6 +972,7 @@ class SceneEditor {
 	public var lastFocusObjects : Array<Object> = [];
 
 	public function new(view, data) {
+		ready = false;
 		ide = hide.Ide.inst;
 		this.view = view;
 		this.sceneData = data;
@@ -1141,6 +1145,15 @@ class SceneEditor {
 		scene.s3d.renderer.showEditorOutlines = show;
 	}
 
+	public function delayReady(callback: () -> Void) {
+		if (ready) {
+			callback();
+		}
+		else {
+			readyDelayed.push(callback);
+		}
+	}
+
 	public function updateGrid() {
 		if(grid != null) {
 			grid.remove();
@@ -1594,7 +1607,6 @@ class SceneEditor {
     }
 
 	function onSceneReady() {
-
 		tree.saveDisplayKey = view.saveDisplayKey + '/tree';
 		renderPropsTree.saveDisplayKey = view.saveDisplayKey + '/renderPropsTree';
 
@@ -1877,11 +1889,18 @@ class SceneEditor {
 
 		tree.applyStyle = function(p, el) applyTreeStyle(p, el);
 		renderPropsTree.applyStyle = function(p, el) applyTreeStyle(p, el, renderPropsTree);
-		selectElements([]);
+
+		//selectElements([]);
 		refreshScene();
 		this.camera2D = camera2D;
 
 		updateViewportOverlays();
+
+		ready = true;
+		for (callback in readyDelayed) {
+			callback();
+		}
+		readyDelayed.empty();
 	}
 
 	function checkAllowParent(prefabInf:hrt.prefab.Prefab.PrefabInfo, prefabParent : PrefabElement) : Bool {
@@ -3327,6 +3346,21 @@ class SceneEditor {
 		impl(elts,mode);
 	}
 
+	/**
+		Select prefabs that are in a clone of sceneData
+	**/
+	public function selectElementsIndirect(elts : Array<PrefabElement>, ?mode : SelectMode = Default) {
+		var toSelect : Array<PrefabElement> = [];
+		var flat = sceneData.flatten();
+		for (elt in elts) {
+			var idx = elt.getRoot().flatten().indexOf(elt);
+			var found = flat[idx];
+			if (found != null)
+				toSelect.push(found);
+		}
+		selectElements(toSelect, mode);
+	}
+
 	function hasBeenRemoved( e : hrt.prefab.Prefab ) {
 		var root = e;
 

+ 1 - 1
hide/comp/cdb/Editor.hx

@@ -1433,7 +1433,7 @@ class Editor extends Component {
 	}
 
 	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));
+		hide.Ide.inst.open("hide.view.CdbTable", {}, null, function(view) Std.downcast(view,hide.view.CdbTable).goto2(rootSheet,path));
 	}
 
 	function openReference( s : cdb.Sheet, line : Int, column : Int, ?scriptLine: Int ) {

+ 7 - 2
hide/view/CdbTable.hx

@@ -25,11 +25,16 @@ class CdbTable extends hide.ui.View<{}> {
 	}
 
 	public function goto2(rootSheet : cdb.Sheet, path: hide.comp.cdb.Editor.Path) {
-
-
 		var sheets = [for( s in getSheets() ) s.name];
 		var index = sheets.indexOf(rootSheet.name);
 		if( index < 0 ) return;
+
+		// Tabs can be null if the sheet is opened but hasn't had time to properly initilalize, so we delay the call to this function
+		if (tabs == null) {
+			haxe.Timer.delay(() -> goto2(rootSheet, path), 50);
+			return;
+		}
+
 		if (tabs.currentTab.get(0) != tabContents[index].parent().get(0)) {
 			@:privateAccess editor.currentFilters = [];
 			tabs.currentTab = tabContents[index].parent();

+ 20 - 0
hide/view/FXEditor.hx

@@ -311,6 +311,7 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 class FXEditor extends hide.view.FileView {
 
 	var sceneEditor : FXSceneEditor;
+	public var selectOnLoad : Array<hrt.prefab.Prefab> = null;
 	var data : hrt.prefab.fx.BaseFX;
 	var is2D : Bool = false;
 
@@ -444,6 +445,11 @@ class FXEditor extends hide.view.FileView {
 		var tabs = new hide.comp.Tabs(null,element.find(".tabs"));
 		sceneEditor = new FXSceneEditor(this, cast(data, hrt.prefab.Prefab));
 
+		for (callback in sceneReadyDelayed) {
+			sceneEditor.delayReady(callback);
+		}
+		sceneReadyDelayed.empty();
+
 		if (json.type == "fx2d") {
 			is2D = true;
 			sceneEditor.is2D = true;
@@ -541,6 +547,20 @@ class FXEditor extends hide.view.FileView {
 		setRenderPropsEditionVisibility(rpEditionvisible);
 	}
 
+	var sceneReadyDelayed : Array<() -> Void> = [];
+
+	/**
+		Call a function when the sceneEditor is properly initialized
+	**/
+	public function delaySceneEditor(callback : () -> Void) {
+		if (sceneEditor != null) {
+			sceneEditor.delayReady(callback);
+		}
+		else {
+			sceneReadyDelayed.push(callback);
+		}
+	}
+
 	function refreshLayout() {
 		if (animPanel != null) animPanel.setSize();
 		if (treePanel != null) treePanel.setSize();

+ 18 - 3
hide/view/Prefab.hx

@@ -186,9 +186,6 @@ class Prefab extends hide.view.FileView {
 
 	var resizablePanel : hide.comp.ResizablePanel;
 
-
-
-
 	// autoSync
 	var autoSync : Bool;
 	var currentVersion : Int = 0;
@@ -226,8 +223,26 @@ class Prefab extends hide.view.FileView {
 		data = new hrt.prefab.Prefab(null, null);
 	}
 
+	var sceneReadyDelayed : Array<() -> Void> = [];
+
+	/**
+		Call a function when the sceneEditor is properly initialized
+	**/
+	public function delaySceneEditor(callback : () -> Void) {
+		if (sceneEditor != null) {
+			sceneEditor.delayReady(callback);
+		}
+		else {
+			sceneReadyDelayed.push(callback);
+		}
+	}
+
 	function createEditor() {
 		sceneEditor = new PrefabSceneEditor(this, data);
+		for (callback in sceneReadyDelayed) {
+			sceneEditor.delayReady(callback);
+		}
+		sceneReadyDelayed.empty();
 	}
 
 	override function onDisplay() {