Procházet zdrojové kódy

Add util functions to fileview context menu

Namely Explore, Copy Path and Open in Resources
Leonardo Jeanteur před 4 roky
rodič
revize
51086a6a9f
2 změnil soubory, kde provedl 51 přidání a 11 odebrání
  1. 25 3
      hide/view/FileTree.hx
  2. 26 8
      hide/view/FileView.hx

+ 25 - 3
hide/view/FileTree.hx

@@ -149,7 +149,12 @@ class FileTree extends FileView {
 						onRename(current, "/"+dir+"/"+current.split("/").pop());
 					});
 				}},
-				{ label : "Delete", enabled : current != null, click : function() if( js.Browser.window.confirm("Delete " + current + "?") ) { onDeleteFile(current); tree.refresh(); } },
+				{ label : "Delete", enabled : current != null, click : function() {
+					if( js.Browser.window.confirm("Delete " + current + "?") ) {
+						onDeleteFile(current);
+						tree.refresh();
+					}
+				}},
 			]);
 		});
 		tree.onDblClick = onOpenFile;
@@ -339,11 +344,15 @@ class FileTree extends FileView {
 		return true;
 	}
 
-	function onExploreFile( path : String ) {
-		var fullPath = sys.FileSystem.absolutePath(getFilePath(path));
+	public static function exploreFile(path : String) {
+		var fullPath = sys.FileSystem.absolutePath(path);
 		Sys.command("explorer.exe /select," + fullPath);
 	}
 
+	function onExploreFile( path : String ) {
+		exploreFile(getFilePath(path));
+	}
+
 	function onCloneFile( path : String ) {
 		var sourcePath = getFilePath(path);
 		var nameNewFile = ide.ask("New filename:");
@@ -403,6 +412,19 @@ class FileTree extends FileView {
 		return true;
 	}
 
+	public function revealNode( path : String ) {
+		function doreveal() {
+			tree.revealNode(path);
+			tree.setSelection([path]);
+		}
+		if( tree.async ) {
+			tree.async = false;
+			tree.refresh(doreveal);
+		}
+		else
+			doreveal();
+	}
+
 	function createNew( basePath : String, ext : ExtensionDesc ) {
 		if( basePath == null )
 			basePath = "";

+ 26 - 8
hide/view/FileView.hx

@@ -173,14 +173,32 @@ class FileView extends hide.ui.View<{ path : String }> {
 	}
 
 	override function buildTabMenu() {
-		var arr : Array<hide.comp.ContextMenu.ContextMenuItem> = [
-			{ label : "Save", enabled : canSave() && modified, click : function() { save(); modified = false; } },
-			{ label : "Save As...", enabled : canSave(), click : saveAs },
-			{ label : null, isSeparator : true },
-			{ label : "Reload", click : function() rebuild() },
-			{ label : null, isSeparator : true },
-		];
+		var hasPath = state.path != null && state.path != "";
+		var reloadItem : hide.comp.ContextMenu.ContextMenuItem = { label : "Reload", click : function() rebuild() };
+		var arr : Array<hide.comp.ContextMenu.ContextMenuItem>;
+		if( !hasPath && !canSave() ) {
+			arr = [
+				reloadItem,
+				{ label : null, isSeparator : true },
+			];
+		}
+		else {
+			arr = [
+				{ label : "Save", enabled : canSave() && modified, click : function() { save(); modified = false; } },
+				{ label : "Save As...", enabled : canSave(), click : saveAs },
+				{ label : null, isSeparator : true },
+				reloadItem,
+				{ label : "Explore", enabled : hasPath, click : function() { FileTree.exploreFile(getPath()); } },
+				{ label : "Copy Path", enabled : hasPath, click : function() { ide.setClipboard(state.path); } },
+				{ label : "Open in Resources", enabled : hasPath, click : function() {
+					var filetree = ide.getViews(FileTree)[0];
+					if( filetree != null ) {
+						filetree.revealNode(state.path);
+					}
+				}},
+				{ label : null, isSeparator : true },
+			];
+		}
 		return arr.concat(super.buildTabMenu());
 	}
-
 }