From 5eff561b2b27e6f687c9e10ca1f36d189f49b944 Mon Sep 17 00:00:00 2001 From: Postremus Date: Wed, 24 Jun 2015 13:49:58 +0200 Subject: [PATCH] Handle double click on the contentTree .net opens the windows explorer mono uses xdg-open to open the directory --- GUI/Main.Designer.cs | 1 + GUI/Main.cs | 19 ++++++++++++------- GUI/MainModInfo.cs | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/GUI/Main.Designer.cs b/GUI/Main.Designer.cs index 927ad407cc..79144b1227 100644 --- a/GUI/Main.Designer.cs +++ b/GUI/Main.Designer.cs @@ -857,6 +857,7 @@ private void InitializeComponent() this.ContentsPreviewTree.Name = "ContentsPreviewTree"; this.ContentsPreviewTree.Size = new System.Drawing.Size(349, 481); this.ContentsPreviewTree.TabIndex = 2; + this.ContentsPreviewTree.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.ContentsPreviewTree_NodeMouseDoubleClick); // // ContentsDownloadButton // diff --git a/GUI/Main.cs b/GUI/Main.cs index 8a9d03f0f2..f7b9f648a5 100644 --- a/GUI/Main.cs +++ b/GUI/Main.cs @@ -1063,15 +1063,20 @@ private void FocusMod(string key, bool exactMatch) private void RecommendedModsToggleCheckbox_CheckedChanged(object sender, EventArgs e) { - var state = ((CheckBox)sender).Checked; - foreach (ListViewItem item in RecommendedModsListView.Items) - { - if (item.Checked != state) + var state = ((CheckBox)sender).Checked; + foreach (ListViewItem item in RecommendedModsListView.Items) { - item.Checked = state; + if (item.Checked != state) + { + item.Checked = state; + } } - } - RecommendedModsListView.Refresh(); + RecommendedModsListView.Refresh(); + } + + private void ContentsPreviewTree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + OpenFileBrowser(e.Node); } } diff --git a/GUI/MainModInfo.cs b/GUI/MainModInfo.cs index 00f60df15a..44373cb32c 100644 --- a/GUI/MainModInfo.cs +++ b/GUI/MainModInfo.cs @@ -3,6 +3,8 @@ using System.ComponentModel; using System.Drawing; using System.Windows.Forms; +using System.IO; +using System.Diagnostics; namespace CKAN { @@ -266,5 +268,32 @@ private void _PostModCaching(CkanModule module) UpdateModContentsTree(module, true); RecreateDialogs(); } + + /// + /// Opens the file browser of the users system + /// with the folder of the clicked node opened + /// TODO: Open a file broweser with the file selected + /// + /// A node of the ContentsPreviewTree + internal void OpenFileBrowser(TreeNode node) + { + string location = node.Text; + + if (File.Exists(location)) + { + //We need the Folder of the file + //Otherwise the OS would try to open the file in it's default application + location = Path.GetDirectoryName(location); + } + + if (!Directory.Exists(location)) + { + //User either selected the parent node + //or he clicked on the tree node of a cached, but not installed mod + return; + } + + Process.Start(location); + } } } \ No newline at end of file