diff --git a/Greenshot/Destinations/PickerDestination.cs b/Greenshot/Destinations/PickerDestination.cs index f94c1af98..23bb29175 100644 --- a/Greenshot/Destinations/PickerDestination.cs +++ b/Greenshot/Destinations/PickerDestination.cs @@ -48,7 +48,8 @@ namespace Greenshot.Destinations { /// true if export was made public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { List destinations = new List(); - foreach(IDestination destination in DestinationHelper.GetAllDestinations()) { + + foreach(var destination in SimpleServiceProvider.Current.GetAllInstances()) { if ("Picker".Equals(destination.Designation)) { continue; } diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index a21335c8f..bfb7e2612 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -223,19 +223,18 @@ namespace Greenshot { using Pen cbBorderPen = new Pen(SystemColors.ActiveBorder); // Loop over all items in the propertiesToolStrip foreach (ToolStripItem item in propertiesToolStrip.Items) { - ToolStripComboBox cb = item as ToolStripComboBox; + var cb = item as ToolStripComboBox; // Only ToolStripComboBox that are visible if (cb == null || !cb.Visible) { continue; } - // Calculate the rectangle - if (cb.ComboBox != null) - { - Rectangle r = new Rectangle(cb.ComboBox.Location.X - 1, cb.ComboBox.Location.Y - 1, cb.ComboBox.Size.Width + 1, cb.ComboBox.Size.Height + 1); + if (cb.ComboBox == null) continue; - // Draw the rectangle - e.Graphics.DrawRectangle(cbBorderPen, r); - } + // Calculate the rectangle + Rectangle r = new Rectangle(cb.ComboBox.Location.X - 1, cb.ComboBox.Location.Y - 1, cb.ComboBox.Size.Width + 1, cb.ComboBox.Size.Height + 1); + + // Draw the rectangle + e.Graphics.DrawRectangle(cbBorderPen, r); } } @@ -705,12 +704,15 @@ namespace Greenshot { HelpFileLoader.LoadHelp(); } - private void AboutToolStripMenuItemClick(object sender, EventArgs e) { - MainForm.Instance.ShowAbout(); + private void AboutToolStripMenuItemClick(object sender, EventArgs e) + { + var mainForm = SimpleServiceProvider.Current.GetInstance(); + mainForm.ShowAbout(); } private void PreferencesToolStripMenuItemClick(object sender, EventArgs e) { - MainForm.Instance.ShowSetting(); + var mainForm = SimpleServiceProvider.Current.GetInstance(); + mainForm.ShowSetting(); } private void BtnSettingsClick(object sender, EventArgs e) { @@ -1251,7 +1253,8 @@ namespace Greenshot { private void Insert_window_toolstripmenuitemMouseEnter(object sender, EventArgs e) { ToolStripMenuItem captureWindowMenuItem = (ToolStripMenuItem)sender; - MainForm.Instance.AddCaptureWindowMenuItems(captureWindowMenuItem, Contextmenu_window_Click); + var mainForm = SimpleServiceProvider.Current.GetInstance(); + mainForm.AddCaptureWindowMenuItems(captureWindowMenuItem, Contextmenu_window_Click); } private void Contextmenu_window_Click(object sender, EventArgs e) { diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index dff93324f..4e768b461 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -302,7 +302,6 @@ namespace Greenshot { } private static MainForm _instance; - public static MainForm Instance => _instance; private readonly CopyData _copyData; @@ -315,13 +314,18 @@ namespace Greenshot { // Timer for the double click test private readonly Timer _doubleClickTimer = new Timer(); - public NotifyIcon NotifyIcon => notifyIcon; + public MainForm(CopyDataTransport dataTransport) { + // The most important form is this + SimpleServiceProvider.Current.AddService
(this); + // Also as itself + SimpleServiceProvider.Current.AddService(this); - public MainForm(CopyDataTransport dataTransport) { _instance = this; // Factory for surface objects - ImageHelper.SurfaceFactory = () => new Surface(); + ISurface SurfaceFactory() => new Surface(); + + SimpleServiceProvider.Current.AddService((Func) SurfaceFactory); // // The InitializeComponent() call is required for Windows Forms designer support. @@ -333,7 +337,12 @@ namespace Greenshot { ex.Data.Add("more information here", "http://support.microsoft.com/kb/943140"); throw; } + // Make the main menu available + SimpleServiceProvider.Current.AddService(contextMenu); + notifyIcon.Icon = GreenshotResources.getGreenshotIcon(); + // Make the notify icon available + SimpleServiceProvider.Current.AddService(notifyIcon); // Disable access to the settings, for feature #3521446 contextmenu_settings.Visible = !_conf.DisableSettings; @@ -347,9 +356,9 @@ namespace Greenshot { UpdateUi(); // This forces the registration of all destinations inside Greenshot itself. - DestinationHelper.GetAllDestinations(); + DestinationHelper.RegisterInternalDestinations(); // This forces the registration of all processors inside Greenshot itself. - ProcessorHelper.GetAllProcessors(); + ProcessorHelper.RegisterInternalProcessors(); // Load all the plugins PluginHelper.Instance.LoadPlugins(); @@ -645,7 +654,8 @@ namespace Greenshot { bool success = false; var warningTitle = Language.GetString(LangKey.warning); var message = string.Format(Language.GetString(LangKey.warning_hotkeys), failedKeys, IsOneDriveBlockingHotkey() ? " (OneDrive)": ""); - DialogResult dr = MessageBox.Show(Instance, message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); + var mainForm = SimpleServiceProvider.Current.GetInstance(); + DialogResult dr = MessageBox.Show(mainForm, message, warningTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); if (dr == DialogResult.Retry) { LOG.DebugFormat("Re-trying to register hotkeys"); HotkeyControl.UnregisterHotkeys(); diff --git a/Greenshot/Forms/SettingsForm.cs b/Greenshot/Forms/SettingsForm.cs index 369f568f6..ffeb5ddb3 100644 --- a/Greenshot/Forms/SettingsForm.cs +++ b/Greenshot/Forms/SettingsForm.cs @@ -25,6 +25,7 @@ using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; +using System.Linq; using System.Windows.Forms; using Greenshot.Configuration; @@ -191,37 +192,38 @@ namespace Greenshot { } private void DisplayPluginTab() { - if (!PluginHelper.Instance.HasPlugins()) { - tabcontrol.TabPages.Remove(tab_plugins); - } else { - // Draw the Plugin listview - listview_plugins.BeginUpdate(); - listview_plugins.Items.Clear(); - listview_plugins.Columns.Clear(); - string[] columns = { - Language.GetString("settings_plugins_name"), - Language.GetString("settings_plugins_version"), - Language.GetString("settings_plugins_createdby"), - Language.GetString("settings_plugins_dllpath")}; - foreach (string column in columns) { - listview_plugins.Columns.Add(column); - } - PluginHelper.Instance.FillListview(listview_plugins); - // Maximize Column size! - for (int i = 0; i < listview_plugins.Columns.Count; i++) { - listview_plugins.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent); - int width = listview_plugins.Columns[i].Width; - listview_plugins.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.HeaderSize); - if (width > listview_plugins.Columns[i].Width) { - listview_plugins.Columns[i].Width = width; - } - } - listview_plugins.EndUpdate(); - listview_plugins.Refresh(); - - // Disable the configure button, it will be enabled when a plugin is selected AND isConfigurable - button_pluginconfigure.Enabled = false; + if (!SimpleServiceProvider.Current.GetAllInstances().Any()) + { + tabcontrol.TabPages.Remove(tab_plugins); + return; + } + // Draw the Plugin listview + listview_plugins.BeginUpdate(); + listview_plugins.Items.Clear(); + listview_plugins.Columns.Clear(); + string[] columns = { + Language.GetString("settings_plugins_name"), + Language.GetString("settings_plugins_version"), + Language.GetString("settings_plugins_createdby"), + Language.GetString("settings_plugins_dllpath")}; + foreach (string column in columns) { + listview_plugins.Columns.Add(column); } + PluginHelper.Instance.FillListView(listview_plugins); + // Maximize Column size! + for (int i = 0; i < listview_plugins.Columns.Count; i++) { + listview_plugins.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent); + int width = listview_plugins.Columns[i].Width; + listview_plugins.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.HeaderSize); + if (width > listview_plugins.Columns[i].Width) { + listview_plugins.Columns[i].Width = width; + } + } + listview_plugins.EndUpdate(); + listview_plugins.Refresh(); + + // Disable the configure button, it will be enabled when a plugin is selected AND isConfigurable + button_pluginconfigure.Enabled = false; } /// @@ -333,9 +335,8 @@ namespace Greenshot { listview_destinations.Items.Clear(); listview_destinations.ListViewItemSorter = new ListviewWithDestinationComparer(); - ImageList imageList = new ImageList(); - imageList.ImageSize = coreConfiguration.ScaledIconSize; - listview_destinations.SmallImageList = imageList; + ImageList imageList = new ImageList {ImageSize = coreConfiguration.ScaledIconSize}; + listview_destinations.SmallImageList = imageList; int imageNr = -1; foreach (IDestination currentDestination in DestinationHelper.GetAllDestinations()) { Image destinationImage = currentDestination.DisplayIcon; @@ -502,7 +503,8 @@ namespace Greenshot { MainForm.RegisterHotkeys(); // Make sure the current language & settings are reflected in the Main-context menu - MainForm.Instance.UpdateUi(); + var mainForm = SimpleServiceProvider.Current.GetInstance(); + mainForm?.UpdateUi(); DialogResult = DialogResult.OK; } else { tabcontrol.SelectTab(tab_output); diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index 1ad014e56..703442d62 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -232,9 +232,11 @@ namespace Greenshot.Helpers { // This fixes a problem when a balloon is still visible and a capture needs to be taken // forcefully removes the balloon! - if (!CoreConfig.HideTrayicon) { - MainForm.Instance.NotifyIcon.Visible = false; - MainForm.Instance.NotifyIcon.Visible = true; + if (!CoreConfig.HideTrayicon) + { + var notifyIcon = SimpleServiceProvider.Current.GetInstance(); + notifyIcon.Visible = false; + notifyIcon.Visible = true; } Log.Debug($"Capturing with mode {_captureMode} and using Cursor {_captureMouseCursor}"); _capture.CaptureDetails.CaptureMode = _captureMode; @@ -512,7 +514,8 @@ namespace Greenshot.Helpers { /// /// private void OpenCaptureOnClick(object sender, EventArgs e) { - if (!(MainForm.Instance.NotifyIcon.Tag is SurfaceMessageEventArgs eventArgs)) { + var notifyIcon = SimpleServiceProvider.Current.GetInstance(); + if (!(notifyIcon.Tag is SurfaceMessageEventArgs eventArgs)) { Log.Warn("OpenCaptureOnClick called without SurfaceMessageEventArgs"); RemoveEventHandler(sender, e); return; @@ -535,9 +538,10 @@ namespace Greenshot.Helpers { } private void RemoveEventHandler(object sender, EventArgs e) { - MainForm.Instance.NotifyIcon.BalloonTipClicked -= OpenCaptureOnClick; - MainForm.Instance.NotifyIcon.BalloonTipClosed -= RemoveEventHandler; - MainForm.Instance.NotifyIcon.Tag = null; + var notifyIcon = SimpleServiceProvider.Current.GetInstance(); + notifyIcon.BalloonTipClicked -= OpenCaptureOnClick; + notifyIcon.BalloonTipClosed -= RemoveEventHandler; + notifyIcon.Tag = null; } /// @@ -549,25 +553,22 @@ namespace Greenshot.Helpers { if (string.IsNullOrEmpty(eventArgs?.Message)) { return; } - if (MainForm.Instance == null) - { - return; - } + var notifyIcon = SimpleServiceProvider.Current.GetInstance(); switch (eventArgs.MessageType) { case SurfaceMessageTyp.Error: - MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Error); + notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Error); break; case SurfaceMessageTyp.Info: - MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info); + notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info); break; case SurfaceMessageTyp.FileSaved: case SurfaceMessageTyp.UploadedUri: // Show a balloon and register an event handler to open the "capture" for if someone clicks the balloon. - MainForm.Instance.NotifyIcon.BalloonTipClicked += OpenCaptureOnClick; - MainForm.Instance.NotifyIcon.BalloonTipClosed += RemoveEventHandler; + notifyIcon.BalloonTipClicked += OpenCaptureOnClick; + notifyIcon.BalloonTipClosed += RemoveEventHandler; // Store for later usage - MainForm.Instance.NotifyIcon.Tag = eventArgs; - MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info); + notifyIcon.Tag = eventArgs; + notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info); break; } } @@ -609,12 +610,11 @@ namespace Greenshot.Helpers { } // Let the processors do their job - foreach(IProcessor processor in ProcessorHelper.GetAllProcessors()) { - if (processor.isActive) { - Log.InfoFormat("Calling processor {0}", processor.Description); - processor.ProcessCapture(surface, _capture.CaptureDetails); - } - } + foreach(var processor in SimpleServiceProvider.Current.GetAllInstances()) { + if (!processor.isActive) continue; + Log.InfoFormat("Calling processor {0}", processor.Description); + processor.ProcessCapture(surface, _capture.CaptureDetails); + } // As the surfaces copies the reference to the image, make sure the image is not being disposed (a trick to save memory) _capture.Image = null; @@ -915,7 +915,8 @@ namespace Greenshot.Helpers { // Workaround for proble with DPI retrieval, the FromHwnd activates the window... WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow(); // Workaround for changed DPI settings in Windows 7 - using (Graphics graphics = Graphics.FromHwnd(MainForm.Instance.Handle)) { + var mainForm = SimpleServiceProvider.Current.GetInstance(); + using (Graphics graphics = Graphics.FromHwnd(mainForm.Handle)) { _capture.CaptureDetails.DpiX = graphics.DpiX; _capture.CaptureDetails.DpiY = graphics.DpiY; } @@ -942,7 +943,8 @@ namespace Greenshot.Helpers { // Make sure the form is hidden after showing, even if an exception occurs, so all errors will be shown DialogResult result; try { - result = captureForm.ShowDialog(MainForm.Instance); + var mainForm = SimpleServiceProvider.Current.GetInstance(); + result = captureForm.ShowDialog(mainForm); } finally { captureForm.Hide(); } diff --git a/Greenshot/Helpers/DestinationHelper.cs b/Greenshot/Helpers/DestinationHelper.cs index e0b99bc5a..9807828d0 100644 --- a/Greenshot/Helpers/DestinationHelper.cs +++ b/Greenshot/Helpers/DestinationHelper.cs @@ -18,9 +18,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + using System; using System.Collections.Generic; - +using System.Linq; using Greenshot.Plugin; using GreenshotPlugin.Core; using Greenshot.IniFile; @@ -32,79 +33,47 @@ namespace Greenshot.Helpers { /// public static class DestinationHelper { private static readonly ILog Log = LogManager.GetLogger(typeof(DestinationHelper)); - private static readonly Dictionary RegisteredDestinations = new Dictionary(); private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection(); - /// Initialize the destinations - static DestinationHelper() { + /// + /// Initialize the internal destinations + /// + public static void RegisterInternalDestinations() { foreach(Type destinationType in InterfaceUtils.GetSubclassesOf(typeof(IDestination),true)) { // Only take our own if (!"Greenshot.Destinations".Equals(destinationType.Namespace)) { continue; } - if (!destinationType.IsAbstract) { - IDestination destination; - try { - destination = (IDestination)Activator.CreateInstance(destinationType); - } catch (Exception e) { - Log.ErrorFormat("Can't create instance of {0}", destinationType); - Log.Error(e); - continue; - } - if (destination.IsActive) { - Log.DebugFormat("Found destination {0} with designation {1}", destinationType.Name, destination.Designation); - RegisterDestination(destination); - } else { - Log.DebugFormat("Ignoring destination {0} with designation {1}", destinationType.Name, destination.Designation); - } - } - } - } - /// - /// Register your destination here, if it doesn't come from a plugin and needs to be available - /// - /// - public static void RegisterDestination(IDestination destination) { - if (CoreConfig.ExcludeDestinations == null || !CoreConfig.ExcludeDestinations.Contains(destination.Designation)) { - // don't test the key, an exception should happen wenn it's not unique - RegisteredDestinations.Add(destination.Designation, destination); - } + if (destinationType.IsAbstract) continue; + + IDestination destination; + try { + destination = (IDestination)Activator.CreateInstance(destinationType); + } catch (Exception e) { + Log.ErrorFormat("Can't create instance of {0}", destinationType); + Log.Error(e); + continue; + } + if (destination.IsActive) { + Log.DebugFormat("Found destination {0} with designation {1}", destinationType.Name, destination.Designation); + SimpleServiceProvider.Current.AddService(destination); + } else { + Log.DebugFormat("Ignoring destination {0} with designation {1}", destinationType.Name, destination.Designation); + } + } } /// /// Method to get all the destinations from the plugins /// /// List of IDestination - private static List GetPluginDestinations() { - List destinations = new List(); - foreach (PluginAttribute pluginAttribute in PluginHelper.Instance.Plugins.Keys) { - IGreenshotPlugin plugin = PluginHelper.Instance.Plugins[pluginAttribute]; - try { - foreach (IDestination destination in plugin.Destinations()) { - if (CoreConfig.ExcludeDestinations == null || !CoreConfig.ExcludeDestinations.Contains(destination.Designation)) { - destinations.Add(destination); - } - } - } catch (Exception ex) { - Log.ErrorFormat("Couldn't get destinations from the plugin {0}", pluginAttribute.Name); - Log.Error(ex); - } - } - destinations.Sort(); - return destinations; - } - - /// - /// Get a list of all destinations, registered or supplied by a plugin - /// - /// - public static List GetAllDestinations() { - List destinations = new List(); - destinations.AddRange(RegisteredDestinations.Values); - destinations.AddRange(GetPluginDestinations()); - destinations.Sort(); - return destinations; + public static IEnumerable GetAllDestinations() + { + return SimpleServiceProvider.Current.GetAllInstances() + .Where(destination => destination.IsActive) + .Where(destination => CoreConfig.ExcludeDestinations == null || + !CoreConfig.ExcludeDestinations.Contains(destination.Designation)).OrderBy(p => p.Priority).ThenBy(p => p.Description); } /// @@ -116,10 +85,7 @@ namespace Greenshot.Helpers { if (designation == null) { return null; } - if (RegisteredDestinations.ContainsKey(designation)) { - return RegisteredDestinations[designation]; - } - foreach (IDestination destination in GetPluginDestinations()) { + foreach (IDestination destination in GetAllDestinations()) { if (designation.Equals(destination.Designation)) { return destination; } diff --git a/Greenshot/Helpers/PluginHelper.cs b/Greenshot/Helpers/PluginHelper.cs index 49c9ceef9..be2dfdf9a 100644 --- a/Greenshot/Helpers/PluginHelper.cs +++ b/Greenshot/Helpers/PluginHelper.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.IO; +using System.Linq; using System.Reflection; using System.Windows.Forms; using Greenshot.Plugin; @@ -41,65 +42,61 @@ namespace Greenshot.Helpers { private static readonly string PluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),Application.ProductName); private static readonly string ApplicationPath = Path.GetDirectoryName(Application.ExecutablePath); private static readonly string PafPath = Path.Combine(Application.StartupPath, @"App\Greenshot"); - private static readonly IDictionary plugins = new SortedDictionary(); public static PluginHelper Instance { get; } = new PluginHelper(); - private PluginHelper() { - PluginUtils.Host = this; - } - - public Form GreenshotForm => MainForm.Instance; - - public NotifyIcon NotifyIcon => MainForm.Instance.NotifyIcon; - - public bool HasPlugins() { - return plugins != null && plugins.Count > 0; - } - - public void Shutdown() { - foreach(var plugin in plugins.Values) { + public void Shutdown() { + foreach(var plugin in SimpleServiceProvider.Current.GetAllInstances()) { plugin.Shutdown(); plugin.Dispose(); } - plugins.Clear(); } - // Add plugins to the Listview - public void FillListview(ListView listview) { - foreach(var pluginAttribute in plugins.Keys) { + /// + /// Add plugins to the ListView + /// + /// + public void FillListView(ListView listView) { + foreach (var plugin in SimpleServiceProvider.Current.GetAllInstances()) + { + var pluginAttribute = plugin.GetType().GetCustomAttribute(); var item = new ListViewItem(pluginAttribute.Name) { Tag = pluginAttribute }; - item.SubItems.Add(pluginAttribute.Version); - item.SubItems.Add(pluginAttribute.CreatedBy); - item.SubItems.Add(pluginAttribute.DllFile); - listview.Items.Add(item); + var assembly = plugin.GetType().Assembly; + + var company = assembly.GetCustomAttribute(); + item.SubItems.Add(assembly.GetName().Version.ToString()); + item.SubItems.Add(company.Company); + item.SubItems.Add(assembly.Location); + listView.Items.Add(item); } } - public bool IsSelectedItemConfigurable(ListView listview) { - if (listview.SelectedItems.Count <= 0) + public bool IsSelectedItemConfigurable(ListView listView) { + if (listView.SelectedItems.Count <= 0) { return false; } - var pluginAttribute = (PluginAttribute)listview.SelectedItems[0].Tag; + var pluginAttribute = (PluginAttribute)listView.SelectedItems[0].Tag; return pluginAttribute != null && pluginAttribute.Configurable; } - public void ConfigureSelectedItem(ListView listview) { - if (listview.SelectedItems.Count <= 0) + public void ConfigureSelectedItem(ListView listView) { + if (listView.SelectedItems.Count <= 0) { return; } - var pluginAttribute = (PluginAttribute)listview.SelectedItems[0].Tag; + var pluginAttribute = (PluginAttribute)listView.SelectedItems[0].Tag; if (pluginAttribute == null) { return; } - var plugin = plugins[pluginAttribute]; - plugin.Configure(); + + var plugin = SimpleServiceProvider.Current.GetAllInstances().FirstOrDefault(p => + p.GetType().GetCustomAttribute().Name == pluginAttribute.Name); + plugin?.Configure(); } /// @@ -121,17 +118,6 @@ namespace Greenshot.Helpers { return true; } - public ContextMenuStrip MainMenu => MainForm.Instance.MainMenu; - - public IDictionary Plugins => plugins; - - public IDestination GetDestination(string designation) { - return DestinationHelper.GetDestination(designation); - } - public List GetAllDestinations() { - return DestinationHelper.GetAllDestinations(); - } - public ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { return DestinationHelper.ExportCapture(manuallyInitiated, designation, surface, captureDetails); } @@ -149,8 +135,10 @@ namespace Greenshot.Helpers { /// Use the supplied image, and handle it as if it's captured. /// /// Image to handle - public void ImportCapture(ICapture captureToImport) { - MainForm.Instance.BeginInvoke((MethodInvoker)delegate { + public void ImportCapture(ICapture captureToImport) + { + var mainForm = SimpleServiceProvider.Current.GetInstance(); + mainForm.BeginInvoke((MethodInvoker)delegate { CaptureHelper.ImportCapture(captureToImport); }); } @@ -171,49 +159,27 @@ namespace Greenshot.Helpers { return capture; } - public PluginAttribute FindPlugin(string name) { - foreach(PluginAttribute pluginAttribute in plugins.Keys) { - if (name.Equals(pluginAttribute.Name)) { - return pluginAttribute; - } - } - return null; - } - - private bool IsNewer(string version1, string version2) { - string [] version1Parts = version1.Split('.'); - string [] version2Parts = version2.Split('.'); - int parts = Math.Min(version1Parts.Length, version2Parts.Length); - for(int i=0; i < parts; i++) { - int v1 = Convert.ToInt32(version1Parts[i]); - int v2 = Convert.ToInt32(version2Parts[i]); - if (v1 > v2) { - return true; - } - if (v1 < v2) { - return false; - } - } - return false; - } - /// + /// /// Private helper to find the plugins in the path /// - /// - /// - private void FindPluginsOnPath(List pluginFiles, string path) { - if (Directory.Exists(path)) { - try { - foreach (string pluginFile in Directory.GetFiles(path, "*Plugin.dll", SearchOption.AllDirectories)) { - pluginFiles.Add(pluginFile); - } - } catch (UnauthorizedAccessException) { - } catch (Exception ex) { - Log.Error("Error loading plugin: ", ex); - } - } - } + /// string + /// IEnumerable with plugin files + private IEnumerable FindPluginsOnPath(string path) + { + var pluginFiles = Enumerable.Empty(); + if (!Directory.Exists(path)) return pluginFiles; + try + { + pluginFiles = Directory.GetFiles(path, "*Plugin.dll", SearchOption.AllDirectories); + + } catch (Exception ex) { + Log.Error("Error loading plugin: ", ex); + } + + return pluginFiles; + + } /// /// Load the plugins @@ -222,107 +188,54 @@ namespace Greenshot.Helpers { List pluginFiles = new List(); if (IniConfig.IsPortable) { - FindPluginsOnPath(pluginFiles, PafPath); + pluginFiles.AddRange(FindPluginsOnPath(PafPath)); } else { - FindPluginsOnPath(pluginFiles, PluginPath); - FindPluginsOnPath(pluginFiles, ApplicationPath); + pluginFiles.AddRange(FindPluginsOnPath(PluginPath)); + pluginFiles.AddRange(FindPluginsOnPath(ApplicationPath)); } - Dictionary tmpAttributes = new Dictionary(); - Dictionary tmpAssemblies = new Dictionary(); // Loop over the list of available files and get the Plugin Attributes foreach (string pluginFile in pluginFiles) { - //LOG.DebugFormat("Checking the following file for plugins: {0}", pluginFile); + try { Assembly assembly = Assembly.LoadFrom(pluginFile); - PluginAttribute[] pluginAttributes = assembly.GetCustomAttributes(typeof(PluginAttribute), false) as PluginAttribute[]; - if (pluginAttributes.Length > 0) { - PluginAttribute pluginAttribute = pluginAttributes[0]; - if (string.IsNullOrEmpty(pluginAttribute.Name)) { - AssemblyProductAttribute[] assemblyProductAttributes = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false) as AssemblyProductAttribute[]; - if (assemblyProductAttributes.Length > 0) { - pluginAttribute.Name = assemblyProductAttributes[0].Product; - } else { - continue; - } - } - if (string.IsNullOrEmpty(pluginAttribute.CreatedBy)) { - AssemblyCompanyAttribute[] assemblyCompanyAttributes = assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false) as AssemblyCompanyAttribute[]; - if (assemblyCompanyAttributes.Length > 0) { - pluginAttribute.CreatedBy = assemblyCompanyAttributes[0].Company; - } else { - continue; - } - } - pluginAttribute.Version = assembly.GetName().Version.ToString(); - pluginAttribute.DllFile = pluginFile; - - // check if this plugin is already available - PluginAttribute checkPluginAttribute = null; - if (tmpAttributes.ContainsKey(pluginAttribute.Name)) { - checkPluginAttribute = tmpAttributes[pluginAttribute.Name]; - } + var assemblyName = assembly.GetName().Name; - if (checkPluginAttribute != null) { - Log.WarnFormat("Duplicate plugin {0} found", pluginAttribute.Name); - if (IsNewer(pluginAttribute.Version, checkPluginAttribute.Version)) { - // Found is newer - tmpAttributes[pluginAttribute.Name] = pluginAttribute; - tmpAssemblies[pluginAttribute.Name] = assembly; - Log.InfoFormat("Loading the newer plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); - } else { - Log.InfoFormat("Skipping (as the duplicate is newer or same version) the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); - } - continue; - } - if (CoreConfig.ExcludePlugins != null && CoreConfig.ExcludePlugins.Contains(pluginAttribute.Name)) { - Log.WarnFormat("Exclude list: {0}", CoreConfig.ExcludePlugins.ToArray()); - Log.WarnFormat("Skipping the excluded plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); - continue; - } - if (CoreConfig.IncludePlugins != null && CoreConfig.IncludePlugins.Count > 0 && !CoreConfig.IncludePlugins.Contains(pluginAttribute.Name)) { - // Whitelist is set - Log.WarnFormat("Include list: {0}", CoreConfig.IncludePlugins.ToArray()); - Log.WarnFormat("Skipping the not included plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); - continue; - } - Log.InfoFormat("Loading the plugin {0} with version {1} from {2}", pluginAttribute.Name, pluginAttribute.Version, pluginAttribute.DllFile); - tmpAttributes[pluginAttribute.Name] = pluginAttribute; - tmpAssemblies[pluginAttribute.Name] = assembly; - } else { - Log.ErrorFormat("Can't find the needed Plugin Attribute ({0}) in the assembly of the file \"{1}\", skipping this file.", typeof(PluginAttribute), pluginFile); - } - } catch (Exception e) { - Log.Warn("Can't load file: " + pluginFile, e); - } - } - foreach(string pluginName in tmpAttributes.Keys) { - try { - PluginAttribute pluginAttribute = tmpAttributes[pluginName]; - Assembly assembly = tmpAssemblies[pluginName]; - Type entryType = assembly.GetType(pluginAttribute.EntryType); - if (entryType == null) { - Log.ErrorFormat("Can't find the in the PluginAttribute referenced type {0} in \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile); - continue; - } - try { - IGreenshotPlugin plugin = (IGreenshotPlugin)Activator.CreateInstance(entryType); - if (plugin != null) { - if (plugin.Initialize(this, pluginAttribute)) { - plugins.Add(pluginAttribute, plugin); - } else { - Log.InfoFormat("Plugin {0} not initialized!", pluginAttribute.Name); - } - } else { - Log.ErrorFormat("Can't create an instance of the in the PluginAttribute referenced type {0} from \"{1}\"", pluginAttribute.EntryType, pluginAttribute.DllFile); - } - } catch(Exception e) { - Log.Error("Can't load Plugin: " + pluginAttribute.Name, e); - } - } catch(Exception e) { - Log.Error("Can't load Plugin: " + pluginName, e); - } + var pluginEntryName = $"{assemblyName}.{assemblyName.Replace("Greenshot", string.Empty)}"; + var pluginEntryType = assembly.GetType(pluginEntryName, false, true); + var pluginAttribute = pluginEntryType.GetCustomAttribute(); + + if (CoreConfig.ExcludePlugins != null && CoreConfig.ExcludePlugins.Contains(pluginAttribute.Name)) + { + Log.WarnFormat("Exclude list: {0}", string.Join(",", CoreConfig.ExcludePlugins)); + Log.WarnFormat("Skipping the excluded plugin {0} with version {1} from {2}", pluginAttribute.Name, assembly.GetName().Version, pluginFile); + continue; + } + + IGreenshotPlugin plugin = (IGreenshotPlugin)Activator.CreateInstance(pluginEntryType); + if (plugin != null) + { + if (plugin.Initialize()) + { + SimpleServiceProvider.Current.AddService(plugin); + } + else + { + + Log.InfoFormat("Plugin {0} not initialized!", pluginAttribute.Name); + } + } + else + { + Log.ErrorFormat("Can't create an instance of {0} from \"{1}\"", assembly.GetName().Name + ".GreenshotPlugin", pluginFile); + } + } + catch (Exception e) + { + Log.ErrorFormat("Can't load Plugin: {0}", pluginFile); + Log.Error(e); + } } } } diff --git a/Greenshot/Helpers/ProcessorHelper.cs b/Greenshot/Helpers/ProcessorHelper.cs index b8a83ed3d..75ce8a1ac 100644 --- a/Greenshot/Helpers/ProcessorHelper.cs +++ b/Greenshot/Helpers/ProcessorHelper.cs @@ -31,108 +31,35 @@ namespace Greenshot.Helpers { /// public static class ProcessorHelper { private static readonly ILog LOG = LogManager.GetLogger(typeof(ProcessorHelper)); - private static readonly Dictionary RegisteredProcessors = new Dictionary(); - /// Initialize the Processors - static ProcessorHelper() { - foreach(Type ProcessorType in InterfaceUtils.GetSubclassesOf(typeof(IProcessor),true)) { + /// + /// Register the internal processors + /// + public static void RegisterInternalProcessors() { + foreach(Type processorType in InterfaceUtils.GetSubclassesOf(typeof(IProcessor),true)) { // Only take our own - if (!"Greenshot.Processors".Equals(ProcessorType.Namespace)) { + if (!"Greenshot.Processors".Equals(processorType.Namespace)) { continue; } try { - if (!ProcessorType.IsAbstract) { - IProcessor Processor; + if (!processorType.IsAbstract) { + IProcessor processor; try { - Processor = (IProcessor)Activator.CreateInstance(ProcessorType); + processor = (IProcessor)Activator.CreateInstance(processorType); } catch (Exception e) { - LOG.ErrorFormat("Can't create instance of {0}", ProcessorType); + LOG.ErrorFormat("Can't create instance of {0}", processorType); LOG.Error(e); continue; } - if (Processor.isActive) { - LOG.DebugFormat("Found Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation); - RegisterProcessor(Processor); + if (processor.isActive) { + LOG.DebugFormat("Found Processor {0} with designation {1}", processorType.Name, processor.Designation); + SimpleServiceProvider.Current.AddService(processor); } else { - LOG.DebugFormat("Ignoring Processor {0} with designation {1}", ProcessorType.Name, Processor.Designation); + LOG.DebugFormat("Ignoring Processor {0} with designation {1}", processorType.Name, processor.Designation); } } } catch (Exception ex) { - LOG.ErrorFormat("Error loading processor {0}, message: ", ProcessorType.FullName, ex.Message); - } - } - } - - /// - /// Register your Processor here, if it doesn't come from a plugin and needs to be available - /// - /// - public static void RegisterProcessor(IProcessor Processor) { - // don't test the key, an exception should happen wenn it's not unique - RegisteredProcessors.Add(Processor.Designation, Processor); - } - - private static List GetPluginsProcessors() { - List processors = new List(); - foreach (PluginAttribute pluginAttribute in PluginHelper.Instance.Plugins.Keys) { - IGreenshotPlugin plugin = PluginHelper.Instance.Plugins[pluginAttribute]; - try { - var procs = plugin.Processors(); - if (procs != null) { - processors.AddRange(procs); - } - } catch (Exception ex) { - LOG.ErrorFormat("Couldn't get processors from the plugin {0}", pluginAttribute.Name); - LOG.Error(ex); - } - } - processors.Sort(); - return processors; - } - - /// - /// Get a list of all Processors, registered or supplied by a plugin - /// - /// - public static List GetAllProcessors() { - List processors = new List(); - processors.AddRange(RegisteredProcessors.Values); - processors.AddRange(GetPluginsProcessors()); - processors.Sort(); - return processors; - } - - /// - /// Get a Processor by a designation - /// - /// Designation of the Processor - /// IProcessor or null - public static IProcessor GetProcessor(string designation) { - if (designation == null) { - return null; - } - if (RegisteredProcessors.ContainsKey(designation)) { - return RegisteredProcessors[designation]; - } - foreach (IProcessor processor in GetPluginsProcessors()) { - if (designation.Equals(processor.Designation)) { - return processor; - } - } - return null; - } - - /// - /// A simple helper method which will call ProcessCapture for the Processor with the specified designation - /// - /// - /// - /// - public static void ProcessCapture(string designation, ISurface surface, ICaptureDetails captureDetails) { - if (RegisteredProcessors.ContainsKey(designation)) { - IProcessor Processor = RegisteredProcessors[designation]; - if (Processor.isActive) { - Processor.ProcessCapture(surface, captureDetails); + LOG.ErrorFormat("Error loading processor {0}, message: ", processorType.FullName, ex.Message); } } } diff --git a/Greenshot/Helpers/ResourceMutex.cs b/Greenshot/Helpers/ResourceMutex.cs index b656e5ff0..7a70031c1 100644 --- a/Greenshot/Helpers/ResourceMutex.cs +++ b/Greenshot/Helpers/ResourceMutex.cs @@ -34,7 +34,7 @@ namespace Greenshot.Helpers /// public class ResourceMutex : IDisposable { - private static readonly ILog Log = LogManager.GetLogger(typeof(DestinationHelper)); + private static readonly ILog Log = LogManager.GetLogger(typeof(ResourceMutex)); private readonly string _mutexId; private readonly string _resourceName; private Mutex _applicationMutex; @@ -82,13 +82,13 @@ namespace Greenshot.Helpers { // Added Mutex Security, hopefully this prevents the UnauthorizedAccessException more gracefully var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null); - var mutexsecurity = new MutexSecurity(); - mutexsecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.FullControl, AccessControlType.Allow)); - mutexsecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.ChangePermissions, AccessControlType.Deny)); - mutexsecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.Delete, AccessControlType.Deny)); + var mutexSecurity = new MutexSecurity(); + mutexSecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.FullControl, AccessControlType.Allow)); + mutexSecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.ChangePermissions, AccessControlType.Deny)); + mutexSecurity.AddAccessRule(new MutexAccessRule(sid, MutexRights.Delete, AccessControlType.Deny)); // 1) Create Mutex - _applicationMutex = new Mutex(true, _mutexId, out var createdNew, mutexsecurity); + _applicationMutex = new Mutex(true, _mutexId, out var createdNew, mutexSecurity); // 2) if the mutex wasn't created new get the right to it, this returns false if it's already locked if (!createdNew && !_applicationMutex.WaitOne(100, false)) { diff --git a/Greenshot/Helpers/UpdateHelper.cs b/Greenshot/Helpers/UpdateHelper.cs index 6a305165d..052ac592b 100644 --- a/Greenshot/Helpers/UpdateHelper.cs +++ b/Greenshot/Helpers/UpdateHelper.cs @@ -88,9 +88,11 @@ namespace Greenshot.Experimental { _latestGreenshot = null; ProcessRssInfo(currentVersion); if (_latestGreenshot != null) { - MainForm.Instance.NotifyIcon.BalloonTipClicked += HandleBalloonTipClick; - MainForm.Instance.NotifyIcon.BalloonTipClosed += CleanupBalloonTipClick; - MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", Language.GetFormattedString(LangKey.update_found, "'" + _latestGreenshot.File + "'"), ToolTipIcon.Info); + var notifyIcon = SimpleServiceProvider.Current.GetInstance(); + + notifyIcon.BalloonTipClicked += HandleBalloonTipClick; + notifyIcon.BalloonTipClosed += CleanupBalloonTipClick; + notifyIcon.ShowBalloonTip(10000, "Greenshot", Language.GetFormattedString(LangKey.update_found, "'" + _latestGreenshot.File + "'"), ToolTipIcon.Info); } } catch (Exception e) { Log.Error("An error occured while checking for updates, the error will be ignored: ", e); @@ -99,8 +101,9 @@ namespace Greenshot.Experimental { } private static void CleanupBalloonTipClick(object sender, EventArgs e) { - MainForm.Instance.NotifyIcon.BalloonTipClicked -= HandleBalloonTipClick; - MainForm.Instance.NotifyIcon.BalloonTipClosed -= CleanupBalloonTipClick; + var notifyIcon = SimpleServiceProvider.Current.GetInstance(); + notifyIcon.BalloonTipClicked -= HandleBalloonTipClick; + notifyIcon.BalloonTipClosed -= CleanupBalloonTipClick; } private static void HandleBalloonTipClick(object sender, EventArgs e) { diff --git a/Greenshot/Languages/help-nl-NL.html b/Greenshot/Languages/help-nl-NL.html index 236d2f304..553564ca5 100644 --- a/Greenshot/Languages/help-nl-NL.html +++ b/Greenshot/Languages/help-nl-NL.html @@ -69,14 +69,14 @@

Een schermopname maken

U kunt een schermopname maken door op uw toetsenbord de Print-toets te drukken of - door middel van een rechtermuisklik op het Greenshot-icoon in het systeemvak.
+ door middel van een rechtermuisklik op het Greenshot-icoon in het systeemvak.
Er zijn meerdere mogelijkheden om een schermopname te maken:

Interactief kader Print

- Deze "regio"-opnamemodus maakt het mogelijk om een gebied van het beeldscherm te selecteren voor een schermopname.
+ Deze "regio"-opnamemodus maakt het mogelijk om een gebied van het beeldscherm te selecteren voor een schermopname.
Bij het vastleggen van het opnamegebied verandert de mouse-cursor in een haarkruis. Positioneer de muis naar een hoek van het gebied waarvan u een schermopname wilt maken en druk op de linkermuisknop en houd deze ingedrukt. Beweeg nu de muis naar de diagonale hoek @@ -115,7 +115,7 @@ het actieve venster te fotograferen, maar een venster interactief te selecteren. Als deze optie geactiveerd is, kunt u een venster selecteren door het te klikken. Net als bij Interactief kader, zal Greenshot het te fotograferen - gebied markeren.
Wilt u een deelvenster fotograferen, zoals bijv. een browservenster + gebied markeren.
Wilt u een deelvenster fotograferen, zoals bijv. een browservenster zonder menu of gereedschapsbalk of een enkel onderdeel in een webpagina, positioneer dan de muis over het deelvenster en druk de Page Down-toets. Hierna kunt u de specifieke vensterelementen selecteren voor de schermopname. @@ -168,15 +168,15 @@

Kies een van de vormen in de gereedschapsbalk aan de linkerzijde van de beeldbewerker of van het menu Object. Aan elke toets is tevens een sneltoets gekoppeld - voor snelle toegang via het toetsenbord.
+ voor snelle toegang via het toetsenbord.
Beschikbare vormen zijn: rechthoek R, ellips E, lijn L - pijl A en vrije vorm F.
+ pijl A en vrije vorm F.
Klik en sleep de muis om de positie en de grootte van de vorm te bepalen. Laat de muisknop los als de vorm van de juiste afmetingen is.

Getekende vormen kunnen worden verplaatst en vergroot met behulp van de knop Selectie - ESC op de gereedschapsbalk.
Voor elk vormtype zijn specifieke + ESC op de gereedschapsbalk.
Voor elk vormtype zijn specifieke opties beschikbaar om de karakteristieken aan te passen (bijv. lijndikte, lijnkleur, vulkleur). U kunt het uiterlijk veranderen voor een bestaand geselecteerd object, maar u kunt ook de eigenschappen instellen voor de volgende te tekenen vorm. @@ -188,7 +188,7 @@

Wilt u een symmetrische vorm tekenen (bijv. een vierkant of een cirkel)? Houd dan tijdens het tekenen de Shift-toets ingedrukt. Bij het tekenen van pijlen, beperkt de Shift-toets - de mogelijke hoeken tot veelvouden van 15°.
+ de mogelijke hoeken tot veelvouden van 15°.
Bij het vergroten van een bestaand object zorgt de Shift-toets ervoor dat de verhoudingen behouden blijven.

@@ -202,8 +202,8 @@

Het gebruik van de Tekst-functie T is vergelijkbaar met dat van Vormen toevoegen. Plaats een tekstkader van de gewenste grootte - en typ de tekst.
- Dubbelklik een bestaande tekst om deze te bewerken.
+ en typ de tekst.
+ Dubbelklik een bestaande tekst om deze te bewerken.
Gebruik Return of Enter als u klaar bent met bewerken.

@@ -215,7 +215,7 @@

Markeren

Met de Markeer-functie H, kunt u een gebied markeren op precies dezelfde wijze - als waarmee u een vorm shape tekent.
+ als waarmee u een vorm shape tekent.
De volgende opties bij het markeren zijn beschilbaar via de meest linkse knop in de gereedschapsbalk:

@@ -231,8 +231,8 @@

Maskeren

Delen van een schermopname maskeren is een goed gebruik wanneer persoonlijke gegevens in beeld zijn - die beter privé kunnen blijven, zoals bijv. bankgegevens, namen, wachtwoorden of herkenbare personen.
- De functie Maskeren O gebruikt u net als het Markeren.
+ die beter privé kunnen blijven, zoals bijv. bankgegevens, namen, wachtwoorden of herkenbare personen.
+ De functie Maskeren O gebruikt u net als het Markeren.
Beschikbare opties voor Maskeren zijn:

@@ -245,7 +245,7 @@ * Afhankelijk van uw computer kan het vervagingseffect de werking van Greenshot's beeldbewerker trager maken. Merkt u dat de beeldbewerker bij de toepassing van Vervagen traag en sloom wordt, probeer dan de kwaliteit van de voorvertoning in de gereedschapsbalk te verminderen of - verlaag de waarde voor de Vervagings-radius.
+ verlaag de waarde voor de Vervagings-radius.
Blijft de functie Vervagen traag reageren, probeer dan de functie Pixeleren te gebuiken.

@@ -262,9 +262,9 @@

Schermopname bijsnijden

Als u maar een deel van de schermopname nodig hebt, gebruik dan de functie bijsnijden C - om overtollige delen weg te snijden.
+ om overtollige delen weg te snijden.
Teken hiertoe een rechthoek om het gebied van de schermopname dat behouden moet worden. - U kunt de afmetingen van het geselecteerde gebied naar wens aanpassen.
+ U kunt de afmetingen van het geselecteerde gebied naar wens aanpassen.
Bent u tevreden over het geselecteerde gebied, bevestig het bijsnijden dan in de gereedschapsbalk of toets Enter. U kunt het bijsnijden afbreken met de toets ESC. @@ -294,7 +294,7 @@

Als u regelmatig dezelfde elementen toepast in de bewerking van uw schermopnamen (bijv. een tekstkader met browsertype en versienummer, of het maskeren van hetzelfde - element in verschillende schermopnamen) dan kunt u deze elementen hergebruiken.
+ element in verschillende schermopnamen) dan kunt u deze elementen hergebruiken.
Kies in het menu Objecten, Objecten opslaan om de huidige elementen op te slaan voor later gebruik. Objecten laden past deze eerder opgeslagen elementen toe op een andere schermopname. @@ -331,7 +331,7 @@

