Bläddra i källkod

handle file assoc, and a few more things

Nicolas Cannasse 8 år sedan
förälder
incheckning
2d9818463a

+ 5 - 0
bin/defaultProps.json

@@ -2,6 +2,11 @@
 	// define location of animations in HMD files
 	"hmd.animPaths" : [],
 
+	// model names that are hidden when open in viewer
+	"scene.autoHide" : [],
+	// background color for 2D/3D viewer
+	"scene.backgroundColor" : "#111111",
+
 	// controls
 	"key.undo" : "Ctrl-Z",
 	"key.redo" : "Ctrl-Y",

+ 0 - 4
bin/hide.bat

@@ -1,4 +0,0 @@
-@echo off
-cd bin 2>NUL
-set PATH=nwjs;%PATH%
-nw.exe --nwapp package.json

+ 2 - 0
bin/hide.cmd

@@ -0,0 +1,2 @@
+@cd %~dp0
+@nwjs\nw.exe --nwapp package.json %*

+ 1 - 1
hide.hxproj

@@ -56,7 +56,7 @@
   <options>
     <option showHiddenPaths="False" />
     <option testMovie="OpenDocument" />
-    <option testMovieCommand="bin/hide.bat" />
+    <option testMovieCommand="bin/hide" />
   </options>
   <!-- Plugin storage -->
   <storage />

+ 20 - 0
hide/comp/Scene.hx

@@ -98,6 +98,18 @@ class Scene extends Component implements h3d.IDrawable {
 		engine.init();
 	}
 
+	public function init( props : hide.ui.Props ) {
+		var autoHide : Array<String> = props.get("scene.autoHide");
+		function initRec( obj : h3d.scene.Object ) {
+			if( autoHide.indexOf(obj.name) >= 0 )
+				obj.visible = false;
+			for( o in obj )
+				initRec(o);
+		}
+		initRec(s3d);
+		engine.backgroundColor = Std.parseInt("0x"+props.get("scene.backgroundColor").substr(1)) | 0xFF000000;
+	}
+
 	function setCurrent() {
 		engine.setCurrent();
 		stage.setCurrent();
@@ -161,6 +173,14 @@ class Scene extends Component implements h3d.IDrawable {
 		var fullPath = ide.getPath(filePath);
 		if( exists(fullPath) )
 			return fullPath;
+
+		// swap drive letter
+		if( fullPath.charAt(1) == ":" && fullPath.charAt(0) != ide.projectDir.charAt(0) ) {
+			fullPath = ide.projectDir.charAt(0) + fullPath.substr(1);
+			if( exists(fullPath) )
+				return fullPath;
+		}
+
 		filePath = filePath.split("\\").join("/");
 		modelPath = ide.getPath(modelPath);
 

+ 33 - 3
hide/ui/Ide.hx

@@ -34,7 +34,8 @@ class Ide {
 	function new() {
 		inst = this;
 		window = nw.Window.get();
-		props = Props.loadForProject(Sys.getCwd());
+		var cwd = Sys.getCwd();
+		props = Props.loadForProject(cwd, cwd+"/res");
 
 		var wp = props.global.current.hide.windowPos;
 		if( wp != null ) {
@@ -60,6 +61,15 @@ class Ide {
 			window.close(true);
 		});
 
+		nw.App.on("open", function(cmd) {
+			~/"([^"]+)"/g.map(cmd, function(r) {
+				var file = r.matched(1);
+				if( sys.FileSystem.exists(file) ) openFile(file);
+				return "";
+			});
+		});
+
+		// handle cancel on type=file
 		var body = window.window.document.body;
 		body.onfocus = function(_) haxe.Timer.delay(function() new Element(body).find("input[type=file]").change().remove(), 200);
 	}
