Przeglądaj źródła

added default position for panels (easier layout create/manage)

Nicolas Cannnasse 8 lat temu
rodzic
commit
a188949000

+ 123 - 22
bin/hide.js

@@ -10512,6 +10512,29 @@ haxe_ds_ObjectMap.prototype = {
 	}
 	,__class__: haxe_ds_ObjectMap
 };
+var haxe_ds__$StringMap_StringMapIterator = function(map,keys) {
+	this.map = map;
+	this.keys = keys;
+	this.index = 0;
+	this.count = keys.length;
+};
+$hxClasses["haxe.ds._StringMap.StringMapIterator"] = haxe_ds__$StringMap_StringMapIterator;
+haxe_ds__$StringMap_StringMapIterator.__name__ = ["haxe","ds","_StringMap","StringMapIterator"];
+haxe_ds__$StringMap_StringMapIterator.prototype = {
+	hasNext: function() {
+		return this.index < this.count;
+	}
+	,next: function() {
+		var _this = this.map;
+		var key = this.keys[this.index++];
+		if(__map_reserved[key] != null) {
+			return _this.getReserved(key);
+		} else {
+			return _this.h[key];
+		}
+	}
+	,__class__: haxe_ds__$StringMap_StringMapIterator
+};
 var haxe_ds_StringMap = function() {
 	this.h = { };
 };
