Browse Source

Better handling of Open In Explorer

Valden 1 year ago
parent
commit
984e0b839d
4 changed files with 19 additions and 18 deletions
  1. 16 0
      hide/Ide.hx
  2. 1 3
      hide/comp/FileSelect.hx
  3. 1 14
      hide/view/FileTree.hx
  4. 1 1
      hide/view/FileView.hx

+ 16 - 0
hide/Ide.hx

@@ -1393,6 +1393,22 @@ class Ide {
 		window.menu = new hide.ui.Menu(menu).root;
 	}
 
+	public static function showFileInExplorer(path : String) {
+		if(!haxe.io.Path.isAbsolute(path)) {
+			path = Ide.inst.getPath(path);
+		}
+
+		switch(Sys.systemName()) {
+			case "Windows": {
+				var cmd = "explorer.exe /select," + '"' + StringTools.replace(path, "/", "\\") + '"';
+				trace("OpenInExplorer: " + cmd);
+				Sys.command(cmd);
+			};
+			case "Mac":	Sys.command("open " + haxe.io.Path.directory(path));
+			default: throw "Exploration not implemented on this platform";
+		}
+	}
+
 	public function openFile( file : String, ?onCreate, ?onOpen) {
 		var ext = @:privateAccess hide.view.FileTree.getExtension(file);
 		if( ext == null ) return;

+ 1 - 3
hide/comp/FileSelect.hx

@@ -34,9 +34,7 @@ class FileSelect extends Component {
 					onChange();
 				}},
 				{ label : "Open in explorer", enabled : fpath != null, click : function(){
-					var p = "/select,"+fpath.split("/").join("\\");
-					trace(p);
-					Sys.command("explorer.exe",[p]);
+					Ide.showFileInExplorer(fpath);
 				} },
 			]);
 			return false;

+ 1 - 14
hide/view/FileTree.hx

@@ -362,21 +362,8 @@ class FileTree extends FileView {
 		return true;
 	}
 
-	public static function exploreFile(path : String) {
-		var fullPath = sys.FileSystem.absolutePath(path);
-
-		switch(Sys.systemName()) {
-			case "Windows": {
-				var cmd = "explorer.exe /select," + '"' + StringTools.replace(fullPath, "/", "\\") + '"';
-				Sys.command(cmd);
-			};
-			case "Mac":	Sys.command("open " + haxe.io.Path.directory(fullPath));
-			default: throw "Exploration not implemented on this platform";
-		}
-	}
-
 	function onExploreFile( path : String ) {
-		exploreFile(getFilePath(path));
+		Ide.showFileInExplorer(path);
 	}
 
 	function onCloneFile( path : String ) {

+ 1 - 1
hide/view/FileView.hx

@@ -200,7 +200,7 @@ class FileView extends hide.ui.View<{ path : String }> {
 				{ label : null, isSeparator : true },
 				reloadItem,
 				{ label : "Copy Path", enabled : hasPath, click : function() { ide.setClipboard(state.path); } },
-				{ label : "Open in Explorer", enabled : hasPath, click : function() { FileTree.exploreFile(getPath()); } },
+				{ label : "Open in Explorer", enabled : hasPath, click : function() { Ide.showFileInExplorer(getPath()); } },
 				{ label : "Open in Resources", enabled : hasPath, click : function() {
 					var filetree = ide.getViews(FileTree)[0];
 					if( filetree != null ) {