mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 10:47:02 -07:00
Introduced a very simple "singleton" service-locator, which allowed for a removal of specific implementations which were very limited. With this it's easier to access dependencies.
This commit is contained in:
parent
3ebdf3d2fe
commit
80d8f51fc5
53 changed files with 744 additions and 1230 deletions
4
GreenshotPlugin/Interfaces/Plugin/HotKeyHandler.cs
Normal file
4
GreenshotPlugin/Interfaces/Plugin/HotKeyHandler.cs
Normal file
|
@ -0,0 +1,4 @@
|
|||
namespace Greenshot.Plugin
|
||||
{
|
||||
public delegate void HotKeyHandler();
|
||||
}
|
48
GreenshotPlugin/Interfaces/Plugin/IGreenshotHost.cs
Normal file
48
GreenshotPlugin/Interfaces/Plugin/IGreenshotHost.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System.Drawing;
|
||||
|
||||
namespace Greenshot.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface is the GreenshotPluginHost, that which "Hosts" the plugin.
|
||||
/// For Greenshot this is implemented in the PluginHelper
|
||||
/// </summary>
|
||||
public interface IGreenshotHost {
|
||||
/// <summary>
|
||||
/// Create a Thumbnail
|
||||
/// </summary>
|
||||
/// <param name="image">Image of which we need a Thumbnail</param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns>Image with Thumbnail</returns>
|
||||
Image GetThumbnail(Image image, int width, int height);
|
||||
|
||||
/// <summary>
|
||||
/// Export a surface to the destination with has the supplied designation
|
||||
/// </summary>
|
||||
/// <param name="manuallyInitiated"></param>
|
||||
/// <param name="designation"></param>
|
||||
/// <param name="surface"></param>
|
||||
/// <param name="captureDetails"></param>
|
||||
ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails);
|
||||
|
||||
/// <summary>
|
||||
/// Make region capture with specified Handler
|
||||
/// </summary>
|
||||
/// <param name="captureMouseCursor">bool false if the mouse should not be captured, true if the configuration should be checked</param>
|
||||
/// <param name="destination">IDestination destination</param>
|
||||
void CaptureRegion(bool captureMouseCursor, IDestination destination);
|
||||
|
||||
/// <summary>
|
||||
/// Use the supplied capture, and handle it as if it's captured.
|
||||
/// </summary>
|
||||
/// <param name="captureToImport">ICapture to import</param>
|
||||
void ImportCapture(ICapture captureToImport);
|
||||
|
||||
/// <summary>
|
||||
/// Use the supplied image, and ICapture a capture object for it
|
||||
/// </summary>
|
||||
/// <param name="imageToCapture">Image to create capture for</param>
|
||||
/// <returns>ICapture</returns>
|
||||
ICapture GetCapture(Image imageToCapture);
|
||||
}
|
||||
}
|
25
GreenshotPlugin/Interfaces/Plugin/IGreenshotPlugin.cs
Normal file
25
GreenshotPlugin/Interfaces/Plugin/IGreenshotPlugin.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
|
||||
namespace Greenshot.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// This defines the plugin
|
||||
/// </summary>
|
||||
public interface IGreenshotPlugin : IDisposable {
|
||||
/// <summary>
|
||||
/// Is called after the plugin is instantiated, the Plugin should keep a copy of the host and pluginAttribute.
|
||||
/// </summary>
|
||||
/// <returns>true if plugin is initialized, false if not (doesn't show)</returns>
|
||||
bool Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Unload of the plugin
|
||||
/// </summary>
|
||||
void Shutdown();
|
||||
|
||||
/// <summary>
|
||||
/// Open the Configuration Form, will/should not be called before handshaking is done
|
||||
/// </summary>
|
||||
void Configure();
|
||||
}
|
||||
}
|
51
GreenshotPlugin/Interfaces/Plugin/PluginAttribute.cs
Normal file
51
GreenshotPlugin/Interfaces/Plugin/PluginAttribute.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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;
|
||||
|
||||
namespace Greenshot.Plugin {
|
||||
[Serializable]
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class PluginAttribute : Attribute, IComparable {
|
||||
public string Name {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool Configurable {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public PluginAttribute(string name, bool configurable)
|
||||
{
|
||||
Name = name;
|
||||
Configurable = configurable;
|
||||
}
|
||||
|
||||
public int CompareTo(object obj) {
|
||||
if (obj is PluginAttribute other) {
|
||||
return string.Compare(Name, other.Name, StringComparison.Ordinal);
|
||||
}
|
||||
throw new ArgumentException("object is not a PluginAttribute");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,267 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using GreenshotPlugin.Effects;
|
||||
|
||||
namespace Greenshot.Plugin {
|
||||
[Serializable]
|
||||
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class PluginAttribute : Attribute, IComparable {
|
||||
public string Name {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string CreatedBy {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string Version {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public string EntryType {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public bool Configurable {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public string DllFile {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public PluginAttribute(string entryType, bool configurable) {
|
||||
EntryType = entryType;
|
||||
Configurable = configurable;
|
||||
}
|
||||
|
||||
public int CompareTo(object obj) {
|
||||
if (obj is PluginAttribute other) {
|
||||
return Name.CompareTo(other.Name);
|
||||
}
|
||||
throw new ArgumentException("object is not a PluginAttribute");
|
||||
}
|
||||
}
|
||||
|
||||
// Delegates for hooking up events.
|
||||
public delegate void HotKeyHandler();
|
||||
|
||||
public class SurfaceOutputSettings {
|
||||
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private bool _reduceColors;
|
||||
private bool _disableReduceColors;
|
||||
|
||||
public SurfaceOutputSettings() {
|
||||
_disableReduceColors = false;
|
||||
Format = CoreConfig.OutputFileFormat;
|
||||
JPGQuality = CoreConfig.OutputFileJpegQuality;
|
||||
ReduceColors = CoreConfig.OutputFileReduceColors;
|
||||
}
|
||||
|
||||
public SurfaceOutputSettings(OutputFormat format) : this() {
|
||||
Format = format;
|
||||
}
|
||||
|
||||
public SurfaceOutputSettings(OutputFormat format, int quality) : this(format) {
|
||||
JPGQuality = quality;
|
||||
}
|
||||
|
||||
public SurfaceOutputSettings(OutputFormat format, int quality, bool reduceColors) : this(format, quality) {
|
||||
ReduceColors = reduceColors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BUG-2056 reported a logical issue, using greenshot format as the default causes issues with the external commands.
|
||||
/// </summary>
|
||||
/// <returns>this for fluent API usage</returns>
|
||||
public SurfaceOutputSettings PreventGreenshotFormat()
|
||||
{
|
||||
// If OutputFormat is Greenshot, use PNG instead.
|
||||
if (Format == OutputFormat.greenshot)
|
||||
{
|
||||
Format = OutputFormat.png;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public OutputFormat Format {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public int JPGQuality {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool SaveBackgroundOnly {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public List<IEffect> Effects { get; } = new List<IEffect>();
|
||||
|
||||
public bool ReduceColors {
|
||||
get {
|
||||
// Fix for Bug #3468436, force quantizing when output format is gif as this has only 256 colors!
|
||||
if (OutputFormat.gif.Equals(Format)) {
|
||||
return true;
|
||||
}
|
||||
return _reduceColors;
|
||||
}
|
||||
set {
|
||||
_reduceColors = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable the reduce colors option, this overrules the enabling
|
||||
/// </summary>
|
||||
public bool DisableReduceColors {
|
||||
get {
|
||||
return _disableReduceColors;
|
||||
}
|
||||
set {
|
||||
// Quantizing os needed when output format is gif as this has only 256 colors!
|
||||
if (!OutputFormat.gif.Equals(Format)) {
|
||||
_disableReduceColors = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This interface is the GreenshotPluginHost, that which "Hosts" the plugin.
|
||||
/// For Greenshot this is implmented in the PluginHelper
|
||||
/// </summary>
|
||||
public interface IGreenshotHost {
|
||||
ContextMenuStrip MainMenu {
|
||||
get;
|
||||
}
|
||||
|
||||
// This is a reference to the MainForm, can be used for Invoking on the UI thread.
|
||||
Form GreenshotForm {
|
||||
get;
|
||||
}
|
||||
|
||||
NotifyIcon NotifyIcon {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a Thumbnail
|
||||
/// </summary>
|
||||
/// <param name="image">Image of which we need a Thumbnail</param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns>Image with Thumbnail</returns>
|
||||
Image GetThumbnail(Image image, int width, int height);
|
||||
|
||||
/// <summary>
|
||||
/// List of available plugins with their PluginAttributes
|
||||
/// This can be usefull for a plugin manager plugin...
|
||||
/// </summary>
|
||||
IDictionary<PluginAttribute, IGreenshotPlugin> Plugins {
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a destination by it's designation
|
||||
/// </summary>
|
||||
/// <param name="designation"></param>
|
||||
/// <returns>IDestination</returns>
|
||||
IDestination GetDestination(string designation);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all available destinations
|
||||
/// </summary>
|
||||
/// <returns>List of IDestination</returns>
|
||||
List<IDestination> GetAllDestinations();
|
||||
|
||||
/// <summary>
|
||||
/// Export a surface to the destination with has the supplied designation
|
||||
/// </summary>
|
||||
/// <param name="manuallyInitiated"></param>
|
||||
/// <param name="designation"></param>
|
||||
/// <param name="surface"></param>
|
||||
/// <param name="captureDetails"></param>
|
||||
ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails);
|
||||
|
||||
/// <summary>
|
||||
/// Make region capture with specified Handler
|
||||
/// </summary>
|
||||
/// <param name="captureMouseCursor">bool false if the mouse should not be captured, true if the configuration should be checked</param>
|
||||
/// <param name="destination">IDestination destination</param>
|
||||
void CaptureRegion(bool captureMouseCursor, IDestination destination);
|
||||
|
||||
/// <summary>
|
||||
/// Use the supplied capture, and handle it as if it's captured.
|
||||
/// </summary>
|
||||
/// <param name="captureToImport">ICapture to import</param>
|
||||
void ImportCapture(ICapture captureToImport);
|
||||
|
||||
/// <summary>
|
||||
/// Use the supplied image, and ICapture a capture object for it
|
||||
/// </summary>
|
||||
/// <param name="imageToCapture">Image to create capture for</param>
|
||||
/// <returns>ICapture</returns>
|
||||
ICapture GetCapture(Image imageToCapture);
|
||||
}
|
||||
|
||||
public interface IGreenshotPlugin : IDisposable {
|
||||
/// <summary>
|
||||
/// Is called after the plugin is instanciated, the Plugin should keep a copy of the host and pluginAttribute.
|
||||
/// </summary>
|
||||
/// <param name="host">The IPluginHost that will be hosting the plugin</param>
|
||||
/// <param name="pluginAttribute">The PluginAttribute for the actual plugin</param>
|
||||
/// <returns>true if plugin is initialized, false if not (doesn't show)</returns>
|
||||
bool Initialize(IGreenshotHost host, PluginAttribute pluginAttribute);
|
||||
|
||||
/// <summary>
|
||||
/// Unload of the plugin
|
||||
/// </summary>
|
||||
void Shutdown();
|
||||
|
||||
/// <summary>
|
||||
/// Open the Configuration Form, will/should not be called before handshaking is done
|
||||
/// </summary>
|
||||
void Configure();
|
||||
|
||||
/// <summary>
|
||||
/// Return IDestination's, if the plugin wants to
|
||||
/// </summary>
|
||||
IEnumerable<IDestination> Destinations();
|
||||
|
||||
/// <summary>
|
||||
/// Return IProcessor's, if the plugin wants to
|
||||
/// </summary>
|
||||
IEnumerable<IProcessor> Processors();
|
||||
}
|
||||
}
|
91
GreenshotPlugin/Interfaces/Plugin/SurfaceOutputSettings.cs
Normal file
91
GreenshotPlugin/Interfaces/Plugin/SurfaceOutputSettings.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
using System.Collections.Generic;
|
||||
using Greenshot.IniFile;
|
||||
using GreenshotPlugin.Core;
|
||||
using GreenshotPlugin.Effects;
|
||||
|
||||
namespace Greenshot.Plugin
|
||||
{
|
||||
public class SurfaceOutputSettings {
|
||||
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private bool _reduceColors;
|
||||
private bool _disableReduceColors;
|
||||
|
||||
public SurfaceOutputSettings() {
|
||||
_disableReduceColors = false;
|
||||
Format = CoreConfig.OutputFileFormat;
|
||||
JPGQuality = CoreConfig.OutputFileJpegQuality;
|
||||
ReduceColors = CoreConfig.OutputFileReduceColors;
|
||||
}
|
||||
|
||||
public SurfaceOutputSettings(OutputFormat format) : this() {
|
||||
Format = format;
|
||||
}
|
||||
|
||||
public SurfaceOutputSettings(OutputFormat format, int quality) : this(format) {
|
||||
JPGQuality = quality;
|
||||
}
|
||||
|
||||
public SurfaceOutputSettings(OutputFormat format, int quality, bool reduceColors) : this(format, quality) {
|
||||
ReduceColors = reduceColors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BUG-2056 reported a logical issue, using greenshot format as the default causes issues with the external commands.
|
||||
/// </summary>
|
||||
/// <returns>this for fluent API usage</returns>
|
||||
public SurfaceOutputSettings PreventGreenshotFormat()
|
||||
{
|
||||
// If OutputFormat is Greenshot, use PNG instead.
|
||||
if (Format == OutputFormat.greenshot)
|
||||
{
|
||||
Format = OutputFormat.png;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public OutputFormat Format {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public int JPGQuality {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool SaveBackgroundOnly {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public List<IEffect> Effects { get; } = new List<IEffect>();
|
||||
|
||||
public bool ReduceColors {
|
||||
get {
|
||||
// Fix for Bug #3468436, force quantizing when output format is gif as this has only 256 colors!
|
||||
if (OutputFormat.gif.Equals(Format)) {
|
||||
return true;
|
||||
}
|
||||
return _reduceColors;
|
||||
}
|
||||
set {
|
||||
_reduceColors = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable the reduce colors option, this overrules the enabling
|
||||
/// </summary>
|
||||
public bool DisableReduceColors {
|
||||
get {
|
||||
return _disableReduceColors;
|
||||
}
|
||||
set {
|
||||
// Quantizing os needed when output format is gif as this has only 256 colors!
|
||||
if (!OutputFormat.gif.Equals(Format)) {
|
||||
_disableReduceColors = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue