mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Made the plug-in work with the new ini configuration framework
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@859 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
bb7f216567
commit
f000080bc4
6 changed files with 133 additions and 137 deletions
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RunAtOutput {
|
||||
/// <summary>
|
||||
/// Description of Configuration.
|
||||
/// </summary>
|
||||
[XmlRoot("RunAtOutput")]
|
||||
public class Configuration {
|
||||
public Configuration() {
|
||||
Commands = new List<Commando>();
|
||||
}
|
||||
[XmlElement("Commando")]
|
||||
public List<Commando> Commands {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
public class Commando {
|
||||
public Commando() {
|
||||
}
|
||||
[XmlAttribute("Name")]
|
||||
public string Name {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
[XmlElement("Commandline")]
|
||||
public string Commandline {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
[XmlElement("Arguments")]
|
||||
public string Arguments {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
[XmlAttribute("Active")]
|
||||
public bool Active{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,15 +49,14 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration.cs" />
|
||||
<Compile Include="RunAtOutput.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RunAtOutputConfiguration.cs" />
|
||||
<Compile Include="SettingsForm.cs" />
|
||||
<Compile Include="SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\AssemblyInfo.cs.template" />
|
||||
<None Include="runatoutput.properties" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
|
||||
|
|
|
@ -29,6 +29,7 @@ using System.Windows.Forms;
|
|||
using System.Xml.Serialization;
|
||||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
namespace RunAtOutput {
|
||||
|
@ -40,7 +41,7 @@ namespace RunAtOutput {
|
|||
private IGreenshotPluginHost host;
|
||||
private ICaptureHost captureHost = null;
|
||||
private PluginAttribute myAttributes;
|
||||
private Configuration config = new Configuration();
|
||||
private RunAtOutputConfiguration config;
|
||||
|
||||
public RunAtOutputPlugin() {
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ namespace RunAtOutput {
|
|||
this.myAttributes = myAttributes;
|
||||
this.host.OnImageOutput += new OnImageOutputHandler(ImageOutput);
|
||||
|
||||
LoadConfig();
|
||||
this.config = IniConfig.GetIniSection<RunAtOutputConfiguration>();
|
||||
}
|
||||
|
||||
public virtual void Shutdown() {
|
||||
|
@ -72,29 +73,7 @@ namespace RunAtOutput {
|
|||
/// </summary>
|
||||
public virtual void Configure() {
|
||||
LOG.Debug("Configure called");
|
||||
SettingsForm settingsForm = new SettingsForm(config);
|
||||
if (settingsForm.ShowDialog() == DialogResult.OK) {
|
||||
SaveConfig();
|
||||
}
|
||||
settingsForm.Dispose();
|
||||
}
|
||||
|
||||
private void LoadConfig() {
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
|
||||
string filename = Path.Combine(host.ConfigurationPath, "RunAtOutputPlugin.xml");
|
||||
if (File.Exists(filename)) {
|
||||
using (TextReader reader = new StreamReader(filename)) {
|
||||
config = (Configuration)xmlSerializer.Deserialize(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveConfig() {
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
|
||||
string filename = Path.Combine(host.ConfigurationPath, "RunAtOutputPlugin.xml");
|
||||
using (TextWriter writer = new StreamWriter(filename)) {
|
||||
xmlSerializer.Serialize(writer, config);
|
||||
}
|
||||
new SettingsForm().ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -103,22 +82,22 @@ namespace RunAtOutput {
|
|||
/// <param name="ImageOutputEventArgs">Has the FullPath to the image</param>
|
||||
private void ImageOutput(object sender, ImageOutputEventArgs eventArgs) {
|
||||
LOG.Debug("ImageOutput called with full path: " + eventArgs.FullPath);
|
||||
foreach(Commando commando in config.Commands) {
|
||||
if (commando.Active) {
|
||||
if (commando.Commandline != null && commando.Commandline.Length > 0) {
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = commando.Commandline;
|
||||
p.StartInfo.Arguments = String.Format(commando.Arguments, eventArgs.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);
|
||||
}
|
||||
foreach(string commando in config.active) {
|
||||
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, eventArgs.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
75
Greenshot-RunAtOutput-Plugin/RunAtOutputConfiguration.cs
Normal file
75
Greenshot-RunAtOutput-Plugin/RunAtOutputConfiguration.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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 Greenshot.Core;
|
||||
|
||||
namespace RunAtOutput {
|
||||
/// <summary>
|
||||
/// Description of FlickrConfiguration.
|
||||
/// </summary>
|
||||
[IniSection("RunAtOutput", Description="Greenshot TitRunAtOutputleFix Plugin configuration")]
|
||||
public class RunAtOutputConfiguration : IniSection {
|
||||
[IniProperty("Commands", Description="The commands that are available.")]
|
||||
public List<string> commands;
|
||||
|
||||
//[IniProperty("Matcher", Description="Match filenames or types.")]
|
||||
//public Dictionary<string, string> matchers;
|
||||
|
||||
[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;
|
||||
|
||||
[IniProperty("ActiveCommands", Description="The commands that are active.")]
|
||||
public List<string> active;
|
||||
|
||||
/// <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>();
|
||||
commandDefaults.Add("Paint.NET");
|
||||
return commandDefaults;
|
||||
case "Commandline":
|
||||
Dictionary<string, string> commandlineDefaults = new Dictionary<string, string>();
|
||||
commandlineDefaults.Add("Paint.NET", @"C:\Programme\Paint.NET\PaintDotNet.exe");
|
||||
return commandlineDefaults;
|
||||
// case "Matcher":
|
||||
// Dictionary<string, string> matcherDefaults = new Dictionary<string, string>();
|
||||
// matcherDefaults.Add("Paint.NET", "*");
|
||||
// return matcherDefaults;
|
||||
case "ActiveCommands":
|
||||
return new List<string>();
|
||||
case "Argument":
|
||||
Dictionary<string, string> argumentDefaults = new Dictionary<string, string>();
|
||||
argumentDefaults.Add("Paint.NET", "\"{0}\"");
|
||||
return argumentDefaults;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,16 +22,18 @@ using System;
|
|||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Core;
|
||||
|
||||
namespace RunAtOutput {
|
||||
/// <summary>
|
||||
/// Description of SettingsForm.
|
||||
/// </summary>
|
||||
public partial class SettingsForm : Form {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm));
|
||||
private Configuration config;
|
||||
private RunAtOutputConfiguration config;
|
||||
|
||||
public SettingsForm(Configuration config) {
|
||||
this.config = config;
|
||||
public SettingsForm() {
|
||||
this.config = IniConfig.GetIniSection<RunAtOutputConfiguration>();
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
|
@ -40,6 +42,7 @@ namespace RunAtOutput {
|
|||
}
|
||||
|
||||
void ButtonOkClick(object sender, EventArgs e) {
|
||||
IniConfig.Save();
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
|
@ -49,38 +52,43 @@ namespace RunAtOutput {
|
|||
|
||||
void ShowSelectedItem() {
|
||||
foreach ( ListViewItem item in listView1.SelectedItems ) {
|
||||
Commando commando = item.Tag as Commando;
|
||||
textBox_arguments.Text = commando.Arguments;
|
||||
textBox_commandline.Text = commando.Commandline;
|
||||
textBox_name.Text = commando.Name;
|
||||
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) {
|
||||
Commando commando = new Commando();
|
||||
commando.Arguments = textBox_arguments.Text;
|
||||
commando.Commandline = textBox_commandline.Text;
|
||||
commando.Name = textBox_name.Text;
|
||||
config.Commands.Add(commando);
|
||||
config.commands.Add(textBox_name.Text);
|
||||
config.commandlines.Add(textBox_name.Text, textBox_commandline.Text);
|
||||
config.arguments.Add(textBox_name.Text, textBox_arguments.Text);
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
void ButtonDeleteClick(object sender, EventArgs e) {
|
||||
foreach ( ListViewItem item in listView1.SelectedItems ) {
|
||||
Commando commando = item.Tag as Commando;
|
||||
config.Commands.Remove(commando);
|
||||
string commando = item.Tag as string;
|
||||
config.active.Remove(textBox_name.Text);
|
||||
config.commands.Remove(textBox_name.Text);
|
||||
config.commandlines.Remove(textBox_name.Text);
|
||||
config.arguments.Remove(textBox_name.Text);
|
||||
}
|
||||
UpdateView();
|
||||
}
|
||||
|
||||
void UpdateView() {
|
||||
listView1.Items.Clear();
|
||||
foreach(Commando commando in config.Commands) {
|
||||
ListViewItem item = new ListViewItem("");
|
||||
item.SubItems.Add(commando.Name);
|
||||
item.Checked = commando.Active;
|
||||
item.Tag = commando;
|
||||
listView1.Items.Add(item);
|
||||
if (config.commands != null) {
|
||||
foreach(string commando in config.commands) {
|
||||
ListViewItem item = new ListViewItem("");
|
||||
item.SubItems.Add(commando);
|
||||
if (config.active != null) {
|
||||
item.Checked = config.active.Contains(commando);
|
||||
}
|
||||
item.Tag = commando;
|
||||
listView1.Items.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,9 +98,14 @@ namespace RunAtOutput {
|
|||
}
|
||||
|
||||
void ListView1ItemChecked(object sender, ItemCheckedEventArgs e) {
|
||||
Commando commando = e.Item.Tag as Commando;
|
||||
LOG.Debug("ItemChecked " + commando.Name + " to " + e.Item.Checked);
|
||||
commando.Active = e.Item.Checked;
|
||||
string commando = e.Item.Tag as string;
|
||||
LOG.Debug("ItemChecked " + commando + " to " + e.Item.Checked);
|
||||
if (e.Item.Checked && !config.active.Contains(commando)) {
|
||||
config.active.Add(commando);
|
||||
}
|
||||
if (!e.Item.Checked) {
|
||||
config.active.Remove(commando);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
active=OptiPNG,Paint.NET
|
||||
command.Paint.NET=C:\Programme\Paint.NET\PaintDotNet.exe {0}
|
||||
pattern.OptiPNG=*.png
|
||||
command.OptiPNG=D:\05018085\downloads\optipng-0.6.4-exe\optipng.exe {0}
|
Loading…
Add table
Add a link
Reference in a new issue