Browse Source

sound view, open without tree exit closes previous

Nicolas Cannnasse 8 years ago
parent
commit
fef87e2a23
9 changed files with 169 additions and 23 deletions
  1. 85 11
      bin/hide.js
  2. 12 2
      hide/ui/Ide.hx
  3. 10 1
      hide/ui/View.hx
  4. 24 1
      hide/view/FileTree.hx
  5. 13 0
      hide/view/FileView.hx
  6. 1 5
      hide/view/Image.hx
  7. 14 0
      hide/view/Sound.hx
  8. 5 1
      libs/golden/Container.hx
  9. 5 2
      libs/golden/ContentItem.hx

+ 85 - 11
bin/hide.js

@@ -10921,6 +10921,7 @@ hide_ui_Ide.prototype = {
 	}
 	}
 	,initLayout: function(state) {
 	,initLayout: function(state) {
 		var _gthis = this;
 		var _gthis = this;
+		this.initializing = true;
 		if(this.layout != null) {
 		if(this.layout != null) {
 			this.layout.destroy();
 			this.layout.destroy();
 			this.layout = null;
 			this.layout = null;
@@ -10977,6 +10978,7 @@ hide_ui_Ide.prototype = {
 			_gthis.props.save();
 			_gthis.props.save();
 		});
 		});
 		haxe_Timer.delay(function() {
 		haxe_Timer.delay(function() {
+			_gthis.initializing = false;
 			if(_gthis.layout.isInitialised) {
 			if(_gthis.layout.isInitialised) {
 				return;
 				return;
 			}
 			}
@@ -11150,11 +11152,18 @@ hide_ui_Ide.prototype = {
 		});
 		});
 		this.window.menu = new hide_ui_Menu(this.menu).root;
 		this.window.menu = new hide_ui_Menu(this.menu).root;
 	}
 	}
-	,open: function(component,state) {
+	,open: function(component,state,onCreate) {
 		if(this.layout.root.contentItems.length == 0) {
 		if(this.layout.root.contentItems.length == 0) {
 			this.layout.root.addChild({ type : "row"});
 			this.layout.root.addChild({ type : "row"});
 		}
 		}
-		this.layout.root.contentItems[0].addChild({ type : "component", componentName : component, componentState : state});
+		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});
 	}
 	}
 	,__class__: hide_ui_Ide
 	,__class__: hide_ui_Ide
 };
 };
@@ -11325,7 +11334,9 @@ var hide_ui_View = function(state) {
 $hxClasses["hide.ui.View"] = hide_ui_View;
 $hxClasses["hide.ui.View"] = hide_ui_View;
 hide_ui_View.__name__ = ["hide","ui","View"];
 hide_ui_View.__name__ = ["hide","ui","View"];
 hide_ui_View.register = function(cl) {
 hide_ui_View.register = function(cl) {
-	hide_ui_View.viewClasses.push(cl);
+	if(hide_ui_View.viewClasses.indexOf(cl) < 0) {
+		hide_ui_View.viewClasses.push(cl);
+	}
 	return null;
 	return null;
 };
 };
 hide_ui_View.prototype = {
 hide_ui_View.prototype = {
@@ -11341,6 +11352,7 @@ hide_ui_View.prototype = {
 			_gthis.container.getElement().find("*").trigger("resize");
 			_gthis.container.getElement().find("*").trigger("resize");
 			_gthis.onResize();
 			_gthis.onResize();
 		});
 		});
