mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
Moving back to trunk!
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1602 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
ad265b2c54
commit
8d458998a1
332 changed files with 17647 additions and 9466 deletions
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using GreenshotPlugin.Core;
|
||||
using IniFile;
|
||||
|
||||
namespace ExternalCommand {
|
||||
/// <summary>
|
||||
/// Description of FlickrConfiguration.
|
||||
/// </summary>
|
||||
[IniSection("ExternalCommand", Description="Greenshot ExternalCommand Plugin configuration")]
|
||||
public class ExternalCommandConfiguration : IniSection {
|
||||
[IniProperty("Commands", Description="The commands that are available.")]
|
||||
public List<string> commands;
|
||||
|
||||
[IniProperty("Commandline", Description="The commandline for the output command.")]
|
||||
public Dictionary<string, string> commandlines;
|
||||
|
||||
[IniProperty("Argument", Description="The arguments for the output command.")]
|
||||
public Dictionary<string, string> arguments;
|
||||
|
||||
private const string MSPAINT = "MS Paint";
|
||||
private static string paintPath = AbstractDestination.GetExePath("pbrush.exe");
|
||||
private static bool hasPaint = !string.IsNullOrEmpty(paintPath) && File.Exists(paintPath);
|
||||
|
||||
private const string PAINTDOTNET = "Paint.NET";
|
||||
private static string paintDotNetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Paint.NET\PaintDotNet.exe");
|
||||
private static bool hasPaintDotNet = !string.IsNullOrEmpty(paintDotNetPath) && File.Exists(paintDotNetPath);
|
||||
|
||||
/// <summary>
|
||||
/// Supply values we can't put as defaults
|
||||
/// </summary>
|
||||
/// <param name="property">The property to return a default for</param>
|
||||
/// <returns>object with the default value for the supplied property</returns>
|
||||
public override object GetDefault(string property) {
|
||||
switch(property) {
|
||||
case "Commands":
|
||||
List<string> commandDefaults = new List<string>();
|
||||
if (hasPaintDotNet) {
|
||||
commandDefaults.Add(PAINTDOTNET);
|
||||
}
|
||||
if (hasPaint) {
|
||||
commandDefaults.Add(MSPAINT);
|
||||
}
|
||||
return commandDefaults;
|
||||
case "Commandline":
|
||||
Dictionary<string, string> commandlineDefaults = new Dictionary<string, string>();
|
||||
if (hasPaintDotNet) {
|
||||
commandlineDefaults.Add(PAINTDOTNET, paintDotNetPath);
|
||||
}
|
||||
if (hasPaint) {
|
||||
commandlineDefaults.Add(MSPAINT, paintPath);
|
||||
}
|
||||
return commandlineDefaults;
|
||||
case "Argument":
|
||||
Dictionary<string, string> argumentDefaults = new Dictionary<string, string>();
|
||||
argumentDefaults.Add(PAINTDOTNET, "\"{0}\"");
|
||||
if (hasPaint) {
|
||||
argumentDefaults.Add(MSPAINT, "\"{0}\"");
|
||||
}
|
||||
return argumentDefaults;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
127
GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
Normal file
127
GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Core;
|
||||
using IniFile;
|
||||
|
||||
namespace ExternalCommand {
|
||||
/// <summary>
|
||||
/// Description of OCRDestination.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
public ExternalCommandDestination(IGreenshotHost host, string commando) {
|
||||
this.host = host;
|
||||
this.presetCommand = commando;
|
||||
}
|
||||
|
||||
public override string Designation {
|
||||
get {
|
||||
return "External " + presetCommand.Replace(',','_');
|
||||
}
|
||||
}
|
||||
|
||||
public override string Description {
|
||||
get {
|
||||
return presetCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool isActive {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<IDestination> DynamicDestinations() {
|
||||
yield break;
|
||||
}
|
||||
|
||||
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]);
|
||||
} catch{};
|
||||
}
|
||||
iconCache.Add(presetCommand, icon);
|
||||
}
|
||||
return iconCache[presetCommand];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) {
|
||||
string fullPath = captureDetails.Filename;
|
||||
if (fullPath == null) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
fullPath = host.SaveNamedTmpFile(image, captureDetails, OutputFormat.png, 100);
|
||||
}
|
||||
}
|
||||
if (presetCommand != null) {
|
||||
Thread commandThread = new Thread (delegate() {
|
||||
CallExternalCommand(presetCommand, fullPath);
|
||||
});
|
||||
commandThread.IsBackground = true;
|
||||
commandThread.Start();
|
||||
surface.SendMessageEvent(this, SurfaceMessageTyp.Info, host.CoreLanguage.GetFormattedString("exported_to", Description));
|
||||
surface.Modified = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CallExternalCommand(string commando, string fullPath) {
|
||||
string commandline = config.commandlines[commando];
|
||||
string arguments = config.arguments[commando];
|
||||
if (commandline != null && commandline.Length > 0) {
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = commandline;
|
||||
p.StartInfo.Arguments = String.Format(arguments, fullPath);
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
LOG.Info("Starting : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments);
|
||||
p.Start();
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
if (output != null && output.Trim().Length > 0) {
|
||||
LOG.Info("Output:\n" + output);
|
||||
}
|
||||
LOG.Info("Finished : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
83
GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs
Normal file
83
GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Greenshot.Plugin;
|
||||
using IniFile;
|
||||
|
||||
namespace ExternalCommand {
|
||||
/// <summary>
|
||||
/// An Plugin to run commands after an image was written
|
||||
/// </summary>
|
||||
public class ExternalCommandPlugin : IGreenshotPlugin {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandPlugin));
|
||||
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
private IGreenshotHost host;
|
||||
private PluginAttribute myAttributes;
|
||||
|
||||
public ExternalCommandPlugin() {
|
||||
}
|
||||
|
||||
public IEnumerable<IDestination> Destinations() {
|
||||
foreach(string command in config.commands) {
|
||||
yield return new ExternalCommandDestination(host, command);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IProcessor> Processors() {
|
||||
yield break;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the IGreenshotPlugin.Initialize
|
||||
/// </summary>
|
||||
/// <param name="host">Use the IGreenshotPluginHost interface to register events</param>
|
||||
/// <param name="captureHost">Use the ICaptureHost interface to register in the MainContextMenu</param>
|
||||
/// <param name="pluginAttribute">My own attributes</param>
|
||||
public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) {
|
||||
LOG.Debug("Initialize called of " + myAttributes.Name);
|
||||
|
||||
// Cleanup configuration
|
||||
foreach(string command in config.commandlines.Keys) {
|
||||
if (!File.Exists(config.commandlines[command])) {
|
||||
config.commands.Remove(command);
|
||||
}
|
||||
}
|
||||
this.host = pluginHost;
|
||||
this.myAttributes = myAttributes;
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void Shutdown() {
|
||||
LOG.Debug("Shutdown of " + myAttributes.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the IPlugin.Configure
|
||||
/// </summary>
|
||||
public virtual void Configure() {
|
||||
LOG.Debug("Configure called");
|
||||
new SettingsForm().ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{47F23C86-604E-4CC3-8767-B3D4088F30BB}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>GreenshotExternalCommandPlugin</RootNamespace>
|
||||
<AssemblyName>GreenshotExternalCommandPlugin</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<SourceAnalysisOverrideSettingsFile>C:\Users\Robin\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>Full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<DebugType>None</DebugType>
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ExternalCommandDestination.cs" />
|
||||
<Compile Include="ExternalCommandPlugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ExternalCommandConfiguration.cs" />
|
||||
<Compile Include="SettingsForm.cs" />
|
||||
<Compile Include="SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\AssemblyInfo.cs.template" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
|
||||
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
|
||||
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
|
||||
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
|
||||
<Name>GreenshotPlugin</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("GreenshotExternalCommandPlugin")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("GreenshotExternalCommandPlugin")]
|
||||
[assembly: AssemblyCopyright("Copyright (C) 2007-2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: PluginAttribute("ExternalCommand.ExternalCommandPlugin", true)]
|
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.$WCREV$")]
|
216
GreenshotExternalCommandPlugin/SettingsForm.Designer.cs
generated
Normal file
216
GreenshotExternalCommandPlugin/SettingsForm.Designer.cs
generated
Normal file
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace ExternalCommand {
|
||||
partial class SettingsForm {
|
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the form.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
if (components != null) {
|
||||
components.Dispose();
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.textBox_commandline = new System.Windows.Forms.TextBox();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonOk = new System.Windows.Forms.Button();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.textBox_arguments = new System.Windows.Forms.TextBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.listView1 = new System.Windows.Forms.ListView();
|
||||
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.textBox_name = new System.Windows.Forms.TextBox();
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBox_commandline
|
||||
//
|
||||
this.textBox_commandline.Location = new System.Drawing.Point(156, 245);
|
||||
this.textBox_commandline.Name = "textBox_commandline";
|
||||
this.textBox_commandline.Size = new System.Drawing.Size(225, 20);
|
||||
this.textBox_commandline.TabIndex = 2;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(339, 302);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
this.buttonOk.Location = new System.Drawing.Point(258, 302);
|
||||
this.buttonOk.Name = "buttonOk";
|
||||
this.buttonOk.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonOk.TabIndex = 6;
|
||||
this.buttonOk.Text = "OK";
|
||||
this.buttonOk.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Click += new System.EventHandler(this.ButtonOkClick);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Location = new System.Drawing.Point(94, 248);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(56, 17);
|
||||
this.label1.TabIndex = 3;
|
||||
this.label1.Text = "Command";
|
||||
//
|
||||
// textBox_arguments
|
||||
//
|
||||
this.textBox_arguments.Location = new System.Drawing.Point(156, 271);
|
||||
this.textBox_arguments.Name = "textBox_arguments";
|
||||
this.textBox_arguments.Size = new System.Drawing.Size(257, 20);
|
||||
this.textBox_arguments.TabIndex = 3;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.Location = new System.Drawing.Point(94, 274);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(56, 17);
|
||||
this.label2.TabIndex = 5;
|
||||
this.label2.Text = "Arguments";
|
||||
//
|
||||
// listView1
|
||||
//
|
||||
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.columnHeader1});
|
||||
this.listView1.FullRowSelect = true;
|
||||
this.listView1.Location = new System.Drawing.Point(13, 13);
|
||||
this.listView1.MultiSelect = false;
|
||||
this.listView1.Name = "listView1";
|
||||
this.listView1.Size = new System.Drawing.Size(400, 183);
|
||||
this.listView1.Sorting = System.Windows.Forms.SortOrder.Ascending;
|
||||
this.listView1.TabIndex = 0;
|
||||
this.listView1.UseCompatibleStateImageBehavior = false;
|
||||
this.listView1.View = System.Windows.Forms.View.Details;
|
||||
this.listView1.SelectedIndexChanged += new System.EventHandler(this.ListView1ItemSelectionChanged);
|
||||
//
|
||||
// columnHeader1
|
||||
//
|
||||
this.columnHeader1.Text = "Name";
|
||||
this.columnHeader1.Width = 395;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(13, 202);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||
this.button1.TabIndex = 4;
|
||||
this.button1.Text = "Add";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.ButtonAddClick);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(12, 231);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(75, 23);
|
||||
this.button2.TabIndex = 5;
|
||||
this.button2.Text = "Delete";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.ButtonDeleteClick);
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.Location = new System.Drawing.Point(94, 222);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(56, 17);
|
||||
this.label3.TabIndex = 10;
|
||||
this.label3.Text = "Name";
|
||||
//
|
||||
// textBox_name
|
||||
//
|
||||
this.textBox_name.Location = new System.Drawing.Point(156, 219);
|
||||
this.textBox_name.Name = "textBox_name";
|
||||
this.textBox_name.Size = new System.Drawing.Size(257, 20);
|
||||
this.textBox_name.TabIndex = 1;
|
||||
//
|
||||
// button3
|
||||
//
|
||||
this.button3.Location = new System.Drawing.Point(387, 245);
|
||||
this.button3.Name = "button3";
|
||||
this.button3.Size = new System.Drawing.Size(26, 23);
|
||||
this.button3.TabIndex = 11;
|
||||
this.button3.Text = "...";
|
||||
this.button3.UseVisualStyleBackColor = true;
|
||||
this.button3.Click += new System.EventHandler(this.Button3Click);
|
||||
//
|
||||
// SettingsForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(426, 336);
|
||||
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
|
||||
this.Controls.Add(this.button3);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.textBox_name);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.listView1);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.textBox_arguments);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.buttonOk);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.textBox_commandline);
|
||||
this.Name = "SettingsForm";
|
||||
this.Text = "Command Editor";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
}
|
||||
private System.Windows.Forms.Button button3;
|
||||
private System.Windows.Forms.TextBox textBox_name;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader1;
|
||||
private System.Windows.Forms.ListView listView1;
|
||||
private System.Windows.Forms.TextBox textBox_arguments;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.TextBox textBox_commandline;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Button buttonOk;
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
}
|
||||
}
|
132
GreenshotExternalCommandPlugin/SettingsForm.cs
Normal file
132
GreenshotExternalCommandPlugin/SettingsForm.cs
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using GreenshotPlugin.Core;
|
||||
using IniFile;
|
||||
|
||||
namespace ExternalCommand {
|
||||
/// <summary>
|
||||
/// Description of SettingsForm.
|
||||
/// </summary>
|
||||
public partial class SettingsForm : Form {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm));
|
||||
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
|
||||
public SettingsForm() {
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
InitializeComponent();
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
void ButtonOkClick(object sender, EventArgs e) {
|
||||
// Update the details with those in the textboxes, if one is selected
|
||||
foreach(string command in config.commands) {
|
||||
if (command.Equals(textBox_name.Text)) {
|
||||
config.commandlines[command] = textBox_commandline.Text;
|
||||
config.arguments[command] = textBox_arguments.Text;
|
||||
}
|
||||
}
|
||||
IniConfig.Save();
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
void ButtonCancelClick(object sender, EventArgs e) {
|
||||
DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
|
||||
void ShowSelectedItem() {
|
||||
foreach ( ListViewItem item in listView1.SelectedItems ) {
|
||||
string commando = item.Tag as string;
|
||||
textBox_name.Text = commando;
|
||||
textBox_commandline.Text = config.commandlines[commando];
|
||||
textBox_arguments.Text = config.arguments[commando];
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonAddClick(object sender, EventArgs e) {
|
||||
string commandName = textBox_name.Text;
|
||||
string commandLine = textBox_commandline.Text;
|
||||
string arguments = textBox_arguments.Text;
|
||||
if (config.commands.Contains(commandName)) {
|
||||
config.commandlines[commandName] = commandLine;
|
||||
config.arguments[commandName] = arguments;
|
||||
} else {
|
||||
config.commands.Add(commandName);
|
||||
config.commandlines.Add(commandName, commandLine);
|
||||
config.arguments.Add(commandName, arguments);
|
||||
}
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
void ButtonDeleteClick(object sender, EventArgs e) {
|
||||
foreach ( ListViewItem item in listView1.SelectedItems ) {
|
||||
string commando = item.Tag as string;
|
||||
config.commands.Remove(textBox_name.Text);
|
||||
config.commandlines.Remove(textBox_name.Text);
|
||||
config.arguments.Remove(textBox_name.Text);
|
||||
}
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
void UpdateView() {
|
||||
listView1.Items.Clear();
|
||||
if (config.commands != null) {
|
||||
foreach(string commando in config.commands) {
|
||||
ListViewItem item = new ListViewItem(commando);
|
||||
item.Tag = commando;
|
||||
listView1.Items.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ListView1ItemSelectionChanged(object sender, EventArgs e) {
|
||||
ShowSelectedItem();
|
||||
}
|
||||
|
||||
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;
|
||||
string initialPath = null;
|
||||
try {
|
||||
initialPath = Path.GetDirectoryName(textBox_commandline.Text);
|
||||
} catch {}
|
||||
if (initialPath != null && Directory.Exists(initialPath)) {
|
||||
openFileDialog.InitialDirectory = initialPath;
|
||||
} else {
|
||||
initialPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
|
||||
openFileDialog.InitialDirectory = initialPath;
|
||||
}
|
||||
LOG.DebugFormat("Starting OpenFileDialog at {0}", initialPath);
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
||||
textBox_commandline.Text = openFileDialog.FileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue