From 28346d2eab87db4778067e443c4768c9ee46c3c0 Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 3 Apr 2013 07:18:26 +0000 Subject: [PATCH] Fixes for bug #1484, disabling the edit button after redrawing the items. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2551 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- .../ExternalCommandDestination.cs | 2 +- GreenshotExternalCommandPlugin/IconCache.cs | 16 ++++++++-------- GreenshotExternalCommandPlugin/SettingsForm.cs | 10 +++++++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs index 8dffe81a6..3204fd92f 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs @@ -58,7 +58,7 @@ namespace ExternalCommand { public override Image DisplayIcon { get { - return IconCache.IconForExe(presetCommand); + return IconCache.IconForCommand(presetCommand); } } diff --git a/GreenshotExternalCommandPlugin/IconCache.cs b/GreenshotExternalCommandPlugin/IconCache.cs index 7fb5abef6..fc608c28d 100644 --- a/GreenshotExternalCommandPlugin/IconCache.cs +++ b/GreenshotExternalCommandPlugin/IconCache.cs @@ -11,20 +11,20 @@ namespace ExternalCommand { 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)) { + public static Image IconForCommand(string commandName) { + if (commandName != null) { + if (!iconCache.ContainsKey(commandName)) { Image icon = null; - if (File.Exists(config.commandlines[exepath])) { + if (File.Exists(config.commandlines[commandName])) { try { - icon = PluginUtils.GetExeIcon(config.commandlines[exepath], 0); + icon = PluginUtils.GetExeIcon(config.commandlines[commandName], 0); } catch (Exception ex) { - LOG.Warn("Problem loading icon for " + config.commandlines[exepath], ex); + LOG.Warn("Problem loading icon for " + config.commandlines[commandName], ex); } } - iconCache.Add(exepath, icon); + iconCache.Add(commandName, icon); } - return iconCache[exepath]; + return iconCache[commandName]; } else { return null; } diff --git a/GreenshotExternalCommandPlugin/SettingsForm.cs b/GreenshotExternalCommandPlugin/SettingsForm.cs index 8e7a72275..411bf4c69 100644 --- a/GreenshotExternalCommandPlugin/SettingsForm.cs +++ b/GreenshotExternalCommandPlugin/SettingsForm.cs @@ -76,7 +76,7 @@ namespace ExternalCommand { int imageNr = 0; foreach (string commando in config.commands) { ListViewItem item = null; - Image iconForExe = IconCache.IconForExe(commando); + Image iconForExe = IconCache.IconForCommand(commando); if (iconForExe != null) { imageList.Images.Add(iconForExe); item = new ListViewItem(commando, imageNr++); @@ -87,6 +87,8 @@ namespace ExternalCommand { listView1.Items.Add(item); } } + // Fix for bug #1484, getting an ArgumentOutOfRangeException as there is nothing selected but the edit button was still active. + button_edit.Enabled = listView1.SelectedItems.Count > 0; } void ListView1ItemSelectionChanged(object sender, EventArgs e) { @@ -98,6 +100,12 @@ namespace ExternalCommand { } void ListView1DoubleClick(object sender, EventArgs e) { + // Safety check for bug #1484 + bool selectionActive = listView1.SelectedItems.Count > 0; + if (!selectionActive) { + button_edit.Enabled = false; + return; + } string commando = listView1.SelectedItems[0].Tag as string; SettingsFormDetail form = new SettingsFormDetail(commando);