+		cont.parent.__view = this;
 	}
 	}
 	,onDisplay: function(j) {
 	,onDisplay: function(j) {
 		j.text(Type.getClassName(js_Boot.getClass(this)) + (this.state == null ? "" : " " + Std.string(this.state)));
 		j.text(Type.getClassName(js_Boot.getClass(this)) + (this.state == null ? "" : " " + Std.string(this.state)));
@@ -11350,6 +11362,12 @@ hide_ui_View.prototype = {
 	,saveState: function() {
 	,saveState: function() {
 		this.container.setState(this.state);
 		this.container.setState(this.state);
 	}
 	}
+	,close: function() {
+		if(this.container != null) {
+			this.container.close();
+			this.container = null;
+		}
+	}
 	,get_contentWidth: function() {
 	,get_contentWidth: function() {
 		return this.container.width;
 		return this.container.width;
 	}
 	}
@@ -11461,10 +11479,28 @@ hide_view_FileTree.prototype = $extend(hide_ui_View.prototype,{
 			}
 			}
 			_gthis.saveState();
 			_gthis.saveState();
 		};
 		};
+		var mouseLeft = false;
+		var leftCount = 0;
+		e.on("mouseenter",null,function(_) {
+			mouseLeft = false;
+		});
+		e.on("mouseleave",null,function(_1) {
+			mouseLeft = true;
+			var k = leftCount += 1;
+			if(_gthis.lastOpen != null) {
+				haxe_Timer.delay(function() {
+					if(!mouseLeft || leftCount != k) {
+						return;
+					}
+					_gthis.lastOpen = null;
+				},1000);
+			}
+		});
 		this.tree.onDblClick = $bind(this,this.onOpenFile);
 		this.tree.onDblClick = $bind(this,this.onOpenFile);
 		this.tree.init();
 		this.tree.init();
 	}
 	}
 	,onOpenFile: function(path) {
 	,onOpenFile: function(path) {
+		var _gthis = this;
 		var fullPath = this.ide.getPath(this.state.root) + path;
 		var fullPath = this.ide.getPath(this.state.root) + path;
 		if(js_node_Fs.statSync(fullPath).isDirectory()) {
 		if(js_node_Fs.statSync(fullPath).isDirectory()) {
 			return;
 			return;
@@ -11473,7 +11509,14 @@ hide_view_FileTree.prototype = $extend(hide_ui_View.prototype,{
 		if(ext == null) {
 		if(ext == null) {
 			return;
 			return;
 		}
 		}
-		this.ide.open(ext.component,{ path : path});
+		var prev = this.lastOpen;
+		this.lastOpen = null;
+		this.ide.open(ext.component,{ path : path},function(c) {
+			_gthis.lastOpen = c;
+		});
+		if(prev != null) {
+			prev.close();
+		}
 	}
 	}
 	,isIgnored: function(path,file) {
 	,isIgnored: function(path,file) {
 		if(HxOverrides.cca(file,0) == 46) {
 		if(HxOverrides.cca(file,0) == 46) {
@@ -11483,17 +11526,29 @@ hide_view_FileTree.prototype = $extend(hide_ui_View.prototype,{
 	}
 	}
 	,__class__: hide_view_FileTree
 	,__class__: hide_view_FileTree
 });
 });
-var hide_view_Image = function(state) {
+var hide_view_FileView = function(state) {
 	hide_ui_View.call(this,state);
 	hide_ui_View.call(this,state);
 };
 };
-$hxClasses["hide.view.Image"] = hide_view_Image;
-hide_view_Image.__name__ = ["hide","view","Image"];
-hide_view_Image.__super__ = hide_ui_View;
-hide_view_Image.prototype = $extend(hide_ui_View.prototype,{
-	getTitle: function() {
+$hxClasses["hide.view.FileView"] = hide_view_FileView;
+hide_view_FileView.__name__ = ["hide","view","FileView"];
+hide_view_FileView.__super__ = hide_ui_View;
+hide_view_FileView.prototype = $extend(hide_ui_View.prototype,{
+	getPath: function() {
+		return this.ide.getPath(this.state.path);
+	}
+	,getTitle: function() {
 		return this.state.path.split("/").pop();
 		return this.state.path.split("/").pop();
 	}
 	}
-	,onDisplay: function(e) {
+	,__class__: hide_view_FileView
+});
+var hide_view_Image = function(state) {
+	hide_view_FileView.call(this,state);
+};
+$hxClasses["hide.view.Image"] = hide_view_Image;
+hide_view_Image.__name__ = ["hide","view","Image"];
+hide_view_Image.__super__ = hide_view_FileView;
+hide_view_Image.prototype = $extend(hide_view_FileView.prototype,{
+	onDisplay: function(e) {
 		var _gthis = this;
 		var _gthis = this;
 		this.scene = new hide_comp_Scene(e);
 		this.scene = new hide_comp_Scene(e);
 		this.scene.onReady = function() {
 		this.scene.onReady = function() {
@@ -11524,6 +11579,19 @@ hide_view_Image.prototype = $extend(hide_ui_View.prototype,{
 	}
 	}
 	,__class__: hide_view_Image
 	,__class__: hide_view_Image
 });
 });
+var hide_view_Sound = function(state) {
+	hide_view_FileView.call(this,state);
+};
+$hxClasses["hide.view.Sound"] = hide_view_Sound;
+hide_view_Sound.__name__ = ["hide","view","Sound"];
+hide_view_Sound.__super__ = hide_view_FileView;
+hide_view_Sound.prototype = $extend(hide_view_FileView.prototype,{
+	onDisplay: function(e) {
+		var path = this.getPath();
+		$("<audio " + (this.ide.initializing ? "" : "autoplay=\"autoplay\"") + " controls=\"controls\"><source src=\"file://" + this.getPath() + "\"/></audio>").appendTo(e);
+	}
+	,__class__: hide_view_Sound
+});
 var hxd_BitmapData = function() { };
 var hxd_BitmapData = function() { };
 $hxClasses["hxd.BitmapData"] = hxd_BitmapData;
 $hxClasses["hxd.BitmapData"] = hxd_BitmapData;
 hxd_BitmapData.__name__ = ["hxd","BitmapData"];
 hxd_BitmapData.__name__ = ["hxd","BitmapData"];
@@ -19984,6 +20052,12 @@ hide_view_About._ = hide_ui_View.register(hide_view_About);
 hide_view_FileTree.EXTENSIONS = new haxe_ds_StringMap();
 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_view_Image._ = hide_view_FileTree.registerExtension(hide_view_Image,["png","jpg","jpeg","gif"],{ icon : "picture-o"});
 hide_view_Image._ = hide_view_FileTree.registerExtension(hide_view_Image,["png","jpg","jpeg","gif"],{ icon : "picture-o"});
+hide_view_Sound._ = (function($this) {
+	var $r;
+	hide_view_FileTree.registerExtension(hide_view_Sound,["wav"],{ icon : "file-audio-o"});
+	$r = hide_view_FileTree.registerExtension(hide_view_Sound,["mp3","ogg"],{ icon : "music"});
+	return $r;
+}(this));
 hxd_System.setCursor = hxd_System.setNativeCursor;
 hxd_System.setCursor = hxd_System.setNativeCursor;
 hxd_System.loopInit = false;
 hxd_System.loopInit = false;
 hxd_Timer.tmod = 1;
 hxd_Timer.tmod = 1;

+ 12 - 2
hide/ui/Ide.hx

@@ -5,6 +5,7 @@ class Ide {
 	public var props : Props;
 	public var props : Props;
 	public var projectDir(get,never) : String;
 	public var projectDir(get,never) : String;
 	public var resourceDir(get,never) : String;
 	public var resourceDir(get,never) : String;
+	public var initializing(default,null) : Bool;
 
 
 	var window : nw.Window;
 	var window : nw.Window;
 
 
@@ -52,6 +53,8 @@ class Ide {
 
 
 	function initLayout( ?state : { name : String, state : Dynamic } ) {
 	function initLayout( ?state : { name : String, state : Dynamic } ) {
 
 
+		initializing = true;
+
 		if( layout != null ) {
 		if( layout != null ) {
 			layout.destroy();
 			layout.destroy();
 			layout = null;
 			layout = null;
@@ -96,6 +99,7 @@ class Ide {
 
 
 		// error recovery if invalid component
 		// error recovery if invalid component
 		haxe.Timer.delay(function() {
 		haxe.Timer.delay(function() {
+			initializing = false;
 			if( layout.isInitialised ) return;
 			if( layout.isInitialised ) return;
 			state.state = [];
 			state.state = [];
 			initLayout();
 			initLayout();
@@ -227,10 +231,16 @@ class Ide {
 		window.menu = new Menu(menu).root;
 		window.menu = new Menu(menu).root;
 	}
 	}
 
 
-	public function open( component : String, state : Dynamic ) {
+	public function open( component : String, state : Dynamic, ?onCreate : View<Dynamic> -> Void ) {
 		if( layout.root.contentItems.length == 0 )
 		if( layout.root.contentItems.length == 0 )
 			layout.root.addChild({ type : Row });
 			layout.root.addChild({ type : Row });
-		layout.root.contentItems[0].addChild({
+		var target = layout.root.contentItems[0];
+		if( onCreate != null )
+			target.on("componentCreated", function(c) {
+				target.off("componentCreated");
+				onCreate(untyped c.origin.__view);
+			});
+		target.addChild({
 			type : Component,
 			type : Component,
 			componentName : component,
 			componentName : component,
 			componentState : state,
 			componentState : state,

+ 10 - 1
hide/ui/View.hx

@@ -27,6 +27,7 @@ class View<T> {
 			container.getElement().find('*').trigger('resize');
 			container.getElement().find('*').trigger('resize');
 			onResize();
 			onResize();
 		});
 		});
+		untyped cont.parent.__view = this;
 	}
 	}
 
 
 	public function onDisplay( j : js.jquery.JQuery ) {
 	public function onDisplay( j : js.jquery.JQuery ) {
@@ -40,12 +41,20 @@ class View<T> {
 		container.setState(state);
 		container.setState(state);
 	}
 	}
 
 
+	public function close() {
+		if( container != null ) {
+			container.close();
+			container = null;
+		}
+	}
+
 	function get_contentWidth() return container.width;
 	function get_contentWidth() return container.width;
 	function get_contentHeight() return container.height;
 	function get_contentHeight() return container.height;
 
 
 	public static var viewClasses = new Array<Class<View<Dynamic>>>();
 	public static var viewClasses = new Array<Class<View<Dynamic>>>();
 	public static function register<T>( cl : Class<View<T>> ) {
 	public static function register<T>( cl : Class<View<T>> ) {
-		viewClasses.push(cl);
+		if( viewClasses.indexOf(cl) < 0 )
+			viewClasses.push(cl);
 		return null;
 		return null;
 	}
 	}
 
 

+ 24 - 1
hide/view/FileTree.hx

@@ -7,6 +7,7 @@ typedef ExtensionOptions = {
 class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 
 
 	var tree : hide.comp.IconTree;
 	var tree : hide.comp.IconTree;
+	var lastOpen : hide.ui.View<Dynamic>;
 
 
 	function getExtension( file : String ) {
 	function getExtension( file : String ) {
 		return file.indexOf(".") < 0 ? null : EXTENSIONS.get(file.split(".").pop().toLowerCase());
 		return file.indexOf(".") < 0 ? null : EXTENSIONS.get(file.split(".").pop().toLowerCase());
@@ -50,6 +51,25 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 				state.opened.push(path);
 				state.opened.push(path);
 			saveState();
 			saveState();
 		};
 		};
+		
+		
+		// prevent dummy mouseLeft from breaking our quickOpen feature
+		var mouseLeft = false;
+		var leftCount = 0;
+		e.on("mouseenter", function(_) {
+			mouseLeft = false;
+		});
+		e.on("mouseleave", function(_) {
+			mouseLeft = true;
+			leftCount++;
+			var k = leftCount;
+			if( lastOpen != null ) 
+				haxe.Timer.delay(function() {
+					if( !mouseLeft || leftCount != k ) return;
+					lastOpen = null;
+				},1000);
+		});
+
 		tree.onDblClick = onOpenFile;
 		tree.onDblClick = onOpenFile;
 		tree.init();
 		tree.init();
 	}
 	}
@@ -61,7 +81,10 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 		var ext = getExtension(path);
 		var ext = getExtension(path);
 		if( ext == null )
 		if( ext == null )
 			return;
 			return;
-		ide.open(ext.component, { path : path });
+		var prev = lastOpen;
+		lastOpen = null;
+		ide.open(ext.component, { path : path }, function(c) lastOpen = c);
+		if( prev != null ) prev.close();
 	}
 	}
  
  
 	function isIgnored( path : String, file : String ) {
 	function isIgnored( path : String, file : String ) {

+ 13 - 0
hide/view/FileView.hx

@@ -0,0 +1,13 @@
+package hide.view;
+
+class FileView extends hide.ui.View<{ path : String }> {
+
+	function getPath() {
+		return ide.getPath(state.path);
+	}
+
+	override function getTitle() {
+		return state.path.split("/").pop();
+	}
+
+}

+ 1 - 5
hide/view/Image.hx

@@ -1,14 +1,10 @@
 package hide.view;
 package hide.view;
 
 
-class Image extends hide.ui.View<{ path : String }> {
+class Image extends FileView {
 
 
 	var bmp : h2d.Bitmap;
 	var bmp : h2d.Bitmap;
 	var scene : hide.comp.Scene;
 	var scene : hide.comp.Scene;
 
 
-	override function getTitle() {
-		return state.path.split("/").pop();
-	}
-
 	override function onDisplay( e : Element ) {
 	override function onDisplay( e : Element ) {
 		scene = new hide.comp.Scene(e);
 		scene = new hide.comp.Scene(e);
 		scene.onReady = function() {
 		scene.onReady = function() {

+ 14 - 0
hide/view/Sound.hx

@@ -0,0 +1,14 @@
+package hide.view;
+
+class Sound extends FileView {
+
+	override function onDisplay( e : Element ) {
+		var path = getPath();
+		new Element('<audio ${ide.initializing ? '' : 'autoplay="autoplay"'} controls="controls"><source src="file://${getPath()}"/></audio>').appendTo(e);	
+	}
+	
+	static var _ = {
+		FileTree.registerExtension(Sound,["wav"],{ icon : "file-audio-o" });
+		FileTree.registerExtension(Sound,["mp3","ogg"],{ icon : "music" });
+	};
+}

+ 5 - 1
libs/golden/Container.hx

@@ -4,7 +4,8 @@ extern class Container {
 
 
 	public var width(default,null) : Int;
 	public var width(default,null) : Int;
 	public var height(default,null) : Int;
 	public var height(default,null) : Int;
-	//public var parent :
+	public var parent : ContentItem;
+
 	//public var tab
 	//public var tab
 	public var title(default,null) : String;
 	public var title(default,null) : String;
 	public var layoutManager(default,null) : Layout;
 	public var layoutManager(default,null) : Layout;
@@ -15,6 +16,9 @@ extern class Container {
 	public function setTitle( title : String ) : Void;
 	public function setTitle( title : String ) : Void;
 	public function setState( state : Dynamic ) : Void;
 	public function setState( state : Dynamic ) : Void;
 
 
+	public function close() : Bool;
+
 	public function on( type : String, callb : Void -> Void ) : Void;
 	public function on( type : String, callb : Void -> Void ) : Void;
+	public function off( type : String ) : Void;
 
 
 }
 }

+ 5 - 2
libs/golden/ContentItem.hx

@@ -4,7 +4,10 @@ extern class ContentItem {
 
 
 	var parent : ContentItem;
 	var parent : ContentItem;
 	var contentItems : Array<ContentItem>;
 	var contentItems : Array<ContentItem>;
+	var element : Container;
+	var childElementContainer : Container;
 
 
-	public function addChild( config : Config.ItemConfig ) : Void;
-
+	public function addChild( config : Config.ItemConfig, ?index : Int ) : Void;
+	public function on( type : String, callb : { name : String, origin : ContentItem } -> Void ) : Void;
+	public function off( type : String ) : Void;
 }
 }