mirror of
https://github.com/greenshot/greenshot
synced 2025-07-30 19:50:11 -07:00
Added icons to the external commands editor & added a check for the OK button
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1746 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
5780560fbe
commit
cdba70d227
8 changed files with 109 additions and 22 deletions
|
@ -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<ExternalCommandConfiguration>();
|
||||
private static Dictionary<string, Image> iconCache = new Dictionary<string, Image>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="ExternalCommandDestination.cs" />
|
||||
<Compile Include="ExternalCommandPlugin.cs" />
|
||||
<Compile Include="IconCache.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ExternalCommandConfiguration.cs" />
|
||||
<Compile Include="SettingsForm.cs" />
|
||||
|
|
34
GreenshotExternalCommandPlugin/IconCache.cs
Normal file
34
GreenshotExternalCommandPlugin/IconCache.cs
Normal file
|
@ -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<string, Image> iconCache = new Dictionary<string, Image>();
|
||||
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,12 +112,12 @@
|
|||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
AAABAAUAAAAAAAEACAClFwAAVgAAADAwAAABAAgAqA4AAPsXAAAgIAAAAQAIAKgIAACjJgAAGBgAAAEA
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,9 +112,9 @@
|
|||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
Add table
Add a link
Reference in a new issue