2
0
Эх сурвалжийг харах

added tab popup menu / saveAs

Nicolas Cannasse 8 жил өмнө
parent
commit
8938a3d009

+ 3 - 3
hide/comp/PropsEditor.hx

@@ -20,7 +20,7 @@ class PropsEditor extends Component {
 	public function addMaterial( m : h3d.mat.Material, ?parent : Element ) {
 	public function addMaterial( m : h3d.mat.Material, ?parent : Element ) {
 		var props = m.props;
 		var props = m.props;
 		var def = h3d.mat.MaterialSetup.current.editMaterial(props);
 		var def = h3d.mat.MaterialSetup.current.editMaterial(props);
-		def = add(def, props, function(_, undo) {
+		def = add(def, props, function(_) {
 			if( m.model != null )
 			if( m.model != null )
 				h3d.mat.MaterialSetup.current.saveModelMaterial(m);
 				h3d.mat.MaterialSetup.current.saveModelMaterial(m);
 			m.refreshProps();
 			m.refreshProps();
@@ -31,7 +31,7 @@ class PropsEditor extends Component {
 			def.appendTo(parent);
 			def.appendTo(parent);
 	}
 	}
 
 
-	public function add( e : Element, ?context : Dynamic, ?onChange : String -> Bool -> Void ) {
+	public function add( e : Element, ?context : Dynamic, ?onChange : String -> Void ) {
 
 
 		e.appendTo(root);
 		e.appendTo(root);
 		e = e.wrap("<div></div>").parent(); // necessary to have find working on top level element
 		e = e.wrap("<div></div>").parent(); // necessary to have find working on top level element
@@ -83,7 +83,7 @@ class PropsEditor extends Component {
 		// init input reflection
 		// init input reflection
 		for( f in e.find("[field]").elements() ) {
 		for( f in e.find("[field]").elements() ) {
 			var f = new PropsField(this, f, context);
 			var f = new PropsField(this, f, context);
-			if( onChange != null ) f.onChange = function(undo) onChange(@:privateAccess f.fname,undo);
+			if( onChange != null ) f.onChange = function(undo) onChange(@:privateAccess f.fname);
 			fields.push(f);
 			fields.push(f);
 		}
 		}
 
 

+ 25 - 1
hide/ui/Ide.hx

@@ -10,6 +10,8 @@ class Ide {
 	public var mouseX : Int = 0;
 	public var mouseX : Int = 0;
 	public var mouseY : Int = 0;
 	public var mouseY : Int = 0;
 
 
+	public var isWindows(get, never) : Bool;
+
 	var props : {
 	var props : {
 		global : Props,
 		global : Props,
 		project : Props,
 		project : Props,
@@ -86,6 +88,10 @@ class Ide {
 		});
 		});
 	}
 	}
 
 
+	function get_isWindows() {
+		return true;
+	}
+
 	function onWindowChange() {
 	function onWindowChange() {
 		if( ideProps.windowPos == null ) ideProps.windowPos = { x : 0, y : 0, w : 0, h : 0, max : false };
 		if( ideProps.windowPos == null ) ideProps.windowPos = { x : 0, y : 0, w : 0, h : 0, max : false };
 		ideProps.windowPos.max = maximized;
 		ideProps.windowPos.max = maximized;
@@ -273,6 +279,20 @@ class Ide {
 		}).appendTo(window.window.document.body).click();
 		}).appendTo(window.window.document.body).click();
 	}
 	}
 
 
+	public function chooseFileSave( defaultPath : String, onSelect : String -> Void ) {
+		var path = getPath(defaultPath).split("/");
+		var file = path.pop();
+		var c = isWindows ? "\\" : "/";
+		var path = path.join(c);
+		var e = new Element('<input type="file" style="visibility:hidden" value="" nwworkingdir="$path" nwsaveas="$path$c$file"/>');
+		e.change(function(_) {
+			var file = makeRelative(e.val());
+			e.remove();
+			onSelect(file == "" ? null : file);
+		}).appendTo(window.window.document.body).click();
+	}
+
+
 	public function chooseDirectory( onSelect : String -> Void ) {
 	public function chooseDirectory( onSelect : String -> Void ) {
 		var e = new Element('<input type="file" style="visibility:hidden" value="" nwdirectory/>');
 		var e = new Element('<input type="file" style="visibility:hidden" value="" nwdirectory/>');
 		e.change(function(ev) {
 		e.change(function(ev) {
@@ -366,7 +386,7 @@ class Ide {
 		}).prop("checked",ideProps.autoSaveLayout);
 		}).prop("checked",ideProps.autoSaveLayout);
 
 
 		menu.find(".layout .saveas").click(function(_) {
 		menu.find(".layout .saveas").click(function(_) {
-			var name = js.Browser.window.prompt("Please enter a layout name:");
+			var name = ask("Please enter a layout name:");
 			if( name == null || name == "" ) return;
 			if( name == null || name == "" ) return;
 			ideProps.layouts.push({ name : name, state : saveLayout() });
 			ideProps.layouts.push({ name : name, state : saveLayout() });
 			props.global.save();
 			props.global.save();
@@ -460,6 +480,10 @@ class Ide {
 			target.addChild(config, index);
 			target.addChild(config, index);
 	}
 	}
 
 
+	public function ask( text : String, ?defaultValue = "" ) {
+		return js.Browser.window.prompt(text, defaultValue);
+	}
+
 	public static var inst : Ide;
 	public static var inst : Ide;
 
 
 	static function main() {
 	static function main() {

+ 22 - 3
hide/ui/View.hx

@@ -86,10 +86,23 @@ class View<T> extends hide.comp.Component {
 				return;
 				return;
 			}
 			}
 			@:privateAccess ide.views.remove(this);
 			@:privateAccess ide.views.remove(this);
+			for( c in container.getElement().find("canvas") ) {
+				var s : hide.comp.Scene = Reflect.field(c, "__scene");
+				if( s != null )
+					s.dispose();
+			}
 		});
 		});
 		container.getElement().keydown(function(e) {
 		container.getElement().keydown(function(e) {
 			keys.processEvent(e);
 			keys.processEvent(e);
 		});
 		});
+
+		container.on("tab", function(e) {
+			container.tab.element.contextmenu(function(e) {
+				new hide.comp.ContextMenu(buildTabMenu());
+				e.preventDefault();
+			});
+		});
+
 		untyped cont.parent.__view = this;
 		untyped cont.parent.__view = this;
 		root = cont.getElement();
 		root = cont.getElement();
 	}
 	}
@@ -113,10 +126,16 @@ class View<T> extends hide.comp.Component {
 	}
 	}
 
 
 	public function close() {
 	public function close() {
-		if( container != null ) {
+		if( container != null )
 			container.close();
 			container.close();
-			container = null;
-		}
+	}
+
+	function buildTabMenu() : Array<hide.comp.ContextMenu.ContextMenuItem> {
+		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() },
+			{ label : "Close All", click : function() for( v in @:privateAccess ide.views ) if( v.container.tab.header == container.tab.header ) v.close() },
+		];
 	}
 	}
 
 
 	function get_contentWidth() return container.width;
 	function get_contentWidth() return container.width;

+ 1 - 1
hide/view/FileTree.hx

@@ -149,7 +149,7 @@ class FileTree extends FileView {
 			basePath = new haxe.io.Path(basePath).dir;
 			basePath = new haxe.io.Path(basePath).dir;
 			fullPath = getFilePath(basePath);
 			fullPath = getFilePath(basePath);
 		}
 		}
-		var file = js.Browser.window.prompt(ext.options.createNew + " name:");
+		var file = ide.ask(ext.options.createNew + " name:");
 		if( file == null ) return;
 		if( file == null ) return;
 		if( file.indexOf(".") < 0 ) file += "." + ext.extensions[0].split(".").shift();
 		if( file.indexOf(".") < 0 ) file += "." + ext.extensions[0].split(".").shift();
 
 

+ 19 - 0
hide/view/FileView.hx

@@ -34,6 +34,16 @@ class FileView extends hide.ui.View<{ path : String }> {
 	public function save() {
 	public function save() {
 	}
 	}
 
 
+	public function saveAs() {
+		ide.chooseFileSave(state.path, function(target) {
+			if( target == null ) return;
+			state.path = target;
+			save();
+			modified = false;
+			syncTitle();
+		});
+	}
+
 	override function onBeforeClose() {
 	override function onBeforeClose() {
 		if( modified && !js.Browser.window.confirm(state.path+" has been modified, quit without saving?") )
 		if( modified && !js.Browser.window.confirm(state.path+" has been modified, quit without saving?") )
 			return false;
 			return false;
@@ -73,4 +83,13 @@ class FileView extends hide.ui.View<{ path : String }> {
 			haxe.Timer.delay(function() container.tab.element.attr("title",getPath()), 100);
 			haxe.Timer.delay(function() container.tab.element.attr("title",getPath()), 100);
 	}
 	}
 
 
+	override function buildTabMenu() {
+		var arr : Array<hide.comp.ContextMenu.ContextMenuItem> = [
+			{ label : "Save", enabled : modified, click : function() { save(); modified = false; } },
+			{ label : "Save As...", click : saveAs },
+			{ label : null, isSeparator : true },
+		];
+		return arr.concat(super.buildTabMenu());
+	}
+
 }
 }

+ 1 - 1
hide/view/Particles3D.hx

@@ -295,7 +295,7 @@ class Particles3D extends FileView {
 			ide.cleanObject(props);
 			ide.cleanObject(props);
 		}
 		}
 		syncProps();
 		syncProps();
