mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
FEATURE-945: Added environment variables to the external command (also removed unused imports and made some variables readonly)
This commit is contained in:
parent
4f326c9c0e
commit
d25021631e
90 changed files with 390 additions and 373 deletions
|
@ -24,44 +24,45 @@ using System;
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
namespace ExternalCommand {
|
||||
/// <summary>
|
||||
/// Description of SettingsFormDetail.
|
||||
/// </summary>
|
||||
public partial class SettingsFormDetail : ExternalCommandForm {
|
||||
private string commando;
|
||||
private int commandIndex;
|
||||
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsFormDetail));
|
||||
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
private static readonly ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
|
||||
private readonly string _commando;
|
||||
private readonly int _commandIndex;
|
||||
|
||||
public SettingsFormDetail(string commando) {
|
||||
InitializeComponent();
|
||||
AcceptButton = buttonOk;
|
||||
CancelButton = buttonCancel;
|
||||
this.commando = commando;
|
||||
_commando = commando;
|
||||
|
||||
if(commando != null) {
|
||||
textBox_name.Text = commando;
|
||||
textBox_commandline.Text = config.commandlines[commando];
|
||||
textBox_arguments.Text = config.arguments[commando];
|
||||
commandIndex = config.commands.FindIndex(delegate(string s) { return s == commando; });
|
||||
_commandIndex = config.commands.FindIndex(delegate(string s) { return s == commando; });
|
||||
} else {
|
||||
textBox_arguments.Text = "\"{0}\"";
|
||||
}
|
||||
OKButtonState();
|
||||
OkButtonState();
|
||||
}
|
||||
|
||||
void ButtonOkClick(object sender, EventArgs e) {
|
||||
string commandName = textBox_name.Text;
|
||||
string commandLine = textBox_commandline.Text;
|
||||
string arguments = textBox_arguments.Text;
|
||||
if(commando != null) {
|
||||
config.commands[commandIndex] = commandName;
|
||||
config.commandlines.Remove(commando);
|
||||
if(_commando != null) {
|
||||
config.commands[_commandIndex] = commandName;
|
||||
config.commandlines.Remove(_commando);
|
||||
config.commandlines.Add(commandName, commandLine);
|
||||
config.arguments.Remove(commando);
|
||||
config.arguments.Remove(_commando);
|
||||
config.arguments.Add(commandName, arguments);
|
||||
} else {
|
||||
config.commands.Add(commandName);
|
||||
|
@ -71,15 +72,23 @@ namespace ExternalCommand {
|
|||
}
|
||||
|
||||
void Button3Click(object sender, EventArgs e) {
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.Filter = "Executables (*.exe, *.bat, *.com)|*.exe; *.bat; *.com|All files (*)|*";
|
||||
openFileDialog.FilterIndex = 1;
|
||||
openFileDialog.CheckFileExists = true;
|
||||
openFileDialog.Multiselect = false;
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog
|
||||
{
|
||||
Filter = "Executables (*.exe, *.bat, *.com)|*.exe; *.bat; *.com|All files (*)|*",
|
||||
FilterIndex = 1,
|
||||
CheckFileExists = true,
|
||||
Multiselect = false
|
||||
};
|
||||
string initialPath = null;
|
||||
try {
|
||||
try
|
||||
{
|
||||
initialPath = Path.GetDirectoryName(textBox_commandline.Text);
|
||||
} catch { }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.WarnFormat("Can't get the initial path via {0}", textBox_commandline.Text);
|
||||
LOG.Warn("Exception: ", ex);
|
||||
}
|
||||
if(initialPath != null && Directory.Exists(initialPath)) {
|
||||
openFileDialog.InitialDirectory = initialPath;
|
||||
} else {
|
||||
|
@ -92,7 +101,7 @@ namespace ExternalCommand {
|
|||
}
|
||||
}
|
||||
|
||||
private void OKButtonState() {
|
||||
private void OkButtonState() {
|
||||
// Assume OK
|
||||
buttonOk.Enabled = true;
|
||||
textBox_name.BackColor = Color.White;
|
||||
|
@ -103,7 +112,7 @@ namespace ExternalCommand {
|
|||
buttonOk.Enabled = false;
|
||||
}
|
||||
// Check if commandname is unique
|
||||
if(commando == null && !string.IsNullOrEmpty(textBox_name.Text) && config.commands.Contains(textBox_name.Text)) {
|
||||
if(_commando == null && !string.IsNullOrEmpty(textBox_name.Text) && config.commands.Contains(textBox_name.Text)) {
|
||||
buttonOk.Enabled = false;
|
||||
textBox_name.BackColor = Color.Red;
|
||||
}
|
||||
|
@ -111,15 +120,27 @@ namespace ExternalCommand {
|
|||
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;
|
||||
|
||||
if (!string.IsNullOrEmpty(textBox_commandline.Text))
|
||||
{
|
||||
// Added this to be more flexible, using the Greenshot var format
|
||||
string cmdPath = FilenameHelper.FillVariables(textBox_commandline.Text, true);
|
||||
// And also replace the "DOS" Variables
|
||||
cmdPath = FilenameHelper.FillCmdVariables(cmdPath, true);
|
||||
// Is the command available?
|
||||
if (!File.Exists(cmdPath))
|
||||
{
|
||||
buttonOk.Enabled = false;
|
||||
textBox_commandline.BackColor = Color.Red;
|
||||
}
|
||||
}
|
||||
// Are the arguments in a valid format?
|
||||
try
|
||||
// Are the arguments in a valid format?
|
||||
try
|
||||
{
|
||||
ExternalCommandDestination.FormatArguments(textBox_arguments.Text, string.Empty);
|
||||
string arguments = FilenameHelper.FillVariables(textBox_arguments.Text, false);
|
||||
arguments = FilenameHelper.FillCmdVariables(arguments, false);
|
||||
|
||||
ExternalCommandDestination.FormatArguments(arguments, string.Empty);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -129,16 +150,16 @@ namespace ExternalCommand {
|
|||
}
|
||||
|
||||
private void textBox_name_TextChanged(object sender, EventArgs e) {
|
||||
OKButtonState();
|
||||
OkButtonState();
|
||||
}
|
||||
|
||||
private void textBox_commandline_TextChanged(object sender, EventArgs e) {
|
||||
OKButtonState();
|
||||
OkButtonState();
|
||||
}
|
||||
|
||||
private void textBox_arguments_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
OKButtonState();
|
||||
OkButtonState();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue