From a03537bb99543e99724bb9fe8503ba24edb3ddd3 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 18 Dec 2013 23:12:42 -0500 Subject: [PATCH] Add Open in Explorer to context menu --- NBTExplorer/Controllers/NodeTreeController.cs | 26 +++++++++++++++++-- NBTExplorer/Properties/AssemblyInfo.cs | 4 +-- NBTExplorer/Windows/MainForm.cs | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/NBTExplorer/Controllers/NodeTreeController.cs b/NBTExplorer/Controllers/NodeTreeController.cs index 4c58441..74ad4f2 100644 --- a/NBTExplorer/Controllers/NodeTreeController.cs +++ b/NBTExplorer/Controllers/NodeTreeController.cs @@ -729,8 +729,8 @@ namespace NBTExplorer.Controllers ToolStripMenuItem itemExpandTree = new ToolStripMenuItem("Expand &Tree", null, _contextExpandTree_Click); menu.Items.AddRange(new ToolStripItem[] { - itemCollapse, new ToolStripSeparator(), itemExpandChildren, itemExpandTree, - }); + itemCollapse, new ToolStripSeparator(), itemExpandChildren, itemExpandTree, + }); } else { ToolStripMenuItem itemExpand = new ToolStripMenuItem("&Expand", null, _contextExpand_Click); @@ -751,6 +751,14 @@ namespace NBTExplorer.Controllers menu.Items.Add(itemDn); } + if (node is DirectoryDataNode) { + if (menu.Items.Count > 0) + menu.Items.Add(new ToolStripSeparator()); + + ToolStripMenuItem itemOpenExplorer = new ToolStripMenuItem("Open in E&xplorer", null, _contextOpenInExplorer_Click); + menu.Items.Add(itemOpenExplorer); + } + return (menu.Items.Count > 0) ? menu : null; } @@ -791,6 +799,20 @@ namespace NBTExplorer.Controllers MoveSelectionDown(); } + private void _contextOpenInExplorer_Click (object sender, EventArgs e) + { + if (_multiTree.SelectedNode != null && _multiTree.SelectedNode.Tag is DirectoryDataNode) { + DirectoryDataNode ddNode = _multiTree.SelectedNode.Tag as DirectoryDataNode; + try { + string path = (!Interop.IsWindows ? "file://" : "") + ddNode.NodeDirPath; + System.Diagnostics.Process.Start(path); + } + catch (Exception ex) { + MessageBox.Show(ex.Message, "Can't open directory", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + #region Capability Checking #region Capability Predicates diff --git a/NBTExplorer/Properties/AssemblyInfo.cs b/NBTExplorer/Properties/AssemblyInfo.cs index 556a6d5..6b3ce9f 100644 --- a/NBTExplorer/Properties/AssemblyInfo.cs +++ b/NBTExplorer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.6.1.0")] -[assembly: AssemblyFileVersion("2.6.1.0")] +[assembly: AssemblyVersion("2.6.2.0")] +[assembly: AssemblyFileVersion("2.6.2.0")] diff --git a/NBTExplorer/Windows/MainForm.cs b/NBTExplorer/Windows/MainForm.cs index ca2d327..ac49ab2 100644 --- a/NBTExplorer/Windows/MainForm.cs +++ b/NBTExplorer/Windows/MainForm.cs @@ -121,7 +121,8 @@ namespace NBTExplorer.Windows if (_nodeTree.SelectedNode.Tag is DirectoryDataNode) { DirectoryDataNode ddNode = _nodeTree.SelectedNode.Tag as DirectoryDataNode; try { - System.Diagnostics.Process.Start(ddNode.NodeDirPath); + string path = (!Interop.IsWindows ? "file://" : "") + ddNode.NodeDirPath; + System.Diagnostics.Process.Start(path); } catch (Win32Exception ex) { MessageBox.Show(ex.Message, "Can't open directory", MessageBoxButtons.OK, MessageBoxIcon.Error); }