-		extra = properties.add(extra, props, function(_, _) syncProps());
+		extra = properties.add(extra, props, function(_) syncProps());
 
 
 		extra.find(".bounds").change(function(e) bounds.visible = e.getThis().prop("checked"));
 		extra.find(".bounds").change(function(e) bounds.visible = e.getThis().prop("checked"));
 		var defAmbient = scene.s3d.lightSystem.ambientLight.clone();
 		var defAmbient = scene.s3d.lightSystem.ambientLight.clone();

+ 1 - 0
libs/golden/ContentItem.hx

@@ -8,6 +8,7 @@ extern class ContentItem {
 	var element : js.jquery.JQuery;
 	var element : js.jquery.JQuery;
 	var childElementContainer : Container;
 	var childElementContainer : Container;
 	var config : Config.ItemConfig;
 	var config : Config.ItemConfig;
+	var header : Header;
 
 
 	public function addChild( config : Config.ItemConfig, ?index : Int ) : Void;
 	public function addChild( config : Config.ItemConfig, ?index : Int ) : Void;
 	public function on( type : String, callb : Event<ContentItem> -> Void ) : Void;
 	public function on( type : String, callb : Event<ContentItem> -> Void ) : Void;

+ 2 - 0
libs/golden/Header.hx

@@ -2,6 +2,8 @@ package golden;
 
 
 extern class Header {
 extern class Header {
 
 
+	public var tabs : Array<Tab>;
+
 	function setActiveContentItem( it : ContentItem ) : Void;
 	function setActiveContentItem( it : ContentItem ) : Void;
 
 
 }
 }