Browse Source

Cdb better path directory (#113)

Open up smarter working directory when editing a path cell :
- If the cell is empty, open the working directory to the last opened directory.
- If the cell is filled with a path within the project, open the directory of this file.
-Cell containing "#MISSING" are handle just like empty cells -> open the root directory of the project.
Jed974 4 years ago
parent
commit
6624e75981
2 changed files with 11 additions and 3 deletions
  1. 10 2
      hide/Ide.hx
  2. 1 1
      hide/comp/cdb/Cell.hx

+ 10 - 2
hide/Ide.hx

@@ -840,8 +840,16 @@ class Ide {
 		}).appendTo(window.window.document.body).click();
 	}
 
-	public function chooseFile( exts : Array<String>, onSelect : Null<String> -> Void, allowNull=false ) {
-		var e = new Element('<input type="file" style="visibility:hidden" value="" accept="${[for( e in exts ) "."+e].join(",")}"/>');
+	public function chooseFile( workingdir : String =null, exts : Array<String>, onSelect : Null<String> -> Void, allowNull=false ) {
+		var path = "";
+		if (workingdir != null && workingdir != "#MISSING")
+		{
+			var pathArray = getPath(workingdir).split("/");
+			var c = isWindows ? "\\" : "/";
+			path = pathArray.join(c);
+		}
+		
+		var e = new Element('<input type="file" style="visibility:hidden" value="" nwworkingdir="$path" accept="${[for( e in exts ) "."+e].join(",")}"/>');
 		e.change(function(_) {
 			var file = e.val();
 			if( file == "" && !allowNull ) return;

+ 1 - 1
hide/comp/cdb/Cell.hx

@@ -661,7 +661,7 @@ class Cell extends Component {
 			};
 			modal.click(function(_) color.close());
 		case TFile:
-			ide.chooseFile(["*"], function(file) {
+			ide.chooseFile(currentValue, ["*"], function(file) {
 				setValue(file);
 				refresh();
 			});