Browse Source

activate() instead open() when view already exists

Nicolas Cannasse 7 years ago
parent
commit
0bbed9a6b1
4 changed files with 22 additions and 5 deletions
  1. 1 1
      hide/comp/PropsEditor.hx
  2. 11 1
      hide/ui/Ide.hx
  3. 8 1
      hide/ui/View.hx
  4. 2 2
      hide/view/Particles3D.hx

+ 1 - 1
hide/comp/PropsEditor.hx

@@ -23,7 +23,7 @@ class PropsEditor extends Component {
 	}
 	}
 
 
 	public function clear() {
 	public function clear() {
-		root.html('');
+		root.empty();
 		fields = [];
 		fields = [];
 	}
 	}
 
 

+ 11 - 1
hide/ui/Ide.hx

@@ -472,11 +472,21 @@ class Ide {
 	}
 	}
 
 
 	public function open( component : String, state : Dynamic, ?onCreate : View<Dynamic> -> Void ) {
 	public function open( component : String, state : Dynamic, ?onCreate : View<Dynamic> -> Void ) {
-		var c = View.viewClasses.get(component);
+		if( state == null ) state = {};
 
 
+		var c = View.viewClasses.get(component);
 		if( c == null )
 		if( c == null )
 			throw "Unknown component " + component;
 			throw "Unknown component " + component;
 
 
+		state.componentName = component;
+		for( v in views ) {
+			if( v.viewClass == component && haxe.Json.stringify(v.state) == haxe.Json.stringify(state) ) {
+				v.activate();
+				if( onCreate != null ) onCreate(v);
+				return;
+			}
+		}
+
 		var options = c.options;
 		var options = c.options;
 
 
 		var bestTarget : golden.Container = null;
 		var bestTarget : golden.Container = null;

+ 8 - 1
hide/ui/View.hx

@@ -124,7 +124,7 @@ class View<T> extends hide.comp.Component {
 				watches.remove(w);
 				watches.remove(w);
 			}
 			}
 		syncTitle();
 		syncTitle();
-		root.html('');
+		root.empty();
 		root.off();
 		root.off();
 		onDisplay();
 		onDisplay();
 	}
 	}
@@ -136,6 +136,13 @@ class View<T> extends hide.comp.Component {
 	public function onResize() {
 	public function onResize() {
 	}
 	}
 
 
+	/**
+		Gives focus if part of a tab group
+	**/
+	public function activate() {
+		if( container != null ) container.parent.parent.setActiveContentItem(container.parent);
+	}
+
 	public function saveState() {
 	public function saveState() {
 		container.setState(state);
 		container.setState(state);
 	}
 	}

+ 2 - 2
hide/view/Particles3D.hx

@@ -257,7 +257,7 @@ class Particles3D extends FileView {
 					scene.init(this.props, model);
 					scene.init(this.props, model);
 
 
 					var prev = attach.val();
 					var prev = attach.val();
-					attach.html('');
+					attach.empty();
 					function addRec(o:h3d.scene.Object) {
 					function addRec(o:h3d.scene.Object) {
 						if( o.name != null )
 						if( o.name != null )
 							new Element('<option value="${o.name}" ${o.name == prev ? "selected='selected'" : ""}>${o.name}</option>').appendTo(attach);
 							new Element('<option value="${o.name}" ${o.name == prev ? "selected='selected'" : ""}>${o.name}</option>').appendTo(attach);
@@ -271,7 +271,7 @@ class Particles3D extends FileView {
 					addRec(model);
 					addRec(model);
 
 
 					var prev = anim.val();
 					var prev = anim.val();
-					anim.html('');
+					anim.empty();
 					var anims = scene.listAnims(props.model);
 					var anims = scene.listAnims(props.model);
 					new Element('<option value="">-- none --</option>').appendTo(anim);
 					new Element('<option value="">-- none --</option>').appendTo(anim);
 					for( a in anims ) {
 					for( a in anims ) {