ncannasse пре 7 година
родитељ
комит
4d40b9450b
7 измењених фајлова са 99 додато и 27 уклоњено
  1. 1 1
      .vscode/launch.json
  2. 7 0
      bin/style.css
  3. 11 2
      bin/style.less
  4. 0 1
      hide.hxml
  5. 75 22
      hide/Ide.hx
  6. 4 1
      hide/ui/View.hx
  7. 1 0
      libs/nw/Window.hx

+ 1 - 1
.vscode/launch.json

@@ -9,7 +9,7 @@
             "request": "attach",
             "name": "Attach to NWjs",
             "port": 9222,
-            "webRoot": "${workspaceFolder}"
+            "webRoot": "${workspaceFolder}/bin"
         }
     ]
 }

+ 7 - 0
bin/style.css

@@ -456,6 +456,13 @@ div.lm_close_tab {
 div.lm_close_tab:hover {
   background-color: #555 !important;
 }
+body.hide-subview .lm_header .lm_tab {
+  padding-right: 10px;
+}
+body.hide-subview .lm_close_tab,
+body.hide-subview .lm_controls {
+  display: none;
+}
 /* JSTree fixes */
 .jstree {
   background: transparent !important;

+ 11 - 2
bin/style.less

@@ -260,7 +260,7 @@ input[type=checkbox] {
 			font-size: 12px;
 			margin-left: 6px;
 			margin-right: 6px;
-			text-shadow: none;	
+			text-shadow: none;
 		}
 		label.locked {
 			color: #000;
@@ -493,11 +493,20 @@ input[type=checkbox] {
 div.lm_close_tab { top : 0px !important; right : 0px !important; width : 20px !important; height : 18px !important; }
 div.lm_close_tab:hover { background-color : #555 !important; }
 
+body.hide-subview {
+	.lm_header .lm_tab {
+		padding-right: 10px;
+	}
+	.lm_close_tab, .lm_controls {
+		display : none;
+	}
+}
+
 /* JSTree fixes */
 
 .jstree {
 	background:transparent !important;
-	
+
 	.filtered {
 		display: none;
 	}

+ 0 - 1
hide.hxml

@@ -7,7 +7,6 @@
 -js bin/hide.js
 -main hide.Ide
 -D hscriptPos
--D old-error-format
 -D multidriver
 -D editor
 -dce no

+ 75 - 22
hide/Ide.hx

@@ -38,6 +38,7 @@ class Ide {
 	var views : Array<hide.ui.View<Dynamic>> = [];
 
 	var renderers : Array<h3d.mat.MaterialSetup>;
+	var subView : { component : String, state : Dynamic, events : {} };
 
 	static var firstInit = true;
 
@@ -47,13 +48,30 @@ class Ide {
 		var cwd = Sys.getCwd();
 		props = Props.loadForProject(cwd, cwd+"/res");
 
-		var wp = props.global.current.hide.windowPos;
-		if( wp != null ) {
-			if( wp.w > 400 && wp.h > 300 )
-				window.resizeBy(wp.w - Std.int(window.window.outerWidth), wp.h - Std.int(window.window.outerHeight));
-			if( wp.x >= 0 && wp.y >= 0 ) {
-				window.moveTo(wp.x, wp.y);
-				if( wp.max ) window.maximize();
+		var args = js.Browser.document.URL.split("?")[1];
+		if( args != null ) {
+			var parts = args.split("&");
+			var vars = new Map();
+			for( p in parts ) {
+				var p = p.split("=");
+				vars.set(p[0],StringTools.urlDecode(p[1]));
+			}
+			var sub = vars.get("subView");
+			if( sub != null ) {
+				var obj = untyped global.sharedRefs.get(Std.parseInt(vars.get("sid")));
+				subView = { component : sub, state : obj.state, events : obj.events };
+			}
+		}
+
+		if( subView == null ) {
+			var wp = props.global.current.hide.windowPos;
+			if( wp != null ) {
+				if( wp.w > 400 && wp.h > 300 )
+					window.resizeBy(wp.w - Std.int(window.window.outerWidth), wp.h - Std.int(window.window.outerHeight));
+				if( wp.x >= 0 && wp.y >= 0 ) {
+					window.moveTo(wp.x, wp.y);
+					if( wp.max ) window.maximize();
+				}
 			}
 		}
 		window.show(true);
@@ -113,6 +131,8 @@ class Ide {
 			return false;
 		}
 
+		if( subView != null ) body.className +=" hide-subview";
+
 		// Listen to FileTree dnd
 		new Element(window.window.document).on("dnd_stop.vakata.jstree", function(e, data) {
 			if(data.data.jstree == null) return;
@@ -183,7 +203,8 @@ class Ide {
 			ideProps.windowPos.w = Std.int(window.window.outerWidth);
 			ideProps.windowPos.h = Std.int(window.window.outerHeight);
 		}
-		props.global.save();
+		if( subView == null )
+			props.global.save();
 	}
 
 	function initLayout( ?state : { name : String, state : Dynamic } ) {
@@ -210,6 +231,9 @@ class Ide {
 		if( state == null )
 			state = defaultLayout;
 
+		if( subView != null )
+			state = { name : "SubView", state : [] };
+
 		this.currentLayout = state;
 
 		var config : golden.Config = {
@@ -241,25 +265,34 @@ class Ide {
 			if( !ideProps.autoSaveLayout )
 				return;
 			defaultLayout.state = saveLayout();
-			props.global.save();
+			if( subView == null ) props.global.save();
 		});
 
-		// error recovery if invalid component
-		haxe.Timer.delay(function() {
-			initializing = false;
-			if( layout.isInitialised ) {
-				if( firstInit ) {
-					firstInit = false;
-					for( file in nw.App.argv ) {
-						if( !sys.FileSystem.exists(file) ) continue;
-						openFile(file);
-					}
+		var waitCount = 0;
+		function waitInit() {
+			waitCount++;
+			if( !layout.isInitialised ) {
+				if( waitCount > 20 ) {
+					// timeout : error recovery if invalid component
+					state.state = [];
+					initLayout();
+					return;
 				}
+				haxe.Timer.delay(waitInit, 50);
 				return;
 			}
-			state.state = [];
-			initLayout();
-		}, 1000);
+			initializing = false;
+			if( firstInit ) {
+				firstInit = false;
+				for( file in nw.App.argv ) {
+					if( !sys.FileSystem.exists(file) ) continue;
+					openFile(file);
+				}
+				if( subView != null )
+					open(subView.component, subView.state);
+			}
+		};
+		waitInit();
 
 		hxd.System.setLoop(mainLoop);
 	}
@@ -433,6 +466,9 @@ class Ide {
 	}
 
 	function initMenu() {
+
+		if( subView != null ) return;
+
 		var menu = new Element(new Element("#mainmenu").get(0).outerHTML);
 
 		// project
@@ -543,6 +579,23 @@ class Ide {
 		open(ext.component, { path : path }, onCreate);
 	}
 
+	public function openSubView<T>( component : Class<hide.ui.View<T>>, state : T, events : {} ) {
+		var sharedRefs : Map<Int,Dynamic> = untyped global.sharedRefs;
+		if( sharedRefs == null ) {
+			sharedRefs = new Map();
+			untyped global.sharedRefs = sharedRefs;
+		}
+		var id = 0;
+		while( sharedRefs.exists(id) ) id++;
+		sharedRefs.set(id,{ state : state, events : events });
+		var compName = Type.getClassName(component);
+		nw.Window.open("app.html?subView="+compName+"&sid="+id,{ id : compName });
+	}
+
+	public function callParentView( name : String, param : Dynamic ) {
+		if( subView != null ) Reflect.callMethod(subView.events,Reflect.field(subView.events,name),[param]);
+	}
+
 	public function open( component : String, state : Dynamic, ?onCreate : hide.ui.View<Dynamic> -> Void ) {
 		if( state == null ) state = {};
 

+ 4 - 1
hide/ui/View.hx

@@ -107,7 +107,8 @@ class View<T> extends hide.comp.Component {
 
 		container.on("tab", function(e) {
 			container.tab.element.contextmenu(function(e) {
-				new hide.comp.ContextMenu(buildTabMenu());
+				var menu = buildTabMenu();
+				if( menu.length > 0 ) new hide.comp.ContextMenu(menu);
 				e.preventDefault();
 			});
 		});
@@ -169,6 +170,8 @@ class View<T> extends hide.comp.Component {
 	}
 
 	function buildTabMenu() : Array<hide.comp.ContextMenu.ContextMenuItem> {
+		if( @:privateAccess ide.subView != null )
+			return [];
 		return [
 			{ label : "Close", click : close },
 			{ label : "Close Others", click : function() for( v in @:privateAccess ide.views ) if( v != this && v.container.tab.header == container.tab.header ) v.close() },

+ 1 - 0
libs/nw/Window.hx

@@ -30,5 +30,6 @@ extern class Window {
 	public function close( ?force : Bool ) : Void;
 
 	public static function get() : Window;
+	public static function open( url : String, ?params : {?new_instance:Bool,?inject_js_start:String,?inject_js_end:String,?id:String}, ?callb:Window->Void ) : Void;
 
 }