@@ -137,7 +147,13 @@ class Ide {
 		// error recovery if invalid component
 		haxe.Timer.delay(function() {
 			initializing = false;
-			if( layout.isInitialised ) return;
+			if( layout.isInitialised ) {
+				for( file in nw.App.argv ) {
+						if( !sys.FileSystem.exists(file) ) continue;
+						openFile(file);
+					}
+				return;
+			}
 			state.state = [];
 			initLayout();
 		}, 1000);
@@ -188,7 +204,7 @@ class Ide {
 			props.global.save();
 		}
 		window.title = "HIDE - " + dir;
-		props = Props.loadForProject(resourceDir);
+		props = Props.loadForProject(projectDir, resourceDir);
 		renderers = [
 			new h3d.mat.MaterialSetup("Default"),
 		];
@@ -339,6 +355,20 @@ class Ide {
 		window.menu = new Menu(menu).root;
 	}
 
+	public function openFile( file : String, ?onCreate ) {
+		var ext = @:privateAccess hide.view.FileTree.getExtension(file);
+		if( ext == null ) return;
+		// look if already open
+		var path = makeRelative(file);
+		for( v in views )
+			if( Type.getClassName(Type.getClass(v)) == ext.component && v.state.path == path ) {
+				if( v.container.tab != null )
+					v.container.parent.parent.setActiveContentItem(v.container.parent);
+				return;
+			}
+		open(ext.component, { path : path }, onCreate);
+	}
+
 	public function open( component : String, state : Dynamic, ?onCreate : View<Dynamic> -> Void ) {
 		var options = View.viewClasses.get(component).options;
 

+ 3 - 3
hide/ui/Props.hx

@@ -83,7 +83,7 @@ class Props {
 		return Reflect.field(current,key);
 	}
 
-	public static function loadForProject( resourcePath : String ) {
+	public static function loadForProject( projectPath : String, resourcePath : String ) {
 		var path = js.Node.process.argv[0].split("\\").join("/").split("/");
 		path.pop();
 		var hidePath = path.join("/");
@@ -106,7 +106,7 @@ class Props {
 				autoSaveLayout : true,
 				layouts : [],
 				recentProjects : [],
-				currentProject : resourcePath,
+				currentProject : projectPath,
 				windowPos : null,
 				renderer : null,
 			};
@@ -115,7 +115,7 @@ class Props {
 		perProject.load(resourcePath + "/props.json");
 
 		var projectUserCustom = new Props(perProject);
-		projectUserCustom.load(hidePath + "/" + resourcePath.split("/").join("_").split(":").join("_") + "_Defaults.json");
+		projectUserCustom.load(nw.App.dataPath + "/" + projectPath.split("/").join("_").split(":").join("_") + ".json");
 
 		var current = new Props(projectUserCustom);
 

+ 2 - 2
hide/view/FileTree.hx

@@ -31,7 +31,7 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 		}
 	}
 
-	function getExtension( file : String ) {
+	static function getExtension( file : String ) {
 		var ext = new haxe.io.Path(file).ext;
 		if( ext == null ) return null;
 		ext = ext.toLowerCase();
@@ -146,7 +146,7 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 			return;
 		var prev = lastOpen;
 		lastOpen = null;
-		ide.open(ext.component, { path : haxe.io.Path.isAbsolute(state.root) ? fullPath : path }, function(c) {
+		ide.openFile(fullPath, function(c) {
 			if( prev != null ) prev.close();
 			lastOpen = c;
 		});

+ 1 - 9
hide/view/Model.hx

@@ -24,18 +24,9 @@ class Model extends FileView {
 		scene.onReady = init;
 	}
 
-	function initRec( obj : h3d.scene.Object ) {
-		if( obj.name == "Selection" || obj.name == "Collide" )
-			obj.visible = false;
-		for( o in obj )
-			initRec(o);
-	}
-
 	function init() {
 		obj = scene.loadModel(state.path);
 
-		initRec(obj);
-
 		new h3d.scene.Object(scene.s3d).addChild(obj);
 		control = new h3d.scene.CameraController(scene.s3d);
 		tree = new hide.comp.SceneTree(obj,overlay, obj.name != null);
@@ -61,6 +52,7 @@ class Model extends FileView {
 			};
 		}
 
+		scene.init(props);
 		//tools.addButton("cube","Test");
 		//tools.addToggle("bank","Test toggle");
 	}

+ 1 - 0
hide/view/Particles3D.hx

@@ -172,6 +172,7 @@ class Particles3D extends FileView {
 
 		scene.resetCamera(2);
 		new h3d.scene.CameraController(scene.s3d).loadFromCamera();
+		scene.init(props);
 	}
 
 	static var _ = FileTree.registerExtension(Particles3D, ["json.particles3D"], { icon : "snowflake-o", createNew: "Particle 3D" });

+ 3 - 0
libs/golden/Container.hx

@@ -17,6 +17,9 @@ extern class Container {
 	public function setState( state : Dynamic ) : Void;
 	public function setSize( width : Int, height : Int ) : Void;
 
+	public function hide() : Void;
+	public function show() : Bool;
+
 	public function close() : Bool;
 
 	public function on( type : String, callb : Event<Container> -> Void ) : Void;

+ 1 - 0
libs/golden/ContentItem.hx

@@ -14,5 +14,6 @@ extern class ContentItem {
 	public function off( type : String ) : Void;
 	public function replaceChild( c : ContentItem, config : Config.ItemConfig ) : Void;
 	public function getItemsByFilter( f : ContentItem -> Bool ) : Array<ContentItem>;
+	public function setActiveContentItem( item : ContentItem ) : Void;
 
 }

+ 7 - 0
libs/golden/Header.hx

@@ -0,0 +1,7 @@
+package golden;
+
+extern class Header {
+
+	function setActiveContentItem( it : ContentItem ) : Void;
+
+}

+ 2 - 1
libs/golden/Tab.hx

@@ -3,6 +3,7 @@ package golden;
 extern class Tab {
 
 	public var isActive : Bool;
+	public var header : Header;
 	public var element : js.jquery.JQuery;
 
-} 
+}

+ 9 - 0
libs/nw/App.hx

@@ -0,0 +1,9 @@
+package nw;
+
+extern class App {
+
+	public static var argv(default, never) : Array<String>;
+	public static var dataPath(default, never) : String;
+	public static function on( event : String, callb : String -> Void ) : Void;
+
+}