@@ -10964,23 +10987,23 @@ hide_ui_Ide.prototype = {
 		this.currentLayout = state;
 		var config = { content : state.state};
 		this.layout = new GoldenLayout(config);
-		var _g2 = 0;
-		var _g11 = hide_ui_View.viewClasses;
-		while(_g2 < _g11.length) {
-			var cl = [_g11[_g2]];
-			++_g2;
-			this.layout.registerComponent(Type.getClassName(cl[0]),(function(cl1) {
+		var _this = hide_ui_View.viewClasses;
+		var vcl = new haxe_ds__$StringMap_StringMapIterator(_this,_this.arrayKeys());
+		while(vcl.hasNext()) {
+			var vcl1 = vcl.next();
+			var vcl2 = [vcl1];
+			this.layout.registerComponent(vcl2[0].name,(function(vcl3) {
 				return function(cont,state1) {
-					var view = Type.createInstance(cl1[0],[state1]);
+					var view = Type.createInstance(vcl3[0].cl,[state1]);
 					view.setContainer(cont);
 					try {
 						view.onDisplay(cont.getElement());
 					} catch( e ) {
 						if (e instanceof js__$Boot_HaxeError) e = e.val;
-						js_Browser.alert(Type.getClassName(cl1[0]) + ":" + Std.string(e));
+						js_Browser.alert(vcl3[0].name + ":" + Std.string(e));
 					}
 				};
-			})(cl));
+			})(vcl2));
 		}
 		this.layout.init();
 		this.layout.on("stateChanged",function() {
@@ -11166,17 +11189,63 @@ hide_ui_Ide.prototype = {
 		this.window.menu = new hide_ui_Menu(this.menu).root;
 	}
 	,open: function(component,state,onCreate) {
-		if(this.layout.root.contentItems.length == 0) {
-			this.layout.root.addChild({ type : "row"});
+		var _this = hide_ui_View.viewClasses;
+		var pos = (__map_reserved[component] != null ? _this.getReserved(component) : _this.h[component]).position;
+		var bestTarget = null;
+		var _g = 0;
+		var _g1 = this.views;
+		while(_g < _g1.length) {
+			var v = _g1[_g];
+			++_g;
+			if(v.get_defaultPosition() == pos) {
+				if(bestTarget == null || bestTarget.width * bestTarget.height < v.container.width * v.container.height) {
+					bestTarget = v.container;
+				}
+			}
+		}
+		var index = null;
+		var target;
+		if(bestTarget != null) {
+			target = bestTarget.parent.parent;
+		} else {
+			target = this.layout.root.contentItems[0];
+			var reqKind = pos == hide_ui_DisplayPosition.Bottom ? "column" : "row";
+			if(target == null) {
+				this.layout.root.addChild({ type : "row"});
+				target = this.layout.root.contentItems[0];
+			} else if(target.type != reqKind) {
+				var config = this.layout.toConfig().content;
+				var items = target.getItemsByFilter(function(r) {
+					return r.type == "component";
+				});
+				var _g2 = 0;
+				var _g11 = this.views.slice();
+				while(_g2 < _g11.length) {
+					var v1 = _g11[_g2];
+					++_g2;
+					if(HxOverrides.remove(items,v1.container.parent)) {
+						v1.container.close();
+					}
+				}
+				this.layout.root.addChild({ type : reqKind, content : config});
+				target = this.layout.root.contentItems[0];
+				if(pos == hide_ui_DisplayPosition.Left) {
+					index = 0;
+				}
+			}
 		}
-		var target = this.layout.root.contentItems[0];
 		if(onCreate != null) {
 			target.on("componentCreated",function(c) {
 				target.off("componentCreated");
 				onCreate(c.origin.__view);
 			});
 		}
-		target.addChild({ type : "component", componentName : component, componentState : state});
+		var config1 = { type : "component", componentName : component, componentState : state};
+		if(index == null) {
+			target.addChild(config1);
+		} else {
+			target.addChild(config1,index);
+		}
 	}
 	,__class__: hide_ui_Ide
 };
@@ -11340,15 +11409,41 @@ hide_ui_Props.prototype = {
 	}
 	,__class__: hide_ui_Props
 };
+var hide_ui_DisplayPosition = $hxClasses["hide.ui.DisplayPosition"] = { __ename__ : true, __constructs__ : ["Left","Center","Right","Bottom"] };
+hide_ui_DisplayPosition.Left = ["Left",0];
+hide_ui_DisplayPosition.Left.toString = $estr;
+hide_ui_DisplayPosition.Left.__enum__ = hide_ui_DisplayPosition;
+hide_ui_DisplayPosition.Center = ["Center",1];
+hide_ui_DisplayPosition.Center.toString = $estr;
+hide_ui_DisplayPosition.Center.__enum__ = hide_ui_DisplayPosition;
+hide_ui_DisplayPosition.Right = ["Right",2];
+hide_ui_DisplayPosition.Right.toString = $estr;
+hide_ui_DisplayPosition.Right.__enum__ = hide_ui_DisplayPosition;
+hide_ui_DisplayPosition.Bottom = ["Bottom",3];
+hide_ui_DisplayPosition.Bottom.toString = $estr;
+hide_ui_DisplayPosition.Bottom.__enum__ = hide_ui_DisplayPosition;
+hide_ui_DisplayPosition.__empty_constructs__ = [hide_ui_DisplayPosition.Left,hide_ui_DisplayPosition.Center,hide_ui_DisplayPosition.Right,hide_ui_DisplayPosition.Bottom];
 var hide_ui_View = function(state) {
 	this.state = state;
 	this.ide = hide_ui_Ide.inst;
 };
 $hxClasses["hide.ui.View"] = hide_ui_View;
 hide_ui_View.__name__ = ["hide","ui","View"];
-hide_ui_View.register = function(cl) {
-	if(hide_ui_View.viewClasses.indexOf(cl) < 0) {
-		hide_ui_View.viewClasses.push(cl);
+hide_ui_View.register = function(cl,position) {
+	var name = Type.getClassName(cl);
+	var _this = hide_ui_View.viewClasses;
+	if(__map_reserved[name] != null ? _this.existsReserved(name) : _this.h.hasOwnProperty(name)) {
+		return null;
+	}
+	if(position == null) {
+		position = hide_ui_DisplayPosition.Center;
+	}
+	var _this1 = hide_ui_View.viewClasses;
+	var value = { name : name, cl : cl, position : position};
+	if(__map_reserved[name] != null) {
+		_this1.setReserved(name,value);
+	} else {
+		_this1.h[name] = value;
 	}
 	return null;
 };
@@ -11401,6 +11496,12 @@ hide_ui_View.prototype = {
 	,get_contentHeight: function() {
 		return this.container.height;
 	}
+	,get_defaultPosition: function() {
+		var this1 = hide_ui_View.viewClasses;
+		var key = Type.getClassName(js_Boot.getClass(this));
+		var _this = this1;
+		return (__map_reserved[key] != null ? _this.getReserved(key) : _this.h[key]).position;
+	}
 	,__class__: hide_ui_View
 };
 var hide_view_About = function(state) {
@@ -11539,11 +11640,11 @@ hide_view_FileTree.prototype = $extend(hide_ui_View.prototype,{
 		var prev = this.lastOpen;
 		this.lastOpen = null;
 		this.ide.open(ext.component,{ path : path},function(c) {
+			if(prev != null) {
+				prev.close();
+			}
 			_gthis.lastOpen = c;
 		});
-		if(prev != null) {
-			prev.close();
-		}
 	}
 	,isIgnored: function(path,file) {
 		if(HxOverrides.cca(file,0) == 46) {
@@ -20145,10 +20246,10 @@ h3d_shader_VolumeDecal.SRC = "oy4:namey22:h3d.shader.VolumeDecaly4:funsaoy3:retj
 haxe_Unserializer.DEFAULT_RESOLVER = new haxe__$Unserializer_DefaultResolver();
 haxe_Unserializer.BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%:";
 haxe_ds_ObjectMap.count = 0;
-hide_ui_View.viewClasses = [];
-hide_view_About._ = hide_ui_View.register(hide_view_About);
+hide_ui_View.viewClasses = new haxe_ds_StringMap();
+hide_view_About._ = hide_ui_View.register(hide_view_About,hide_ui_DisplayPosition.Bottom);
 hide_view_FileTree.EXTENSIONS = new haxe_ds_StringMap();
-hide_view_FileTree._ = hide_ui_View.register(hide_view_FileTree);
+hide_view_FileTree._ = hide_ui_View.register(hide_view_FileTree,hide_ui_DisplayPosition.Left);
 hide_view_Image._ = hide_view_FileTree.registerExtension(hide_view_Image,["png","jpg","jpeg","gif"],{ icon : "picture-o"});
 hide_view_Script._ = (function($this) {
 	var $r;

+ 0 - 0
bin/libs/monaco/vs/language/typescript/src/worker.js


+ 43 - 10
hide/ui/Ide.hx

@@ -40,7 +40,7 @@ class Ide {
 		window.on('resize', function() haxe.Timer.delay(onWindowChange,100));
 		window.on('close', function() {
 			for( v in views )
-				if( @:privateAccess !v.onBeforeClose() )
+				if( !v.onBeforeClose() )
 					return;
 			window.close(true);
 		});
@@ -89,11 +89,11 @@ class Ide {
 		};
 		layout = new golden.Layout(config);
 
-		for( cl in @:privateAccess View.viewClasses )
-			layout.registerComponent(Type.getClassName(cl),function(cont,state) {
-				var view = Type.createInstance(cl,[state]);
+		for( vcl in View.viewClasses )
+			layout.registerComponent(vcl.name,function(cont,state) {
+				var view = Type.createInstance(vcl.cl,[state]);
 				view.setContainer(cont);
-				try view.onDisplay(cont.getElement()) catch( e : Dynamic ) js.Browser.alert(Type.getClassName(cl)+":"+e);
+				try view.onDisplay(cont.getElement()) catch( e : Dynamic ) js.Browser.alert(vcl.name+":"+e);
 			});
 
 		layout.init();
@@ -239,19 +239,52 @@ class Ide {
 	}
 
 	public function open( component : String, state : Dynamic, ?onCreate : View<Dynamic> -> Void ) {
-		if( layout.root.contentItems.length == 0 )
-			layout.root.addChild({ type : Row });
-		var target = layout.root.contentItems[0];
+		var pos = View.viewClasses.get(component).position;
+		
+		var bestTarget : golden.Container = null;
+		for( v in views )
+			if( v.defaultPosition == pos ) {
+				if( bestTarget == null || bestTarget.width * bestTarget.height < v.container.width * v.container.height )
+					bestTarget = v.container;
+			}
+
+		var index : Null<Int> = null;
+		var target;
+		if( bestTarget != null ) 
+			target = bestTarget.parent.parent;
+		else {
+			target = layout.root.contentItems[0];
+			var reqKind : golden.Config.ItemType = pos == Bottom ? Column : Row;
+			if( target == null ) {
+				layout.root.addChild({ type : Row });
+				target = layout.root.contentItems[0];
+			} else if( target.type != reqKind ) {
+				// a bit tricky : change the top 'stack' into a 'row'
+				// require closing all and reopening (sadly)
+				var config = layout.toConfig().content;
+				var items = target.getItemsByFilter(function(r) return r.type == Component);
+				for( v in views.copy() )
+					if( items.remove(v.container.parent) )
+						v.container.close();
+				layout.root.addChild({ type : reqKind, content : config });
+				target = layout.root.contentItems[0];
+				if( pos == Left ) index = 0;
+			}
+		}
 		if( onCreate != null )
 			target.on("componentCreated", function(c) {
 				target.off("componentCreated");
 				onCreate(untyped c.origin.__view);
 			});
-		target.addChild({
+		var config : golden.Config.ItemConfig = {
 			type : Component,
 			componentName : component,
 			componentState : state,
-		});		
+		};
+		if( index == null )
+			target.addChild(config);
+		else
+			target.addChild(config, index);
 	}
 
 	public static var inst : Ide;

+ 18 - 5
hide/ui/View.hx

@@ -1,11 +1,19 @@
 package hide.ui;
 
-@:keepSub
+enum DisplayPosition {
+	Left;
+	Center;
+	Right;
+	Bottom;
+}
+
+@:keepSub @:allow(hide.ui.Ide)
 class View<T> {
 
 	var ide : Ide;
 	var container : golden.Container;
 	var state : T;
+	public var defaultPosition(get,never) : DisplayPosition;
 
 	var contentWidth(get,never) : Int;
 	var contentHeight(get,never) : Int;
@@ -66,11 +74,16 @@ class View<T> {
 
 	function get_contentWidth() return container.width;
 	function get_contentHeight() return container.height;
+	function get_defaultPosition() return viewClasses.get(Type.getClassName(Type.getClass(this))).position;
 
-	public static var viewClasses = new Array<Class<View<Dynamic>>>();
-	public static function register<T>( cl : Class<View<T>> ) {
-		if( viewClasses.indexOf(cl) < 0 )
-			viewClasses.push(cl);
+	public static var viewClasses = new Map<String,{ name : String, cl : Class<View<Dynamic>>, position : DisplayPosition }>();
+	public static function register<T>( cl : Class<View<T>>, ?position : DisplayPosition ) {
+		var name = Type.getClassName(cl);
+		if( viewClasses.exists(name) )
+			return null;
+		if( position == null )
+			position = Center;
+		viewClasses.set(name, { name : name, cl : cl, position : position });
 		return null;
 	}
 

+ 1 - 1
hide/view/About.hx

@@ -15,6 +15,6 @@ class About extends hide.ui.View<{}> {
 		');
 	}
 
-	static var _ = hide.ui.View.register(About);
+	static var _ = hide.ui.View.register(About, Bottom);
 
 }

+ 9 - 3
hide/view/FileTree.hx

@@ -9,6 +9,10 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 	var tree : hide.comp.IconTree;
 	var lastOpen : hide.ui.View<Dynamic>;
 
+	public function new(state) {
+		super(state);
+	}
+
 	function getExtension( file : String ) {
 		return file.indexOf(".") < 0 ? null : EXTENSIONS.get(file.split(".").pop().toLowerCase());
 	}
@@ -83,8 +87,10 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 			return;
 		var prev = lastOpen;
 		lastOpen = null;
-		ide.open(ext.component, { path : path }, function(c) lastOpen = c);
-		if( prev != null ) prev.close();
+		ide.open(ext.component, { path : path }, function(c) {
+			if( prev != null ) prev.close();
+			lastOpen = c;
+		});
 	}
  
 	function isIgnored( path : String, file : String ) {
@@ -103,6 +109,6 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 		return null;
 	}
 
-	static var _ = hide.ui.View.register(FileTree);
+	static var _ = hide.ui.View.register(FileTree, Left);
 
 }

+ 6 - 1
libs/golden/ContentItem.hx

@@ -2,12 +2,17 @@ package golden;
 
 extern class ContentItem {
 
+	var type : Config.ItemType;
 	var parent : ContentItem;
 	var contentItems : Array<ContentItem>;
-	var element : Container;
+	var element : js.jquery.JQuery;
 	var childElementContainer : Container;
+	var config : Config.ItemConfig;
 
 	public function addChild( config : Config.ItemConfig, ?index : Int ) : Void;
 	public function on( type : String, callb : Event<ContentItem> -> Void ) : Void;
 	public function off( type : String ) : Void;
+	public function replaceChild( c : ContentItem, config : Config.ItemConfig ) : Void;
+	public function getItemsByFilter( f : ContentItem -> Bool ) : Array<ContentItem>;
+
 }