mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Fixed for latest SVN state and refactored for IniConfig
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@865 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
13dad61313
commit
aeefa9a767
4 changed files with 142 additions and 144 deletions
58
PluginExample/ExampleConfiguration.cs
Normal file
58
PluginExample/ExampleConfiguration.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 PluginExample {
|
||||
public enum Location {
|
||||
TopLeft, TopCenter, TopRight,
|
||||
CenterLeft, CenterCenter, CenterRight,
|
||||
BottomLeft, BottomCenter, BottomRight
|
||||
}
|
||||
/// <summary>
|
||||
/// Description of FlickrConfiguration.
|
||||
/// </summary>
|
||||
[IniSection("Example", Description="Greenshot Example Plugin configuration")]
|
||||
public class ExampleConfiguration : IniSection {
|
||||
[IniProperty("AddAnnotations", Description="Do we need to add annotations?")]
|
||||
public bool AddAnnotations;
|
||||
|
||||
[IniProperty("Annotations", Description="The annotations")]
|
||||
public Dictionary<Location, string> annotations;
|
||||
|
||||
/// <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 "Annotations":
|
||||
Dictionary<Location, string> annotationDefaults = new Dictionary<Location, string>();
|
||||
annotationDefaults.Add(Location.TopLeft, "%user%");
|
||||
annotationDefaults.Add(Location.BottomRight, "%hostname%");
|
||||
return annotationDefaults;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ using System.Text;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Core;
|
||||
using Greenshot.Drawing;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Plugin;
|
||||
|
@ -40,7 +41,7 @@ namespace PluginExample {
|
|||
private IGreenshotPluginHost host;
|
||||
private ICaptureHost captureHost = null;
|
||||
private PluginAttribute myAttributes;
|
||||
private bool testAnnotations = false;
|
||||
private ExampleConfiguration config;
|
||||
|
||||
public PluginExample() {
|
||||
}
|
||||
|
@ -61,6 +62,8 @@ namespace PluginExample {
|
|||
this.host.OnImageEditorOpen += new OnImageEditorOpenHandler(ImageEditorOpened);
|
||||
this.host.OnSurfaceFromCapture += new OnSurfaceFromCaptureHandler(SurfaceFromCapture);
|
||||
this.host.OnImageOutput += new OnImageOutputHandler(ImageOutput);
|
||||
|
||||
this.config = IniConfig.GetIniSection<ExampleConfiguration>();
|
||||
}
|
||||
|
||||
public virtual void Shutdown() {
|
||||
|
@ -75,10 +78,10 @@ namespace PluginExample {
|
|||
/// </summary>
|
||||
public virtual void Configure() {
|
||||
LOG.Debug("Configure called");
|
||||
SettingsForm settingsForm = new SettingsForm(testAnnotations);
|
||||
SettingsForm settingsForm = new SettingsForm(config.AddAnnotations);
|
||||
DialogResult result = settingsForm.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
testAnnotations = settingsForm.TestAnnotations;
|
||||
config.AddAnnotations = settingsForm.TestAnnotations;
|
||||
}
|
||||
settingsForm.Dispose();
|
||||
}
|
||||
|
@ -118,10 +121,10 @@ namespace PluginExample {
|
|||
ToolStripMenuItem item = (ToolStripMenuItem)sender;
|
||||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||
|
||||
string file = host.GetFilename("png", null);
|
||||
string file = host.GetFilename(OutputFormat.Png, null);
|
||||
string filePath = Path.Combine(host.ConfigurationPath,file);
|
||||
using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
|
||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
||||
imageEditor.SaveToStream(stream, OutputFormat.Png, 100);
|
||||
}
|
||||
LOG.Debug("Saved test file to: " + filePath);
|
||||
}
|
||||
|
@ -170,28 +173,87 @@ namespace PluginExample {
|
|||
/// <param name="SurfaceFromCaptureEventArgs">Has the ICapture and ISurface</param>
|
||||
public void SurfaceFromCapture(object sender, SurfaceFromCaptureEventArgs eventArgs) {
|
||||
LOG.Debug("SurfaceFromCapture called");
|
||||
if (!testAnnotations) {
|
||||
if (!config.AddAnnotations) {
|
||||
return;
|
||||
}
|
||||
ISurface surface = eventArgs.Surface;
|
||||
|
||||
surface.SelectElement(surface.AddCursorContainer(Cursors.Hand, 100, 100));
|
||||
// Do something with the screenshot
|
||||
string title = eventArgs.Capture.CaptureDetails.Title;
|
||||
if (title != null) {
|
||||
LOG.Debug("Added title to surface: " + title);
|
||||
surface.SelectElement(surface.AddTextContainer(title, HorizontalAlignment.Center, VerticalAlignment.CENTER,
|
||||
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
|
||||
surface.SelectElement(surface.AddTextContainer(Environment.UserName, HorizontalAlignment.Right, VerticalAlignment.TOP,
|
||||
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
|
||||
surface.SelectElement(surface.AddTextContainer(Environment.MachineName, HorizontalAlignment.Right, VerticalAlignment.BOTTOM,
|
||||
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
|
||||
surface.SelectElement(surface.AddTextContainer(eventArgs.Capture.CaptureDetails.DateTime.ToLongDateString(), HorizontalAlignment.Left, VerticalAlignment.BOTTOM,
|
||||
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
|
||||
// Example, add a Cursor
|
||||
//surface.SelectElement(surface.AddCursorContainer(Cursors.Hand, 100, 100));
|
||||
|
||||
} else {
|
||||
LOG.Debug("No title available, doing nothing.");
|
||||
}
|
||||
DateTime captureTaken = DateTime.Now;
|
||||
// Use default application name for title
|
||||
string title = Application.ProductName;
|
||||
|
||||
// Check if we have capture details
|
||||
if ( eventArgs.Capture.CaptureDetails != null) {
|
||||
captureTaken = eventArgs.Capture.CaptureDetails.DateTime;
|
||||
if (eventArgs.Capture.CaptureDetails.Title != null) {
|
||||
title = eventArgs.Capture.CaptureDetails.Title;
|
||||
}
|
||||
}
|
||||
foreach(Location location in config.annotations.Keys) {
|
||||
string pattern = config.annotations[location];
|
||||
pattern = pattern.Replace("%YYYY%",captureTaken.Year.ToString());
|
||||
pattern = pattern.Replace("%MM%", zeroPad(captureTaken.Month.ToString(), 2));
|
||||
pattern = pattern.Replace("%DD%", zeroPad(captureTaken.Day.ToString(), 2));
|
||||
pattern = pattern.Replace("%hh%", zeroPad(captureTaken.Hour.ToString(), 2));
|
||||
pattern = pattern.Replace("%mm%", zeroPad(captureTaken.Minute.ToString(), 2));
|
||||
pattern = pattern.Replace("%ss%", zeroPad(captureTaken.Second.ToString(), 2));
|
||||
pattern = pattern.Replace("%domain%", Environment.UserDomainName);
|
||||
pattern = pattern.Replace("%user%", Environment.UserName);
|
||||
pattern = pattern.Replace("%hostname%", Environment.MachineName);
|
||||
pattern = pattern.Replace("%title%", title);
|
||||
HorizontalAlignment hAlign = HorizontalAlignment.Center;
|
||||
VerticalAlignment vAlign = VerticalAlignment.CENTER;
|
||||
switch(location) {
|
||||
case Location.TopLeft:
|
||||
hAlign = HorizontalAlignment.Left;
|
||||
vAlign = VerticalAlignment.TOP;
|
||||
break;
|
||||
case Location.TopCenter:
|
||||
hAlign = HorizontalAlignment.Center;
|
||||
vAlign = VerticalAlignment.TOP;
|
||||
break;
|
||||
case Location.TopRight:
|
||||
hAlign = HorizontalAlignment.Right;
|
||||
vAlign = VerticalAlignment.TOP;
|
||||
break;
|
||||
|
||||
case Location.CenterLeft:
|
||||
hAlign = HorizontalAlignment.Left;
|
||||
vAlign = VerticalAlignment.CENTER;
|
||||
break;
|
||||
case Location.CenterCenter:
|
||||
hAlign = HorizontalAlignment.Center;
|
||||
vAlign = VerticalAlignment.CENTER;
|
||||
break;
|
||||
case Location.CenterRight:
|
||||
hAlign = HorizontalAlignment.Right;
|
||||
vAlign = VerticalAlignment.CENTER;
|
||||
break;
|
||||
|
||||
case Location.BottomLeft:
|
||||
hAlign = HorizontalAlignment.Left;
|
||||
vAlign = VerticalAlignment.BOTTOM;
|
||||
break;
|
||||
case Location.BottomCenter:
|
||||
hAlign = HorizontalAlignment.Center;
|
||||
vAlign = VerticalAlignment.BOTTOM;
|
||||
break;
|
||||
case Location.BottomRight:
|
||||
hAlign = HorizontalAlignment.Right;
|
||||
vAlign = VerticalAlignment.BOTTOM;
|
||||
break;
|
||||
}
|
||||
surface.SelectElement(surface.AddTextContainer(pattern, hAlign, vAlign,
|
||||
FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
|
||||
}
|
||||
}
|
||||
|
||||
private static string zeroPad(string input, int chars) {
|
||||
while(input.Length < chars) input = "0" + input;
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,6 +49,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DrawingUtils.cs" />
|
||||
<Compile Include="ExampleConfiguration.cs" />
|
||||
<Compile Include="PluginExample.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SettingsForm.cs" />
|
||||
|
@ -56,9 +57,6 @@
|
|||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\AssemblyInfo.cs.template" />
|
||||
<EmbeddedResource Include="SettingsForm.resx">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
Loading…
Add table
Add a link
Reference in a new issue