Algemene instellingen

    -
  • Taal: De taal waarin Greenshot wordt weergegeven.
    +
  • Taal: De taal waarin Greenshot wordt weergegeven.
    Aanvullende taalbestanden zijn te downloaden van de Greenshot website.
  • Greenshot met Windows opstarten: Start het programma als de PC wordt opgestart.
  • Sneltoetsen: Hier kunt u de sneltoetsen voor het maken van schermopnames aanpassen.
  • @@ -414,7 +414,7 @@

    Op dit moment zoeken we geen hulp bij de ontwikkeling. - Maar dit betekent niet dat u niets kunt doen om het Greenshot ontwikkelteam te ondersteunen.
    + Maar dit betekent niet dat u niets kunt doen om het Greenshot ontwikkelteam te ondersteunen.
    Bij voorbaat dank :)

    @@ -425,8 +425,8 @@ goede software gratis en vrij toegankelijk te houden. Als Greenshot u helpt in uw werkzaamheden, als het u (of uw bedrijf) tijd en geld bespaart, of u vindt het gewoon een fijn programma en - u staat positief tegenover het concept van open source software: Ondersteun ons werk dan met een donatie.
    - Bezoek onze website en lees daar hoe u het Greenshot-team kunt ondersteunen:
    + u staat positief tegenover het concept van open source software: Ondersteun ons werk dan met een donatie.
    + Bezoek onze website en lees daar hoe u het Greenshot-team kunt ondersteunen:
    http://getgreenshot.org/support/

    @@ -434,7 +434,7 @@

    Vertel het door

    Bevalt Greenshot u? Vertel het dan door: vertel uw vrienden en collega's over Greenshot. - En ook uw aanhang en achterban ! :)
    + En ook uw aanhang en achterban ! :)
    Bespreek Greenshot met goede kritieken op software portals of plaats een verwijzing naar Greenshot in uw blog of op uw website.

    @@ -443,10 +443,10 @@

    Is Greenshot niet beschikbaar in uw favoriete taal en u denkt dat u software kunt vertalen dan bent u van harte welkom! Als geregisteerde gebruiker bij sourceforge.net kunt u uw vertaling in onze - vertalings tracker aanmelden.
    + vertalings tracker aanmelden.
    Voordat u begint is het verstandig om te kijken of Greenshot niet al in de taal vertaald is, zie de downloads pagina. Ook kunt u op onze vertalings tracker kijken. - Het zou namelijk kunnen zijn dat iemand al aan de vertaling werkt of misschien hierover heeft gecommuniceerd.
    + Het zou namelijk kunnen zijn dat iemand al aan de vertaling werkt of misschien hierover heeft gecommuniceerd.
    Merk op dat vertalingen alleen kunnen worden geaccepteerd als ze afkomstig zijn van een geregistreerde sourceforge.net-gebruiker. Wij kunnen niet elke vertaling doorgronden en daarom is het belangrijk dat we diff --git a/GreenshotBoxPlugin/BoxPlugin.cs b/GreenshotBoxPlugin/BoxPlugin.cs index ebabaf8a7..18b2b8d0e 100644 --- a/GreenshotBoxPlugin/BoxPlugin.cs +++ b/GreenshotBoxPlugin/BoxPlugin.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; @@ -33,11 +32,10 @@ namespace GreenshotBoxPlugin { ///

    /// This is the Box base code /// + [Plugin("Box", true)] public class BoxPlugin : IGreenshotPlugin { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(BoxPlugin)); private static BoxConfiguration _config; - public static PluginAttribute Attributes; - private IGreenshotHost _host; private ComponentResourceManager _resources; private ToolStripMenuItem _itemPlugInConfig; @@ -46,7 +44,7 @@ namespace GreenshotBoxPlugin { GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { + protected void Dispose(bool disposing) { if (disposing) { if (_itemPlugInConfig != null) { _itemPlugInConfig.Dispose(); @@ -55,35 +53,22 @@ namespace GreenshotBoxPlugin { } } - public IEnumerable Destinations() { - yield return new BoxDestination(this); - } - - - public IEnumerable Processors() { - yield break; - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute pluginAttribute) { - _host = pluginHost; - Attributes = pluginAttribute; + public bool Initialize() { // Register configuration (don't need the configuration itself) _config = IniConfig.GetIniSection(); _resources = new ComponentResourceManager(typeof(BoxPlugin)); - + SimpleServiceProvider.Current.AddService(new BoxDestination(this)); _itemPlugInConfig = new ToolStripMenuItem { Image = (Image) _resources.GetObject("Box"), Text = Language.GetString("box", LangKey.Configure) }; _itemPlugInConfig.Click += ConfigMenuClick; - PluginUtils.AddToContextMenu(_host, _itemPlugInConfig); + PluginUtils.AddToContextMenu(_itemPlugInConfig); Language.LanguageChanged += OnLanguageChanged; return true; } @@ -94,14 +79,14 @@ namespace GreenshotBoxPlugin { } } - public virtual void Shutdown() { + public void Shutdown() { LOG.Debug("Box Plugin shutdown."); } /// /// Implementation of the IPlugin.Configure /// - public virtual void Configure() { + public void Configure() { _config.ShowConfigDialog(); } @@ -119,7 +104,7 @@ namespace GreenshotBoxPlugin { string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails)); SurfaceContainer imageToUpload = new SurfaceContainer(surfaceToUpload, outputSettings, filename); - new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("box", LangKey.communication_wait), + new PleaseWaitForm().ShowAndWait("Box", Language.GetString("box", LangKey.communication_wait), delegate { url = BoxUtils.UploadToBox(imageToUpload, captureDetails.Title, filename); } diff --git a/GreenshotBoxPlugin/Properties/AssemblyInfo.cs b/GreenshotBoxPlugin/Properties/AssemblyInfo.cs index 78e96157f..2ccef9573 100644 --- a/GreenshotBoxPlugin/Properties/AssemblyInfo.cs +++ b/GreenshotBoxPlugin/Properties/AssemblyInfo.cs @@ -27,8 +27,6 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyDescription("A plugin to upload images to Box")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotBoxPlugin.BoxPlugin", 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. diff --git a/GreenshotConfluencePlugin/ConfluenceDestination.cs b/GreenshotConfluencePlugin/ConfluenceDestination.cs index 1c42041dd..966c4f4e9 100644 --- a/GreenshotConfluencePlugin/ConfluenceDestination.cs +++ b/GreenshotConfluencePlugin/ConfluenceDestination.cs @@ -42,10 +42,6 @@ namespace GreenshotConfluencePlugin { private static readonly Image ConfluenceIcon; private readonly Page _page; - public static bool IsInitialized { - get; - private set; - } static ConfluenceDestination() { IsInitialized = false; try { @@ -60,7 +56,13 @@ namespace GreenshotConfluencePlugin { Log.ErrorFormat("Problem in the confluence static initializer: {0}", ex.Message); } } - + + public static bool IsInitialized + { + get; + private set; + } + public ConfluenceDestination() { } diff --git a/GreenshotConfluencePlugin/ConfluencePlugin.cs b/GreenshotConfluencePlugin/ConfluencePlugin.cs index 651fbeea0..40f4248b6 100644 --- a/GreenshotConfluencePlugin/ConfluencePlugin.cs +++ b/GreenshotConfluencePlugin/ConfluencePlugin.cs @@ -24,7 +24,6 @@ using Greenshot.IniFile; using Greenshot.Plugin; using GreenshotPlugin.Core; using System; -using System.Collections.Generic; using System.Windows; using TranslationByMarkupExtension; @@ -42,11 +41,11 @@ namespace GreenshotConfluencePlugin { GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { + protected void Dispose(bool disposing) { //if (disposing) {} } - private static void CreateConfluenceConntector() { + private static void CreateConfluenceConnector() { if (_confluenceConnector == null) { if (_config.Url.Contains("soap-axis")) { _confluenceConnector = new ConfluenceConnector(_config.Url, _config.Timeout); @@ -65,7 +64,7 @@ namespace GreenshotConfluencePlugin { public static ConfluenceConnector ConfluenceConnector { get { if (_confluenceConnector == null) { - CreateConfluenceConntector(); + CreateConfluenceConnector(); } try { if (_confluenceConnector != null && !_confluenceConnector.IsLoggedIn) { @@ -78,22 +77,10 @@ namespace GreenshotConfluencePlugin { } } - public IEnumerable Destinations() { - if (ConfluenceDestination.IsInitialized) { - yield return new ConfluenceDestination(); - } - } - - public IEnumerable Processors() { - yield break; - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { + public bool Initialize() { // Register configuration (don't need the configuration itself) _config = IniConfig.GetIniSection(); if(_config.IsDirty) { @@ -106,10 +93,14 @@ namespace GreenshotConfluencePlugin { LOG.ErrorFormat("Problem in ConfluencePlugin.Initialize: {0}", ex.Message); return false; } + if (ConfluenceDestination.IsInitialized) + { + SimpleServiceProvider.Current.AddService(new ConfluenceDestination()); + } return true; } - public virtual void Shutdown() { + public void Shutdown() { LOG.Debug("Confluence Plugin shutdown."); if (_confluenceConnector != null) { _confluenceConnector.Logout(); @@ -120,7 +111,7 @@ namespace GreenshotConfluencePlugin { /// /// Implementation of the IPlugin.Configure /// - public virtual void Configure() { + public void Configure() { ConfluenceConfiguration clonedConfig = _config.Clone(); ConfluenceConfigurationForm configForm = new ConfluenceConfigurationForm(clonedConfig); string url = _config.Url; diff --git a/GreenshotConfluencePlugin/Properties/AssemblyInfo.cs b/GreenshotConfluencePlugin/Properties/AssemblyInfo.cs deleted file mode 100644 index edc19b7cb..000000000 --- a/GreenshotConfluencePlugin/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +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 . - */ - -using Greenshot.Plugin; -using System.Runtime.InteropServices; - -// 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. -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotConfluencePlugin.ConfluencePlugin", 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)] diff --git a/GreenshotDropboxPlugin/DropboxPlugin.cs b/GreenshotDropboxPlugin/DropboxPlugin.cs index deea0de44..d75f4704c 100644 --- a/GreenshotDropboxPlugin/DropboxPlugin.cs +++ b/GreenshotDropboxPlugin/DropboxPlugin.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; @@ -33,11 +32,10 @@ namespace GreenshotDropboxPlugin { /// /// This is the Dropbox base code /// + [Plugin("Dropbox", true)] public class DropboxPlugin : IGreenshotPlugin { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(DropboxPlugin)); private static DropboxPluginConfiguration _config; - public static PluginAttribute Attributes; - private IGreenshotHost _host; private ComponentResourceManager _resources; private ToolStripMenuItem _itemPlugInConfig; @@ -46,7 +44,7 @@ namespace GreenshotDropboxPlugin { GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { + protected void Dispose(bool disposing) { if (disposing) { if (_itemPlugInConfig != null) { _itemPlugInConfig.Dispose(); @@ -55,37 +53,23 @@ namespace GreenshotDropboxPlugin { } } - public IEnumerable Destinations() { - yield return new DropboxDestination(this); - } - - - public IEnumerable Processors() { - yield break; - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { - _host = pluginHost; - Attributes = myAttributes; + public bool Initialize() { // Register configuration (don't need the configuration itself) _config = IniConfig.GetIniSection(); _resources = new ComponentResourceManager(typeof(DropboxPlugin)); - + SimpleServiceProvider.Current.AddService(new DropboxDestination(this)); _itemPlugInConfig = new ToolStripMenuItem { Text = Language.GetString("dropbox", LangKey.Configure), - Tag = _host, Image = (Image)_resources.GetObject("Dropbox") }; _itemPlugInConfig.Click += ConfigMenuClick; - PluginUtils.AddToContextMenu(_host, _itemPlugInConfig); + PluginUtils.AddToContextMenu(_itemPlugInConfig); Language.LanguageChanged += OnLanguageChanged; return true; } @@ -96,14 +80,14 @@ namespace GreenshotDropboxPlugin { } } - public virtual void Shutdown() { + public void Shutdown() { Log.Debug("Dropbox Plugin shutdown."); } /// /// Implementation of the IPlugin.Configure /// - public virtual void Configure() { + public void Configure() { _config.ShowConfigDialog(); } @@ -119,7 +103,7 @@ namespace GreenshotDropboxPlugin { SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality, false); try { string dropboxUrl = null; - new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("dropbox", LangKey.communication_wait), + new PleaseWaitForm().ShowAndWait("Dropbox", Language.GetString("dropbox", LangKey.communication_wait), delegate { string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails)); diff --git a/GreenshotDropboxPlugin/Properties/AssemblyInfo.cs b/GreenshotDropboxPlugin/Properties/AssemblyInfo.cs index ff72c88e9..10b737886 100644 --- a/GreenshotDropboxPlugin/Properties/AssemblyInfo.cs +++ b/GreenshotDropboxPlugin/Properties/AssemblyInfo.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ -using Greenshot.Plugin; using System.Reflection; using System.Runtime.InteropServices; @@ -27,8 +26,6 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyDescription("A plugin to upload images to Dropbox")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotDropboxPlugin.DropboxPlugin", 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. diff --git a/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs b/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs index 6ed823c48..1ecb2ef43 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs @@ -32,12 +32,11 @@ namespace ExternalCommand { /// /// An Plugin to run commands after an image was written /// + [Plugin("ExternalCommand", true)] public class ExternalCommandPlugin : IGreenshotPlugin { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(ExternalCommandPlugin)); private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection(); private static readonly ExternalCommandConfiguration ExternalCommandConfig = IniConfig.GetIniSection(); - private IGreenshotHost _host; - private PluginAttribute _myAttributes; private ToolStripMenuItem _itemPlugInRoot; public void Dispose() { @@ -45,24 +44,19 @@ namespace ExternalCommand { GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { - if (disposing) { - if (_itemPlugInRoot != null) { - _itemPlugInRoot.Dispose(); - _itemPlugInRoot = null; - } - } - } - - public IEnumerable Destinations() { + protected virtual void Dispose(bool disposing) + { + if (!disposing) return; + if (_itemPlugInRoot == null) return; + _itemPlugInRoot.Dispose(); + _itemPlugInRoot = null; + } + private IEnumerable Destinations() { foreach(string command in ExternalCommandConfig.Commands) { yield return new ExternalCommandDestination(command); } } - public IEnumerable Processors() { - yield break; - } /// /// Check and eventually fix the command settings @@ -91,15 +85,14 @@ namespace ExternalCommand { Log.WarnFormat("Found 'invalid' commandline {0} for command {1}", ExternalCommandConfig.Commandline[command], command); return false; } + SimpleServiceProvider.Current.AddService(Destinations()); return true; } /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { - Log.DebugFormat("Initialize called of {0}", myAttributes.Name); + public virtual bool Initialize() { + Log.DebugFormat("Initialize called"); List commandsToDelete = new List(); // Check configuration @@ -114,16 +107,12 @@ namespace ExternalCommand { ExternalCommandConfig.Delete(command); } - _host = pluginHost; - _myAttributes = myAttributes; - - - _itemPlugInRoot = new ToolStripMenuItem {Tag = _host}; + _itemPlugInRoot = new ToolStripMenuItem(); + _itemPlugInRoot.Click += ConfigMenuClick; OnIconSizeChanged(this, new PropertyChangedEventArgs("IconSize")); OnLanguageChanged(this, null); - _itemPlugInRoot.Click += ConfigMenuClick; - PluginUtils.AddToContextMenu(_host, _itemPlugInRoot); + PluginUtils.AddToContextMenu(_itemPlugInRoot); Language.LanguageChanged += OnLanguageChanged; CoreConfig.PropertyChanged += OnIconSizeChanged; return true; @@ -154,7 +143,7 @@ namespace ExternalCommand { } public virtual void Shutdown() { - Log.Debug("Shutdown of " + _myAttributes.Name); + Log.Debug("Shutdown"); } private void ConfigMenuClick(object sender, EventArgs eventArgs) { diff --git a/GreenshotExternalCommandPlugin/Properties/AssemblyInfo.cs b/GreenshotExternalCommandPlugin/Properties/AssemblyInfo.cs deleted file mode 100644 index 5958ed162..000000000 --- a/GreenshotExternalCommandPlugin/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,34 +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 . - */ - -using Greenshot.Plugin; -using System.Reflection; -using System.Runtime.InteropServices; - -// 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. -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("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)] diff --git a/GreenshotFlickrPlugin/FlickrPlugin.cs b/GreenshotFlickrPlugin/FlickrPlugin.cs index 9211293d8..1a3676332 100644 --- a/GreenshotFlickrPlugin/FlickrPlugin.cs +++ b/GreenshotFlickrPlugin/FlickrPlugin.cs @@ -20,7 +20,6 @@ */ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; @@ -39,8 +38,6 @@ namespace GreenshotFlickrPlugin public class FlickrPlugin : IGreenshotPlugin { private static readonly ILog Log = LogManager.GetLogger(typeof(FlickrPlugin)); private static FlickrConfiguration _config; - public static PluginAttribute Attributes; - private IGreenshotHost _host; private ComponentResourceManager _resources; private ToolStripMenuItem _itemPlugInConfig; @@ -49,7 +46,7 @@ namespace GreenshotFlickrPlugin GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { + protected void Dispose(bool disposing) { if (!disposing) { return; } @@ -60,25 +57,10 @@ namespace GreenshotFlickrPlugin _itemPlugInConfig = null; } - public IEnumerable Destinations() { - yield return new FlickrDestination(this); - } - - - public IEnumerable Processors() { - yield break; - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute pluginAttribute) { - _host = pluginHost; - Attributes = pluginAttribute; - - + public bool Initialize() { // Register configuration (don't need the configuration itself) _config = IniConfig.GetIniSection(); _resources = new ComponentResourceManager(typeof(FlickrPlugin)); @@ -86,12 +68,11 @@ namespace GreenshotFlickrPlugin _itemPlugInConfig = new ToolStripMenuItem { Text = Language.GetString("flickr", LangKey.Configure), - Tag = _host, Image = (Image) _resources.GetObject("flickr") }; _itemPlugInConfig.Click += ConfigMenuClick; - - PluginUtils.AddToContextMenu(_host, _itemPlugInConfig); + SimpleServiceProvider.Current.AddService(new FlickrDestination(this)); + PluginUtils.AddToContextMenu(_itemPlugInConfig); Language.LanguageChanged += OnLanguageChanged; return true; } @@ -102,14 +83,14 @@ namespace GreenshotFlickrPlugin } } - public virtual void Shutdown() { + public void Shutdown() { Log.Debug("Flickr Plugin shutdown."); } /// /// Implementation of the IPlugin.Configure /// - public virtual void Configure() { + public void Configure() { _config.ShowConfigDialog(); } @@ -122,7 +103,7 @@ namespace GreenshotFlickrPlugin uploadUrl = null; try { string flickrUrl = null; - new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("flickr", LangKey.communication_wait), + new PleaseWaitForm().ShowAndWait("Flickr", Language.GetString("flickr", LangKey.communication_wait), delegate { string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails)); flickrUrl = FlickrUtils.UploadToFlickr(surface, outputSettings, captureDetails.Title, filename); diff --git a/GreenshotFlickrPlugin/Properties/AssemblyInfo.cs b/GreenshotFlickrPlugin/Properties/AssemblyInfo.cs index 5cbf45777..6b06e2aa5 100644 --- a/GreenshotFlickrPlugin/Properties/AssemblyInfo.cs +++ b/GreenshotFlickrPlugin/Properties/AssemblyInfo.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ -using Greenshot.Plugin; using System.Reflection; using System.Runtime.InteropServices; @@ -27,8 +26,6 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyDescription("A plugin to upload images to Flickr")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotFlickrPlugin.FlickrPlugin", 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. diff --git a/GreenshotImgurPlugin/Forms/ImgurHistory.cs b/GreenshotImgurPlugin/Forms/ImgurHistory.cs index 5a697c8a1..34fb72fb1 100644 --- a/GreenshotImgurPlugin/Forms/ImgurHistory.cs +++ b/GreenshotImgurPlugin/Forms/ImgurHistory.cs @@ -146,7 +146,7 @@ namespace GreenshotImgurPlugin { // Should fix Bug #3378699 pictureBox1.Image = pictureBox1.ErrorImage; try { - new PleaseWaitForm().ShowAndWait(ImgurPlugin.Attributes.Name, Language.GetString("imgur", LangKey.communication_wait), + new PleaseWaitForm().ShowAndWait("Imgur", Language.GetString("imgur", LangKey.communication_wait), delegate { ImgurUtils.DeleteImgurImage(imgurInfo); } diff --git a/GreenshotImgurPlugin/ImgurPlugin.cs b/GreenshotImgurPlugin/ImgurPlugin.cs index a6c5dba4a..fd397ad6b 100644 --- a/GreenshotImgurPlugin/ImgurPlugin.cs +++ b/GreenshotImgurPlugin/ImgurPlugin.cs @@ -33,11 +33,10 @@ namespace GreenshotImgurPlugin { /// /// This is the ImgurPlugin code /// + [Plugin("Imgur", true)] public class ImgurPlugin : IGreenshotPlugin { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(ImgurPlugin)); private static ImgurConfiguration _config; - public static PluginAttribute Attributes; - private IGreenshotHost _host; private ComponentResourceManager _resources; private ToolStripMenuItem _historyMenuItem; private ToolStripMenuItem _itemPlugInConfig; @@ -60,24 +59,15 @@ namespace GreenshotImgurPlugin { } } - public IEnumerable Destinations() { + private IEnumerable Destinations() { yield return new ImgurDestination(this); } - public IEnumerable Processors() { - yield break; - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes /// true if plugin is initialized, false if not (doesn't show) - public bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { - _host = pluginHost; - Attributes = myAttributes; - + public bool Initialize() { // Get configuration _config = IniConfig.GetIniSection(); _resources = new ComponentResourceManager(typeof(ImgurPlugin)); @@ -87,25 +77,21 @@ namespace GreenshotImgurPlugin { Image = (Image) _resources.GetObject("Imgur") }; - _historyMenuItem = new ToolStripMenuItem(Language.GetString("imgur", LangKey.history)) - { - Tag = _host - }; + // Provide the IDestination + SimpleServiceProvider.Current.AddService(Destinations()); + _historyMenuItem = new ToolStripMenuItem(Language.GetString("imgur", LangKey.history)); _historyMenuItem.Click += delegate { ImgurHistory.ShowHistory(); }; itemPlugInRoot.DropDownItems.Add(_historyMenuItem); - _itemPlugInConfig = new ToolStripMenuItem(Language.GetString("imgur", LangKey.configure)) - { - Tag = _host - }; + _itemPlugInConfig = new ToolStripMenuItem(Language.GetString("imgur", LangKey.configure)); _itemPlugInConfig.Click += delegate { _config.ShowConfigDialog(); }; itemPlugInRoot.DropDownItems.Add(_itemPlugInConfig); - PluginUtils.AddToContextMenu(_host, itemPlugInRoot); + PluginUtils.AddToContextMenu(itemPlugInRoot); Language.LanguageChanged += OnLanguageChanged; // Enable history if there are items available @@ -129,7 +115,8 @@ namespace GreenshotImgurPlugin { } try { - _host.GreenshotForm.BeginInvoke((MethodInvoker)delegate + var form = SimpleServiceProvider.Current.GetInstance(); + form.BeginInvoke((MethodInvoker)delegate { var historyMenuItem = _historyMenuItem; if (historyMenuItem == null) diff --git a/GreenshotImgurPlugin/Properties/AssemblyInfo.cs b/GreenshotImgurPlugin/Properties/AssemblyInfo.cs index b9422af90..19a2e1176 100644 --- a/GreenshotImgurPlugin/Properties/AssemblyInfo.cs +++ b/GreenshotImgurPlugin/Properties/AssemblyInfo.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ -using Greenshot.Plugin; using System.Reflection; using System.Runtime.InteropServices; @@ -27,8 +26,6 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyDescription("A plugin to upload images to Imgur")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotImgurPlugin.ImgurPlugin", 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. diff --git a/GreenshotJiraPlugin/JiraConnector.cs b/GreenshotJiraPlugin/JiraConnector.cs index 804491415..853b75e52 100644 --- a/GreenshotJiraPlugin/JiraConnector.cs +++ b/GreenshotJiraPlugin/JiraConnector.cs @@ -55,8 +55,9 @@ namespace GreenshotJiraPlugin { CoreConfig.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(CoreConfig.IconSize)) - { - JiraPlugin.Instance.JiraConnector._jiraClient?.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.ScaledIconSize.Width, Height = CoreConfig.ScaledIconSize.Height }); + { + var jiraConnector = SimpleServiceProvider.Current.GetInstance(); + jiraConnector._jiraClient?.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.ScaledIconSize.Width, Height = CoreConfig.ScaledIconSize.Height }); } }; diff --git a/GreenshotJiraPlugin/JiraDestination.cs b/GreenshotJiraPlugin/JiraDestination.cs index 642dfdff6..ebd2c2910 100644 --- a/GreenshotJiraPlugin/JiraDestination.cs +++ b/GreenshotJiraPlugin/JiraDestination.cs @@ -40,16 +40,10 @@ namespace GreenshotJiraPlugin { public class JiraDestination : AbstractDestination { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(JiraDestination)); private static readonly JiraConfiguration Config = IniConfig.GetIniSection(); - private readonly JiraPlugin _jiraPlugin; private readonly Issue _jiraIssue; - public JiraDestination(JiraPlugin jiraPlugin) { - _jiraPlugin = jiraPlugin; - } - - public JiraDestination(JiraPlugin jiraPlugin, Issue jiraIssue) { - _jiraPlugin = jiraPlugin; - _jiraIssue = jiraIssue; + public JiraDestination(Issue jiraIssue = null) { + _jiraIssue = jiraIssue; } public override string Designation => "Jira"; @@ -73,7 +67,7 @@ namespace GreenshotJiraPlugin { get { Image displayIcon = null; - var jiraConnector = JiraPlugin.Instance.CurrentJiraConnector; + var jiraConnector = SimpleServiceProvider.Current.GetInstance(); if (jiraConnector != null) { if (_jiraIssue != null) @@ -104,13 +98,13 @@ namespace GreenshotJiraPlugin { public override IEnumerable DynamicDestinations() { - var jiraConnector = JiraPlugin.Instance.CurrentJiraConnector; + var jiraConnector = SimpleServiceProvider.Current.GetInstance(); if (jiraConnector == null || !jiraConnector.IsLoggedIn) { yield break; } foreach(var jiraDetails in jiraConnector.Monitor.RecentJiras) { - yield return new JiraDestination(_jiraPlugin,jiraDetails.JiraIssue); + yield return new JiraDestination(jiraDetails.JiraIssue); } } @@ -118,6 +112,7 @@ namespace GreenshotJiraPlugin { ExportInformation exportInformation = new ExportInformation(Designation, Description); string filename = Path.GetFileName(FilenameHelper.GetFilename(Config.UploadFormat, captureDetails)); SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(Config.UploadFormat, Config.UploadJpegQuality, Config.UploadReduceColors); + var jiraConnector = SimpleServiceProvider.Current.GetInstance(); if (_jiraIssue != null) { try { // Run upload in the background @@ -125,8 +120,8 @@ namespace GreenshotJiraPlugin { async () => { var surfaceContainer = new SurfaceContainer(surfaceToUpload, outputSettings, filename); - await _jiraPlugin.JiraConnector.AttachAsync(_jiraIssue.Key, surfaceContainer); - surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri; + await jiraConnector.AttachAsync(_jiraIssue.Key, surfaceContainer); + surfaceToUpload.UploadUrl = jiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri; } ); Log.DebugFormat("Uploaded to Jira {0}", _jiraIssue.Key); @@ -136,12 +131,12 @@ namespace GreenshotJiraPlugin { MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message); } } else { - var jiraForm = new JiraForm(_jiraPlugin.JiraConnector); + var jiraForm = new JiraForm(jiraConnector); jiraForm.SetFilename(filename); var dialogResult = jiraForm.ShowDialog(); if (dialogResult == DialogResult.OK) { try { - surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", jiraForm.GetJiraIssue().Key).AbsoluteUri; + surfaceToUpload.UploadUrl = jiraConnector.JiraBaseUri.AppendSegments("browse", jiraForm.GetJiraIssue().Key).AbsoluteUri; // Run upload in the background new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait), async () => diff --git a/GreenshotJiraPlugin/JiraPlugin.cs b/GreenshotJiraPlugin/JiraPlugin.cs index 1b18c0ef4..7127e6cbe 100644 --- a/GreenshotJiraPlugin/JiraPlugin.cs +++ b/GreenshotJiraPlugin/JiraPlugin.cs @@ -33,11 +33,10 @@ namespace GreenshotJiraPlugin { /// /// This is the JiraPlugin base code /// + [Plugin("Jira", true)] public class JiraPlugin : IGreenshotPlugin { private static readonly ILog Log = LogManager.GetLogger(typeof(JiraPlugin)); private JiraConfiguration _config; - private static JiraPlugin _instance; - private JiraConnector _jiraConnector; public void Dispose() { Dispose(true); @@ -45,58 +44,27 @@ namespace GreenshotJiraPlugin { } protected void Dispose(bool disposing) { - if (disposing) { - if (JiraConnector != null) { - JiraConnector.Dispose(); - JiraConnector = null; - } + if (disposing) + { + var jiraConnector = SimpleServiceProvider.Current.GetInstance(); + jiraConnector?.Dispose(); } } - public static JiraPlugin Instance => _instance; - - public JiraPlugin() { - _instance = this; - } - - public IEnumerable Destinations() { - yield return new JiraDestination(this); - } - - public IEnumerable Processors() { - yield break; - } - - //Needed for a fail-fast - public JiraConnector CurrentJiraConnector => JiraConnector; - - public JiraConnector JiraConnector - { - get - { - lock (_instance) - { - if (_jiraConnector == null) - { - JiraConnector = new JiraConnector(); - } - } - return _jiraConnector; - } - private set { _jiraConnector = value; } - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes /// true if plugin is initialized, false if not (doesn't show) - public bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { + public bool Initialize() { // Register configuration (don't need the configuration itself) _config = IniConfig.GetIniSection(); - // Make sure the loggin is enable for the corect level. + // Provide the JiraConnector + SimpleServiceProvider.Current.AddService(new JiraConnector()); + // Provide the IDestination + SimpleServiceProvider.Current.AddService(new JiraDestination()); + + // Make sure the log is enabled for the correct level. if (Log.IsDebugEnabled) { LogSettings.RegisterDefaultLogger(LogLevels.Verbose); @@ -142,7 +110,8 @@ namespace GreenshotJiraPlugin { public void Shutdown() { Log.Debug("Jira Plugin shutdown."); - JiraConnector?.Logout(); + var jiraConnector = SimpleServiceProvider.Current.GetInstance(); + jiraConnector?.Logout(); } /// @@ -152,12 +121,13 @@ namespace GreenshotJiraPlugin { string url = _config.Url; if (ShowConfigDialog()) { // check for re-login - if (JiraConnector != null && JiraConnector.IsLoggedIn && !string.IsNullOrEmpty(url)) { + var jiraConnector = SimpleServiceProvider.Current.GetInstance(); + if (jiraConnector != null && jiraConnector.IsLoggedIn && !string.IsNullOrEmpty(url)) { if (!url.Equals(_config.Url)) { - JiraConnector.Logout(); + jiraConnector.Logout(); Task.Run(async () => { - await JiraConnector.LoginAsync(); + await jiraConnector.LoginAsync(); }); } } diff --git a/GreenshotPlugin/Core/Func.cs b/GreenshotOCRPlugin/ModiLanguage.cs similarity index 56% rename from GreenshotPlugin/Core/Func.cs rename to GreenshotOCRPlugin/ModiLanguage.cs index e76abe766..b707d3f69 100644 --- a/GreenshotPlugin/Core/Func.cs +++ b/GreenshotOCRPlugin/ModiLanguage.cs @@ -18,12 +18,33 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -namespace GreenshotPlugin.Core +namespace GreenshotOCR { - public delegate TResult Func(); - public delegate TResult Func(T arg); - public delegate TResult Func(T1 arg1, T2 arg2); - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); -} + /// + /// Needed for the drop down, available languages for OCR + /// + public enum ModiLanguage { + CHINESE_SIMPLIFIED = 2052, + CHINESE_TRADITIONAL = 1028, + CZECH = 5, + DANISH = 6, + DUTCH = 19, + ENGLISH = 9, + FINNISH = 11, + FRENCH = 12, + GERMAN = 7, + GREEK = 8, + HUNGARIAN = 14, + ITALIAN = 16, + JAPANESE = 17, + KOREAN = 18, + NORWEGIAN = 20, + POLISH = 21, + PORTUGUESE = 22, + RUSSIAN = 25, + SPANISH = 10, + SWEDISH = 29, + TURKISH = 31, + SYSDEFAULT = 2048 + } +} \ No newline at end of file diff --git a/GreenshotOCRPlugin/OCRPlugin.cs b/GreenshotOCRPlugin/OCRPlugin.cs index 45902295c..107be1da7 100644 --- a/GreenshotOCRPlugin/OCRPlugin.cs +++ b/GreenshotOCRPlugin/OCRPlugin.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Windows.Forms; @@ -31,39 +30,14 @@ using GreenshotPlugin.Effects; //using Microsoft.Win32; namespace GreenshotOCR { - // Needed for the drop down, available languages for OCR - public enum ModiLanguage { - CHINESE_SIMPLIFIED = 2052, - CHINESE_TRADITIONAL = 1028, - CZECH = 5, - DANISH = 6, - DUTCH = 19, - ENGLISH = 9, - FINNISH = 11, - FRENCH = 12, - GERMAN = 7, - GREEK = 8, - HUNGARIAN = 14, - ITALIAN = 16, - JAPANESE = 17, - KOREAN = 18, - NORWEGIAN = 20, - POLISH = 21, - PORTUGUESE = 22, - RUSSIAN = 25, - SPANISH = 10, - SWEDISH = 29, - TURKISH = 31, - SYSDEFAULT = 2048 - } /// /// OCR Plugin Greenshot /// + [Plugin("Ocr", true)] public class OcrPlugin : IGreenshotPlugin { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(OcrPlugin)); private string _ocrCommand; - private static OCRConfiguration config; - private PluginAttribute _myAttributes; + private static OCRConfiguration _config; private ToolStripMenuItem _ocrMenuItem = new ToolStripMenuItem(); public void Dispose() { @@ -80,24 +54,14 @@ namespace GreenshotOCR { } } - public IEnumerable Destinations() { - yield return new OCRDestination(this); - } - public IEnumerable Processors() { - yield break; - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes /// true if plugin is initialized, false if not (doesn't show) - public virtual bool Initialize(IGreenshotHost greenshotHost, PluginAttribute myAttributes) { - Log.Debug("Initialize called of " + myAttributes.Name); - _myAttributes = myAttributes; + public bool Initialize() { + Log.Debug("Initialize called"); - var ocrDirectory = Path.GetDirectoryName(myAttributes.DllFile); + var ocrDirectory = Path.GetDirectoryName(GetType().Assembly.Location); if (ocrDirectory == null) { return false; @@ -108,11 +72,13 @@ namespace GreenshotOCR { Log.Warn("No MODI found!"); return false; } + // Provide the IDestination + SimpleServiceProvider.Current.AddService(new OCRDestination(this)); // Load configuration - config = IniConfig.GetIniSection(); + _config = IniConfig.GetIniSection(); - if (config.Language != null) { - config.Language = config.Language.Replace("miLANG_","").Replace("_"," "); + if (_config.Language != null) { + _config.Language = _config.Language.Replace("miLANG_","").Replace("_"," "); } return true; } @@ -121,18 +87,18 @@ namespace GreenshotOCR { /// Implementation of the IGreenshotPlugin.Shutdown /// public void Shutdown() { - Log.Debug("Shutdown of " + _myAttributes.Name); + Log.Debug("Shutdown"); } /// /// Implementation of the IPlugin.Configure /// - public virtual void Configure() { + public void Configure() { if (!HasModi()) { MessageBox.Show("Sorry, is seems that Microsoft Office Document Imaging (MODI) is not installed, therefor the OCR Plugin cannot work."); return; } - SettingsForm settingsForm = new SettingsForm(Enum.GetNames(typeof(ModiLanguage)), config); + SettingsForm settingsForm = new SettingsForm(Enum.GetNames(typeof(ModiLanguage)), _config); DialogResult result = settingsForm.ShowDialog(); if (result == DialogResult.OK) { // "Re"set hotkeys @@ -177,7 +143,7 @@ namespace GreenshotOCR { string text = ""; try { - ProcessStartInfo processStartInfo = new ProcessStartInfo(_ocrCommand, "\"" + filePath + "\" " + config.Language + " " + config.Orientimage + " " + config.StraightenImage) + ProcessStartInfo processStartInfo = new ProcessStartInfo(_ocrCommand, "\"" + filePath + "\" " + _config.Language + " " + _config.Orientimage + " " + _config.StraightenImage) { CreateNoWindow = true, RedirectStandardOutput = true, diff --git a/GreenshotOCRPlugin/Properties/AssemblyInfo.cs b/GreenshotOCRPlugin/Properties/AssemblyInfo.cs deleted file mode 100644 index 242541957..000000000 --- a/GreenshotOCRPlugin/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,34 +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 . - */ - -using Greenshot.Plugin; -using System.Reflection; -using System.Runtime.InteropServices; - -// 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. -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotOCR.OcrPlugin", 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)] diff --git a/GreenshotOfficePlugin/OfficePlugin.cs b/GreenshotOfficePlugin/OfficePlugin.cs index 1db639e85..2b1228cb9 100644 --- a/GreenshotOfficePlugin/OfficePlugin.cs +++ b/GreenshotOfficePlugin/OfficePlugin.cs @@ -21,12 +21,15 @@ using System; using System.Collections.Generic; using Greenshot.Plugin; +using GreenshotPlugin.Core; namespace GreenshotOfficePlugin { /// /// This is the OfficePlugin base code /// - public class OfficePlugin : IGreenshotPlugin { + [Plugin("Office", false)] + public class OfficePlugin : IGreenshotPlugin + { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OfficePlugin)); public void Dispose() { @@ -38,7 +41,7 @@ namespace GreenshotOfficePlugin { // Do nothing } - public IEnumerable Destinations() { + private IEnumerable Destinations() { IDestination destination; try { destination = new ExcelDestination(); @@ -86,21 +89,17 @@ namespace GreenshotOfficePlugin { } } - public IEnumerable Processors() { - yield break; - } /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes /// true if plugin is initialized, false if not (doesn't show) - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { + public bool Initialize() { + SimpleServiceProvider.Current.AddService(Destinations()); return true; } - public virtual void Shutdown() { + public void Shutdown() { LOG.Debug("Office Plugin shutdown."); } diff --git a/GreenshotOfficePlugin/Properties/AssemblyInfo.cs b/GreenshotOfficePlugin/Properties/AssemblyInfo.cs index cd86fb7ca..50c27e0ec 100644 --- a/GreenshotOfficePlugin/Properties/AssemblyInfo.cs +++ b/GreenshotOfficePlugin/Properties/AssemblyInfo.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ -using Greenshot.Plugin; using System.Reflection; using System.Runtime.InteropServices; @@ -27,8 +26,6 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyDescription("A plugin to export images to Office applications")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotOfficePlugin.OfficePlugin", false)] // 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. diff --git a/GreenshotPhotobucketPlugin/PhotobucketConfiguration.cs b/GreenshotPhotobucketPlugin/PhotobucketConfiguration.cs index 9b3f8aa4e..f519f905f 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketConfiguration.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketConfiguration.cs @@ -58,7 +58,7 @@ namespace GreenshotPhotobucketPlugin { public bool ShowConfigDialog() { SettingsForm settingsForm = null; - new PleaseWaitForm().ShowAndWait(PhotobucketPlugin.Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait), + new PleaseWaitForm().ShowAndWait("Photobucket", Language.GetString("photobucket", LangKey.communication_wait), delegate { settingsForm = new SettingsForm(); } diff --git a/GreenshotPhotobucketPlugin/PhotobucketDestination.cs b/GreenshotPhotobucketPlugin/PhotobucketDestination.cs index 9f897db30..4687a7aaa 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketDestination.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketDestination.cs @@ -37,7 +37,7 @@ namespace GreenshotPhotobucketPlugin { /// /// /// path to the album, null for default - public PhotobucketDestination(PhotobucketPlugin plugin, string albumPath) { + public PhotobucketDestination(PhotobucketPlugin plugin, string albumPath = null) { _plugin = plugin; _albumPath = albumPath; } diff --git a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs index ee7483ef4..7c2be8feb 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; @@ -33,11 +32,10 @@ namespace GreenshotPhotobucketPlugin { /// /// This is the GreenshotPhotobucketPlugin base code /// + [Plugin("Photobucket", true)] public class PhotobucketPlugin : IGreenshotPlugin { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(PhotobucketPlugin)); private static PhotobucketConfiguration _config; - public static PluginAttribute Attributes; - private IGreenshotHost _host; private ComponentResourceManager _resources; private ToolStripMenuItem _itemPlugInConfig; @@ -46,32 +44,20 @@ namespace GreenshotPhotobucketPlugin { GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { - if (disposing) { - if (_itemPlugInConfig != null) { - _itemPlugInConfig.Dispose(); - _itemPlugInConfig = null; - } - } - } - - public IEnumerable Destinations() { - yield return new PhotobucketDestination(this, null); - } - - public IEnumerable Processors() { - yield break; - } + protected void Dispose(bool disposing) + { + if (!disposing) return; + if (_itemPlugInConfig == null) return; + _itemPlugInConfig.Dispose(); + _itemPlugInConfig = null; + } /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes /// true if plugin is initialized, false if not (doesn't show) - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { - _host = pluginHost; - Attributes = myAttributes; + public bool Initialize() { + SimpleServiceProvider.Current.AddService(new PhotobucketDestination(this)); // Get configuration _config = IniConfig.GetIniSection(); @@ -79,14 +65,13 @@ namespace GreenshotPhotobucketPlugin { _itemPlugInConfig = new ToolStripMenuItem(Language.GetString("photobucket", LangKey.configure)) { - Tag = _host, Image = (Image)_resources.GetObject("Photobucket") }; _itemPlugInConfig.Click += delegate { _config.ShowConfigDialog(); }; - PluginUtils.AddToContextMenu(_host, _itemPlugInConfig); + PluginUtils.AddToContextMenu(_itemPlugInConfig); Language.LanguageChanged += OnLanguageChanged; return true; } @@ -97,7 +82,7 @@ namespace GreenshotPhotobucketPlugin { } } - public virtual void Shutdown() { + public void Shutdown() { Log.Debug("Photobucket Plugin shutdown."); Language.LanguageChanged -= OnLanguageChanged; } @@ -105,7 +90,7 @@ namespace GreenshotPhotobucketPlugin { /// /// Implementation of the IPlugin.Configure /// - public virtual void Configure() { + public void Configure() { _config.ShowConfigDialog(); } @@ -124,7 +109,7 @@ namespace GreenshotPhotobucketPlugin { PhotobucketInfo photobucketInfo = null; // Run upload in the background - new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait), + new PleaseWaitForm().ShowAndWait("Photobucket", Language.GetString("photobucket", LangKey.communication_wait), delegate { photobucketInfo = PhotobucketUtils.UploadToPhotobucket(surfaceToUpload, outputSettings, albumPath, captureDetails.Title, filename); } diff --git a/GreenshotPhotobucketPlugin/Properties/AssemblyInfo.cs b/GreenshotPhotobucketPlugin/Properties/AssemblyInfo.cs index 9f85c8546..9aa4884a4 100644 --- a/GreenshotPhotobucketPlugin/Properties/AssemblyInfo.cs +++ b/GreenshotPhotobucketPlugin/Properties/AssemblyInfo.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ -using Greenshot.Plugin; using System.Reflection; using System.Runtime.InteropServices; @@ -28,8 +27,6 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyDescription("A plugin to upload images to Photobucket")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotPhotobucketPlugin.PhotobucketPlugin", 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. diff --git a/GreenshotPicasaPlugin/PicasaPlugin.cs b/GreenshotPicasaPlugin/PicasaPlugin.cs index 76bd80250..ea20eb070 100644 --- a/GreenshotPicasaPlugin/PicasaPlugin.cs +++ b/GreenshotPicasaPlugin/PicasaPlugin.cs @@ -18,7 +18,6 @@ * along with this program. If not, see . */ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; @@ -32,11 +31,10 @@ namespace GreenshotPicasaPlugin { /// /// This is the Picasa base code /// + [Plugin("Picasa", true)] public class PicasaPlugin : IGreenshotPlugin { private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(PicasaPlugin)); private static PicasaConfiguration _config; - public static PluginAttribute Attributes; - private IGreenshotHost _host; private ComponentResourceManager _resources; private ToolStripMenuItem _itemPlugInRoot; @@ -45,7 +43,7 @@ namespace GreenshotPicasaPlugin { GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { + protected void Dispose(bool disposing) { if (disposing) { if (_itemPlugInRoot != null) { _itemPlugInRoot.Dispose(); @@ -54,23 +52,11 @@ namespace GreenshotPicasaPlugin { } } - public IEnumerable Destinations() { - yield return new PicasaDestination(this); - } - - - public IEnumerable Processors() { - yield break; - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes - public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { - _host = pluginHost; - Attributes = myAttributes; + public bool Initialize() { + SimpleServiceProvider.Current.AddService(new PicasaDestination(this)); // Get configuration _config = IniConfig.GetIniSection(); @@ -79,11 +65,10 @@ namespace GreenshotPicasaPlugin { _itemPlugInRoot = new ToolStripMenuItem { Text = Language.GetString("picasa", LangKey.Configure), - Tag = _host, Image = (Image) _resources.GetObject("Picasa") }; _itemPlugInRoot.Click += ConfigMenuClick; - PluginUtils.AddToContextMenu(_host, _itemPlugInRoot); + PluginUtils.AddToContextMenu(_itemPlugInRoot); Language.LanguageChanged += OnLanguageChanged; return true; } @@ -94,7 +79,7 @@ namespace GreenshotPicasaPlugin { } } - public virtual void Shutdown() { + public void Shutdown() { Log.Debug("Picasa Plugin shutdown."); Language.LanguageChanged -= OnLanguageChanged; //host.OnImageEditorOpen -= new OnImageEditorOpenHandler(ImageEditorOpened); @@ -103,7 +88,7 @@ namespace GreenshotPicasaPlugin { /// /// Implementation of the IPlugin.Configure /// - public virtual void Configure() { + public void Configure() { _config.ShowConfigDialog(); } @@ -115,7 +100,7 @@ namespace GreenshotPicasaPlugin { SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality); try { string url = null; - new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("picasa", LangKey.communication_wait), + new PleaseWaitForm().ShowAndWait("Picasa", Language.GetString("picasa", LangKey.communication_wait), delegate { string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails)); diff --git a/GreenshotPicasaPlugin/Properties/AssemblyInfo.cs b/GreenshotPicasaPlugin/Properties/AssemblyInfo.cs index 481007a5c..35cc458c3 100644 --- a/GreenshotPicasaPlugin/Properties/AssemblyInfo.cs +++ b/GreenshotPicasaPlugin/Properties/AssemblyInfo.cs @@ -19,7 +19,6 @@ * along with this program. If not, see . */ -using Greenshot.Plugin; using System.Reflection; using System.Runtime.InteropServices; @@ -27,8 +26,6 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyDescription("A plugin to upload images to Picasa")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotPicasaPlugin.PicasaPlugin", 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. diff --git a/GreenshotPlugin/Core/AbstractDestination.cs b/GreenshotPlugin/Core/AbstractDestination.cs index 0a0220642..33aff20c1 100644 --- a/GreenshotPlugin/Core/AbstractDestination.cs +++ b/GreenshotPlugin/Core/AbstractDestination.cs @@ -260,7 +260,7 @@ namespace GreenshotPlugin.Core { location.Offset(-40, -10); } // This prevents the problem that the context menu shows in the task-bar - User32.SetForegroundWindow(PluginUtils.Host.NotifyIcon.ContextMenuStrip.Handle); + User32.SetForegroundWindow(SimpleServiceProvider.Current.GetInstance().ContextMenuStrip.Handle); menu.Show(location); menu.Focus(); diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index a17f75d3d..3359048a9 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -52,16 +52,11 @@ namespace GreenshotPlugin.Core { private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection(); private const int ExifOrientationId = 0x0112; - /// - /// This is a factory method to create a surface, set from the Greenshot main project - /// - public static Func SurfaceFactory { get; set; } - - static ImageHelper() + static ImageHelper() { StreamConverters["greenshot"] = (stream, s) => { - var surface = SurfaceFactory(); + var surface = SimpleServiceProvider.Current.GetInstance>().Invoke(); return surface.GetImageForExport(); }; diff --git a/GreenshotPlugin/Core/PluginUtils.cs b/GreenshotPlugin/Core/PluginUtils.cs index 4edb453c2..781585076 100644 --- a/GreenshotPlugin/Core/PluginUtils.cs +++ b/GreenshotPlugin/Core/PluginUtils.cs @@ -45,14 +45,6 @@ namespace GreenshotPlugin.Core { CoreConfig.PropertyChanged += OnIconSizeChanged; } - /// - /// Simple global property to get the Greenshot host - /// - public static IGreenshotHost Host { - get; - set; - } - /// /// Clear icon cache /// @@ -220,11 +212,10 @@ namespace GreenshotPlugin.Core { /// /// Helper method to add a plugin MenuItem to the Greenshot context menu /// - /// IGreenshotHost /// ToolStripMenuItem - public static void AddToContextMenu(IGreenshotHost host, ToolStripMenuItem item) { - // Here we can hang ourselves to the main context menu! - ContextMenuStrip contextMenu = host.MainMenu; + public static void AddToContextMenu(ToolStripMenuItem item) { + // Here we can hang ourselves to the main context menu! + var contextMenu = SimpleServiceProvider.Current.GetInstance(); bool addedItem = false; // Try to find a separator, so we insert ourselves after it diff --git a/GreenshotPlugin/Core/SimpleServiceProvider.cs b/GreenshotPlugin/Core/SimpleServiceProvider.cs new file mode 100644 index 000000000..5482f107a --- /dev/null +++ b/GreenshotPlugin/Core/SimpleServiceProvider.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using GreenshotPlugin.Interfaces; + +namespace GreenshotPlugin.Core +{ + /// + /// A really cheap and simple DI system + /// + public class SimpleServiceProvider : IServiceLocator + { + private readonly Dictionary> _services = new Dictionary>(); + + public static IServiceLocator Current { get; } = new SimpleServiceProvider(); + + public IEnumerable GetAllInstances() + { + var typeOfService = typeof(TService); + if (!_services.TryGetValue(typeOfService, out var results)) + { + yield break; + } + foreach (TService result in results) + { + yield return result; + } + } + + public TService GetInstance() + { + return GetAllInstances().SingleOrDefault(); + } + + public void AddService(IEnumerable services) + { + var serviceType = typeof(TService); + if (!_services.TryGetValue(serviceType, out var currentServices)) + { + currentServices = new List(); + _services.Add(serviceType, currentServices); + } + + foreach (var service in services) + { + currentServices.Add(service); + } + } + + public void AddService(params TService[] services) + { + AddService(services.AsEnumerable()); + } + } +} diff --git a/GreenshotPlugin/Interfaces/IServiceLocator.cs b/GreenshotPlugin/Interfaces/IServiceLocator.cs new file mode 100644 index 000000000..1ef9df723 --- /dev/null +++ b/GreenshotPlugin/Interfaces/IServiceLocator.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace GreenshotPlugin.Interfaces +{ + public interface IServiceLocator + { + IEnumerable GetAllInstances(); + TService GetInstance(); + + void AddService(params TService[] services); + + void AddService(IEnumerable services); + } +} diff --git a/GreenshotPlugin/Interfaces/Plugin/HotKeyHandler.cs b/GreenshotPlugin/Interfaces/Plugin/HotKeyHandler.cs new file mode 100644 index 000000000..dd76ac113 --- /dev/null +++ b/GreenshotPlugin/Interfaces/Plugin/HotKeyHandler.cs @@ -0,0 +1,4 @@ +namespace Greenshot.Plugin +{ + public delegate void HotKeyHandler(); +} \ No newline at end of file diff --git a/GreenshotPlugin/Interfaces/Plugin/IGreenshotHost.cs b/GreenshotPlugin/Interfaces/Plugin/IGreenshotHost.cs new file mode 100644 index 000000000..4ba2c15a0 --- /dev/null +++ b/GreenshotPlugin/Interfaces/Plugin/IGreenshotHost.cs @@ -0,0 +1,48 @@ +using System.Drawing; + +namespace Greenshot.Plugin +{ + /// + /// This interface is the GreenshotPluginHost, that which "Hosts" the plugin. + /// For Greenshot this is implemented in the PluginHelper + /// + public interface IGreenshotHost { + /// + /// Create a Thumbnail + /// + /// Image of which we need a Thumbnail + /// + /// + /// Image with Thumbnail + Image GetThumbnail(Image image, int width, int height); + + /// + /// Export a surface to the destination with has the supplied designation + /// + /// + /// + /// + /// + ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails); + + /// + /// Make region capture with specified Handler + /// + /// bool false if the mouse should not be captured, true if the configuration should be checked + /// IDestination destination + void CaptureRegion(bool captureMouseCursor, IDestination destination); + + /// + /// Use the supplied capture, and handle it as if it's captured. + /// + /// ICapture to import + void ImportCapture(ICapture captureToImport); + + /// + /// Use the supplied image, and ICapture a capture object for it + /// + /// Image to create capture for + /// ICapture + ICapture GetCapture(Image imageToCapture); + } +} \ No newline at end of file diff --git a/GreenshotPlugin/Interfaces/Plugin/IGreenshotPlugin.cs b/GreenshotPlugin/Interfaces/Plugin/IGreenshotPlugin.cs new file mode 100644 index 000000000..e5afec985 --- /dev/null +++ b/GreenshotPlugin/Interfaces/Plugin/IGreenshotPlugin.cs @@ -0,0 +1,25 @@ +using System; + +namespace Greenshot.Plugin +{ + /// + /// This defines the plugin + /// + public interface IGreenshotPlugin : IDisposable { + /// + /// Is called after the plugin is instantiated, the Plugin should keep a copy of the host and pluginAttribute. + /// + /// true if plugin is initialized, false if not (doesn't show) + bool Initialize(); + + /// + /// Unload of the plugin + /// + void Shutdown(); + + /// + /// Open the Configuration Form, will/should not be called before handshaking is done + /// + void Configure(); + } +} \ No newline at end of file diff --git a/GreenshotJiraPlugin/Properties/AssemblyInfo.cs b/GreenshotPlugin/Interfaces/Plugin/PluginAttribute.cs similarity index 55% rename from GreenshotJiraPlugin/Properties/AssemblyInfo.cs rename to GreenshotPlugin/Interfaces/Plugin/PluginAttribute.cs index 4cebd18d8..9d75082f9 100644 --- a/GreenshotJiraPlugin/Properties/AssemblyInfo.cs +++ b/GreenshotPlugin/Interfaces/Plugin/PluginAttribute.cs @@ -1,35 +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 . - */ - -using Greenshot.Plugin; -using System.Reflection; -using System.Runtime.InteropServices; - -// 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. -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotJiraPlugin.JiraPlugin", 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)] - +/* + * 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 . + */ + +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"); + } + } +} \ No newline at end of file diff --git a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs deleted file mode 100644 index eab16499a..000000000 --- a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs +++ /dev/null @@ -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 . - */ -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(); - 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; - } - - /// - /// BUG-2056 reported a logical issue, using greenshot format as the default causes issues with the external commands. - /// - /// this for fluent API usage - 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 Effects { get; } = new List(); - - 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; - } - } - - /// - /// Disable the reduce colors option, this overrules the enabling - /// - 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; - } - } - } - } - - /// - /// This interface is the GreenshotPluginHost, that which "Hosts" the plugin. - /// For Greenshot this is implmented in the PluginHelper - /// - 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; - } - - /// - /// Create a Thumbnail - /// - /// Image of which we need a Thumbnail - /// - /// - /// Image with Thumbnail - Image GetThumbnail(Image image, int width, int height); - - /// - /// List of available plugins with their PluginAttributes - /// This can be usefull for a plugin manager plugin... - /// - IDictionary Plugins { - get; - } - - /// - /// Get a destination by it's designation - /// - /// - /// IDestination - IDestination GetDestination(string designation); - - /// - /// Get a list of all available destinations - /// - /// List of IDestination - List GetAllDestinations(); - - /// - /// Export a surface to the destination with has the supplied designation - /// - /// - /// - /// - /// - ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails); - - /// - /// Make region capture with specified Handler - /// - /// bool false if the mouse should not be captured, true if the configuration should be checked - /// IDestination destination - void CaptureRegion(bool captureMouseCursor, IDestination destination); - - /// - /// Use the supplied capture, and handle it as if it's captured. - /// - /// ICapture to import - void ImportCapture(ICapture captureToImport); - - /// - /// Use the supplied image, and ICapture a capture object for it - /// - /// Image to create capture for - /// ICapture - ICapture GetCapture(Image imageToCapture); - } - - public interface IGreenshotPlugin : IDisposable { - /// - /// Is called after the plugin is instanciated, the Plugin should keep a copy of the host and pluginAttribute. - /// - /// The IPluginHost that will be hosting the plugin - /// The PluginAttribute for the actual plugin - /// true if plugin is initialized, false if not (doesn't show) - bool Initialize(IGreenshotHost host, PluginAttribute pluginAttribute); - - /// - /// Unload of the plugin - /// - void Shutdown(); - - /// - /// Open the Configuration Form, will/should not be called before handshaking is done - /// - void Configure(); - - /// - /// Return IDestination's, if the plugin wants to - /// - IEnumerable Destinations(); - - /// - /// Return IProcessor's, if the plugin wants to - /// - IEnumerable Processors(); - } -} \ No newline at end of file diff --git a/GreenshotPlugin/Interfaces/Plugin/SurfaceOutputSettings.cs b/GreenshotPlugin/Interfaces/Plugin/SurfaceOutputSettings.cs new file mode 100644 index 000000000..aaa7a026c --- /dev/null +++ b/GreenshotPlugin/Interfaces/Plugin/SurfaceOutputSettings.cs @@ -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(); + 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; + } + + /// + /// BUG-2056 reported a logical issue, using greenshot format as the default causes issues with the external commands. + /// + /// this for fluent API usage + 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 Effects { get; } = new List(); + + 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; + } + } + + /// + /// Disable the reduce colors option, this overrules the enabling + /// + 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; + } + } + } + } +} \ No newline at end of file diff --git a/GreenshotPlugin/Interop/COMWrapper.cs b/GreenshotPlugin/Interop/COMWrapper.cs index 76d74a39d..2c03d48ec 100644 --- a/GreenshotPlugin/Interop/COMWrapper.cs +++ b/GreenshotPlugin/Interop/COMWrapper.cs @@ -597,7 +597,10 @@ namespace Greenshot.Interop { if (destinationName == null) { destinationName = _interceptType.FullName; } - DialogResult result = MessageBox.Show(PluginUtils.Host.GreenshotForm, Language.GetFormattedString("com_rejected", destinationName), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); + + var form = SimpleServiceProvider.Current.GetInstance(); + + DialogResult result = MessageBox.Show(form, Language.GetFormattedString("com_rejected", destinationName), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { continue; } diff --git a/GreenshotWin10Plugin/Properties/AssemblyInfo.cs b/GreenshotWin10Plugin/Properties/AssemblyInfo.cs index c8555b0b0..ae2eaf0b0 100644 --- a/GreenshotWin10Plugin/Properties/AssemblyInfo.cs +++ b/GreenshotWin10Plugin/Properties/AssemblyInfo.cs @@ -7,9 +7,6 @@ using System.Runtime.InteropServices; // associated with an assembly. [assembly: AssemblyDescription("A plug-in for Windows 10 only functionality")] -// The PluginAttribute describes the "entryType" and if the plugin is configurable -[assembly: Plugin("GreenshotWin10Plugin.Win10Plugin", false)] - // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. diff --git a/GreenshotWin10Plugin/Win10Plugin.cs b/GreenshotWin10Plugin/Win10Plugin.cs index 340d17f04..40d12094b 100644 --- a/GreenshotWin10Plugin/Win10Plugin.cs +++ b/GreenshotWin10Plugin/Win10Plugin.cs @@ -29,6 +29,7 @@ namespace GreenshotWin10Plugin /// /// This is the Win10Plugin /// + [Plugin("Win10", false)] public class Win10Plugin : IGreenshotPlugin { public void Dispose() @@ -52,7 +53,7 @@ namespace GreenshotWin10Plugin /// yields the windows 10 destinations if Windows 10 is detected /// /// IEnumerable with the destinations - public IEnumerable Destinations() + private IEnumerable Destinations() { if (!WindowsVersion.IsWindows10OrLater) { @@ -62,19 +63,13 @@ namespace GreenshotWin10Plugin yield return new Win10ShareDestination(); } - public IEnumerable Processors() - { - yield break; - } - - /// + /// /// Implementation of the IGreenshotPlugin.Initialize /// - /// Use the IGreenshotPluginHost interface to register events - /// My own attributes /// true if plugin is initialized, false if not (doesn't show) - public bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) + public bool Initialize() { + SimpleServiceProvider.Current.AddService(Destinations()); return true; }