diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs index 7beadd52e..d5fe85e3a 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs @@ -36,7 +36,6 @@ namespace ExternalCommand { public class ExternalCommandDestination : AbstractDestination { private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandDestination)); private static ExternalCommandConfiguration config = IniConfig.GetIniSection(); - private static Dictionary iconCache = new Dictionary(); private IGreenshotHost host; private string presetCommand; @@ -69,20 +68,7 @@ namespace ExternalCommand { public override Image DisplayIcon { get { - if (presetCommand != null) { - if (!iconCache.ContainsKey(presetCommand)) { - Image icon = null; - if (File.Exists(config.commandlines[presetCommand])) { - try { - icon = GetExeIcon(config.commandlines[presetCommand], 0); - } catch{}; - } - iconCache.Add(presetCommand, icon); - } - return iconCache[presetCommand]; - } else { - return null; - } + return IconCache.IconForExe(presetCommand); } } diff --git a/GreenshotExternalCommandPlugin/GreenshotExternalCommandPlugin.csproj b/GreenshotExternalCommandPlugin/GreenshotExternalCommandPlugin.csproj index 1db493331..f05f2bcb5 100644 --- a/GreenshotExternalCommandPlugin/GreenshotExternalCommandPlugin.csproj +++ b/GreenshotExternalCommandPlugin/GreenshotExternalCommandPlugin.csproj @@ -55,6 +55,7 @@ + diff --git a/GreenshotExternalCommandPlugin/IconCache.cs b/GreenshotExternalCommandPlugin/IconCache.cs new file mode 100644 index 000000000..00bb99e6d --- /dev/null +++ b/GreenshotExternalCommandPlugin/IconCache.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using System.IO; +using Greenshot.IniFile; +using GreenshotPlugin.Core; + +namespace ExternalCommand { + public static class IconCache { + private static Dictionary iconCache = new Dictionary(); + private static ExternalCommandConfiguration config = IniConfig.GetIniSection(); + private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IconCache)); + + public static Image IconForExe(string exepath) { + if (exepath != null) { + if (!iconCache.ContainsKey(exepath)) { + Image icon = null; + if (File.Exists(config.commandlines[exepath])) { + try { + icon = AbstractDestination.GetExeIcon(config.commandlines[exepath], 0); + } catch (Exception ex) { + LOG.Warn("Problem loading icon for " + config.commandlines[exepath], ex); + } + } + iconCache.Add(exepath, icon); + } + return iconCache[exepath]; + } else { + return null; + } + } + } +} diff --git a/GreenshotExternalCommandPlugin/SettingsForm.cs b/GreenshotExternalCommandPlugin/SettingsForm.cs index 86f18582b..d7138e99f 100644 --- a/GreenshotExternalCommandPlugin/SettingsForm.cs +++ b/GreenshotExternalCommandPlugin/SettingsForm.cs @@ -72,8 +72,19 @@ namespace ExternalCommand { void UpdateView() { listView1.Items.Clear(); if (config.commands != null) { - foreach(string commando in config.commands) { - ListViewItem item = new ListViewItem(commando); + listView1.ListViewItemSorter = new ListviewComparer(); + ImageList imageList = new ImageList(); + listView1.SmallImageList = imageList; + int imageNr = 0; + foreach (string commando in config.commands) { + ListViewItem item = null; + Image iconForExe = IconCache.IconForExe(commando); + if (iconForExe != null) { + imageList.Images.Add(iconForExe); + item = new ListViewItem(commando, imageNr++); + } else { + item = new ListViewItem(commando); + } item.Tag = commando; listView1.Items.Add(item); } @@ -99,4 +110,21 @@ namespace ExternalCommand { UpdateView(); } } + public class ListviewComparer : System.Collections.IComparer { + public int Compare(object x, object y) { + if (!(x is ListViewItem)) { + return (0); + } + if (!(y is ListViewItem)) { + return (0); + } + + ListViewItem l1 = (ListViewItem)x; + ListViewItem l2 = (ListViewItem)y; + if (l2 == null) { + return 1; + } + return l1.Text.CompareTo(l2.Text); + } + } } diff --git a/GreenshotExternalCommandPlugin/SettingsForm.resx b/GreenshotExternalCommandPlugin/SettingsForm.resx index b8fc29ba0..6361616af 100644 --- a/GreenshotExternalCommandPlugin/SettingsForm.resx +++ b/GreenshotExternalCommandPlugin/SettingsForm.resx @@ -112,12 +112,12 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + AAABAAUAAAAAAAEACAClFwAAVgAAADAwAAABAAgAqA4AAPsXAAAgIAAAAQAIAKgIAACjJgAAGBgAAAEA diff --git a/GreenshotExternalCommandPlugin/SettingsFormDetail.Designer.cs b/GreenshotExternalCommandPlugin/SettingsFormDetail.Designer.cs index b1e47a64f..5f4927be7 100644 --- a/GreenshotExternalCommandPlugin/SettingsFormDetail.Designer.cs +++ b/GreenshotExternalCommandPlugin/SettingsFormDetail.Designer.cs @@ -52,6 +52,7 @@ namespace GreenshotExternalCommandPlugin // // buttonOk // + this.buttonOk.Enabled = false; this.buttonOk.Location = new System.Drawing.Point(273, 140); this.buttonOk.Name = "buttonOk"; this.buttonOk.Size = new System.Drawing.Size(75, 23); @@ -120,6 +121,7 @@ namespace GreenshotExternalCommandPlugin this.textBox_name.Name = "textBox_name"; this.textBox_name.Size = new System.Drawing.Size(225, 20); this.textBox_name.TabIndex = 12; + this.textBox_name.TextChanged += new System.EventHandler(this.textBox_name_TextChanged); // // label2 // @@ -150,6 +152,7 @@ namespace GreenshotExternalCommandPlugin this.textBox_commandline.Name = "textBox_commandline"; this.textBox_commandline.Size = new System.Drawing.Size(225, 20); this.textBox_commandline.TabIndex = 13; + this.textBox_commandline.TextChanged += new System.EventHandler(this.textBox_commandline_TextChanged); // // SettingsFormDetail // @@ -168,6 +171,7 @@ namespace GreenshotExternalCommandPlugin this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.ResumeLayout(false); + } private System.Windows.Forms.Label label4; private System.Windows.Forms.GroupBox groupBox1; diff --git a/GreenshotExternalCommandPlugin/SettingsFormDetail.cs b/GreenshotExternalCommandPlugin/SettingsFormDetail.cs index e72f83fad..d3764d52a 100644 --- a/GreenshotExternalCommandPlugin/SettingsFormDetail.cs +++ b/GreenshotExternalCommandPlugin/SettingsFormDetail.cs @@ -41,6 +41,7 @@ namespace GreenshotExternalCommandPlugin } else { textBox_arguments.Text = "\"{0}\""; } + OKButtonState(); } void ButtonOkClick(object sender, EventArgs e) @@ -91,5 +92,38 @@ namespace GreenshotExternalCommandPlugin } } + private void OKButtonState() { + // Assume OK + buttonOk.Enabled = true; + textBox_name.BackColor = Color.White; + textBox_commandline.BackColor = Color.White; + // Is there a text in the name field + if (string.IsNullOrEmpty(textBox_name.Text)) { + buttonOk.Enabled = false; + } + // Check if commandname is unique + if (commando == null && !string.IsNullOrEmpty(textBox_name.Text) && config.commands.Contains(textBox_name.Text)) { + buttonOk.Enabled = false; + textBox_name.BackColor = Color.Red; + } + // Is there a text in the commandline field + if (string.IsNullOrEmpty(textBox_commandline.Text)) { + buttonOk.Enabled = false; + } + // Is the command available? + if (!string.IsNullOrEmpty(textBox_commandline.Text) && !File.Exists(textBox_commandline.Text)) { + buttonOk.Enabled = false; + textBox_commandline.BackColor = Color.Red; + } + } + + private void textBox_name_TextChanged(object sender, EventArgs e) { + OKButtonState(); + } + + private void textBox_commandline_TextChanged(object sender, EventArgs e) { + OKButtonState(); + } + } } diff --git a/GreenshotExternalCommandPlugin/SettingsFormDetail.resx b/GreenshotExternalCommandPlugin/SettingsFormDetail.resx index 29dcb1b3a..5ea0895e3 100644 --- a/GreenshotExternalCommandPlugin/SettingsFormDetail.resx +++ b/GreenshotExternalCommandPlugin/SettingsFormDetail.resx @@ -112,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file