diff --git a/src/Greenshot.Addons/Interfaces/Plugin/IGreenshotPlugin.cs b/src/Greenshot.Addon.Box/BoxAddonModule.cs similarity index 52% rename from src/Greenshot.Addons/Interfaces/Plugin/IGreenshotPlugin.cs rename to src/Greenshot.Addon.Box/BoxAddonModule.cs index 9eacb4f63..080a5ebed 100644 --- a/src/Greenshot.Addons/Interfaces/Plugin/IGreenshotPlugin.cs +++ b/src/Greenshot.Addon.Box/BoxAddonModule.cs @@ -1,4 +1,4 @@ -#region Greenshot GNU General Public License +#region Greenshot GNU General Public License // Greenshot - a free and open source screenshot tool // Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom @@ -21,37 +21,29 @@ #endregion -#region Usings +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Box.ViewModels; +using Greenshot.Addons.Components; -using System; -using System.Collections.Generic; -using Greenshot.Addons.Addons; - -#endregion - -namespace Greenshot.Addons.Interfaces.Plugin +namespace Greenshot.Addon.Box { - public interface IGreenshotPlugin : IDisposable - { - /// - /// Is called after the plugin is instanciated - /// - /// true if plugin is initialized, false if not (doesn't show) - bool Initialize(); + /// + public class BoxAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); - /// - /// Unload of the plugin - /// - void Shutdown(); - - /// - /// 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 + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Box/BoxDestination.cs b/src/Greenshot.Addon.Box/BoxDestination.cs index c0ee744ce..446a7fe94 100644 --- a/src/Greenshot.Addon.Box/BoxDestination.cs +++ b/src/Greenshot.Addon.Box/BoxDestination.cs @@ -25,22 +25,21 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.IO; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.HttpExtensions; using Dapplo.HttpExtensions.OAuth; using Dapplo.Log; using Dapplo.Utils; using Greenshot.Addon.Box.Entities; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Extensions; @@ -58,19 +57,23 @@ namespace Greenshot.Addon.Box private readonly IBoxConfiguration _boxConfiguration; private readonly IBoxLanguage _boxLanguage; private readonly INetworkConfiguration _networkConfiguration; + private readonly IResourceProvider _resourceProvider; private readonly OAuth2Settings _oauth2Settings; private static readonly Uri UploadFileUri = new Uri("https://upload.box.com/api/2.0/files/content"); private static readonly Uri FilesUri = new Uri("https://www.box.com/api/2.0/files/"); - [ImportingConstructor] public BoxDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, IBoxConfiguration boxConfiguration, IBoxLanguage boxLanguage, - INetworkConfiguration networkConfiguration) + INetworkConfiguration networkConfiguration, + IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage) { _boxConfiguration = boxConfiguration; _boxLanguage = boxLanguage; _networkConfiguration = networkConfiguration; + _resourceProvider = resourceProvider; _oauth2Settings = new OAuth2Settings { @@ -100,8 +103,7 @@ namespace Greenshot.Addon.Box get { // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*box\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "box.png")) { return BitmapHelper.FromStream(bitmapStream); } @@ -152,7 +154,7 @@ namespace Greenshot.Addon.Box catch (Exception ex) { Log.Error().WriteLine(ex, "Error uploading."); - MessageBox.Show(_boxLanguage.UploadFailure + " " + ex.Message); + MessageBox.Show(_boxLanguage.UploadFailure + @" " + ex.Message); return null; } } diff --git a/src/Greenshot.Addon.Box/Greenshot.Addon.Box.csproj b/src/Greenshot.Addon.Box/Greenshot.Addon.Box.csproj index 2380b9d46..57a3dcfa0 100644 --- a/src/Greenshot.Addon.Box/Greenshot.Addon.Box.csproj +++ b/src/Greenshot.Addon.Box/Greenshot.Addon.Box.csproj @@ -25,6 +25,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -37,29 +46,29 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -70,14 +79,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -151,6 +160,7 @@ + @@ -203,7 +213,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.Box/IBoxConfiguration.cs b/src/Greenshot.Addon.Box/IBoxConfiguration.cs index 0b0cefccf..1f71beb71 100644 --- a/src/Greenshot.Addon.Box/IBoxConfiguration.cs +++ b/src/Greenshot.Addon.Box/IBoxConfiguration.cs @@ -29,7 +29,6 @@ using Dapplo.HttpExtensions.OAuth; using Dapplo.Ini; using Dapplo.InterfaceImpl.Extensions; using Greenshot.Addons.Core; -using Greenshot.Addons.Core.Enums; #endregion diff --git a/src/Greenshot.Addon.Box/ViewModels/BoxConfigViewModel.cs b/src/Greenshot.Addon.Box/ViewModels/BoxConfigViewModel.cs index 142e15f53..ff3218f20 100644 --- a/src/Greenshot.Addon.Box/ViewModels/BoxConfigViewModel.cs +++ b/src/Greenshot.Addon.Box/ViewModels/BoxConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -31,7 +30,6 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.Box.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class BoxConfigViewModel : SimpleConfigScreen { /// @@ -39,17 +37,26 @@ namespace Greenshot.Addon.Box.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IBoxConfiguration BoxConfiguration { get; set; } + public IBoxConfiguration BoxConfiguration { get; } - [Import] - public IBoxLanguage BoxLanguage { get; set; } + public IBoxLanguage BoxLanguage { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } + + public BoxConfigViewModel( + IBoxConfiguration boxConfiguration, + IBoxLanguage boxLanguage, + IGreenshotLanguage greenshotLanguage, + FileConfigPartViewModel fileConfigPartViewModel + ) + { + BoxConfiguration = boxConfiguration; + BoxLanguage = boxLanguage; + GreenshotLanguage = greenshotLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.Box/app.config b/src/Greenshot.Addon.Box/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Box/app.config +++ b/src/Greenshot.Addon.Box/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Box/packages.config b/src/Greenshot.Addon.Box/packages.config index b0d80b323..52052b2a6 100644 --- a/src/Greenshot.Addon.Box/packages.config +++ b/src/Greenshot.Addon.Box/packages.config @@ -1,22 +1,25 @@  + + + - - - - - - - - + + + + + + + + - + - + diff --git a/src/Greenshot.Addon.Confluence/ConfluenceAddonModule.cs b/src/Greenshot.Addon.Confluence/ConfluenceAddonModule.cs new file mode 100644 index 000000000..795969a98 --- /dev/null +++ b/src/Greenshot.Addon.Confluence/ConfluenceAddonModule.cs @@ -0,0 +1,49 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Confluence.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Confluence +{ + /// + public class ConfluenceAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs b/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs index d08740672..21324db8e 100644 --- a/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs +++ b/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Drawing; using System.Threading; @@ -33,7 +32,8 @@ using System.Windows; using Dapplo.Confluence; using Dapplo.Confluence.Entities; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -55,7 +55,7 @@ namespace Greenshot.Addon.Confluence private readonly IConfluenceConfiguration _confluenceConfiguration; private readonly IConfluenceLanguage _confluenceLanguage; private IConfluenceClient _confluenceClient; - private Content _page; + private readonly Content _page; static ConfluenceDestination() { @@ -76,14 +76,27 @@ namespace Greenshot.Addon.Confluence } } - [ImportingConstructor] - public ConfluenceDestination(IConfluenceConfiguration confluenceConfiguration, IConfluenceLanguage confluenceLanguage) + public ConfluenceDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + IConfluenceConfiguration confluenceConfiguration, + IConfluenceLanguage confluenceLanguage) : base(coreConfiguration, greenshotLanguage) { _confluenceConfiguration = confluenceConfiguration; _confluenceLanguage = confluenceLanguage; } - public static bool IsInitialized { get; private set; } + protected ConfluenceDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + IConfluenceConfiguration confluenceConfiguration, + IConfluenceLanguage confluenceLanguage, + Content page) : this(coreConfiguration, greenshotLanguage, confluenceConfiguration, confluenceLanguage) + { + _page = page; + } + + public static bool IsInitialized { get; private set; } public override string Description { @@ -112,7 +125,7 @@ namespace Greenshot.Addon.Confluence } foreach (var currentPage in currentPages) { - yield return new ConfluenceDestination(_confluenceConfiguration, _confluenceLanguage); + yield return new ConfluenceDestination(CoreConfiguration, GreenshotLanguage, _confluenceConfiguration, _confluenceLanguage, currentPage); } } diff --git a/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj b/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj index 20a4fff56..cfabe9bcf 100644 --- a/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj +++ b/src/Greenshot.Addon.Confluence/Greenshot.Addon.Confluence.csproj @@ -41,6 +41,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -53,32 +62,32 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Costura.Fody.2.0.0\lib\net452\Costura.dll + + ..\packages\Costura.Fody.2.0.1\lib\net452\Costura.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.Confluence.0.7.19\lib\net45\Dapplo.Confluence.dll @@ -92,14 +101,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -182,6 +191,7 @@ + @@ -223,7 +233,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" @@ -232,9 +242,9 @@ copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuratio This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + - + \ No newline at end of file diff --git a/src/Greenshot.Addon.Confluence/ViewModels/ConfluenceConfigViewModel.cs b/src/Greenshot.Addon.Confluence/ViewModels/ConfluenceConfigViewModel.cs index 9c00398d8..a219837ff 100644 --- a/src/Greenshot.Addon.Confluence/ViewModels/ConfluenceConfigViewModel.cs +++ b/src/Greenshot.Addon.Confluence/ViewModels/ConfluenceConfigViewModel.cs @@ -22,7 +22,6 @@ #endregion using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -33,7 +32,6 @@ using Greenshot.Addons.Extensions; namespace Greenshot.Addon.Confluence.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class ConfluenceConfigViewModel : SimpleConfigScreen { /// @@ -41,14 +39,19 @@ namespace Greenshot.Addon.Confluence.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IConfluenceConfiguration ConfluenceConfiguration { get; set; } + public IConfluenceConfiguration ConfluenceConfiguration { get; } + public IConfluenceLanguage ConfluenceLanguage { get; } + public IGreenshotLanguage GreenshotLanguage { get; } - [Import] - public IConfluenceLanguage ConfluenceLanguage { get; set; } - - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public ConfluenceConfigViewModel( + IConfluenceConfiguration confluenceConfiguration, + IConfluenceLanguage confluenceLanguage, + IGreenshotLanguage greenshotLanguage) + { + ConfluenceConfiguration = confluenceConfiguration; + ConfluenceLanguage = confluenceLanguage; + GreenshotLanguage = greenshotLanguage; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.Confluence/app.config b/src/Greenshot.Addon.Confluence/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Confluence/app.config +++ b/src/Greenshot.Addon.Confluence/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Confluence/packages.config b/src/Greenshot.Addon.Confluence/packages.config index 48b7bb7b2..ff0b49ca3 100644 --- a/src/Greenshot.Addon.Confluence/packages.config +++ b/src/Greenshot.Addon.Confluence/packages.config @@ -1,24 +1,27 @@  + + + - - - - - - - - - + + + + + + + + + - + - + diff --git a/src/Greenshot.Addon.Dropbox/DropboxAddonModule.cs b/src/Greenshot.Addon.Dropbox/DropboxAddonModule.cs new file mode 100644 index 000000000..b5d3951a0 --- /dev/null +++ b/src/Greenshot.Addon.Dropbox/DropboxAddonModule.cs @@ -0,0 +1,49 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Dropbox.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Dropbox +{ + /// + public class DropboxAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Dropbox/DropboxDestination.cs b/src/Greenshot.Addon.Dropbox/DropboxDestination.cs index 070d1f956..8e6c04b3d 100644 --- a/src/Greenshot.Addon.Dropbox/DropboxDestination.cs +++ b/src/Greenshot.Addon.Dropbox/DropboxDestination.cs @@ -25,22 +25,21 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.IO; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.HttpExtensions; using Dapplo.HttpExtensions.OAuth; using Dapplo.Log; using Dapplo.Utils; using Greenshot.Addon.Dropbox.Entities; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Extensions; @@ -61,17 +60,22 @@ namespace Greenshot.Addon.Dropbox private readonly IDropboxConfiguration _dropboxPluginConfiguration; private readonly IDropboxLanguage _dropboxLanguage; + private readonly IResourceProvider _resourceProvider; private OAuth2Settings _oAuth2Settings; private IHttpBehaviour _oAuthHttpBehaviour; - [ImportingConstructor] public DropboxDestination( IDropboxConfiguration dropboxPluginConfiguration, IDropboxLanguage dropboxLanguage, - INetworkConfiguration networkConfiguration) - { + INetworkConfiguration networkConfiguration, + IResourceProvider resourceProvider, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _dropboxPluginConfiguration = dropboxPluginConfiguration; _dropboxLanguage = dropboxLanguage; + _resourceProvider = resourceProvider; _oAuth2Settings = new OAuth2Settings { @@ -92,7 +96,7 @@ namespace Greenshot.Addon.Dropbox RedirectUrl = "http://localhost:47336", Token = dropboxPluginConfiguration }; - var httpBehaviour = OAuth2HttpBehaviourFactory.Create(_oAuth2Settings) as IChangeableHttpBehaviour; + var httpBehaviour = OAuth2HttpBehaviourFactory.Create(_oAuth2Settings); _oAuthHttpBehaviour = httpBehaviour; // Use the default network settings @@ -103,9 +107,8 @@ namespace Greenshot.Addon.Dropbox { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*Dropbox\.gif").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this by caching + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "Dropbox.gif")) { return BitmapHelper.FromStream(bitmapStream); } @@ -166,19 +169,20 @@ namespace Greenshot.Addon.Dropbox catch (Exception e) { Log.Error().WriteLine(e); - MessageBox.Show(_dropboxLanguage.UploadFailure + " " + e.Message); + MessageBox.Show(_dropboxLanguage.UploadFailure + @" " + e.Message); } return dropboxUrl; } /// - /// Upload the HttpContent to dropbox - /// - /// Name of the file - /// HttpContent - /// CancellationToken - /// Url as string - private async Task UploadAsync(string filename, HttpContent content, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken)) + /// Upload the HttpContent to dropbox + /// + /// Name of the file + /// HttpContent + /// IProgress + /// CancellationToken + /// Url as string + private async Task UploadAsync(string filename, HttpContent content, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken)) { var oAuthHttpBehaviour = _oAuthHttpBehaviour.ShallowClone(); // Use UploadProgress diff --git a/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj b/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj index bd02d333f..2b229e251 100644 --- a/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj +++ b/src/Greenshot.Addon.Dropbox/Greenshot.Addon.Dropbox.csproj @@ -37,6 +37,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -49,29 +58,29 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -82,14 +91,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -162,6 +171,7 @@ + @@ -219,7 +229,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.Dropbox/IDropboxConfiguration.cs b/src/Greenshot.Addon.Dropbox/IDropboxConfiguration.cs index 319691289..0281e2dc0 100644 --- a/src/Greenshot.Addon.Dropbox/IDropboxConfiguration.cs +++ b/src/Greenshot.Addon.Dropbox/IDropboxConfiguration.cs @@ -29,7 +29,6 @@ using Dapplo.HttpExtensions.OAuth; using Dapplo.Ini; using Dapplo.InterfaceImpl.Extensions; using Greenshot.Addons.Core; -using Greenshot.Addons.Core.Enums; #endregion diff --git a/src/Greenshot.Addon.Dropbox/ViewModels/DropboxConfigViewModel.cs b/src/Greenshot.Addon.Dropbox/ViewModels/DropboxConfigViewModel.cs index f0f871e3b..c8b239b2d 100644 --- a/src/Greenshot.Addon.Dropbox/ViewModels/DropboxConfigViewModel.cs +++ b/src/Greenshot.Addon.Dropbox/ViewModels/DropboxConfigViewModel.cs @@ -21,17 +21,14 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; -using Greenshot.Addons; using Greenshot.Addons.Core; using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.Dropbox.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class DropboxConfigViewModel : SimpleConfigScreen { /// @@ -39,15 +36,23 @@ namespace Greenshot.Addon.Dropbox.ViewModels /// private CompositeDisposable _disposables; - [Import] public IDropboxConfiguration DropboxConfiguration { get; set; } - [Import] public IDropboxLanguage DropboxLanguage { get; set; } - [Import] public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public DropboxConfigViewModel( + IDropboxConfiguration dropboxConfiguration, + IDropboxLanguage dropboxLanguage, + FileConfigPartViewModel fileConfigPartViewModel + ) + { + DropboxConfiguration = dropboxConfiguration; + DropboxLanguage = dropboxLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } + public override void Initialize(IConfig config) { FileConfigPartViewModel.DestinationFileConfiguration = DropboxConfiguration; diff --git a/src/Greenshot.Addon.Dropbox/app.config b/src/Greenshot.Addon.Dropbox/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Dropbox/app.config +++ b/src/Greenshot.Addon.Dropbox/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Dropbox/packages.config b/src/Greenshot.Addon.Dropbox/packages.config index b0d80b323..52052b2a6 100644 --- a/src/Greenshot.Addon.Dropbox/packages.config +++ b/src/Greenshot.Addon.Dropbox/packages.config @@ -1,22 +1,25 @@  + + + - - - - - - - - + + + + + + + + - + - + diff --git a/src/Greenshot.Addons/Interfaces/Plugin/IGreenshotHost.cs b/src/Greenshot.Addon.ExternalCommand/ExternalCommandAddonModule.cs similarity index 51% rename from src/Greenshot.Addons/Interfaces/Plugin/IGreenshotHost.cs rename to src/Greenshot.Addon.ExternalCommand/ExternalCommandAddonModule.cs index e55aa6486..c9c2900c8 100644 --- a/src/Greenshot.Addons/Interfaces/Plugin/IGreenshotHost.cs +++ b/src/Greenshot.Addon.ExternalCommand/ExternalCommandAddonModule.cs @@ -1,4 +1,4 @@ -#region Greenshot GNU General Public License +#region Greenshot GNU General Public License // Greenshot - a free and open source screenshot tool // Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom @@ -21,36 +21,31 @@ #endregion -#region Usings +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.ExternalCommand.ViewModels; +using Greenshot.Addons.Components; -using System.Windows.Forms; -using Dapplo.Windows.Dpi; - -#endregion - -namespace Greenshot.Addons.Interfaces.Plugin +namespace Greenshot.Addon.ExternalCommand { - /// - /// This interface is the GreenshotPluginHost, that which "Hosts" the plugin. - /// For Greenshot this is implmented in the PluginHelper - /// - public interface IGreenshotHost - { - ContextMenuStrip MainMenu { get; } + /// + public class ExternalCommandAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); - // This is a reference to the MainForm, can be used for Invoking on the UI thread. - Form GreenshotForm { get; } + base.Load(builder); + } - NotifyIcon NotifyIcon { get; } - - /// - /// The DPI handler for the context menu, which should be used for the plugins too - /// - DpiHandler ContextMenuDpiHandler { get; } - - /// - /// Initialize the form - /// - void Initialize(); - } -} \ No newline at end of file + } +} diff --git a/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs b/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs index d07bad34a..6d545fd21 100644 --- a/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs +++ b/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs @@ -32,7 +32,8 @@ using System.Text.RegularExpressions; using System.Threading; using Dapplo.Ini; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces.Plugin; @@ -41,10 +42,10 @@ using Greenshot.Addons.Interfaces.Plugin; namespace Greenshot.Addon.ExternalCommand { - /// - /// Description of OCRDestination. - /// - public class ExternalCommandDestination : AbstractDestination + /// + /// ExternalCommandDestination provides a destination to export to an external command + /// + public class ExternalCommandDestination : AbstractDestination { private static readonly LogSource Log = new LogSource(); @@ -54,8 +55,11 @@ namespace Greenshot.Addon.ExternalCommand private static readonly IExternalCommandConfiguration Config = IniConfig.Current.Get(); private readonly string _presetCommand; - public ExternalCommandDestination(string commando) - { + public ExternalCommandDestination(string commando, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _presetCommand = commando; } @@ -79,41 +83,43 @@ namespace Greenshot.Addon.ExternalCommand var outputSettings = new SurfaceOutputSettings(); outputSettings.PreventGreenshotFormat(); - if (_presetCommand != null) - { - if (!Config.RunInbackground.ContainsKey(_presetCommand)) - { - Config.RunInbackground.Add(_presetCommand, true); - } - var runInBackground = Config.RunInbackground[_presetCommand]; - var fullPath = captureDetails.Filename; - if (fullPath == null) - { - fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings); - } + if (_presetCommand == null) + { + return exportInformation; + } - if (runInBackground) - { - var commandThread = new Thread(() => - { - CallExternalCommand(exportInformation, fullPath, out _, out _); - ProcessExport(exportInformation, surface); - }) - { - Name = "Running " + _presetCommand, - IsBackground = true - }; - commandThread.SetApartmentState(ApartmentState.STA); - commandThread.Start(); - exportInformation.ExportMade = true; - } - else - { - CallExternalCommand(exportInformation, fullPath, out _, out _); - ProcessExport(exportInformation, surface); - } - } - return exportInformation; + if (!Config.RunInbackground.ContainsKey(_presetCommand)) + { + Config.RunInbackground.Add(_presetCommand, true); + } + var runInBackground = Config.RunInbackground[_presetCommand]; + var fullPath = captureDetails.Filename; + if (fullPath == null) + { + fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings); + } + + if (runInBackground) + { + var commandThread = new Thread(() => + { + CallExternalCommand(exportInformation, fullPath, out _, out _); + ProcessExport(exportInformation, surface); + }) + { + Name = "Running " + _presetCommand, + IsBackground = true + }; + commandThread.SetApartmentState(ApartmentState.STA); + commandThread.Start(); + exportInformation.ExportMade = true; + } + else + { + CallExternalCommand(exportInformation, fullPath, out _, out _); + ProcessExport(exportInformation, surface); + } + return exportInformation; } /// @@ -133,24 +139,29 @@ namespace Greenshot.Addon.ExternalCommand if (CallExternalCommand(_presetCommand, fullPath, out output, out error) == 0) { exportInformation.ExportMade = true; - if (!string.IsNullOrEmpty(output)) - { - var uriMatches = UriRegexp.Matches(output); - // Place output on the clipboard before the URI, so if one is found this overwrites - if (Config.OutputToClipboard) - { - ClipboardHelper.SetClipboardData(output); - } - if (uriMatches.Count > 0) - { - exportInformation.Uri = uriMatches[0].Groups[1].Value; - Log.Info().WriteLine("Got URI : {0} ", exportInformation.Uri); - if (Config.UriToClipboard) - { - ClipboardHelper.SetClipboardData(exportInformation.Uri); - } - } - } + if (string.IsNullOrEmpty(output)) + { + return; + } + + var uriMatches = UriRegexp.Matches(output); + // Place output on the clipboard before the URI, so if one is found this overwrites + if (Config.OutputToClipboard) + { + ClipboardHelper.SetClipboardData(output); + } + + if (uriMatches.Count <= 0) + { + return; + } + + exportInformation.Uri = uriMatches[0].Groups[1].Value; + Log.Info().WriteLine("Got URI : {0} ", exportInformation.Uri); + if (Config.UriToClipboard) + { + ClipboardHelper.SetClipboardData(exportInformation.Uri); + } } else { @@ -217,56 +228,57 @@ namespace Greenshot.Addon.ExternalCommand var arguments = Config.Argument[commando]; output = null; error = null; - if (!string.IsNullOrEmpty(commandline)) - { - using (var process = new Process()) - { - // Fix variables - commandline = FilenameHelper.FillVariables(commandline, true); - commandline = FilenameHelper.FillCmdVariables(commandline); + if (string.IsNullOrEmpty(commandline)) + { + return -1; + } - arguments = FilenameHelper.FillVariables(arguments, false); - arguments = FilenameHelper.FillCmdVariables(arguments, false); + using (var process = new Process()) + { + // Fix variables + commandline = FilenameHelper.FillVariables(commandline, true); + commandline = FilenameHelper.FillCmdVariables(commandline); - process.StartInfo.FileName = FilenameHelper.FillCmdVariables(commandline); - process.StartInfo.Arguments = FormatArguments(arguments, fullPath); - process.StartInfo.UseShellExecute = false; - if (Config.RedirectStandardOutput) - { - process.StartInfo.RedirectStandardOutput = true; - } - if (Config.RedirectStandardError) - { - process.StartInfo.RedirectStandardError = true; - } - if (verb != null) - { - process.StartInfo.Verb = verb; - } - Log.Info().WriteLine("Starting : {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); - process.Start(); - process.WaitForExit(); - if (Config.RedirectStandardOutput) - { - output = process.StandardOutput.ReadToEnd(); - if (Config.ShowStandardOutputInLog && output.Trim().Length > 0) - { - Log.Info().WriteLine("Output:\n{0}", output); - } - } - if (Config.RedirectStandardError) - { - error = process.StandardError.ReadToEnd(); - if (error.Trim().Length > 0) - { - Log.Warn().WriteLine("Error:\n{0}", error); - } - } - Log.Info().WriteLine("Finished : {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); - return process.ExitCode; - } - } - return -1; + arguments = FilenameHelper.FillVariables(arguments, false); + arguments = FilenameHelper.FillCmdVariables(arguments, false); + + process.StartInfo.FileName = FilenameHelper.FillCmdVariables(commandline); + process.StartInfo.Arguments = FormatArguments(arguments, fullPath); + process.StartInfo.UseShellExecute = false; + if (Config.RedirectStandardOutput) + { + process.StartInfo.RedirectStandardOutput = true; + } + if (Config.RedirectStandardError) + { + process.StartInfo.RedirectStandardError = true; + } + if (verb != null) + { + process.StartInfo.Verb = verb; + } + Log.Info().WriteLine("Starting : {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); + process.Start(); + process.WaitForExit(); + if (Config.RedirectStandardOutput) + { + output = process.StandardOutput.ReadToEnd(); + if (Config.ShowStandardOutputInLog && output.Trim().Length > 0) + { + Log.Info().WriteLine("Output:\n{0}", output); + } + } + if (Config.RedirectStandardError) + { + error = process.StandardError.ReadToEnd(); + if (error.Trim().Length > 0) + { + Log.Warn().WriteLine("Error:\n{0}", error); + } + } + Log.Info().WriteLine("Finished : {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); + return process.ExitCode; + } } public static string FormatArguments(string arguments, string fullpath) diff --git a/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestinationProvider.cs b/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestinationProvider.cs new file mode 100644 index 000000000..957d7ceb1 --- /dev/null +++ b/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestinationProvider.cs @@ -0,0 +1,113 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +#region Usings + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Dapplo.Addons; +using Dapplo.Log; +using Greenshot.Addons; +using Greenshot.Addons.Components; +using Greenshot.Addons.Core; + +#endregion + +namespace Greenshot.Addon.ExternalCommand +{ + /// + /// Generate the external command destinations + /// + public sealed class ExternalCommandDestinationProvider : IStartup, IDestinationProvider + { + private static readonly LogSource Log = new LogSource(); + private readonly IExternalCommandConfiguration _externalCommandConfig; + private readonly ICoreConfiguration _coreConfiguration; + private readonly IGreenshotLanguage _greenshotLanguage; + + public ExternalCommandDestinationProvider( + IExternalCommandConfiguration externalCommandConfiguration, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage) + { + _externalCommandConfig = externalCommandConfiguration; + _coreConfiguration = coreConfiguration; + _greenshotLanguage = greenshotLanguage; + + externalCommandConfiguration.AfterLoad(); + } + + public IEnumerable> Provide() + { + return _externalCommandConfig.Commands + .Select(command => new Lazy(() => new ExternalCommandDestination(command, _coreConfiguration, _greenshotLanguage), new DestinationAttribute(command))); + } + + + /// + /// Check and eventually fix the command settings + /// + /// + /// false if the command is not correctly configured + private bool IsCommandValid(string command) + { + if (!_externalCommandConfig.RunInbackground.ContainsKey(command)) + { + Log.Warn().WriteLine("Found missing runInbackground for {0}", command); + // Fix it + _externalCommandConfig.RunInbackground.Add(command, true); + } + if (!_externalCommandConfig.Argument.ContainsKey(command)) + { + Log.Warn().WriteLine("Found missing argument for {0}", command); + // Fix it + _externalCommandConfig.Argument.Add(command, "{0}"); + } + if (!_externalCommandConfig.Commandline.ContainsKey(command)) + { + Log.Warn().WriteLine("Found missing commandline for {0}", command); + return false; + } + var commandline = FilenameHelper.FillVariables(_externalCommandConfig.Commandline[command], true); + commandline = FilenameHelper.FillCmdVariables(commandline, true); + + if (File.Exists(commandline)) + { + return true; + } + Log.Warn().WriteLine("Found 'invalid' commandline {0} for command {1}", _externalCommandConfig.Commandline[command], command); + return false; + } + + public void Start() + { + // Check configuration & cleanup + foreach (var command in _externalCommandConfig.Commands.Where(command => !IsCommandValid(command)).ToList()) + { + _externalCommandConfig.Delete(command); + } + } + } +} \ No newline at end of file diff --git a/src/Greenshot.Addon.ExternalCommand/ExternalCommandPlugin.cs b/src/Greenshot.Addon.ExternalCommand/ExternalCommandPlugin.cs deleted file mode 100644 index fa1733dfd..000000000 --- a/src/Greenshot.Addon.ExternalCommand/ExternalCommandPlugin.cs +++ /dev/null @@ -1,185 +0,0 @@ -#region Greenshot GNU General Public License - -// Greenshot - a free and open source screenshot tool -// Copyright (C) 2007-2018 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 . - -#endregion - -#region Usings - -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.IO; -using System.Linq; -using System.Windows.Forms; -using Dapplo.Log; -using Greenshot.Addons.Addons; -using Greenshot.Addons.Core; -using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; -using Greenshot.Gfx; - -#endregion - -namespace Greenshot.Addon.ExternalCommand -{ - /// - /// An Plugin to run commands after an image was written - /// - [Export(typeof(IGreenshotPlugin))] - public sealed class ExternalCommandPlugin : IGreenshotPlugin - { - private static readonly LogSource Log = new LogSource(); - private readonly IExternalCommandConfiguration _externalCommandConfig; - private readonly IGreenshotHost _greenshotHost; - private ToolStripMenuItem _itemPlugInRoot; - - [ImportingConstructor] - public ExternalCommandPlugin(IGreenshotHost greenshotGreenshotHost, IExternalCommandConfiguration externalCommandConfiguration) - { - _greenshotHost = greenshotGreenshotHost; - _externalCommandConfig = externalCommandConfiguration; - } - - public void Dispose() - { - Dispose(true); - } - - public IEnumerable Destinations() - { - return _externalCommandConfig.Commands.Select(command => new ExternalCommandDestination(command)); - } - - public IEnumerable Processors() - { - yield break; - } - - /// - /// Implementation of the IGreenshotPlugin.Initialize - /// - public bool Initialize() - { - Log.Debug().WriteLine("Initialize called"); - - // Check configuration & cleanup - foreach (var command in _externalCommandConfig.Commands.Where(command => !IsCommandValid(command)).ToList()) - { - _externalCommandConfig.Delete(command); - } - - _itemPlugInRoot = new ToolStripMenuItem {Tag = _greenshotHost}; - _greenshotHost.ContextMenuDpiHandler.OnDpiChanged.Subscribe(OnIconSizeChanged); - OnLanguageChanged(this, null); - - PluginUtils.AddToContextMenu(_greenshotHost, _itemPlugInRoot); - Language.LanguageChanged += OnLanguageChanged; - return true; - } - - public void Shutdown() - { - Log.Debug().WriteLine("Shutdown"); - } - - private void Dispose(bool disposing) - { - if (disposing) - { - if (_itemPlugInRoot != null) - { - _itemPlugInRoot.Dispose(); - _itemPlugInRoot = null; - } - } - } - - /// - /// Check and eventually fix the command settings - /// - /// - /// false if the command is not correctly configured - private bool IsCommandValid(string command) - { - if (!_externalCommandConfig.RunInbackground.ContainsKey(command)) - { - Log.Warn().WriteLine("Found missing runInbackground for {0}", command); - // Fix it - _externalCommandConfig.RunInbackground.Add(command, true); - } - if (!_externalCommandConfig.Argument.ContainsKey(command)) - { - Log.Warn().WriteLine("Found missing argument for {0}", command); - // Fix it - _externalCommandConfig.Argument.Add(command, "{0}"); - } - if (!_externalCommandConfig.Commandline.ContainsKey(command)) - { - Log.Warn().WriteLine("Found missing commandline for {0}", command); - return false; - } - var commandline = FilenameHelper.FillVariables(_externalCommandConfig.Commandline[command], true); - commandline = FilenameHelper.FillCmdVariables(commandline, true); - - if (File.Exists(commandline)) - { - return true; - } - Log.Warn().WriteLine("Found 'invalid' commandline {0} for command {1}", _externalCommandConfig.Commandline[command], command); - return false; - } - - /// - /// Fix icon reference - /// - /// double with DPI - private void OnIconSizeChanged(double dpi) - { - try - { - var exePath = PluginUtils.GetExePath("cmd.exe"); - if (exePath == null || !File.Exists(exePath)) - { - return; - } - if (true.Equals(_itemPlugInRoot.Tag)) - { - _itemPlugInRoot.Image?.Dispose(); - } - var exeIcon = PluginUtils.GetCachedExeIcon(exePath, 0, dpi > 100); - _itemPlugInRoot.Image = exeIcon.ScaleIconForDisplaying(dpi); - _itemPlugInRoot.Tag = !Equals(exeIcon, _itemPlugInRoot.Image); - } - catch (Exception ex) - { - Log.Warn().WriteLine(ex, "Couldn't get the cmd.exe image"); - } - } - - private void OnLanguageChanged(object sender, EventArgs e) - { - if (_itemPlugInRoot != null) - { - _itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure"); - } - } - } -} \ No newline at end of file diff --git a/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj b/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj index c1ea99931..c0312191c 100644 --- a/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj +++ b/src/Greenshot.Addon.ExternalCommand/Greenshot.Addon.ExternalCommand.csproj @@ -37,6 +37,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -49,38 +58,38 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -151,9 +160,10 @@ Form - + + @@ -211,7 +221,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.ExternalCommand/SettingsFormDetail.cs b/src/Greenshot.Addon.ExternalCommand/SettingsFormDetail.cs index fbc13bda9..f3f31ef20 100644 --- a/src/Greenshot.Addon.ExternalCommand/SettingsFormDetail.cs +++ b/src/Greenshot.Addon.ExternalCommand/SettingsFormDetail.cs @@ -63,7 +63,7 @@ namespace Greenshot.Addon.ExternalCommand } else { - textBox_arguments.Text = "\"{0}\""; + textBox_arguments.Text = @"""{0}"""; } OkButtonState(); } diff --git a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs index b1973bd5f..7a24cd528 100644 --- a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs +++ b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -30,7 +29,6 @@ using Greenshot.Addons.Core; namespace Greenshot.Addon.ExternalCommand.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class ExternalCommandConfigViewModel : SimpleConfigScreen { /// @@ -38,14 +36,21 @@ namespace Greenshot.Addon.ExternalCommand.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IExternalCommandConfiguration ExternalCommandConfiguration { get; set; } + public IExternalCommandConfiguration ExternalCommandConfiguration { get; } - [Import] - public IExternalCommandLanguage ExternalCommandLanguage { get; set; } + public IExternalCommandLanguage ExternalCommandLanguage { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } + + public ExternalCommandConfigViewModel( + IExternalCommandConfiguration externalCommandConfiguration, + IExternalCommandLanguage externalCommandLanguage, + IGreenshotLanguage greenshotLanguage) + { + ExternalCommandConfiguration = externalCommandConfiguration; + ExternalCommandLanguage = externalCommandLanguage; + GreenshotLanguage = greenshotLanguage; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.ExternalCommand/app.config b/src/Greenshot.Addon.ExternalCommand/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.ExternalCommand/app.config +++ b/src/Greenshot.Addon.ExternalCommand/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.ExternalCommand/packages.config b/src/Greenshot.Addon.ExternalCommand/packages.config index 054a74387..adcd693f3 100644 --- a/src/Greenshot.Addon.ExternalCommand/packages.config +++ b/src/Greenshot.Addon.ExternalCommand/packages.config @@ -1,19 +1,22 @@  + + + - - - - - - - - - + + + + + + + + + - + diff --git a/src/Greenshot.Addon.Flickr/FlickrAddonModule.cs b/src/Greenshot.Addon.Flickr/FlickrAddonModule.cs new file mode 100644 index 000000000..686ac688a --- /dev/null +++ b/src/Greenshot.Addon.Flickr/FlickrAddonModule.cs @@ -0,0 +1,49 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Flickr.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Flickr +{ + /// + public class FlickrAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Flickr/FlickrDestination.cs b/src/Greenshot.Addon.Flickr/FlickrDestination.cs index 870a3213b..47f052dde 100644 --- a/src/Greenshot.Addon.Flickr/FlickrDestination.cs +++ b/src/Greenshot.Addon.Flickr/FlickrDestination.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.IO; using System.Linq; @@ -35,19 +34,18 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; -using Dapplo.Addons.Bootstrapper.Resolving; -using Dapplo.CaliburnMicro.Configuration; +using Dapplo.Addons; using Dapplo.HttpExtensions; using Dapplo.HttpExtensions.Extensions; using Dapplo.HttpExtensions.Listener; using Dapplo.HttpExtensions.OAuth; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Extensions; using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; using Greenshot.Gfx; #endregion @@ -61,6 +59,7 @@ namespace Greenshot.Addon.Flickr private static readonly Uri FlickrOAuthUri = new Uri("https://api.flickr.com/services/oauth"); private readonly IFlickrConfiguration _flickrConfiguration; private readonly IFlickrLanguage _flickrLanguage; + private readonly IResourceProvider _resourceProvider; private readonly OAuth1Settings _oAuthSettings; private readonly OAuth1HttpBehaviour _oAuthHttpBehaviour; private const string FlickrFarmUrl = "https://farm{0}.staticflickr.com/{1}/{2}_{3}.jpg"; @@ -75,14 +74,20 @@ namespace Greenshot.Addon.Flickr } }); - [ImportingConstructor] - public FlickrDestination(IFlickrConfiguration flickrConfiguration, - IFlickrLanguage flickrLanguage, INetworkConfiguration networkConfiguration) - { + public FlickrDestination( + IFlickrConfiguration flickrConfiguration, + IFlickrLanguage flickrLanguage, + INetworkConfiguration networkConfiguration, + IResourceProvider resourceProvider, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _flickrConfiguration = flickrConfiguration; _flickrLanguage = flickrLanguage; + _resourceProvider = resourceProvider; - _oAuthSettings = new OAuth1Settings + _oAuthSettings = new OAuth1Settings { Token = flickrConfiguration, ClientId = flickrConfiguration.ClientId, @@ -116,9 +121,8 @@ namespace Greenshot.Addon.Flickr { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*flickr\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this by caching + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "flickr.png")) { return BitmapHelper.FromStream(bitmapStream); } @@ -174,7 +178,7 @@ namespace Greenshot.Addon.Flickr catch (Exception e) { Log.Error().WriteLine(e, "Error uploading."); - MessageBox.Show(_flickrLanguage.UploadFailure + " " + e.Message); + MessageBox.Show(_flickrLanguage.UploadFailure + @" " + e.Message); } return uploadUrl; } diff --git a/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj b/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj index da48744a8..0d1714638 100644 --- a/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj +++ b/src/Greenshot.Addon.Flickr/Greenshot.Addon.Flickr.csproj @@ -37,6 +37,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -49,29 +58,29 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -79,14 +88,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -156,6 +165,7 @@ + @@ -208,7 +218,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.Flickr/IFlickrConfiguration.cs b/src/Greenshot.Addon.Flickr/IFlickrConfiguration.cs index 234b22be4..98f90de05 100644 --- a/src/Greenshot.Addon.Flickr/IFlickrConfiguration.cs +++ b/src/Greenshot.Addon.Flickr/IFlickrConfiguration.cs @@ -29,7 +29,6 @@ using Dapplo.HttpExtensions.OAuth; using Dapplo.Ini; using Dapplo.InterfaceImpl.Extensions; using Greenshot.Addons.Core; -using Greenshot.Addons.Core.Enums; #endregion diff --git a/src/Greenshot.Addon.Flickr/ViewModels/FlickrConfigViewModel.cs b/src/Greenshot.Addon.Flickr/ViewModels/FlickrConfigViewModel.cs index 69941ef10..0579c0d60 100644 --- a/src/Greenshot.Addon.Flickr/ViewModels/FlickrConfigViewModel.cs +++ b/src/Greenshot.Addon.Flickr/ViewModels/FlickrConfigViewModel.cs @@ -22,7 +22,6 @@ #endregion using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -32,7 +31,6 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.Flickr.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class FlickrConfigViewModel : SimpleConfigScreen { /// @@ -40,14 +38,21 @@ namespace Greenshot.Addon.Flickr.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IFlickrConfiguration FlickrConfiguration { get; set; } + public IFlickrConfiguration FlickrConfiguration { get; } + + public IFlickrLanguage FlickrLanguage { get; } + + public FileConfigPartViewModel FileConfigPartViewModel { get; } - [Import] - public IFlickrLanguage FlickrLanguage { get; set; } - - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public FlickrConfigViewModel( + IFlickrConfiguration flickrConfiguration, + IFlickrLanguage flickrLanguage, + FileConfigPartViewModel fileConfigPartViewModel) + { + FlickrConfiguration = flickrConfiguration; + FlickrLanguage = flickrLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.Flickr/app.config b/src/Greenshot.Addon.Flickr/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Flickr/app.config +++ b/src/Greenshot.Addon.Flickr/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Flickr/packages.config b/src/Greenshot.Addon.Flickr/packages.config index 0a24fa587..4a314dcfd 100644 --- a/src/Greenshot.Addon.Flickr/packages.config +++ b/src/Greenshot.Addon.Flickr/packages.config @@ -1,21 +1,24 @@  + + + - - - - - - - - + + + + + + + + - + - + diff --git a/src/Greenshot.Addon.GooglePhotos/GooglePhotosAddonModule.cs b/src/Greenshot.Addon.GooglePhotos/GooglePhotosAddonModule.cs new file mode 100644 index 000000000..22c9cf143 --- /dev/null +++ b/src/Greenshot.Addon.GooglePhotos/GooglePhotosAddonModule.cs @@ -0,0 +1,49 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.GooglePhotos.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.GooglePhotos +{ + /// + public class GooglePhotosAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs b/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs index f61205fdb..1b6c24027 100644 --- a/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs +++ b/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs @@ -25,21 +25,20 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.IO; -using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.HttpExtensions; using Dapplo.HttpExtensions.OAuth; using Dapplo.Log; using Dapplo.Utils; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Extensions; @@ -57,17 +56,22 @@ namespace Greenshot.Addon.GooglePhotos private readonly IGooglePhotosConfiguration _googlePhotosConfiguration; private readonly IGooglePhotosLanguage _googlePhotosLanguage; private readonly INetworkConfiguration _networkConfiguration; + private readonly IResourceProvider _resourceProvider; private readonly OAuth2Settings _oAuth2Settings; - [ImportingConstructor] public GooglePhotosDestination( IGooglePhotosConfiguration googlePhotosConfiguration, IGooglePhotosLanguage googlePhotosLanguage, - INetworkConfiguration networkConfiguration) - { + INetworkConfiguration networkConfiguration, + IResourceProvider resourceProvider, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _googlePhotosConfiguration = googlePhotosConfiguration; _googlePhotosLanguage = googlePhotosLanguage; _networkConfiguration = networkConfiguration; + _resourceProvider = resourceProvider; _oAuth2Settings = new OAuth2Settings { @@ -96,9 +100,8 @@ namespace Greenshot.Addon.GooglePhotos { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*GooglePhotos\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this by caching + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "GooglePhotos.png")) { return BitmapHelper.FromStream(bitmapStream); } diff --git a/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj b/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj index 5c9b1269e..2b7e10f05 100644 --- a/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj +++ b/src/Greenshot.Addon.GooglePhotos/Greenshot.Addon.GooglePhotos.csproj @@ -23,6 +23,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -35,29 +44,29 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -65,14 +74,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -143,6 +152,7 @@ + @@ -185,7 +195,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.GooglePhotos/IGooglePhotosConfiguration.cs b/src/Greenshot.Addon.GooglePhotos/IGooglePhotosConfiguration.cs index be0f19da9..6441957a9 100644 --- a/src/Greenshot.Addon.GooglePhotos/IGooglePhotosConfiguration.cs +++ b/src/Greenshot.Addon.GooglePhotos/IGooglePhotosConfiguration.cs @@ -27,7 +27,6 @@ using System.ComponentModel; using System.Runtime.Serialization; using Dapplo.HttpExtensions.OAuth; using Dapplo.Ini; -using Greenshot.Addons.Core.Enums; using Dapplo.InterfaceImpl.Extensions; using Greenshot.Addons.Core; diff --git a/src/Greenshot.Addon.GooglePhotos/ViewModels/GooglePhotosConfigViewModel.cs b/src/Greenshot.Addon.GooglePhotos/ViewModels/GooglePhotosConfigViewModel.cs index 61f233c52..642384ce7 100644 --- a/src/Greenshot.Addon.GooglePhotos/ViewModels/GooglePhotosConfigViewModel.cs +++ b/src/Greenshot.Addon.GooglePhotos/ViewModels/GooglePhotosConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -30,7 +29,6 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.GooglePhotos.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class GooglePhotosConfigViewModel : SimpleConfigScreen { /// @@ -38,14 +36,19 @@ namespace Greenshot.Addon.GooglePhotos.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IGooglePhotosConfiguration GooglePhotosConfiguration { get; set; } + public IGooglePhotosConfiguration GooglePhotosConfiguration { get; } + public IGooglePhotosLanguage GooglePhotosLanguage { get; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } - [Import] - public IGooglePhotosLanguage GooglePhotosLanguage { get; set; } - - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public GooglePhotosConfigViewModel( + IGooglePhotosConfiguration googlePhotosConfiguration, + IGooglePhotosLanguage googlePhotosLanguage, + FileConfigPartViewModel fileConfigPartViewModel) + { + GooglePhotosConfiguration = googlePhotosConfiguration; + GooglePhotosLanguage = googlePhotosLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.GooglePhotos/app.config b/src/Greenshot.Addon.GooglePhotos/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.GooglePhotos/app.config +++ b/src/Greenshot.Addon.GooglePhotos/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.GooglePhotos/packages.config b/src/Greenshot.Addon.GooglePhotos/packages.config index 0a24fa587..4a314dcfd 100644 --- a/src/Greenshot.Addon.GooglePhotos/packages.config +++ b/src/Greenshot.Addon.GooglePhotos/packages.config @@ -1,21 +1,24 @@  + + + - - - - - - - - + + + + + + + + - + - + diff --git a/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj b/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj index 67b6a3d2c..4eab84b37 100644 --- a/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj +++ b/src/Greenshot.Addon.Imgur/Greenshot.Addon.Imgur.csproj @@ -39,6 +39,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -54,29 +63,29 @@ ..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -87,14 +96,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -129,8 +138,8 @@ ..\packages\Dapplo.Windows.User32.0.5.56\lib\net45\Dapplo.Windows.User32.dll - - ..\packages\MahApps.Metro.1.6.1\lib\net45\MahApps.Metro.dll + + ..\packages\MahApps.Metro.1.6.4\lib\net45\MahApps.Metro.dll @@ -172,6 +181,7 @@ + @@ -221,7 +231,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.Imgur/IImgurConfiguration.cs b/src/Greenshot.Addon.Imgur/IImgurConfiguration.cs index bd3370ae4..15d021fb3 100644 --- a/src/Greenshot.Addon.Imgur/IImgurConfiguration.cs +++ b/src/Greenshot.Addon.Imgur/IImgurConfiguration.cs @@ -31,7 +31,6 @@ using Dapplo.Ini; using Dapplo.InterfaceImpl.Extensions; using Greenshot.Addon.Imgur.Entities; using Greenshot.Addons.Core; -using Greenshot.Addons.Core.Enums; #endregion diff --git a/src/Greenshot.Addon.Imgur/ImgurAddonModule.cs b/src/Greenshot.Addon.Imgur/ImgurAddonModule.cs new file mode 100644 index 000000000..e6fecc118 --- /dev/null +++ b/src/Greenshot.Addon.Imgur/ImgurAddonModule.cs @@ -0,0 +1,56 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Imgur.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Imgur +{ + /// + public class ImgurAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .AsSelf(); + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Imgur/ImgurApi.cs b/src/Greenshot.Addon.Imgur/ImgurApi.cs index 7c499a430..84527c6c4 100644 --- a/src/Greenshot.Addon.Imgur/ImgurApi.cs +++ b/src/Greenshot.Addon.Imgur/ImgurApi.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.IO; using System.Net; using System.Net.Http; @@ -50,7 +49,6 @@ namespace Greenshot.Addon.Imgur /// /// This contains the Imgur Api which is used by the destination and the history viewmodel /// - [Export] public class ImgurApi { private static readonly LogSource Log = new LogSource(); @@ -60,7 +58,6 @@ namespace Greenshot.Addon.Imgur private HttpBehaviour Behaviour { get; } - [ImportingConstructor] public ImgurApi( IImgurConfiguration imgurConfiguration, ICoreConfiguration coreConfiguration, diff --git a/src/Greenshot.Addon.Imgur/ImgurDestination.cs b/src/Greenshot.Addon.Imgur/ImgurDestination.cs index 779ed6ac9..a0a53faa9 100644 --- a/src/Greenshot.Addon.Imgur/ImgurDestination.cs +++ b/src/Greenshot.Addon.Imgur/ImgurDestination.cs @@ -24,18 +24,17 @@ #region Usings using System; -using System.ComponentModel.Composition; using System.Drawing; -using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.Log; using Dapplo.Windows.Extensions; using Greenshot.Addon.Imgur.Entities; using Greenshot.Addon.Imgur.ViewModels; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -49,7 +48,6 @@ namespace Greenshot.Addon.Imgur /// Description of ImgurDestination. /// [Destination("Imgur")] - [Export] public class ImgurDestination : AbstractDestination { private static readonly LogSource Log = new LogSource(); @@ -57,14 +55,22 @@ namespace Greenshot.Addon.Imgur private readonly IImgurLanguage _imgurLanguage; private readonly ImgurApi _imgurApi; private readonly ImgurHistoryViewModel _imgurHistoryViewModel; + private readonly IResourceProvider _resourceProvider; - [ImportingConstructor] - public ImgurDestination(IImgurConfiguration imgurConfiguration, IImgurLanguage imgurLanguage, ImgurApi imgurApi, ImgurHistoryViewModel imgurHistoryViewModel) + public ImgurDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + IImgurConfiguration imgurConfiguration, + IImgurLanguage imgurLanguage, + ImgurApi imgurApi, + ImgurHistoryViewModel imgurHistoryViewModel, + IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage) { _imgurConfiguration = imgurConfiguration; _imgurLanguage = imgurLanguage; _imgurApi = imgurApi; _imgurHistoryViewModel = imgurHistoryViewModel; + _resourceProvider = resourceProvider; } public override string Description => _imgurLanguage.UploadMenuItem; @@ -73,9 +79,8 @@ namespace Greenshot.Addon.Imgur { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*Imgur\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this, by caching + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "Imgur.png")) { return BitmapHelper.FromStream(bitmapStream); } diff --git a/src/Greenshot.Addon.Imgur/ViewModels/ImgurConfigViewModel.cs b/src/Greenshot.Addon.Imgur/ViewModels/ImgurConfigViewModel.cs index 928026dc1..9b4422481 100644 --- a/src/Greenshot.Addon.Imgur/ViewModels/ImgurConfigViewModel.cs +++ b/src/Greenshot.Addon.Imgur/ViewModels/ImgurConfigViewModel.cs @@ -21,18 +21,20 @@ #endregion -using System.ComponentModel.Composition; +using System; using System.Reactive.Disposables; +using Autofac.Features.OwnedInstances; using Caliburn.Micro; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; -using Greenshot.Addons; using Greenshot.Addons.Core; using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.Imgur.ViewModels { - [Export(typeof(IConfigScreen))] + /// + /// The imgure config VM + /// public sealed class ImgurConfigViewModel : SimpleConfigScreen { /// @@ -40,21 +42,30 @@ namespace Greenshot.Addon.Imgur.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IImgurConfiguration ImgurConfiguration { get; set; } + public IImgurConfiguration ImgurConfiguration { get; } - [Import] - public IImgurLanguage ImgurLanguage { get; set; } + public IImgurLanguage ImgurLanguage { get; } - [Import] - public IWindowManager WindowManager { get; set; } + public IWindowManager WindowManager { get; } - [Import] - public ImgurHistoryViewModel ImgurHistoryViewModel { get; set; } + public Func> ImgurHistoryViewModelFactory { get;} - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } + public ImgurConfigViewModel( + IImgurConfiguration imgurConfiguration, + IImgurLanguage imgurLanguage , + IWindowManager windowManager, + Func> imgurHistoryViewModelFactory, + FileConfigPartViewModel fileConfigPartViewModel + ) + { + ImgurConfiguration = imgurConfiguration; + ImgurLanguage = imgurLanguage; + WindowManager = windowManager; + ImgurHistoryViewModelFactory = imgurHistoryViewModelFactory; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { // Make sure the destination settings are shown @@ -86,7 +97,10 @@ namespace Greenshot.Addon.Imgur.ViewModels public void ShowHistory() { - WindowManager.ShowWindow(ImgurHistoryViewModel); + using (var imgurHistoryViewModel = ImgurHistoryViewModelFactory()) + { + WindowManager.ShowDialog(imgurHistoryViewModel.Value); + } } } } diff --git a/src/Greenshot.Addon.Imgur/ViewModels/ImgurHistoryViewModel.cs b/src/Greenshot.Addon.Imgur/ViewModels/ImgurHistoryViewModel.cs index f6bcc2998..7f95aa25a 100644 --- a/src/Greenshot.Addon.Imgur/ViewModels/ImgurHistoryViewModel.cs +++ b/src/Greenshot.Addon.Imgur/ViewModels/ImgurHistoryViewModel.cs @@ -23,7 +23,6 @@ using System; using System.Collections.ObjectModel; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Linq; using System.Reactive.Disposables; @@ -38,7 +37,6 @@ using Greenshot.Addons.Core; namespace Greenshot.Addon.Imgur.ViewModels { - [Export] public sealed class ImgurHistoryViewModel : Screen { private static readonly LogSource Log = new LogSource(); @@ -48,19 +46,26 @@ namespace Greenshot.Addon.Imgur.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IImgurConfiguration ImgurConfiguration { get; set; } + public IImgurConfiguration ImgurConfiguration { get; } + public ImgurApi ImgurApi { get; } - [Import] - public ImgurApi ImgurApi { get; set; } + public IImgurLanguage ImgurLanguage { get; } - [Import] - public IImgurLanguage ImgurLanguage { get; set; } - - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } + public ImgurHistoryViewModel( + IImgurConfiguration imgurConfiguration, + ImgurApi imgurApi, + IImgurLanguage imgurLanguage, + IGreenshotLanguage greenshotLanguage + ) + { + ImgurConfiguration = imgurConfiguration; + ImgurApi = imgurApi; + ImgurLanguage = imgurLanguage; + GreenshotLanguage = greenshotLanguage; + } /// /// The list of imgur items /// diff --git a/src/Greenshot.Addon.Imgur/app.config b/src/Greenshot.Addon.Imgur/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Imgur/app.config +++ b/src/Greenshot.Addon.Imgur/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Imgur/packages.config b/src/Greenshot.Addon.Imgur/packages.config index bc6660220..bfd889dc7 100644 --- a/src/Greenshot.Addon.Imgur/packages.config +++ b/src/Greenshot.Addon.Imgur/packages.config @@ -1,23 +1,26 @@  + + + - - - - - - - - + + + + + + + + - + - + @@ -29,7 +32,7 @@ - + diff --git a/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj b/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj index 50aa2335b..c8470eb5f 100644 --- a/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj +++ b/src/Greenshot.Addon.Jira/Greenshot.Addon.Jira.csproj @@ -39,6 +39,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -51,32 +60,32 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Costura.Fody.2.0.0\lib\net452\Costura.dll + + ..\packages\Costura.Fody.2.0.1\lib\net452\Costura.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -87,8 +96,8 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll @@ -96,8 +105,8 @@ ..\packages\Dapplo.Jira.0.7.10\lib\net45\Dapplo.Jira.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -177,6 +186,7 @@ + @@ -185,7 +195,6 @@ - @@ -205,9 +214,6 @@ - - JiraPlugin.cs - @@ -215,6 +221,10 @@ Greenshot.Addons False + + {f041c685-eb96-4ed1-9ace-0f5bd836610f} + Greenshot.Gfx + @@ -248,10 +258,9 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -"$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" del /q /s "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"\* -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" if "$(ConfigurationName)" == "Debug" ( copy "$(ProjectDir)bin\$(Configuration)\Dapplo.*" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" @@ -294,9 +303,9 @@ copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuratio This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + - + \ No newline at end of file diff --git a/src/Greenshot.Addon.Jira/JiraAddonModule.cs b/src/Greenshot.Addon.Jira/JiraAddonModule.cs new file mode 100644 index 000000000..1af741a92 --- /dev/null +++ b/src/Greenshot.Addon.Jira/JiraAddonModule.cs @@ -0,0 +1,63 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Jira.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Jira +{ + /// + public class JiraAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .AsSelf(); + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + builder + .RegisterType() + .As() + .As() + .AsSelf() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Jira/JiraConnector.cs b/src/Greenshot.Addon.Jira/JiraConnector.cs index a29ff1699..8a8ef7c91 100644 --- a/src/Greenshot.Addon.Jira/JiraConnector.cs +++ b/src/Greenshot.Addon.Jira/JiraConnector.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.IO; using System.Threading; @@ -50,7 +49,6 @@ namespace Greenshot.Addon.Jira /// /// This encapsulates the JiraClient to make it possible to change as less old Greenshot code as needed /// - [Export] public class JiraConnector : IDisposable { private static readonly LogSource Log = new LogSource(); @@ -64,7 +62,6 @@ namespace Greenshot.Addon.Jira private readonly IJiraClient _jiraClient; private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue; - [ImportingConstructor] public JiraConnector( IJiraConfiguration jiraConfiguration, JiraMonitor jiraMonitor, diff --git a/src/Greenshot.Addon.Jira/JiraDestination.cs b/src/Greenshot.Addon.Jira/JiraDestination.cs index 955783cba..7b9b5eb11 100644 --- a/src/Greenshot.Addon.Jira/JiraDestination.cs +++ b/src/Greenshot.Addon.Jira/JiraDestination.cs @@ -25,19 +25,22 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.Composition; using System.Drawing; +using System.IO.Compression; using System.Windows.Forms; +using Autofac.Features.OwnedInstances; using Caliburn.Micro; +using Dapplo.Addons; using Dapplo.HttpExtensions; using Dapplo.Jira.Entities; using Dapplo.Log; using Greenshot.Addon.Jira.ViewModels; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; +using Greenshot.Gfx; #endregion @@ -53,27 +56,42 @@ namespace Greenshot.Addon.Jira private readonly Issue _jiraIssue; private readonly JiraConnector _jiraConnector; private readonly IWindowManager _windowManager; - private readonly JiraViewModel _jiraViewModel; + private readonly Func> _jiraViewModelFactory; + private readonly IResourceProvider _resourceProvider; private readonly IJiraConfiguration _jiraConfiguration; private readonly IJiraLanguage _jiraLanguage; - [ImportingConstructor] - public JiraDestination(IJiraConfiguration jiraConfiguration, IJiraLanguage jiraLanguage, JiraConnector jiraConnector, IWindowManager windowManager, JiraViewModel jiraViewModel) + public JiraDestination( + IJiraConfiguration jiraConfiguration, + IJiraLanguage jiraLanguage, + JiraConnector jiraConnector, + Func> jiraViewModelFactory, + IWindowManager windowManager, + IResourceProvider resourceProvider, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) { _jiraConfiguration = jiraConfiguration; _jiraLanguage = jiraLanguage; _jiraConnector = jiraConnector; _windowManager = windowManager; - _jiraViewModel = jiraViewModel; + _jiraViewModelFactory = jiraViewModelFactory; + _resourceProvider = resourceProvider; } - public JiraDestination(IJiraConfiguration jiraConfiguration, IJiraLanguage jiraLanguage, JiraConnector jiraConnector, Issue jiraIssue, IWindowManager windowManager) + protected JiraDestination(IJiraConfiguration jiraConfiguration, + IJiraLanguage jiraLanguage, + JiraConnector jiraConnector, + Func> jiraViewModelFactory, + IWindowManager windowManager, + IResourceProvider resourceProvider, + Issue jiraIssue, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : this(jiraConfiguration, jiraLanguage, jiraConnector, jiraViewModelFactory, windowManager, resourceProvider, coreConfiguration, greenshotLanguage) { - _jiraConfiguration = jiraConfiguration; - _jiraLanguage = jiraLanguage; - _jiraConnector = jiraConnector; _jiraIssue = jiraIssue; - _windowManager = windowManager; } public override string Description @@ -119,8 +137,14 @@ namespace Greenshot.Addon.Jira } if (displayIcon == null) { - var resources = new ComponentResourceManager(typeof(JiraPlugin)); - displayIcon = (Bitmap) resources.GetObject("Jira"); + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "jira.svgz")) + { + using (var gzStream = new GZipStream(bitmapStream, CompressionMode.Decompress)) + { + displayIcon = SvgBitmap.FromStream(gzStream).Bitmap; + } + //displayIcon = BitmapHelper.FromStream(bitmapStream); + } } return displayIcon; } @@ -134,12 +158,10 @@ namespace Greenshot.Addon.Jira } foreach (var jiraDetails in _jiraConnector.RecentJiras) { - yield return new JiraDestination(_jiraConfiguration, _jiraLanguage, _jiraConnector, jiraDetails.JiraIssue, _windowManager) - { - CoreConfiguration = CoreConfiguration, - GreenshotLanguage = GreenshotLanguage - }; - } + yield return new JiraDestination( + _jiraConfiguration, _jiraLanguage, _jiraConnector, _jiraViewModelFactory, + _windowManager, _resourceProvider, jiraDetails.JiraIssue, CoreConfiguration, GreenshotLanguage); + } } protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) @@ -170,33 +192,36 @@ namespace Greenshot.Addon.Jira { // TODO: set filename // _jiraViewModel.SetFilename(filename); - if (_windowManager.ShowDialog(_jiraViewModel) == true) + using (var jiraViewModel = _jiraViewModelFactory()) { - try - { - surface.UploadUrl = _jiraConnector.JiraBaseUri.AppendSegments("browse", _jiraViewModel.JiraIssue.Key).AbsoluteUri; - // Run upload in the background - new PleaseWaitForm().ShowAndWait(Description, _jiraLanguage.CommunicationWait, - async () => - { - await _jiraConnector.AttachAsync(_jiraViewModel.JiraIssue.Key, surface, _jiraViewModel.Filename).ConfigureAwait(true); + if (_windowManager.ShowDialog(jiraViewModel.Value) == true) + { + try + { + surface.UploadUrl = _jiraConnector.JiraBaseUri.AppendSegments("browse", jiraViewModel.Value.JiraIssue.Key).AbsoluteUri; + // Run upload in the background + new PleaseWaitForm().ShowAndWait(Description, _jiraLanguage.CommunicationWait, + async () => + { + await _jiraConnector.AttachAsync(jiraViewModel.Value.JiraIssue.Key, surface, jiraViewModel.Value.Filename).ConfigureAwait(true); - if (!string.IsNullOrEmpty(_jiraViewModel.Comment)) - { - await _jiraConnector.AddCommentAsync(_jiraViewModel.JiraIssue.Key, _jiraViewModel.Comment).ConfigureAwait(true); - } - } - ); - Log.Debug().WriteLine("Uploaded to Jira {0}", _jiraViewModel.JiraIssue.Key); - exportInformation.ExportMade = true; - exportInformation.Uri = surface.UploadUrl; - } - catch (Exception e) - { - MessageBox.Show(_jiraLanguage.UploadFailure + " " + e.Message); - } - } - } + if (!string.IsNullOrEmpty(jiraViewModel.Value.Comment)) + { + await _jiraConnector.AddCommentAsync(jiraViewModel.Value.JiraIssue.Key, jiraViewModel.Value.Comment).ConfigureAwait(true); + } + } + ); + Log.Debug().WriteLine("Uploaded to Jira {0}", jiraViewModel.Value.JiraIssue.Key); + exportInformation.ExportMade = true; + exportInformation.Uri = surface.UploadUrl; + } + catch (Exception e) + { + MessageBox.Show(_jiraLanguage.UploadFailure + " " + e.Message); + } + } + } + } ProcessExport(exportInformation, surface); return exportInformation; } diff --git a/src/Greenshot.Addon.Jira/JiraMonitor.cs b/src/Greenshot.Addon.Jira/JiraMonitor.cs index 58a9ac5b7..fa24f9436 100644 --- a/src/Greenshot.Addon.Jira/JiraMonitor.cs +++ b/src/Greenshot.Addon.Jira/JiraMonitor.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Linq; using System.Reactive.Linq; using System.Text.RegularExpressions; @@ -46,8 +45,7 @@ namespace Greenshot.Addon.Jira /// It keeps a list of the last "accessed" jiras, and makes it easy to upload to one. /// Make sure this is instanciated on the UI thread! /// - [UiStartupAction, Export, UiShutdownAction] - public class JiraMonitor : IUiStartupAction, IUiShutdownAction + public class JiraMonitor : IUiStartup, IUiShutdown { private readonly IJiraConfiguration _jiraConfiguration; private static readonly LogSource Log = new LogSource(); @@ -58,7 +56,6 @@ namespace Greenshot.Addon.Jira // TODO: Add issues from issueHistory (JQL -> Where.IssueKey.InIssueHistory()) private IDictionary _recentJiras = new Dictionary(); - [ImportingConstructor] public JiraMonitor(IJiraConfiguration jiraConfiguration) { _jiraConfiguration = jiraConfiguration; diff --git a/src/Greenshot.Addon.Jira/JiraPlugin.cs b/src/Greenshot.Addon.Jira/JiraPlugin.cs deleted file mode 100644 index f0e53a367..000000000 --- a/src/Greenshot.Addon.Jira/JiraPlugin.cs +++ /dev/null @@ -1,114 +0,0 @@ -#region Greenshot GNU General Public License - -// Greenshot - a free and open source screenshot tool -// Copyright (C) 2007-2018 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 . - -#endregion - -#region Usings - -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.Threading.Tasks; -using Dapplo.Log; -using Dapplo.Windows.Dpi; -using Greenshot.Addons.Addons; -using Greenshot.Addons.Core; -using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; - -#endregion - -namespace Greenshot.Addon.Jira -{ - /// - /// This is the JiraPlugin base code - /// - [Export(typeof(IGreenshotPlugin))] - public sealed class JiraPlugin : IGreenshotPlugin - { - private static readonly LogSource Log = new LogSource(); - private readonly IGreenshotHost _greenshotHost; - private readonly ICoreConfiguration _coreConfiguration; - private readonly JiraConnector _jiraConnector; - - - [ImportingConstructor] - public JiraPlugin(IGreenshotHost greenshotHost, ICoreConfiguration coreConfiguration, JiraConnector jiraConnector) - { - _greenshotHost = greenshotHost; - _coreConfiguration = coreConfiguration; - _jiraConnector = jiraConnector; - Instance = this; - } - - public static JiraPlugin Instance { get; private set; } - - public void Dispose() - { - Dispose(true); - } - - public IEnumerable Destinations() - { - yield break; - } - - public IEnumerable Processors() - { - yield break; - } - - /// - /// Implementation of the IGreenshotPlugin.Initialize - /// - /// true if plugin is initialized, false if not (doesn't show) - public bool Initialize() - { - _greenshotHost.ContextMenuDpiHandler.OnDpiChanged.Subscribe(dpi => - { - var size = DpiHandler.ScaleWithDpi(_coreConfiguration.IconSize.Width, dpi); - - _jiraConnector.UpdateSvgSize(size); - }); - - return true; - } - - public void Shutdown() - { - Log.Debug().WriteLine("Jira Plugin shutdown."); - if (_jiraConnector != null) - { - Task.Run(async () => await _jiraConnector.LogoutAsync()); - } - } - - private void Dispose(bool disposing) - { - if (!disposing) - { - return; - } - - _jiraConnector?.Dispose(); - } - } -} \ No newline at end of file diff --git a/src/Greenshot.Addon.Jira/JiraPlugin.resx b/src/Greenshot.Addon.Jira/JiraPlugin.resx deleted file mode 100644 index d6a7cedd1..000000000 --- a/src/Greenshot.Addon.Jira/JiraPlugin.resx +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAXNJREFUOE9j+I8D - 3H/65r9GcN1/6+Su/99//MKl7D8DTAakqLh/9f/zNx6BhRZvPfFfwKEAjEGGgcD6/ef/dy/ahWIY3IDr - 95+DFVdP2wBW8Pnrj//ZnctQNPgXTfsv4VaCasD2o5eBir+DBUG243Pu6/ef/99+9BKs9vGLd/9PX33w - n0E1sPb/8Ut3cfoRl8Ts9Yf/h1fOgoQBzAXoii/feQK2CRuA6QEbAAocGc/y//H18/+///QVIxAPn78N - FgM5P7hsxn+dsIb/oDADAXgggpwECkRtoOTpq/fBCmGx0D5/+//lO06BAxCEYQaiGADiNM/ZCtfkktkP - Z/sUTIazV+85iz0aYaIZbUvgimEugNEgV6IDuBdgEr9///kfAQxddM0g12EDGAZAYuUHOBnDDAElIFwA - hwHfKTOgBJgn0L0wf9NR4rwASpUwzQ5pPXCXKPhU/gclZbyBCMoHBpHNYANEnIvAuXDzoYtwA0FJFx0A - AF/7VZm9H2iVAAAAAElFTkSuQmCC - - - \ No newline at end of file diff --git a/src/Greenshot.Addon.Jira/ViewModels/JiraConfigViewModel.cs b/src/Greenshot.Addon.Jira/ViewModels/JiraConfigViewModel.cs index 72881b1bc..a2c889c45 100644 --- a/src/Greenshot.Addon.Jira/ViewModels/JiraConfigViewModel.cs +++ b/src/Greenshot.Addon.Jira/ViewModels/JiraConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -30,7 +29,6 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.Jira.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class JiraConfigViewModel : SimpleConfigScreen { /// @@ -38,14 +36,22 @@ namespace Greenshot.Addon.Jira.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IJiraConfiguration JiraConfiguration { get; set; } + public IJiraConfiguration JiraConfiguration { get; } - [Import] - public IJiraLanguage JiraLanguage { get; set; } + public IJiraLanguage JiraLanguage { get; } - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } + + public JiraConfigViewModel( + IJiraConfiguration jiraConfiguration, + IJiraLanguage jiraLanguage, + FileConfigPartViewModel fileConfigPartViewModel + ) + { + JiraConfiguration = jiraConfiguration; + JiraLanguage = jiraLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.Jira/ViewModels/JiraViewModel.cs b/src/Greenshot.Addon.Jira/ViewModels/JiraViewModel.cs index 2522be36d..e82d146ef 100644 --- a/src/Greenshot.Addon.Jira/ViewModels/JiraViewModel.cs +++ b/src/Greenshot.Addon.Jira/ViewModels/JiraViewModel.cs @@ -23,7 +23,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Linq; using System.Reactive.Disposables; using System.Windows; @@ -33,22 +32,30 @@ using Dapplo.Jira.Entities; namespace Greenshot.Addon.Jira.ViewModels { - [Export] public sealed class JiraViewModel : Screen { /// /// Here all disposables are registered, so we can clean the up /// private CompositeDisposable _disposables; + + public IJiraConfiguration JiraConfiguration { get; } - [Import] - public IJiraConfiguration JiraConfiguration { get; set; } + public IJiraLanguage JiraLanguage { get; } - [Import] - public IJiraLanguage JiraLanguage { get; set; } + public JiraConnector JiraConnector { get; } - [Import] - public JiraConnector JiraConnector { get; set; } + + public JiraViewModel( + IJiraConfiguration jiraConfiguration, + IJiraLanguage jiraLanguage, + JiraConnector jiraConnector + ) + { + JiraConfiguration = jiraConfiguration; + JiraLanguage = jiraLanguage; + JiraConnector = jiraConnector; + } public IList Filters { get; private set; } diff --git a/src/Greenshot.Addon.Jira/app.config b/src/Greenshot.Addon.Jira/app.config index 1d1a733da..4e121d920 100644 --- a/src/Greenshot.Addon.Jira/app.config +++ b/src/Greenshot.Addon.Jira/app.config @@ -10,6 +10,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Jira/packages.config b/src/Greenshot.Addon.Jira/packages.config index 5121b709e..e68d85567 100644 --- a/src/Greenshot.Addon.Jira/packages.config +++ b/src/Greenshot.Addon.Jira/packages.config @@ -1,24 +1,27 @@  + + + - - - - - - - - - + + + + + + + + + - + - + diff --git a/src/Greenshot.Addon.LegacyEditor/Drawing/Surface.cs b/src/Greenshot.Addon.LegacyEditor/Drawing/Surface.cs index c46368620..b0ca849bc 100644 --- a/src/Greenshot.Addon.LegacyEditor/Drawing/Surface.cs +++ b/src/Greenshot.Addon.LegacyEditor/Drawing/Surface.cs @@ -26,7 +26,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.ComponentModel.Composition; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -54,7 +53,6 @@ namespace Greenshot.Addon.LegacyEditor.Drawing /// /// Description of Surface. /// - [Export(typeof(ISurface))] public sealed class Surface : Control, ISurface, INotifyPropertyChanged { private static readonly LogSource Log = new LogSource(); diff --git a/src/Greenshot.Addon.LegacyEditor/EditorAddonModule.cs b/src/Greenshot.Addon.LegacyEditor/EditorAddonModule.cs new file mode 100644 index 000000000..6e49d6ece --- /dev/null +++ b/src/Greenshot.Addon.LegacyEditor/EditorAddonModule.cs @@ -0,0 +1,71 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.LegacyEditor.Drawing; +using Greenshot.Addon.LegacyEditor.Forms; +using Greenshot.Addon.LegacyEditor.ViewModels; +using Greenshot.Addons.Components; +using Greenshot.Addons.Interfaces; + +namespace Greenshot.Addon.LegacyEditor +{ + /// + public class EditorAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + builder + .RegisterType() + .AsSelf(); + builder + .RegisterType() + .AsSelf(); + builder + .RegisterType() + .AsSelf(); + builder + .RegisterType() + .AsSelf(); + builder + .RegisterType() + .As(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs b/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs index f80a48aac..62cc664a2 100644 --- a/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs +++ b/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs @@ -25,11 +25,11 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.Linq; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces.Forms; @@ -44,24 +44,31 @@ namespace Greenshot.Addon.LegacyEditor [Destination("Editor", 1)] public class EditorDestination : AbstractDestination { + private readonly EditorFactory _editorFactory; private readonly IEditorLanguage _editorLanguage; private static readonly LogSource Log = new LogSource(); private static readonly Bitmap greenshotIcon = GreenshotResources.GetGreenshotIcon().ToBitmap(); private readonly IImageEditor _editor; - [Import(AllowRecomposition = true, AllowDefault = true)] - private EditorFactory _editorFactory; - /// /// Default constructor so we can initiate this from MEF /// - [ImportingConstructor] - public EditorDestination(IEditorLanguage editorLanguage) + public EditorDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + EditorFactory editorFactory, + IEditorLanguage editorLanguage) : base(coreConfiguration, greenshotLanguage) { + _editorFactory = editorFactory; _editorLanguage = editorLanguage; } - public EditorDestination(EditorFactory editorFactory, IEditorLanguage editorLanguage, IImageEditor editor) : this(editorLanguage) + public EditorDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + EditorFactory editorFactory, + IEditorLanguage editorLanguage, + IImageEditor editor) : this(coreConfiguration, greenshotLanguage, editorFactory, editorLanguage) { _editorFactory = editorFactory; _editor = editor; @@ -85,7 +92,7 @@ namespace Greenshot.Addon.LegacyEditor public override IEnumerable DynamicDestinations() { - return _editorFactory.Editors.Select(someEditor => new EditorDestination(_editorFactory, _editorLanguage, someEditor)); + return _editorFactory.Editors.Select(someEditor => new EditorDestination(CoreConfiguration, GreenshotLanguage, _editorFactory, _editorLanguage, someEditor)); } protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) diff --git a/src/Greenshot.Addon.LegacyEditor/EditorFactory.cs b/src/Greenshot.Addon.LegacyEditor/EditorFactory.cs index 67f82c7d1..ac9d8219c 100644 --- a/src/Greenshot.Addon.LegacyEditor/EditorFactory.cs +++ b/src/Greenshot.Addon.LegacyEditor/EditorFactory.cs @@ -21,10 +21,9 @@ #endregion +using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Linq; -using Dapplo.Log; using Greenshot.Addon.LegacyEditor.Forms; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -35,22 +34,19 @@ namespace Greenshot.Addon.LegacyEditor /// /// This provides a way to find and create the editors /// - [Export] public class EditorFactory { - private static readonly LogSource Log = new LogSource(); private readonly IEditorConfiguration _editorConfiguration; - private readonly ExportFactory _imageEditorExportFactory; + private readonly Func _imageEditorFactory; private readonly IList _editorList = new List(); - [ImportingConstructor] public EditorFactory( IEditorConfiguration editorConfiguration, - ExportFactory imageEditorExportFactory, - ExportFactory surfaceExportFactory) + Func imageEditorFactory, + Func surfaceExportFactory) { _editorConfiguration = editorConfiguration; - _imageEditorExportFactory = imageEditorExportFactory; + _imageEditorFactory = imageEditorFactory; // Factory for surface objects ImageOutput.SurfaceFactory = surfaceExportFactory; } @@ -88,8 +84,7 @@ namespace Greenshot.Addon.LegacyEditor } } - var editorExport = _imageEditorExportFactory.CreateExport(); - editorToReturn = editorExport.Value; + editorToReturn = _imageEditorFactory(); editorToReturn.Surface = surface; _editorList.Add(editorToReturn); if (!string.IsNullOrEmpty(captureDetails?.Filename)) diff --git a/src/Greenshot.Addon.LegacyEditor/Forms/ImageEditorForm.cs b/src/Greenshot.Addon.LegacyEditor/Forms/ImageEditorForm.cs index 7c3be10bd..af78ba510 100644 --- a/src/Greenshot.Addon.LegacyEditor/Forms/ImageEditorForm.cs +++ b/src/Greenshot.Addon.LegacyEditor/Forms/ImageEditorForm.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; @@ -33,6 +32,7 @@ using System.Linq; using System.Reactive.Disposables; using System.Threading.Tasks; using System.Windows.Forms; +using Autofac.Features.OwnedInstances; using Dapplo.Log; using Dapplo.Windows.Clipboard; using Dapplo.Windows.Common.Extensions; @@ -46,7 +46,7 @@ using Greenshot.Addon.LegacyEditor.Controls; using Greenshot.Addon.LegacyEditor.Drawing; using Greenshot.Addon.LegacyEditor.Drawing.Fields; using Greenshot.Addon.LegacyEditor.Drawing.Fields.Binding; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Extensions; @@ -63,16 +63,14 @@ namespace Greenshot.Addon.LegacyEditor.Forms /// /// Description of ImageEditorForm. /// - [Export] public partial class ImageEditorForm : BaseForm, IImageEditor { private static readonly LogSource Log = new LogSource(); private static readonly List IgnoreDestinations = new List { "Picker", "Editor"}; + private static readonly string[] SupportedClipboardFormats = { typeof(string).FullName, "Text", typeof(IDrawableContainerList).FullName }; private readonly IEditorConfiguration _editorConfiguration; private readonly IEditorLanguage _editorLanguage; - private static readonly string[] SupportedClipboardFormats = {typeof(string).FullName, "Text", typeof(IDrawableContainerList).FullName}; - // whether part of the editor controls are disabled depending on selected item(s) private bool _controlsDisabledDueToConfirmable; private bool _originalBoldCheckState; @@ -82,20 +80,29 @@ namespace Greenshot.Addon.LegacyEditor.Forms private BitmapScaleHandler _destinationScaleHandler; private readonly IDisposable _clipboardSubscription; private readonly EditorFactory _editorFactory; + private readonly DestinationHolder _destinationHolder; + private readonly Func> _resizeSettingsFormFactory; + private readonly Func> _tornEdgeSettingsFormFactory; + private readonly Func> _dropShadowSettingsFormFactory; private CompositeDisposable _disposables; - [ImportMany(AllowRecomposition = true)] - private IEnumerable> _destinations; - - [ImportingConstructor] public ImageEditorForm( IEditorConfiguration editorConfiguration, IEditorLanguage editorLanguage, - EditorFactory editorFactory) + EditorFactory editorFactory, + DestinationHolder destinationHolder, + Func> resizeSettingsFormFactory, + Func> tornEdgeSettingsFormFactory, + Func> dropShadowSettingsFormFactory + ) { _editorConfiguration = editorConfiguration; _editorLanguage = editorLanguage; _editorFactory = editorFactory; + _destinationHolder = destinationHolder; + _resizeSettingsFormFactory = resizeSettingsFormFactory; + _tornEdgeSettingsFormFactory = tornEdgeSettingsFormFactory; + _dropShadowSettingsFormFactory = dropShadowSettingsFormFactory; // // The InitializeComponent() call is required for Windows Forms designer support. // @@ -381,7 +388,7 @@ namespace Greenshot.Addon.LegacyEditor.Forms await Task.Run(() => { // Create export buttons - foreach (var destination in _destinations + foreach (var destination in _destinationHolder.AllDestinations .Where(destination => destination.Metadata.Priority > 2 && !IgnoreDestinations.Contains(destination.Metadata.Designation) && destination.Value.IsActive) .OrderBy(destination => destination.Metadata.Priority).ThenBy(destination => destination.Value.Description) .Select(d => d.Value)) @@ -522,7 +529,7 @@ namespace Greenshot.Addon.LegacyEditor.Forms ClearItems(fileStripMenuItem.DropDownItems); // Add the destinations - foreach (var destination in _destinations + foreach (var destination in _destinationHolder.AllDestinations .Where(destination => !IgnoreDestinations.Contains(destination.Metadata.Designation) && destination.Value.IsActive) .OrderBy(destination => destination.Metadata.Priority).ThenBy(destination => destination.Value.Description) .Select(d => d.Value)) @@ -1082,8 +1089,11 @@ namespace Greenshot.Addon.LegacyEditor.Forms apply = true; break; case MouseButtons.Right: - var result = new DropShadowSettingsForm(dropShadowEffect).ShowDialog(this); - apply = result == DialogResult.OK; + using (var dropShadowSettingsForm = _dropShadowSettingsFormFactory(dropShadowEffect)) + { + var result = dropShadowSettingsForm.Value.ShowDialog(this); + apply = result == DialogResult.OK; + } break; default: return; @@ -1100,16 +1110,19 @@ namespace Greenshot.Addon.LegacyEditor.Forms /// /// Open the resize settings from, and resize if ok was pressed /// - /// - /// + /// object + /// EventArgs private void BtnResizeClick(object sender, EventArgs e) { var resizeEffect = new ResizeEffect(_surface.Screenshot.Width, _surface.Screenshot.Height, true); - var result = new ResizeSettingsForm(resizeEffect).ShowDialog(this); - if (result == DialogResult.OK) + using (var resizeSettingsForm = _resizeSettingsFormFactory(resizeEffect)) { - _surface.ApplyBitmapEffect(resizeEffect); - UpdateUndoRedoSurfaceDependencies(); + var result = resizeSettingsForm.Value.ShowDialog(this); + if (result == DialogResult.OK) + { + _surface.ApplyBitmapEffect(resizeEffect); + UpdateUndoRedoSurfaceDependencies(); + } } } @@ -1128,8 +1141,11 @@ namespace Greenshot.Addon.LegacyEditor.Forms apply = true; break; case MouseButtons.Right: - var result = new TornEdgeSettingsForm(tornEdgeEffect).ShowDialog(this); - apply = result == DialogResult.OK; + using (var ownedForm = _tornEdgeSettingsFormFactory(tornEdgeEffect)) + { + var result = ownedForm.Value.ShowDialog(this); + apply = result == DialogResult.OK; + } break; default: return; @@ -1242,12 +1258,12 @@ namespace Greenshot.Addon.LegacyEditor.Forms { destinationDesignation = "FileDialog"; } - _destinations.Find(destinationDesignation)?.ExportCaptureAsync(true, _surface, _surface.CaptureDetails); + _destinationHolder.AllDestinations.Find(destinationDesignation)?.ExportCaptureAsync(true, _surface, _surface.CaptureDetails); } private void BtnClipboardClick(object sender, EventArgs e) { - _destinations.Find("Clipboard")?.ExportCaptureAsync(true, _surface, _surface.CaptureDetails); + _destinationHolder.AllDestinations.Find("Clipboard")?.ExportCaptureAsync(true, _surface, _surface.CaptureDetails); } private void BtnPrintClick(object sender, EventArgs e) @@ -1255,7 +1271,7 @@ namespace Greenshot.Addon.LegacyEditor.Forms // The BeginInvoke is a solution for the printdialog not having focus BeginInvoke((MethodInvoker) delegate { - _destinations.Find("Printer")?.ExportCaptureAsync(true, _surface, _surface.CaptureDetails); + _destinationHolder.AllDestinations.Find("Printer")?.ExportCaptureAsync(true, _surface, _surface.CaptureDetails); }); } @@ -1711,9 +1727,7 @@ namespace Greenshot.Addon.LegacyEditor.Forms // Go through the destinations to check the EditorShortcut Keys // this way the menu entries don't need to be enabled. // This also fixes bugs #3526974 & #3527020 - foreach (var destination in _destinations.Where(destination => destination.Value.IsActive) - .OrderBy(destination => destination.Metadata.Priority).ThenBy(destination => destination.Value.Description) - .Select(d => d.Value)) + foreach (var destination in _destinationHolder.SortedActiveDestinations) { if (destination.EditorShortcutKeys != keys) { diff --git a/src/Greenshot.Addon.LegacyEditor/Forms/ResizeSettingsForm.cs b/src/Greenshot.Addon.LegacyEditor/Forms/ResizeSettingsForm.cs index d536be4fa..a1a0d009c 100644 --- a/src/Greenshot.Addon.LegacyEditor/Forms/ResizeSettingsForm.cs +++ b/src/Greenshot.Addon.LegacyEditor/Forms/ResizeSettingsForm.cs @@ -28,7 +28,6 @@ using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using Greenshot.Addons.Controls; -using Greenshot.Addons.Core; using Greenshot.Gfx.Effects; #endregion @@ -41,15 +40,15 @@ namespace Greenshot.Addon.LegacyEditor.Forms public partial class ResizeSettingsForm : BaseForm { private readonly ResizeEffect _effect; - private readonly string _valuePercent; + private readonly string _valuePercent; private double _newWidth, _newHeight; - public ResizeSettingsForm(ResizeEffect effect) + public ResizeSettingsForm(ResizeEffect effect, IEditorLanguage editorLanguage) { _effect = effect; - InitializeComponent(); - var valuePixel = Language.GetString("editor_resize_pixel"); - _valuePercent = Language.GetString("editor_resize_percent"); + InitializeComponent(); + var valuePixel = editorLanguage.EditorResizePixel; + _valuePercent = editorLanguage.EditorResizePercent; combobox_width.Items.Add(valuePixel); combobox_width.Items.Add(_valuePercent); combobox_width.SelectedItem = valuePixel; diff --git a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj index e3144d636..1001ed1cc 100644 --- a/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj +++ b/src/Greenshot.Addon.LegacyEditor/Greenshot.Addon.LegacyEditor.csproj @@ -15,6 +15,15 @@ true + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -27,35 +36,38 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -205,6 +217,7 @@ + Form @@ -253,6 +266,7 @@ + @@ -270,10 +284,9 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -"$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" del /q /s "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"\* -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.LegacyEditor/ViewModels/EditorConfigViewModel.cs b/src/Greenshot.Addon.LegacyEditor/ViewModels/EditorConfigViewModel.cs index 07524b3df..4389c6ce5 100644 --- a/src/Greenshot.Addon.LegacyEditor/ViewModels/EditorConfigViewModel.cs +++ b/src/Greenshot.Addon.LegacyEditor/ViewModels/EditorConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -29,7 +28,6 @@ using Greenshot.Addons.Core; namespace Greenshot.Addon.LegacyEditor.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class EditorConfigViewModel : SimpleConfigScreen { /// @@ -37,11 +35,17 @@ namespace Greenshot.Addon.LegacyEditor.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IEditorConfiguration EditorConfiguration { get; set; } + public IEditorConfiguration EditorConfiguration { get; } - [Import] - public IEditorLanguage EditorLanguage { get; set; } + public IEditorLanguage EditorLanguage { get; } + + public EditorConfigViewModel( + IEditorConfiguration editorConfiguration, + IEditorLanguage editorLanguage) + { + EditorConfiguration = editorConfiguration; + EditorLanguage = editorLanguage; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.LegacyEditor/app.config b/src/Greenshot.Addon.LegacyEditor/app.config new file mode 100644 index 000000000..5ad3f61fd --- /dev/null +++ b/src/Greenshot.Addon.LegacyEditor/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.LegacyEditor/packages.config b/src/Greenshot.Addon.LegacyEditor/packages.config index afb1c45f7..b2cc34855 100644 --- a/src/Greenshot.Addon.LegacyEditor/packages.config +++ b/src/Greenshot.Addon.LegacyEditor/packages.config @@ -1,18 +1,22 @@  + + + - - - - - - - - + + + + + + + + + - + diff --git a/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj b/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj index 1a4e0689a..d45440a16 100644 --- a/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj +++ b/src/Greenshot.Addon.Lutim/Greenshot.Addon.Lutim.csproj @@ -37,6 +37,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -52,29 +61,29 @@ ..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -82,14 +91,14 @@ ..\packages\Dapplo.HttpExtensions.JsonNet.0.8.35\lib\net45\Dapplo.HttpExtensions.JsonNet.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -124,8 +133,8 @@ ..\packages\Dapplo.Windows.User32.0.5.56\lib\net45\Dapplo.Windows.User32.dll - - ..\packages\MahApps.Metro.1.6.1\lib\net45\MahApps.Metro.dll + + ..\packages\MahApps.Metro.1.6.4\lib\net45\MahApps.Metro.dll @@ -167,6 +176,7 @@ + @@ -232,9 +242,13 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" -copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" -mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" + +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" + +copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" + +mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" + copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" \ No newline at end of file diff --git a/src/Greenshot.Addon.Lutim/LutimAddonModule.cs b/src/Greenshot.Addon.Lutim/LutimAddonModule.cs new file mode 100644 index 000000000..ea605bbb1 --- /dev/null +++ b/src/Greenshot.Addon.Lutim/LutimAddonModule.cs @@ -0,0 +1,53 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Lutim.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Lutim +{ + /// + public class LutimAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Lutim/LutimApi.cs b/src/Greenshot.Addon.Lutim/LutimApi.cs index c26382ef7..e82c73746 100644 --- a/src/Greenshot.Addon.Lutim/LutimApi.cs +++ b/src/Greenshot.Addon.Lutim/LutimApi.cs @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Linq; using System.Net; using System.Threading; @@ -37,14 +36,12 @@ namespace Greenshot.Addon.Lutim /// /// A collection of Lutim API methods /// - [Export] public class LutimApi { private static readonly LogSource Log = new LogSource(); private readonly ILutimConfiguration _lutimConfiguration; private readonly ICoreConfiguration _coreConfiguration; - [ImportingConstructor] public LutimApi(ILutimConfiguration lutimConfiguration, ICoreConfiguration coreConfiguration) { _lutimConfiguration = lutimConfiguration; diff --git a/src/Greenshot.Addon.Lutim/LutimDestination.cs b/src/Greenshot.Addon.Lutim/LutimDestination.cs index b68d822d3..1b29a73fa 100644 --- a/src/Greenshot.Addon.Lutim/LutimDestination.cs +++ b/src/Greenshot.Addon.Lutim/LutimDestination.cs @@ -20,26 +20,23 @@ */ using System; -using System.ComponentModel.Composition; using System.Drawing; -using System.IO; -using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.Log; using Greenshot.Addon.Lutim.Entities; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; using Greenshot.Gfx; namespace Greenshot.Addon.Lutim { /// - /// Description of LutimDestination. + /// This is the destination for Lutim /// [Destination("Lutim")] public class LutimDestination : AbstractDestination @@ -48,22 +45,28 @@ namespace Greenshot.Addon.Lutim { private readonly ILutimConfiguration _lutimConfiguration; private readonly ILutimLanguage _lutimLanguage; private readonly LutimApi _lutimApi; + private readonly IResourceProvider _resourceProvider; - [ImportingConstructor] - public LutimDestination(ILutimConfiguration lutimConfiguration, ILutimLanguage lutimLanguage, LutimApi lutimApi) + public LutimDestination(ILutimConfiguration lutimConfiguration, + ILutimLanguage lutimLanguage, + LutimApi lutimApi, + IResourceProvider resourceProvider, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) { _lutimConfiguration = lutimConfiguration; _lutimLanguage = lutimLanguage; _lutimApi = lutimApi; + _resourceProvider = resourceProvider; } public override string Description => _lutimLanguage.UploadMenuItem; public override Bitmap DisplayIcon { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*Lutim\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this by caching + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "Lutim.png")) { return BitmapHelper.FromStream(bitmapStream); } diff --git a/src/Greenshot.Addon.Lutim/ViewModels/LutimConfigViewModel.cs b/src/Greenshot.Addon.Lutim/ViewModels/LutimConfigViewModel.cs index ee0810800..ccee61b60 100644 --- a/src/Greenshot.Addon.Lutim/ViewModels/LutimConfigViewModel.cs +++ b/src/Greenshot.Addon.Lutim/ViewModels/LutimConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -33,7 +32,6 @@ namespace Greenshot.Addon.Lutim.ViewModels /// /// The ViewModel for the Lutim configuration /// - [Export(typeof(IConfigScreen))] public sealed class LutimConfigViewModel : SimpleConfigScreen { /// @@ -41,14 +39,19 @@ namespace Greenshot.Addon.Lutim.ViewModels /// private CompositeDisposable _disposables; - [Import] - public ILutimConfiguration LutimConfiguration { get; set; } + public ILutimConfiguration LutimConfiguration { get; } + public ILutimLanguage LutimLanguage { get; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } - [Import] - public ILutimLanguage LutimLanguage { get; set; } - - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public LutimConfigViewModel( + ILutimConfiguration lutimConfiguration, + ILutimLanguage lutimLanguage, + FileConfigPartViewModel fileConfigPartViewModel) + { + LutimConfiguration = lutimConfiguration; + LutimLanguage = lutimLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.Lutim/ViewModels/LutimHistoryViewModel.cs b/src/Greenshot.Addon.Lutim/ViewModels/LutimHistoryViewModel.cs index 7314523cf..bfbc3ca85 100644 --- a/src/Greenshot.Addon.Lutim/ViewModels/LutimHistoryViewModel.cs +++ b/src/Greenshot.Addon.Lutim/ViewModels/LutimHistoryViewModel.cs @@ -23,7 +23,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Reactive.Disposables; using System.Threading; @@ -37,27 +36,31 @@ using Greenshot.Addons.Core; namespace Greenshot.Addon.Lutim.ViewModels { - [Export] public sealed class LutimHistoryViewModel : Screen { private static readonly LogSource Log = new LogSource(); + private readonly LutimApi _lutimApi; /// /// Here all disposables are registered, so we can clean the up /// private CompositeDisposable _disposables; - [Import] public ILutimConfiguration LutimConfiguration { get; set; } - - [Import] public ILutimLanguage LutimLanguage { get; set; } - - [Import] public IGreenshotLanguage GreenshotLanguage { get; set; } - [Import] - private LutimApi _lutimApi; + public LutimHistoryViewModel( + ILutimConfiguration lutimConfiguration, + ILutimLanguage lutimLanguage, + LutimApi lutimApi, + IGreenshotLanguage greenshotLanguage) + { + _lutimApi = lutimApi; + LutimConfiguration = lutimConfiguration; + LutimLanguage = lutimLanguage; + GreenshotLanguage = greenshotLanguage; + } /// /// The list of Lutim items /// diff --git a/src/Greenshot.Addon.Lutim/app.config b/src/Greenshot.Addon.Lutim/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Lutim/app.config +++ b/src/Greenshot.Addon.Lutim/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Lutim/packages.config b/src/Greenshot.Addon.Lutim/packages.config index d8d1c09f1..536926bf5 100644 --- a/src/Greenshot.Addon.Lutim/packages.config +++ b/src/Greenshot.Addon.Lutim/packages.config @@ -1,22 +1,25 @@  + + + - - - - - - - - + + + + + + + + - + - + @@ -28,7 +31,7 @@ - + diff --git a/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj b/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj index 917d50caa..2bbfe8b71 100644 --- a/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj +++ b/src/Greenshot.Addon.OCR/Greenshot.Addon.OCR.csproj @@ -37,6 +37,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -49,38 +58,38 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -151,7 +160,7 @@ Form - + Form @@ -187,7 +196,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.OCR/OCRDestination.cs b/src/Greenshot.Addon.OCR/OCRDestination.cs index 1d36ba3aa..9612a895e 100644 --- a/src/Greenshot.Addon.OCR/OCRDestination.cs +++ b/src/Greenshot.Addon.OCR/OCRDestination.cs @@ -24,14 +24,14 @@ #region Usings using System; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Drawing; using System.IO; using System.Reflection; using System.Windows.Forms; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Core.Enums; using Greenshot.Addons.Interfaces; @@ -54,8 +54,11 @@ namespace Greenshot.Addon.OCR private readonly IOCRConfiguration _ocrConfiguration; private readonly string _ocrCommand; - [ImportingConstructor] - public OcrDestination(IOCRConfiguration ocrConfiguration) + public OcrDestination( + IOCRConfiguration ocrConfiguration, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) { _ocrConfiguration = ocrConfiguration; diff --git a/src/Greenshot.Addon.OCR/OCRPlugin.cs b/src/Greenshot.Addon.OCR/OCRPlugin.cs deleted file mode 100644 index 27b26db53..000000000 --- a/src/Greenshot.Addon.OCR/OCRPlugin.cs +++ /dev/null @@ -1,125 +0,0 @@ -#region Greenshot GNU General Public License - -// Greenshot - a free and open source screenshot tool -// Copyright (C) 2007-2018 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 . - -#endregion - -#region Usings - -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.Windows.Forms; -using Dapplo.Log; -using Greenshot.Addons.Addons; -using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; - -#endregion - -namespace Greenshot.Addon.OCR -{ - /// - /// OCR Plugin Greenshot - /// - [Export(typeof(IGreenshotPlugin))] - public sealed class OcrPlugin : IGreenshotPlugin - { - private static readonly LogSource Log = new LogSource(); - private static IOCRConfiguration _ocrConfiguration; - private ToolStripMenuItem _ocrMenuItem = new ToolStripMenuItem(); - - [ImportingConstructor] - public OcrPlugin(IOCRConfiguration ocrConfiguration) - { - _ocrConfiguration = ocrConfiguration; - } - - public void Dispose() - { - Dispose(true); - } - - public IEnumerable Destinations() - { - yield break; - } - - public IEnumerable Processors() - { - yield break; - } - - /// - /// Implementation of the IGreenshotPlugin.Initialize - /// - /// true if plugin is initialized, false if not (doesn't show) - public bool Initialize() - { - Log.Debug().WriteLine("Initialize called"); - if (_ocrConfiguration.Language != null) - { - _ocrConfiguration.Language = _ocrConfiguration.Language.Replace("miLANG_", "").Replace("_", " "); - } - return true; - } - - /// - /// Implementation of the IGreenshotPlugin.Shutdown - /// - public void Shutdown() - { - Log.Debug().WriteLine("Shutdown"); - } - - /// - /// Implementation of the IPlugin.Configure - /// - public void Configure() - { - // TODO - if (false) //!HasModi()) - { - MessageBox.Show("Sorry, is seems that Microsoft Office Document Imaging (MODI) is not installed, therefor the OCR Plugin cannot work."); - return; - } - var settingsForm = new SettingsForm(Enum.GetNames(typeof(ModiLanguage)), _ocrConfiguration); - var result = settingsForm.ShowDialog(); - if (result == DialogResult.OK) - { - // "Re"set hotkeys - //IniConfig.Save(); - } - } - - private void Dispose(bool disposing) - { - if (disposing) - { - if (_ocrMenuItem != null) - { - _ocrMenuItem.Dispose(); - _ocrMenuItem = null; - } - } - } - - } -} \ No newline at end of file diff --git a/src/Greenshot.Addon.OCR/OcrAddonModule.cs b/src/Greenshot.Addon.OCR/OcrAddonModule.cs new file mode 100644 index 000000000..3b7907aec --- /dev/null +++ b/src/Greenshot.Addon.OCR/OcrAddonModule.cs @@ -0,0 +1,71 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using System.Diagnostics; +using System.IO; +using Autofac; +using Dapplo.Addons; +using Dapplo.Addons.Bootstrapper.Resolving; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.OCR +{ + /// + public class OcrAddonModule : AddonModule + { + private bool HasModi() + { + var ocrCommand = Path.Combine(FileTools.NormalizeDirectory("."), "greenshotocrcommand.exe"); + try + { + using (var process = Process.Start(ocrCommand, "-c")) + { + if (process != null) + { + process.WaitForExit(); + return process.ExitCode == 0; + } + } + } + catch + { + // ignored + } + + return false; + } + + /// + protected override void Load(ContainerBuilder builder) + { + if (HasModi()) + { + builder + .RegisterType() + .As() + .SingleInstance(); + } + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.OCR/app.config b/src/Greenshot.Addon.OCR/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.OCR/app.config +++ b/src/Greenshot.Addon.OCR/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.OCR/packages.config b/src/Greenshot.Addon.OCR/packages.config index 054a74387..adcd693f3 100644 --- a/src/Greenshot.Addon.OCR/packages.config +++ b/src/Greenshot.Addon.OCR/packages.config @@ -1,19 +1,22 @@  + + + - - - - - - - - - + + + + + + + + + - + diff --git a/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs b/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs index 9d600d30c..76bde07fa 100644 --- a/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs @@ -28,7 +28,8 @@ using System.Drawing; using System.IO; using System.Text.RegularExpressions; using Greenshot.Addon.Office.OfficeExport; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces.Plugin; @@ -40,7 +41,7 @@ namespace Greenshot.Addon.Office.Destinations /// /// Description of PowerpointDestination. /// - [Destination("Excel", 5)] + [Destination("Excel", DestinationOrder.Excel)] public class ExcelDestination : AbstractDestination { private const int IconApplication = 0; @@ -48,8 +49,11 @@ namespace Greenshot.Addon.Office.Destinations private readonly string _exePath; private readonly string _workbookName; - public ExcelDestination() - { + public ExcelDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _exePath = PluginUtils.GetExePath("EXCEL.EXE"); if (_exePath != null && !File.Exists(_exePath)) { @@ -57,8 +61,11 @@ namespace Greenshot.Addon.Office.Destinations } } - public ExcelDestination(string workbookName) : this() - { + protected ExcelDestination(string workbookName, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : this(coreConfiguration, greenshotLanguage) + { _workbookName = workbookName; } @@ -77,7 +84,7 @@ namespace Greenshot.Addon.Office.Destinations { foreach (var workbookName in ExcelExporter.GetWorkbooks()) { - yield return new ExcelDestination(workbookName); + yield return new ExcelDestination(workbookName, CoreConfiguration, GreenshotLanguage); } } diff --git a/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs b/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs index 0d56f33a5..34d88d93a 100644 --- a/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs @@ -32,7 +32,8 @@ using System.Runtime.InteropServices; using Dapplo.Log; using Greenshot.Addon.Office.OfficeExport; using Greenshot.Addon.Office.OfficeInterop; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -40,7 +41,7 @@ using Greenshot.Addons.Interfaces; namespace Greenshot.Addon.Office.Destinations { - [Destination("OneNote", 4)] + [Destination("OneNote", DestinationOrder.OneNote)] public class OneNoteDestination : AbstractDestination { private const int IconApplication = 0; @@ -48,8 +49,11 @@ namespace Greenshot.Addon.Office.Destinations private readonly string _exePath; private readonly OneNotePage _page; - public OneNoteDestination() - { + public OneNoteDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _exePath = PluginUtils.GetExePath("ONENOTE.EXE"); if (_exePath != null && !File.Exists(_exePath)) { @@ -57,7 +61,10 @@ namespace Greenshot.Addon.Office.Destinations } } - public OneNoteDestination(OneNotePage page) : this() + protected OneNoteDestination(OneNotePage page, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : this(coreConfiguration, greenshotLanguage) { _page = page; } @@ -87,7 +94,7 @@ namespace Greenshot.Addon.Office.Destinations { try { - return OneNoteExporter.GetPages().Where(currentPage => currentPage.IsCurrentlyViewed).Select(currentPage => new OneNoteDestination(currentPage)); + return OneNoteExporter.GetPages().Where(currentPage => currentPage.IsCurrentlyViewed).Select(currentPage => new OneNoteDestination(currentPage, CoreConfiguration, GreenshotLanguage)); } catch (COMException cEx) { diff --git a/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs b/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs index b78ae784f..727a1a37f 100644 --- a/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs @@ -28,11 +28,11 @@ using System.Drawing; using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; -using Dapplo.Ini; using Dapplo.Log; using Greenshot.Addon.Office.OfficeExport; using Greenshot.Addon.Office.OfficeInterop; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces.Plugin; @@ -44,24 +44,29 @@ namespace Greenshot.Addon.Office.Destinations /// /// Description of OutlookDestination. /// - [Destination("Outlook", 3)] + [Destination("Outlook", DestinationOrder.Outlook)] public class OutlookDestination : AbstractDestination { - private const int IconApplication = 0; + private const int IconApplication = 0; private const int IconMeeting = 2; private const string MapiClient = "Microsoft Outlook"; private static readonly LogSource Log = new LogSource(); + private readonly IOfficeConfiguration _officeConfiguration; private static readonly Bitmap MailIcon = GreenshotResources.GetBitmap("Email.Image"); - private static readonly IOfficeConfiguration OfficeConfig = IniConfig.Current.Get(); private readonly string _exePath; private readonly bool _isActiveFlag; private readonly string _outlookInspectorCaption; private readonly OlObjectClass _outlookInspectorType; - public OutlookDestination() - { - if (EmailConfigHelper.HasOutlook()) + public OutlookDestination( + IOfficeConfiguration officeConfiguration, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { + _officeConfiguration = officeConfiguration; + if (EmailConfigHelper.HasOutlook()) { _isActiveFlag = true; } @@ -76,7 +81,13 @@ namespace Greenshot.Addon.Office.Destinations } } - public OutlookDestination(string outlookInspectorCaption, OlObjectClass outlookInspectorType) : this() + protected OutlookDestination( + string outlookInspectorCaption, + OlObjectClass outlookInspectorType, + IOfficeConfiguration officeConfiguration, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : this(officeConfiguration, coreConfiguration, greenshotLanguage) { _outlookInspectorCaption = outlookInspectorCaption; _outlookInspectorType = outlookInspectorType; @@ -113,7 +124,7 @@ namespace Greenshot.Addon.Office.Destinations } foreach (var inspectorCaption in inspectorCaptions.Keys) { - yield return new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption]); + yield return new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption], _officeConfiguration, CoreConfiguration, GreenshotLanguage); } } @@ -166,11 +177,11 @@ namespace Greenshot.Addon.Office.Destinations { var destinations = new List { - new OutlookDestination() + new OutlookDestination(_officeConfiguration, CoreConfiguration, GreenshotLanguage) }; foreach (var inspectorCaption in inspectorCaptions.Keys) { - destinations.Add(new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption])); + destinations.Add(new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption], _officeConfiguration, CoreConfiguration, GreenshotLanguage)); } // Return the ExportInformation from the picker without processing, as this indirectly comes from us self return ShowPickerMenu(false, surface, captureDetails, destinations); @@ -178,9 +189,9 @@ namespace Greenshot.Addon.Office.Destinations } else { - exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(OfficeConfig.OutlookEmailFormat, tmpFile, - FilenameHelper.FillPattern(OfficeConfig.EmailSubjectPattern, captureDetails, false), attachmentName, OfficeConfig.EmailTo, OfficeConfig.EmailCC, - OfficeConfig.EmailBCC, null); + exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(_officeConfiguration.OutlookEmailFormat, tmpFile, + FilenameHelper.FillPattern(_officeConfiguration.EmailSubjectPattern, captureDetails, false), attachmentName, _officeConfiguration.EmailTo, _officeConfiguration.EmailCC, + _officeConfiguration.EmailBCC, null); } } ProcessExport(exportInformation, surface); diff --git a/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs b/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs index 1dcd5e61c..dec8391f9 100644 --- a/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs @@ -29,7 +29,8 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; using Greenshot.Addon.Office.OfficeExport; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces.Plugin; @@ -41,7 +42,7 @@ namespace Greenshot.Addon.Office.Destinations /// /// Description of PowerpointDestination. /// - [Destination("Powerpoint", 4)] + [Destination("Powerpoint", DestinationOrder.Powerpoint)] public class PowerpointDestination : AbstractDestination { private const int IconApplication = 0; @@ -51,8 +52,11 @@ namespace Greenshot.Addon.Office.Destinations private readonly string _presentationName; - public PowerpointDestination() - { + public PowerpointDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _exePath = PluginUtils.GetExePath("POWERPNT.EXE"); if (_exePath != null && !File.Exists(_exePath)) { @@ -60,7 +64,9 @@ namespace Greenshot.Addon.Office.Destinations } } - public PowerpointDestination(string presentationName) : this() + public PowerpointDestination(string presentationName, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage) : this(coreConfiguration, greenshotLanguage) { _presentationName = presentationName; } @@ -93,7 +99,7 @@ namespace Greenshot.Addon.Office.Destinations public override IEnumerable DynamicDestinations() { - return PowerpointExporter.GetPowerpointPresentations().Select(presentationName => new PowerpointDestination(presentationName)); + return PowerpointExporter.GetPowerpointPresentations().Select(presentationName => new PowerpointDestination(presentationName, CoreConfiguration, GreenshotLanguage)); } protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) @@ -117,10 +123,13 @@ namespace Greenshot.Addon.Office.Destinations var presentations = PowerpointExporter.GetPowerpointPresentations(); if (presentations != null && presentations.Count > 0) { - var destinations = new List {new PowerpointDestination()}; + var destinations = new List + { + new PowerpointDestination(CoreConfiguration, GreenshotLanguage) + }; foreach (var presentation in presentations) { - destinations.Add(new PowerpointDestination(presentation)); + destinations.Add(new PowerpointDestination(presentation, CoreConfiguration, GreenshotLanguage)); } // Return the ExportInformation from the picker without processing, as this indirectly comes from us self return ShowPickerMenu(false, surface, captureDetails, destinations); diff --git a/src/Greenshot.Addon.Office/Destinations/WordDestination.cs b/src/Greenshot.Addon.Office/Destinations/WordDestination.cs index c1efb31df..757561599 100644 --- a/src/Greenshot.Addon.Office/Destinations/WordDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/WordDestination.cs @@ -31,7 +31,8 @@ using System.Linq; using System.Text.RegularExpressions; using Dapplo.Log; using Greenshot.Addon.Office.OfficeExport; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces.Plugin; @@ -43,7 +44,7 @@ namespace Greenshot.Addon.Office.Destinations /// /// Description of EmailDestination. /// - [Destination("Word", 4)] + [Destination("Word", DestinationOrder.Word)] public class WordDestination : AbstractDestination { private const int IconApplication = 0; @@ -52,8 +53,11 @@ namespace Greenshot.Addon.Office.Destinations private readonly string _exePath; private readonly string _documentCaption; - public WordDestination() - { + public WordDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _exePath = PluginUtils.GetExePath("WINWORD.EXE"); if (_exePath != null && !File.Exists(_exePath)) { @@ -61,7 +65,9 @@ namespace Greenshot.Addon.Office.Destinations } } - public WordDestination(string wordCaption) : this() + protected WordDestination(string wordCaption, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage) : this(coreConfiguration, greenshotLanguage) { _documentCaption = wordCaption; } @@ -79,7 +85,7 @@ namespace Greenshot.Addon.Office.Destinations public override IEnumerable DynamicDestinations() { - return WordExporter.GetWordDocuments().Select(wordCaption => new WordDestination(wordCaption)); + return WordExporter.GetWordDocuments().Select(wordCaption => new WordDestination(wordCaption, CoreConfiguration, GreenshotLanguage)); } protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) @@ -121,11 +127,11 @@ namespace Greenshot.Addon.Office.Destinations { var destinations = new List { - new WordDestination() + new WordDestination(CoreConfiguration, GreenshotLanguage) }; foreach (var document in documents) { - destinations.Add(new WordDestination(document)); + destinations.Add(new WordDestination(document, CoreConfiguration, GreenshotLanguage)); } // Return the ExportInformation from the picker without processing, as this indirectly comes from us self return ShowPickerMenu(false, surface, captureDetails, destinations); diff --git a/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj b/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj index 55d5db604..2382a4191 100644 --- a/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj +++ b/src/Greenshot.Addon.Office/Greenshot.Addon.Office.csproj @@ -20,6 +20,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -32,41 +41,41 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Costura.Fody.2.0.0\lib\net452\Costura.dll + + ..\packages\Costura.Fody.2.0.1\lib\net452\Costura.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -202,6 +211,7 @@ + @@ -242,7 +252,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" @@ -251,9 +261,9 @@ copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuratio This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + - + \ No newline at end of file diff --git a/src/Greenshot.Addon.Office/OfficeAddonModule.cs b/src/Greenshot.Addon.Office/OfficeAddonModule.cs new file mode 100644 index 000000000..89efa7e56 --- /dev/null +++ b/src/Greenshot.Addon.Office/OfficeAddonModule.cs @@ -0,0 +1,70 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Office.Destinations; +using Greenshot.Addon.Office.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Office +{ + /// + public class OfficeAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + + builder + .RegisterType() + .As() + .SingleInstance(); + + builder + .RegisterType() + .As() + .SingleInstance(); + + builder + .RegisterType() + .As() + .SingleInstance(); + + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Office/ViewModels/OfficeConfigViewModel.cs b/src/Greenshot.Addon.Office/ViewModels/OfficeConfigViewModel.cs index e21e186f3..f278ee429 100644 --- a/src/Greenshot.Addon.Office/ViewModels/OfficeConfigViewModel.cs +++ b/src/Greenshot.Addon.Office/ViewModels/OfficeConfigViewModel.cs @@ -22,7 +22,6 @@ #endregion using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -33,7 +32,6 @@ using Greenshot.Addons.Extensions; namespace Greenshot.Addon.Office.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class OfficeConfigViewModel : SimpleConfigScreen { /// @@ -41,14 +39,19 @@ namespace Greenshot.Addon.Office.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IOfficeConfiguration OfficeConfiguration { get; set; } + public IOfficeConfiguration OfficeConfiguration { get; } + public IOfficeLanguage OfficeLanguage { get; } + public IGreenshotLanguage GreenshotLanguage { get; } - [Import] - public IOfficeLanguage OfficeLanguage { get; set; } - - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public OfficeConfigViewModel( + IOfficeConfiguration officeConfiguration, + IOfficeLanguage officeLanguage, + IGreenshotLanguage greenshotLanguage) + { + OfficeConfiguration = officeConfiguration; + OfficeLanguage = officeLanguage; + GreenshotLanguage = greenshotLanguage; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.Office/app.config b/src/Greenshot.Addon.Office/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Office/app.config +++ b/src/Greenshot.Addon.Office/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Office/packages.config b/src/Greenshot.Addon.Office/packages.config index 72514c8a4..27870aa6d 100644 --- a/src/Greenshot.Addon.Office/packages.config +++ b/src/Greenshot.Addon.Office/packages.config @@ -1,20 +1,23 @@  + + + - - - - - - - - - - + + + + + + + + + + - + diff --git a/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj b/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj index 9709ea0ca..a24cad2e5 100644 --- a/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj +++ b/src/Greenshot.Addon.OneDrive/Greenshot.Addon.OneDrive.csproj @@ -33,6 +33,15 @@ {5B924697-4DCD-4F98-85F1-105CB84B7341} Greenshot.Addons + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -48,29 +57,29 @@ ..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -81,14 +90,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -123,8 +132,8 @@ ..\packages\Dapplo.Windows.User32.0.5.56\lib\net45\Dapplo.Windows.User32.dll - - ..\packages\MahApps.Metro.1.6.1\lib\net45\MahApps.Metro.dll + + ..\packages\MahApps.Metro.1.6.4\lib\net45\MahApps.Metro.dll ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll @@ -141,9 +150,6 @@ ..\packages\System.Reactive.Linq.3.1.1\lib\net45\System.Reactive.Linq.dll True - - ..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll - @@ -158,6 +164,9 @@ + + ..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll + @@ -169,10 +178,12 @@ + + @@ -186,7 +197,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.OneDrive/IOneDriveConfiguration.cs b/src/Greenshot.Addon.OneDrive/IOneDriveConfiguration.cs index 68d32fb62..f1c133630 100644 --- a/src/Greenshot.Addon.OneDrive/IOneDriveConfiguration.cs +++ b/src/Greenshot.Addon.OneDrive/IOneDriveConfiguration.cs @@ -29,7 +29,6 @@ using Dapplo.HttpExtensions.OAuth; using Dapplo.Ini; using Dapplo.InterfaceImpl.Extensions; using Greenshot.Addons.Core; -using Greenshot.Addons.Core.Enums; #endregion diff --git a/src/Greenshot.Addon.OneDrive/OneDriveAddonModule.cs b/src/Greenshot.Addon.OneDrive/OneDriveAddonModule.cs new file mode 100644 index 000000000..b80313c12 --- /dev/null +++ b/src/Greenshot.Addon.OneDrive/OneDriveAddonModule.cs @@ -0,0 +1,49 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.OneDrive.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.OneDrive +{ + /// + public class OneDriveAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs b/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs index d4bd468b3..8f0cb0429 100644 --- a/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs +++ b/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs @@ -25,27 +25,25 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.IO; -using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.HttpExtensions; using Dapplo.HttpExtensions.JsonNet; using Dapplo.HttpExtensions.OAuth; using Dapplo.Log; using Dapplo.Utils; using Greenshot.Addon.OneDrive.Entities; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Extensions; using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; using Greenshot.Gfx; #endregion @@ -61,6 +59,7 @@ namespace Greenshot.Addon.OneDrive private static readonly LogSource Log = new LogSource(); private readonly IOneDriveConfiguration _oneDriveConfiguration; private readonly IOneDriveLanguage _oneDriveLanguage; + private readonly IResourceProvider _resourceProvider; private readonly OAuth2Settings _oauth2Settings; private static readonly Uri GraphUri = new Uri("https://graph.microsoft.com"); private static readonly Uri OneDriveUri = GraphUri.AppendSegments("v1.0", "me", "drive"); @@ -68,14 +67,18 @@ namespace Greenshot.Addon.OneDrive private readonly HttpBehaviour _oneDriveHttpBehaviour; - [ImportingConstructor] public OneDriveDestination( IOneDriveConfiguration oneDriveConfiguration, IOneDriveLanguage oneDriveLanguage, - INetworkConfiguration networkConfiguration) + INetworkConfiguration networkConfiguration, + IResourceProvider resourceProvider, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) { _oneDriveConfiguration = oneDriveConfiguration; _oneDriveLanguage = oneDriveLanguage; + _resourceProvider = resourceProvider; // Configure the OAuth2 settings for OneDrive communication _oauth2Settings = new OAuth2Settings { @@ -109,9 +112,8 @@ namespace Greenshot.Addon.OneDrive { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*onedrive\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this by caching + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "onedrive.png")) { return BitmapHelper.FromStream(bitmapStream); } diff --git a/src/Greenshot.Addon.OneDrive/ViewModels/OneDriveConfigViewModel.cs b/src/Greenshot.Addon.OneDrive/ViewModels/OneDriveConfigViewModel.cs index 9473cabda..104567024 100644 --- a/src/Greenshot.Addon.OneDrive/ViewModels/OneDriveConfigViewModel.cs +++ b/src/Greenshot.Addon.OneDrive/ViewModels/OneDriveConfigViewModel.cs @@ -21,9 +21,7 @@ #endregion -using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -35,7 +33,6 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.OneDrive.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class OneDriveConfigViewModel : SimpleConfigScreen { /// @@ -43,18 +40,23 @@ namespace Greenshot.Addon.OneDrive.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IOneDriveConfiguration OneDriveConfiguration { get; set; } - - [Import] - public IOneDriveLanguage OneDriveLanguage { get; set; } - - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } - - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public IOneDriveConfiguration OneDriveConfiguration { get; } + public IOneDriveLanguage OneDriveLanguage { get; } + public IGreenshotLanguage GreenshotLanguage { get; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } + public OneDriveConfigViewModel( + IOneDriveConfiguration oneDriveConfiguration, + IOneDriveLanguage oneDriveLanguage, + IGreenshotLanguage greenshotLanguage, + FileConfigPartViewModel fileConfigPartViewModel + ) + { + OneDriveConfiguration = oneDriveConfiguration; + OneDriveLanguage = oneDriveLanguage; + GreenshotLanguage = greenshotLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { FileConfigPartViewModel.DestinationFileConfiguration = OneDriveConfiguration; diff --git a/src/Greenshot.Addon.OneDrive/app.config b/src/Greenshot.Addon.OneDrive/app.config new file mode 100644 index 000000000..5ad3f61fd --- /dev/null +++ b/src/Greenshot.Addon.OneDrive/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.OneDrive/packages.config b/src/Greenshot.Addon.OneDrive/packages.config index b0d80b323..bfd889dc7 100644 --- a/src/Greenshot.Addon.OneDrive/packages.config +++ b/src/Greenshot.Addon.OneDrive/packages.config @@ -1,22 +1,26 @@  + + + - - - - - - - - + + + + + + + + + - + - + @@ -28,6 +32,7 @@ + diff --git a/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj b/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj index a4a5da7fc..6d80e800c 100644 --- a/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj +++ b/src/Greenshot.Addon.Photobucket/Greenshot.Addon.Photobucket.csproj @@ -37,6 +37,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -49,29 +58,29 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -79,14 +88,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -157,6 +166,7 @@ + @@ -216,7 +226,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.Photobucket/PhotobucketAddonModule.cs b/src/Greenshot.Addon.Photobucket/PhotobucketAddonModule.cs new file mode 100644 index 000000000..b0a4120b4 --- /dev/null +++ b/src/Greenshot.Addon.Photobucket/PhotobucketAddonModule.cs @@ -0,0 +1,49 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Photobucket.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Photobucket +{ + /// + public class PhotobucketAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs b/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs index bc2472b15..27107f9bd 100644 --- a/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs +++ b/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs @@ -25,21 +25,20 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.IO; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.HttpExtensions; using Dapplo.HttpExtensions.Extensions; using Dapplo.HttpExtensions.OAuth; using Dapplo.Log; using Dapplo.Utils; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Extensions; using Greenshot.Addons.Interfaces; @@ -61,24 +60,24 @@ namespace Greenshot.Addon.Photobucket private readonly IPhotobucketConfiguration _photobucketConfiguration; private readonly IPhotobucketLanguage _photobucketLanguage; private readonly INetworkConfiguration _networkConfiguration; + private readonly IResourceProvider _resourceProvider; private readonly OAuth1Settings _oAuthSettings; private readonly OAuth1HttpBehaviour _oAuthHttpBehaviour; private IList _albumsCache; - /// - /// Create a Photobucket destination - /// - /// IPhotobucketConfiguration - /// IPhotobucketLanguage - [ImportingConstructor] public PhotobucketDestination( IPhotobucketConfiguration photobucketConfiguration, IPhotobucketLanguage photobucketLanguage, - INetworkConfiguration networkConfiguration) - { + INetworkConfiguration networkConfiguration, + IResourceProvider resourceProvider, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { _photobucketConfiguration = photobucketConfiguration; _photobucketLanguage = photobucketLanguage; _networkConfiguration = networkConfiguration; + _resourceProvider = resourceProvider; _oAuthSettings = new OAuth1Settings { @@ -139,13 +138,14 @@ namespace Greenshot.Addon.Photobucket _oAuthHttpBehaviour = oAuthHttpBehaviour; } - /// - /// Create a Photobucket destination, which also has the path to the album in it - /// - /// IPhotobucketConfiguration - /// IPhotobucketLanguage - /// path to the album, null for default - public PhotobucketDestination(IPhotobucketConfiguration photobucketConfiguration, IPhotobucketLanguage photobucketLanguage, INetworkConfiguration networkConfiguration, string albumPath) : this (photobucketConfiguration, photobucketLanguage, networkConfiguration) + protected PhotobucketDestination( + IPhotobucketConfiguration photobucketConfiguration, + IPhotobucketLanguage photobucketLanguage, + INetworkConfiguration networkConfiguration, + IResourceProvider resourceProvider, + string albumPath, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage) : this(photobucketConfiguration, photobucketLanguage, networkConfiguration, resourceProvider, coreConfiguration, greenshotLanguage) { _photobucketConfiguration = photobucketConfiguration; _albumPath = albumPath; @@ -167,9 +167,8 @@ namespace Greenshot.Addon.Photobucket { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*photobucket-logo\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "photobucket-logo.png")) { return BitmapHelper.FromStream(bitmapStream); } @@ -198,7 +197,14 @@ namespace Greenshot.Addon.Photobucket } foreach (var album in albums) { - yield return new PhotobucketDestination(_photobucketConfiguration, _photobucketLanguage, _networkConfiguration, album); + yield return new PhotobucketDestination( + _photobucketConfiguration, + _photobucketLanguage, + _networkConfiguration, + _resourceProvider, + album, + CoreConfiguration, + GreenshotLanguage); } } diff --git a/src/Greenshot.Addon.Photobucket/ViewModels/PhotobucketConfigViewModel.cs b/src/Greenshot.Addon.Photobucket/ViewModels/PhotobucketConfigViewModel.cs index f4372f283..fc1aff8b0 100644 --- a/src/Greenshot.Addon.Photobucket/ViewModels/PhotobucketConfigViewModel.cs +++ b/src/Greenshot.Addon.Photobucket/ViewModels/PhotobucketConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -31,7 +30,6 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.Photobucket.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class PhotobucketConfigViewModel : SimpleConfigScreen { /// @@ -39,17 +37,22 @@ namespace Greenshot.Addon.Photobucket.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IPhotobucketConfiguration PhotobucketConfiguration { get; set; } + public IPhotobucketConfiguration PhotobucketConfiguration { get; } + public IPhotobucketLanguage PhotobucketLanguage { get; } + public IGreenshotLanguage GreenshotLanguage { get; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } - [Import] - public IPhotobucketLanguage PhotobucketLanguage { get; set; } - - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } - - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public PhotobucketConfigViewModel( + IPhotobucketConfiguration photobucketConfiguration, + IPhotobucketLanguage photobucketLanguage, + IGreenshotLanguage greenshotLanguage, + FileConfigPartViewModel fileConfigPartViewModel) + { + PhotobucketConfiguration = photobucketConfiguration; + PhotobucketLanguage = photobucketLanguage; + GreenshotLanguage = greenshotLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot.Addon.Photobucket/app.config b/src/Greenshot.Addon.Photobucket/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Photobucket/app.config +++ b/src/Greenshot.Addon.Photobucket/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Photobucket/packages.config b/src/Greenshot.Addon.Photobucket/packages.config index 0a24fa587..4a314dcfd 100644 --- a/src/Greenshot.Addon.Photobucket/packages.config +++ b/src/Greenshot.Addon.Photobucket/packages.config @@ -1,21 +1,24 @@  + + + - - - - - - - - + + + + + + + + - + - + diff --git a/src/Greenshot.Addon.Tfs/Entities/WorkItemFields.cs b/src/Greenshot.Addon.Tfs/Entities/WorkItemFields.cs index 74aedf0ce..d1a276658 100644 --- a/src/Greenshot.Addon.Tfs/Entities/WorkItemFields.cs +++ b/src/Greenshot.Addon.Tfs/Entities/WorkItemFields.cs @@ -21,7 +21,6 @@ #endregion -using System; using Newtonsoft.Json; namespace Greenshot.Addon.Tfs.Entities diff --git a/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj b/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj index 6dd618aeb..0ce8d107d 100644 --- a/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj +++ b/src/Greenshot.Addon.Tfs/Greenshot.Addon.Tfs.csproj @@ -33,6 +33,15 @@ {5B924697-4DCD-4F98-85F1-105CB84B7341} Greenshot.Addons + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -48,29 +57,29 @@ ..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -78,14 +87,14 @@ ..\packages\Dapplo.HttpExtensions.JsonNet.0.8.35\lib\net45\Dapplo.HttpExtensions.JsonNet.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -120,8 +129,8 @@ ..\packages\Dapplo.Windows.User32.0.5.56\lib\net45\Dapplo.Windows.User32.dll - - ..\packages\MahApps.Metro.1.6.1\lib\net45\MahApps.Metro.dll + + ..\packages\MahApps.Metro.1.6.4\lib\net45\MahApps.Metro.dll ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll @@ -138,9 +147,6 @@ ..\packages\System.Reactive.Linq.3.1.1\lib\net45\System.Reactive.Linq.dll True - - ..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll - @@ -155,6 +161,9 @@ + + ..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll + @@ -171,10 +180,12 @@ + + @@ -189,7 +200,7 @@ mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)" copy "$(ProjectDir)Languages\*.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" diff --git a/src/Greenshot.Addon.Tfs/TfsAddonModule.cs b/src/Greenshot.Addon.Tfs/TfsAddonModule.cs new file mode 100644 index 000000000..6bb11363f --- /dev/null +++ b/src/Greenshot.Addon.Tfs/TfsAddonModule.cs @@ -0,0 +1,53 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro.Configuration; +using Greenshot.Addon.Tfs.ViewModels; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Tfs +{ + /// + public class TfsAddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Tfs/TfsClient.cs b/src/Greenshot.Addon.Tfs/TfsClient.cs index c9dd12112..e3eefe209 100644 --- a/src/Greenshot.Addon.Tfs/TfsClient.cs +++ b/src/Greenshot.Addon.Tfs/TfsClient.cs @@ -23,7 +23,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.IO; using System.Linq; using System.Net.Http; @@ -43,14 +42,12 @@ namespace Greenshot.Addon.Tfs /// /// This capsulates the TFS api calls /// - [Export] public class TfsClient { private readonly ICoreConfiguration _coreConfiguration; private readonly ITfsConfiguration _tfsConfiguration; private readonly HttpBehaviour _tfsHttpBehaviour; - [ImportingConstructor] public TfsClient( ICoreConfiguration coreConfiguration, ITfsConfiguration tfsConfiguration, diff --git a/src/Greenshot.Addon.Tfs/TfsDestination.cs b/src/Greenshot.Addon.Tfs/TfsDestination.cs index 7f4dcd123..24639c3ee 100644 --- a/src/Greenshot.Addon.Tfs/TfsDestination.cs +++ b/src/Greenshot.Addon.Tfs/TfsDestination.cs @@ -25,16 +25,15 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; -using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using Dapplo.Addons.Bootstrapper.Resolving; +using Dapplo.Addons; using Dapplo.Log; using Greenshot.Addon.Tfs.Entities; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -54,27 +53,32 @@ namespace Greenshot.Addon.Tfs private readonly ITfsConfiguration _tfsConfiguration; private readonly ITfsLanguage _tfsLanguage; private readonly TfsClient _tfsClient; + private readonly IResourceProvider _resourceProvider; private readonly WorkItem _workItem; - [ImportingConstructor] public TfsDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, ITfsConfiguration tfsConfiguration, ITfsLanguage tfsLanguage, - TfsClient tfsClient) + TfsClient tfsClient, + IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage) { _tfsConfiguration = tfsConfiguration; _tfsLanguage = tfsLanguage; _tfsClient = tfsClient; + _resourceProvider = resourceProvider; } - public TfsDestination( + protected TfsDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, ITfsConfiguration tfsConfiguration, ITfsLanguage tfsLanguage, - TfsClient tfsClient, WorkItem workItem) + TfsClient tfsClient, + IResourceProvider resourceProvider, + WorkItem workItem) :this(coreConfiguration, greenshotLanguage, tfsConfiguration, tfsLanguage, tfsClient, resourceProvider) { - _tfsConfiguration = tfsConfiguration; - _tfsLanguage = tfsLanguage; - _tfsClient = tfsClient; _workItem = workItem; } @@ -104,11 +108,7 @@ namespace Greenshot.Addon.Tfs } foreach (var workitem in workitems) { - yield return new TfsDestination(_tfsConfiguration, _tfsLanguage, _tfsClient, workitem) - { - CoreConfiguration = CoreConfiguration, - GreenshotLanguage = GreenshotLanguage - }; + yield return new TfsDestination(CoreConfiguration, GreenshotLanguage, _tfsConfiguration, _tfsLanguage, _tfsClient, _resourceProvider, workitem); } } @@ -130,9 +130,8 @@ namespace Greenshot.Addon.Tfs { get { - // TODO: Optimize this - var embeddedResource = GetType().Assembly.FindEmbeddedResources(@".*vsts\.png").FirstOrDefault(); - using (var bitmapStream = GetType().Assembly.GetEmbeddedResourceAsStream(embeddedResource)) + // TODO: Optimize this by using a cache + using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType(), "vsts.png")) { return BitmapHelper.FromStream(bitmapStream); } diff --git a/src/Greenshot.Addon.Tfs/ViewModels/TfsConfigViewModel.cs b/src/Greenshot.Addon.Tfs/ViewModels/TfsConfigViewModel.cs index 01dc30ba7..e211eedf5 100644 --- a/src/Greenshot.Addon.Tfs/ViewModels/TfsConfigViewModel.cs +++ b/src/Greenshot.Addon.Tfs/ViewModels/TfsConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -31,29 +30,36 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Addon.Tfs.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class TfsConfigViewModel : SimpleConfigScreen { /// /// Here all disposables are registered, so we can clean the up /// private CompositeDisposable _disposables; + + public ITfsConfiguration TfsConfiguration { get; } + + public ITfsLanguage TfsLanguage { get; } + + public IGreenshotLanguage GreenshotLanguage { get; } + + public TfsClient TfsClient { get; } - [Import] - public ITfsConfiguration TfsConfiguration { get; set; } - - [Import] - public ITfsLanguage TfsLanguage { get; set; } - - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } - - [Import] - public TfsClient TfsClient { get; private set; } - - [Import] - public FileConfigPartViewModel FileConfigPartViewModel { get; private set; } + public FileConfigPartViewModel FileConfigPartViewModel { get; } + public TfsConfigViewModel( + ITfsConfiguration tfsConfiguration, + ITfsLanguage tfsLanguage, + IGreenshotLanguage greenshotLanguage, + TfsClient tfsClient, + FileConfigPartViewModel fileConfigPartViewModel) + { + TfsConfiguration = tfsConfiguration; + TfsLanguage = tfsLanguage; + GreenshotLanguage = greenshotLanguage; + TfsClient = tfsClient; + FileConfigPartViewModel = fileConfigPartViewModel; + } public override void Initialize(IConfig config) { FileConfigPartViewModel.DestinationFileConfiguration = TfsConfiguration; diff --git a/src/Greenshot.Addon.Tfs/Views/TfsConfigView.xaml b/src/Greenshot.Addon.Tfs/Views/TfsConfigView.xaml index c6f882101..8e53b7525 100644 --- a/src/Greenshot.Addon.Tfs/Views/TfsConfigView.xaml +++ b/src/Greenshot.Addon.Tfs/Views/TfsConfigView.xaml @@ -3,9 +3,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:viewModels="clr-namespace:Greenshot.Addon.Tfs.ViewModels" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:behaviours="http://metro.mahapps.com/winfx/xaml/shared" + xmlns:viewModels="clr-namespace:Greenshot.Addon.Tfs.ViewModels" mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:TfsConfigViewModel,IsDesignTimeCreatable=False}" > diff --git a/src/Greenshot.Addon.Tfs/app.config b/src/Greenshot.Addon.Tfs/app.config new file mode 100644 index 000000000..5ad3f61fd --- /dev/null +++ b/src/Greenshot.Addon.Tfs/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Tfs/packages.config b/src/Greenshot.Addon.Tfs/packages.config index 0eed6ac0d..536926bf5 100644 --- a/src/Greenshot.Addon.Tfs/packages.config +++ b/src/Greenshot.Addon.Tfs/packages.config @@ -1,21 +1,25 @@  + + + - - - - - - - - + + + + + + + + + - + - + @@ -27,6 +31,7 @@ + diff --git a/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj b/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj index 73247f751..ad1395812 100644 --- a/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj +++ b/src/Greenshot.Addon.Win10/Greenshot.Addon.Win10.csproj @@ -33,20 +33,47 @@ 4 + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + + + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll + + + ..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.dll + + + ..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll + ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll + + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll + + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -104,6 +131,10 @@ + + ..\packages\Caliburn.Micro.3.2.0\lib\net45\System.Windows.Interactivity.dll + + @@ -115,6 +146,7 @@ + @@ -142,6 +174,7 @@ + diff --git a/src/Greenshot.Addon.Win10/Win10AddonModule.cs b/src/Greenshot.Addon.Win10/Win10AddonModule.cs new file mode 100644 index 000000000..758221b45 --- /dev/null +++ b/src/Greenshot.Addon.Win10/Win10AddonModule.cs @@ -0,0 +1,48 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2016 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 Autofac; +using Dapplo.Addons; +using Dapplo.Windows.Common; +using Greenshot.Addons.Components; + +namespace Greenshot.Addon.Win10 +{ + /// + public class Win10AddonModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + if (!WindowsVersion.IsWindows10OrLater) + { + builder + .RegisterType() + .As() + .SingleInstance(); + builder + .RegisterType() + .As() + .SingleInstance(); + } + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addon.Win10/Win10OcrDestination.cs b/src/Greenshot.Addon.Win10/Win10OcrDestination.cs index c4a92fd78..2de393e5e 100644 --- a/src/Greenshot.Addon.Win10/Win10OcrDestination.cs +++ b/src/Greenshot.Addon.Win10/Win10OcrDestination.cs @@ -26,7 +26,8 @@ using System.Threading.Tasks; using Windows.Graphics.Imaging; using Windows.Media.Ocr; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces.Plugin; @@ -51,8 +52,11 @@ namespace Greenshot.Addon.Win10 /// /// Constructor, this is only debug information /// - public Win10OcrDestination() - { + public Win10OcrDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { var languages = OcrEngine.AvailableRecognizerLanguages; foreach (var language in languages) { diff --git a/src/Greenshot.Addon.Win10/Win10ShareDestination.cs b/src/Greenshot.Addon.Win10/Win10ShareDestination.cs index 102ea56fe..4a53c81c4 100644 --- a/src/Greenshot.Addon.Win10/Win10ShareDestination.cs +++ b/src/Greenshot.Addon.Win10/Win10ShareDestination.cs @@ -33,7 +33,8 @@ using Windows.Storage.Streams; using Dapplo.Log; using Dapplo.Windows.Messages; using Greenshot.Addon.Win10.Native; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Core.Enums; using Greenshot.Addons.Interfaces; @@ -51,7 +52,13 @@ namespace Greenshot.Addon.Win10 { private static readonly LogSource Log = new LogSource(); - public override string Description { get; } = "Windows 10 share"; + public Win10ShareDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage) : base(coreConfiguration, greenshotLanguage) + { + } + + public override string Description { get; } = "Windows 10 share"; /// /// Icon for the App-share, the icon was found via: http://help4windows.com/windows_8_shell32_dll.shtml diff --git a/src/Greenshot.Addon.Win10/app.config b/src/Greenshot.Addon.Win10/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addon.Win10/app.config +++ b/src/Greenshot.Addon.Win10/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addon.Win10/packages.config b/src/Greenshot.Addon.Win10/packages.config index 21440f4f1..eb0650aeb 100644 --- a/src/Greenshot.Addon.Win10/packages.config +++ b/src/Greenshot.Addon.Win10/packages.config @@ -1,10 +1,18 @@  + + + + + - - + + + + + - + diff --git a/src/Greenshot.Addons/AddonsModule.cs b/src/Greenshot.Addons/AddonsModule.cs new file mode 100644 index 000000000..4f2653def --- /dev/null +++ b/src/Greenshot.Addons/AddonsModule.cs @@ -0,0 +1,46 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Greenshot.Addons.Components; +using Greenshot.Addons.ViewModels; + +namespace Greenshot.Addons +{ + /// + public class AddonsModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .AsSelf(); + builder + .RegisterType() + .AsSelf(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot.Addons/Addons/DestinationAttribute.cs b/src/Greenshot.Addons/Components/DestinationAttribute.cs similarity index 79% rename from src/Greenshot.Addons/Addons/DestinationAttribute.cs rename to src/Greenshot.Addons/Components/DestinationAttribute.cs index d3565cd04..3fa4cc99c 100644 --- a/src/Greenshot.Addons/Addons/DestinationAttribute.cs +++ b/src/Greenshot.Addons/Components/DestinationAttribute.cs @@ -23,41 +23,42 @@ using System; using System.ComponentModel.Composition; -using Dapplo.Addons; -namespace Greenshot.Addons.Addons +namespace Greenshot.Addons.Components { [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, Inherited = false)] - public class DestinationAttribute : ModuleAttribute, IDestinationMetadata + public class DestinationAttribute : Attribute { - /// - /// Default constructor - /// - public DestinationAttribute() : base(typeof(IDestination)) + public DestinationAttribute() { - } - /// - /// Use a specific contract name for the Destination - /// - /// string - public DestinationAttribute(string designation) : base(typeof(IDestination)) - { - Designation = designation; } - /// /// Use a specific contract name for the Destination /// /// string /// int - public DestinationAttribute(string designation, int priority) : base(typeof(IDestination)) + public DestinationAttribute(string designation, int priority) { Designation = designation; Priority = priority; } + /// + /// Use a specific contract name for the Destination + /// + /// string + /// object + public DestinationAttribute(string designation, object priority = null) + { + Designation = designation; + if (priority != null) + { + Priority = Convert.ToInt32(priority); + } + } + public string Designation { get; set; } public int Priority { get; set; } = 10; } diff --git a/src/Greenshot.Addons/Components/DestinationHolder.cs b/src/Greenshot.Addons/Components/DestinationHolder.cs new file mode 100644 index 000000000..6ef4d0ddf --- /dev/null +++ b/src/Greenshot.Addons/Components/DestinationHolder.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Greenshot.Addons.Components +{ + /// + /// This holds the destinations, so other components can easily retrieve them + /// + public class DestinationHolder + { + private readonly IEnumerable> _destinations; + private readonly IEnumerable _destinationProviders; + + public DestinationHolder( + IEnumerable> destinations, + IEnumerable destinationProviders + ) + { + _destinations = destinations; + _destinationProviders = destinationProviders; + } + + /// + /// Return an IEnumerable with sorted IDestination entries + /// + public IEnumerable SortedActiveDestinations => _destinationProviders + .SelectMany(provider => provider.Provide()) + .Concat(_destinations) + .Where(destination => destination.Value.IsActive) + .OrderBy(destination => destination.Metadata.Priority) + .ThenBy(destination => destination.Value.Description) + .Select(d => d.Value); + + /// + /// Return an IEnumerable with all destinations + /// + public IEnumerable> AllDestinations => _destinationProviders + .SelectMany(provider => provider.Provide()) + .Concat(_destinations); + } +} diff --git a/src/Greenshot.Addons/Components/DestinationOrder.cs b/src/Greenshot.Addons/Components/DestinationOrder.cs new file mode 100644 index 000000000..795b10469 --- /dev/null +++ b/src/Greenshot.Addons/Components/DestinationOrder.cs @@ -0,0 +1,41 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +namespace Greenshot.Addons.Components +{ + public enum DestinationOrder + { + FileNoDialog = 0, + FileDialog = 0, + Picker = 1, + Printer = 2, + Clipboard = 2, + Email = 3, + Outlook = 3, + Word = 4, + Powerpoint = 4, + OneNote = 4, + Excel = 5, + + } +} diff --git a/src/Greenshot.Addons/Addons/IDestination.cs b/src/Greenshot.Addons/Components/IDestination.cs similarity index 96% rename from src/Greenshot.Addons/Addons/IDestination.cs rename to src/Greenshot.Addons/Components/IDestination.cs index 88754abb0..ba1d303c1 100644 --- a/src/Greenshot.Addons/Addons/IDestination.cs +++ b/src/Greenshot.Addons/Components/IDestination.cs @@ -34,7 +34,7 @@ using Greenshot.Addons.Interfaces; #endregion -namespace Greenshot.Addons.Addons +namespace Greenshot.Addons.Components { /// /// Description of IDestination. diff --git a/src/Greenshot.Addons/Addons/IDestinationMetaData.cs b/src/Greenshot.Addons/Components/IDestinationProvider.cs similarity index 64% rename from src/Greenshot.Addons/Addons/IDestinationMetaData.cs rename to src/Greenshot.Addons/Components/IDestinationProvider.cs index 58b12265a..4e2e3929d 100644 --- a/src/Greenshot.Addons/Addons/IDestinationMetaData.cs +++ b/src/Greenshot.Addons/Components/IDestinationProvider.cs @@ -21,29 +21,16 @@ #endregion -#region Usings +using System; +using System.Collections.Generic; -using System.ComponentModel; - -#endregion - -namespace Greenshot.Addons.Addons +namespace Greenshot.Addons.Components { - /// - /// Metadata for the IDestination exports - /// - public interface IDestinationMetadata - { - /// - /// Simple "designation" like "File", "Editor" etc, used to store the configuration - /// - string Designation { get; } - - /// - /// Priority, used for sorting - /// - /// - [DefaultValue(10)] - int Priority { get; } - } -} \ No newline at end of file + /// + /// Implement this interface to provide last-minute or dynamic IDestinations + /// + public interface IDestinationProvider + { + IEnumerable> Provide(); + } +} diff --git a/src/Greenshot.Addons/Components/WindowHandle.cs b/src/Greenshot.Addons/Components/WindowHandle.cs index 85ffc0c15..816bd5b55 100644 --- a/src/Greenshot.Addons/Components/WindowHandle.cs +++ b/src/Greenshot.Addons/Components/WindowHandle.cs @@ -22,14 +22,12 @@ #endregion using System; -using System.ComponentModel.Composition; namespace Greenshot.Addons.Components { /// /// This can be used to store the main handle /// - [Export] public class WindowHandle { /// diff --git a/src/Greenshot.Addons/Controls/GreenshotComboBox.cs b/src/Greenshot.Addons/Controls/GreenshotComboBox.cs index a822464a8..4575a6a44 100644 --- a/src/Greenshot.Addons/Controls/GreenshotComboBox.cs +++ b/src/Greenshot.Addons/Controls/GreenshotComboBox.cs @@ -102,13 +102,12 @@ namespace Greenshot.Addons.Controls foreach (Enum enumValue in availableValues) { - var enumKey = enumTypeName + "." + enumValue; - if (!Language.HasKey(enumKey)) + if (!Language.HasKey(enumTypeName, enumValue)) { continue; } - var translation = Language.GetString(enumTypeName + "." + enumValue); + var translation = Language.GetString(enumTypeName,enumValue); if (translation.Equals(selectedValue)) { returnValue = enumValue; diff --git a/src/Greenshot.Addons/Controls/GreenshotForm.cs b/src/Greenshot.Addons/Controls/GreenshotForm.cs index e0ef9cd9f..1e9e9ad08 100644 --- a/src/Greenshot.Addons/Controls/GreenshotForm.cs +++ b/src/Greenshot.Addons/Controls/GreenshotForm.cs @@ -27,7 +27,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; -using System.IO; using System.Reflection; using System.Windows.Forms; using Dapplo.Ini; @@ -122,41 +121,6 @@ namespace Greenshot.Addons.Controls /// /// Code to initialize the language etc during design time /// - protected void InitializeForDesigner() - { - if (DesignMode) - { - _designTimeControls = new Dictionary(); - _designTimeToolStripItems = new Dictionary(); - try - { - var typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService; - - // Add a hard-path if you are using SharpDevelop - // Language.AddLanguageFilePath(@"C:\Greenshot\Greenshot\Languages"); - - // this "type" - var currentAssembly = GetType().Assembly; - if (typeResService != null) - { - var assemblyPath = typeResService.GetPathOfAssembly(currentAssembly.GetName()); - var assemblyDirectory = Path.GetDirectoryName(assemblyPath); - if (assemblyDirectory != null && !Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Greenshot\Languages\"))) - { - Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Greenshot\Languages\")); - } - if (assemblyDirectory != null && !Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Languages\"))) - { - Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Languages\")); - } - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); - } - } - } /// /// This override is only for the design-time of the form @@ -196,13 +160,6 @@ namespace Greenshot.Addons.Controls FillFields(); base.OnLoad(e); } - else - { - Log.Info().WriteLine("OnLoad called from designer."); - InitializeForDesigner(); - base.OnLoad(e); - ApplyLanguage(); - } } /// diff --git a/src/Greenshot.Addons/Core/AbstractDestination.cs b/src/Greenshot.Addons/Core/AbstractDestination.cs index deb465fff..9a0df5095 100644 --- a/src/Greenshot.Addons/Core/AbstractDestination.cs +++ b/src/Greenshot.Addons/Core/AbstractDestination.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.Linq; using System.Threading; @@ -38,7 +37,7 @@ using Dapplo.Windows.Common.Structs; using Dapplo.Windows.Dpi; using Dapplo.Windows.Dpi.Forms; using Dapplo.Windows.Extensions; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Extensions; using Greenshot.Addons.Interfaces; using Greenshot.Gfx; @@ -54,14 +53,13 @@ namespace Greenshot.Addons.Core { private static readonly LogSource Log = new LogSource(); - [Import] - protected IGreenshotLanguage GreenshotLanguage { get; set; } + protected IGreenshotLanguage GreenshotLanguage { get; } + protected ICoreConfiguration CoreConfiguration { get; } - [Import] - protected ICoreConfiguration CoreConfiguration { get; set; } - - protected AbstractDestination() + protected AbstractDestination(ICoreConfiguration coreConfiguration, IGreenshotLanguage greenshotLanguage) { + CoreConfiguration = coreConfiguration; + GreenshotLanguage = greenshotLanguage; Designation = GetType().GetDesignation(); } diff --git a/src/Greenshot.Addons/Core/CaptureDetails.cs b/src/Greenshot.Addons/Core/CaptureDetails.cs index 47d32a553..69c70aa63 100644 --- a/src/Greenshot.Addons/Core/CaptureDetails.cs +++ b/src/Greenshot.Addons/Core/CaptureDetails.cs @@ -25,7 +25,7 @@ using System; using System.Collections.Generic; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Interfaces; #endregion diff --git a/src/Greenshot.Addons/Core/ClipboardHelper.cs b/src/Greenshot.Addons/Core/ClipboardHelper.cs index 74854c1d3..de20b3f7c 100644 --- a/src/Greenshot.Addons/Core/ClipboardHelper.cs +++ b/src/Greenshot.Addons/Core/ClipboardHelper.cs @@ -194,7 +194,7 @@ EndSelection:<<<<<<<4 } else { - messageText = Language.GetString("clipboard_error"); + messageText = Language.GetString("Core","clipboard_error"); } Log.Error().WriteLine(clipboardSetException, messageText); } @@ -227,7 +227,7 @@ EndSelection:<<<<<<<4 } else { - messageText = Language.GetString("clipboard_error"); + messageText = Language.GetString("Core", "clipboard_error"); } Log.Error().WriteLine(ee, messageText); } diff --git a/src/Greenshot.Addons/Core/IDestinationFileConfiguration.cs b/src/Greenshot.Addons/Core/IDestinationFileConfiguration.cs index 77497fe47..39127e82d 100644 --- a/src/Greenshot.Addons/Core/IDestinationFileConfiguration.cs +++ b/src/Greenshot.Addons/Core/IDestinationFileConfiguration.cs @@ -23,15 +23,7 @@ #region Usings -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Drawing; -using Dapplo.Ini; -using Dapplo.InterfaceImpl.Extensions; -using Dapplo.Windows.Common.Structs; -using Greenshot.Addons.Core.Enums; -using Greenshot.Addons.Interfaces; #endregion diff --git a/src/Greenshot.Addons/Core/IFileConfiguration.cs b/src/Greenshot.Addons/Core/IFileConfiguration.cs index 68e3c6922..347dc5c17 100644 --- a/src/Greenshot.Addons/Core/IFileConfiguration.cs +++ b/src/Greenshot.Addons/Core/IFileConfiguration.cs @@ -23,15 +23,8 @@ #region Usings -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Drawing; -using Dapplo.Ini; -using Dapplo.InterfaceImpl.Extensions; -using Dapplo.Windows.Common.Structs; using Greenshot.Addons.Core.Enums; -using Greenshot.Addons.Interfaces; #endregion diff --git a/src/Greenshot.Addons/Core/ImageOutput.cs b/src/Greenshot.Addons/Core/ImageOutput.cs index 659ca9b34..30503ebb1 100644 --- a/src/Greenshot.Addons/Core/ImageOutput.cs +++ b/src/Greenshot.Addons/Core/ImageOutput.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; @@ -65,7 +64,9 @@ namespace Greenshot.Addons.Core { BitmapHelper.StreamConverters["greenshot"] = (stream, s) => { - var surface = SurfaceFactory.CreateExport().Value; + // TODO: Create surface from stream + var surface = SurfaceFactory(); + surface.LoadElementsFromStream(stream); return surface.GetBitmapForExport(); }; } @@ -73,7 +74,7 @@ namespace Greenshot.Addons.Core /// /// This is a factory method to create a surface, set from the Greenshot main project /// - public static ExportFactory SurfaceFactory { get; set; } + public static Func SurfaceFactory { get; set; } /// /// Creates a PropertyItem (Metadata) to store with the image. diff --git a/src/Greenshot.Addons/Core/Language.cs b/src/Greenshot.Addons/Core/Language.cs index 3cc25764f..a9e0bce23 100644 --- a/src/Greenshot.Addons/Core/Language.cs +++ b/src/Greenshot.Addons/Core/Language.cs @@ -25,13 +25,8 @@ using System; using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Text.RegularExpressions; -using System.Xml; -using Dapplo.Ini; -using Dapplo.Log; -using Microsoft.Win32; +using System.Linq; +using Dapplo.Language; #endregion @@ -45,545 +40,31 @@ namespace Greenshot.Addons.Core /// public class Language { - private const string DefaultLanguage = "en-US"; - private const string HelpFilenamePattern = @"help-*.html"; - private const string LanguageFilenamePattern = @"language*.xml"; - private const string LanguageGroupsKey = @"SYSTEM\CurrentControlSet\Control\Nls\Language Groups"; - private static readonly LogSource Log = new LogSource(); - private static readonly IList LanguagePaths = new List(); - private static readonly IDictionary> LanguageFiles = new Dictionary>(); - private static readonly IDictionary HelpFiles = new Dictionary(); - private static readonly Regex PrefixRegexp = new Regex(@"language_([a-zA-Z0-9]+).*"); - private static readonly Regex IetfCleanRegexp = new Regex(@"[^a-zA-Z]+"); - private static readonly Regex IetfRegexp = new Regex(@"^.*([a-zA-Z]{2,3}-[a-zA-Z]{1,2})\.xml$"); - private static readonly IList UnsupportedLanguageGroups = new List(); - private static readonly IDictionary Resources = new Dictionary(); - private static string _currentLanguage; - - /// - /// Static initializer for the language code - /// - static Language() - { - try - { - var location = string.IsNullOrEmpty(Assembly.GetExecutingAssembly().Location) ? new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath : Assembly.GetExecutingAssembly().Location; - - var applicationFolder = Path.GetDirectoryName(location); - - // PAF Path - if (applicationFolder != null) - { - AddPath(Path.Combine(applicationFolder, @"App\Greenshot\Languages")); - } - // Application data path - var applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - AddPath(Path.Combine(applicationDataFolder, @"Greenshot\Languages\")); - - // Startup path - if (applicationFolder != null) - { - AddPath(Path.Combine(applicationFolder, @"Languages")); - } - } - catch (Exception pathException) - { - Log.Error().WriteLine(pathException); - } - - try - { - using (var languageGroupsKey = Registry.LocalMachine.OpenSubKey(LanguageGroupsKey, false)) - { - if (languageGroupsKey != null) - { - var groups = languageGroupsKey.GetValueNames(); - foreach (var group in groups) - { - var groupValue = (string) languageGroupsKey.GetValue(group); - var isGroupNotInstalled = "0".Equals(groupValue); - if (isGroupNotInstalled) - { - UnsupportedLanguageGroups.Add(group.ToLower()); - } - } - } - } - } - catch (Exception e) - { - Log.Warn().WriteLine(e, "Couldn't read the installed language groups."); - } - - var coreConfig = IniConfig.Current.Get(); - ScanFiles(); - if (!string.IsNullOrEmpty(coreConfig.Language)) - { - CurrentLanguage = coreConfig.Language; - if (CurrentLanguage != null && CurrentLanguage != coreConfig.Language) - { - coreConfig.Language = CurrentLanguage; - } - } - - if (CurrentLanguage == null) - { - Log.Warn().WriteLine("Couldn't set language from configuration, changing to default. Installation problem?"); - CurrentLanguage = DefaultLanguage; - if (CurrentLanguage != null) - { - coreConfig.Language = CurrentLanguage; - } - } - - if (CurrentLanguage == null) - { - Log.Error().WriteLine(null, "Couldn't set language, installation problem?"); - } - } - + private static LanguageLoader languageLoader = LanguageLoader.Current; /// /// Get or set the current language /// public static string CurrentLanguage { - get { return _currentLanguage; } - set - { - var ietf = FindBestIETFMatch(value); - if (!LanguageFiles.ContainsKey(ietf)) - { - Log.Warn().WriteLine("No match for language {0} found!", ietf); - } - else - { - if (_currentLanguage == null || !_currentLanguage.Equals(ietf)) - { - _currentLanguage = ietf; - Reload(); - if (LanguageChanged == null) - { - return; - } - try - { - LanguageChanged(null, null); - } - catch - { - // ignored - } - return; - } - } - Log.Debug().WriteLine("CurrentLanguage not changed!"); - } + get => languageLoader.CurrentLanguage; + set { languageLoader.ChangeLanguageAsync(value); } } /// /// Return a list of all the supported languages /// - public static IList SupportedLanguages - { - get - { - IList languages = new List(); - // Loop over all languages with all the files in there - foreach (var langs in LanguageFiles.Values) - { - // Loop over all the files for a language - foreach (var langFile in langs) - { - // Only take the ones without prefix, these are the "base" language files - if (langFile.Prefix == null) - { - languages.Add(langFile); - break; - } - } - } - return languages; - } - } + public static IDictionary SupportedLanguages => languageLoader.AvailableLanguages; + /// - /// Return the path to the help-file + /// Check if a resource with prefix.key exists /// - public static string HelpFilePath + /// + /// + /// true if available + public static bool HasKey(string prefix, string key) { - get - { - if (HelpFiles.ContainsKey(_currentLanguage)) - { - return HelpFiles[_currentLanguage]; - } - return HelpFiles[DefaultLanguage]; - } - } - - public static event LanguageChangedHandler LanguageChanged; - - /// - /// Internal method to add a path to the paths that will be scanned for language files! - /// - /// - /// true if the path exists and is added - private static bool AddPath(string path) - { - if (!LanguagePaths.Contains(path)) - { - if (Directory.Exists(path)) - { - Log.Debug().WriteLine("Adding language path {0}", path); - LanguagePaths.Add(path); - return true; - } - Log.Info().WriteLine("Not adding non existing language path {0}", path); - } - return false; - } - - /// - /// Add a new path to the paths that will be scanned for language files! - /// - /// - /// true if the path exists and is added - public static bool AddLanguageFilePath(string path) - { - if (!LanguagePaths.Contains(path)) - { - Log.Debug().WriteLine("New language path {0}", path); - if (AddPath(path)) - { - ScanFiles(); - Reload(); - } - else - { - return false; - } - } - return true; - } - - /// - /// Load the files for the specified ietf - /// - /// - private static void LoadFiles(string ietf) - { - ietf = ReformatIETF(ietf); - if (!LanguageFiles.ContainsKey(ietf)) - { - Log.Error().WriteLine("No language {0} available.", ietf); - return; - } - var filesToLoad = LanguageFiles[ietf]; - foreach (var fileToLoad in filesToLoad) - { - LoadResources(fileToLoad); - } - } - - /// - /// Load the language resources from the scanned files - /// - private static void Reload() - { - Resources.Clear(); - LoadFiles(DefaultLanguage); - if (_currentLanguage != null && !_currentLanguage.Equals(DefaultLanguage)) - { - LoadFiles(_currentLanguage); - } - } - - /// - /// Try to find the best match for the supplied IETF - /// - /// - /// IETF - private static string FindBestIETFMatch(string inputIETF) - { - var returnIETF = inputIETF; - if (string.IsNullOrEmpty(returnIETF)) - { - returnIETF = DefaultLanguage; - } - returnIETF = ReformatIETF(returnIETF); - if (!LanguageFiles.ContainsKey(returnIETF)) - { - Log.Warn().WriteLine("Unknown language {0}, trying best match!", returnIETF); - if (returnIETF.Length == 5) - { - returnIETF = returnIETF.Substring(0, 2); - } - foreach (var availableIETF in LanguageFiles.Keys) - { - if (availableIETF.StartsWith(returnIETF)) - { - Log.Info().WriteLine("Found language {0}, best match for {1}!", availableIETF, returnIETF); - returnIETF = availableIETF; - break; - } - } - } - return returnIETF; - } - - /// - /// This helper method clears all non alpha characters from the IETF, and does a reformatting. - /// This prevents problems with multiple formats or typos. - /// - /// string - /// - private static string ReformatIETF(string inputIETF) - { - if (string.IsNullOrEmpty(inputIETF)) - { - return null; - } - - string returnIETF = inputIETF.ToLower(); - returnIETF = IetfCleanRegexp.Replace(returnIETF, ""); - if (returnIETF.Length == 4) - { - returnIETF = returnIETF.Substring(0, 2) + "-" + returnIETF.Substring(2, 2).ToUpper(); - } - return returnIETF; - } - - /// - /// Load the resources from the language file - /// - /// File to load from - private static void LoadResources(LanguageFile languageFile) - { - Log.Info().WriteLine("Loading language file {0}", languageFile.Filepath); - try - { - var xmlDocument = new XmlDocument(); - xmlDocument.Load(languageFile.Filepath); - var resourceNodes = xmlDocument.GetElementsByTagName("resource"); - foreach (XmlNode resourceNode in resourceNodes) - { - var key = resourceNode.Attributes["name"].Value; - if (!string.IsNullOrEmpty(languageFile.Prefix)) - { - key = languageFile.Prefix + "." + key; - } - var text = resourceNode.InnerText; - if (!string.IsNullOrEmpty(text)) - { - text = text.Trim(); - } - if (!Resources.ContainsKey(key)) - { - Resources.Add(key, text); - } - else - { - Resources[key] = text; - } - } - } - catch (Exception e) - { - Log.Error().WriteLine(e, "Could not load language file " + languageFile.Filepath); - } - } - - /// - /// Load the language file information - /// - /// - /// - private static LanguageFile LoadFileInfo(string languageFilePath) - { - try - { - var xmlDocument = new XmlDocument(); - xmlDocument.Load(languageFilePath); - var nodes = xmlDocument.GetElementsByTagName("language"); - if (nodes.Count <= 0) - { - throw new XmlException("Root element is missing"); - } - - var languageFile = new LanguageFile - { - Filepath = languageFilePath - }; - var node = nodes.Item(0); - if (node?.Attributes == null) - { - return languageFile; - } - - languageFile.Description = node.Attributes["description"]?.Value; - languageFile.Ietf = ReformatIETF(node.Attributes["ietf"]?.Value); - if (node.Attributes["version"]?.Value != null) - { - languageFile.Version = new Version(node.Attributes["version"].Value); - } - languageFile.Prefix = node.Attributes["prefix"]?.Value.ToLower(); - languageFile.LanguageGroup = node.Attributes["languagegroup"]?.Value.ToLower(); - return languageFile; - } - catch (Exception e) - { - Log.Error().WriteLine(e, "Could not load language file " + languageFilePath); - } - return null; - } - - /// - /// Scan the files in all directories - /// - private static void ScanFiles() - { - LanguageFiles.Clear(); - HelpFiles.Clear(); - foreach (var languagePath in LanguagePaths) - { - if (!Directory.Exists(languagePath)) - { - Log.Info().WriteLine("Skipping non existing language path {0}", languagePath); - continue; - } - Log.Info().WriteLine("Searching language directory '{0}' for language files with pattern '{1}'", languagePath, LanguageFilenamePattern); - try - { - foreach (var languageFilepath in Directory.GetFiles(languagePath, LanguageFilenamePattern, SearchOption.AllDirectories)) - { - //Log.Debug().WriteLine("Found language file: {0}", languageFilepath); - var languageFile = LoadFileInfo(languageFilepath); - if (languageFile == null) - { - continue; - } - if (string.IsNullOrEmpty(languageFile.Ietf)) - { - Log.Warn().WriteLine("Fixing missing ietf in language-file {0}", languageFilepath); - var languageFilename = Path.GetFileName(languageFilepath); - if (IetfRegexp.IsMatch(languageFilename)) - { - var replacementIETF = IetfRegexp.Replace(languageFilename, "$1"); - languageFile.Ietf = ReformatIETF(replacementIETF); - Log.Info().WriteLine("Fixed IETF to {0}", languageFile.Ietf); - } - else - { - Log.Error().WriteLine("Missing ietf , no recover possible... skipping language-file {0}!", languageFilepath); - continue; - } - } - - // Check if we can display the file - if (!string.IsNullOrEmpty(languageFile.LanguageGroup) && UnsupportedLanguageGroups.Contains(languageFile.LanguageGroup)) - { - Log.Info().WriteLine("Skipping unsuported (not able to display) language {0} from file {1}", languageFile.Description, languageFilepath); - continue; - } - - // build prefix, based on the filename, but only if it's not set in the file itself. - if (string.IsNullOrEmpty(languageFile.Prefix)) - { - var languageFilename = Path.GetFileNameWithoutExtension(languageFilepath); - if (PrefixRegexp.IsMatch(languageFilename)) - { - languageFile.Prefix = PrefixRegexp.Replace(languageFilename, "$1"); - if (!string.IsNullOrEmpty(languageFile.Prefix)) - { - languageFile.Prefix = languageFile.Prefix.Replace("plugin", "").ToLower(); - } - } - } - List currentFiles = null; - if (LanguageFiles.ContainsKey(languageFile.Ietf)) - { - currentFiles = LanguageFiles[languageFile.Ietf]; - var needToAdd = true; - var deleteList = new List(); - foreach (var compareWithLangfile in currentFiles) - { - if ((languageFile.Prefix != null || compareWithLangfile.Prefix != null) && - (languageFile.Prefix == null || - !languageFile.Prefix.Equals(compareWithLangfile.Prefix))) - { - continue; - } - - if (compareWithLangfile.Version == null || languageFile.Version == null) - { - continue; - } - if (compareWithLangfile.Version > languageFile.Version) - { - Log.Warn().WriteLine("Skipping {0}:{1}:{2} as {3}:{4}:{5} is newer", languageFile.Filepath, languageFile.Prefix, languageFile.Version, compareWithLangfile.Filepath, - compareWithLangfile.Prefix, compareWithLangfile.Version); - needToAdd = false; - break; - } - Log.Warn().WriteLine("Found {0}:{1}:{2} and deleting {3}:{4}:{5}", languageFile.Filepath, languageFile.Prefix, languageFile.Version, compareWithLangfile.Filepath, - compareWithLangfile.Prefix, compareWithLangfile.Version); - deleteList.Add(compareWithLangfile); - } - if (needToAdd) - { - foreach (var deleteFile in deleteList) - { - currentFiles.Remove(deleteFile); - } - Log.Info().WriteLine("Added language definition {0} from: {1}", languageFile.Description, languageFile.Filepath); - currentFiles.Add(languageFile); - } - } - else - { - currentFiles = new List {languageFile}; - LanguageFiles.Add(languageFile.Ietf, currentFiles); - Log.Info().WriteLine("Added language definition {0} from: {1}", languageFile.Description, languageFile.Filepath); - } - } - } - catch (DirectoryNotFoundException) - { - Log.Info().WriteLine("Non existing language directory: {0}", languagePath); - } - catch (Exception e) - { - Log.Error().WriteLine(e, "Error trying for read directory " + languagePath); - } - - // Now find the help files - Log.Info().WriteLine("Searching language directory '{0}' for help files with pattern '{1}'", languagePath, HelpFilenamePattern); - try - { - foreach (var helpFilepath in Directory.GetFiles(languagePath, HelpFilenamePattern, SearchOption.AllDirectories)) - { - Log.Debug().WriteLine("Found help file: {0}", helpFilepath); - var helpFilename = Path.GetFileName(helpFilepath); - var ietf = ReformatIETF(helpFilename.Replace(".html", "").Replace("help-", "")); - if (!HelpFiles.ContainsKey(ietf)) - { - HelpFiles.Add(ietf, helpFilepath); - } - else - { - Log.Warn().WriteLine("skipping help file {0}, already a file with the same IETF {1} found!", helpFilepath, ietf); - } - } - } - catch (DirectoryNotFoundException) - { - Log.Info().WriteLine("Non existing language directory: {0}", languagePath); - } - catch (Exception e) - { - Log.Error().WriteLine(e, "Error trying for read directory " + languagePath); - } - } + return languageLoader[prefix].Keys().Contains(key); } /// @@ -594,61 +75,18 @@ namespace Greenshot.Addons.Core /// true if available public static bool HasKey(string prefix, Enum key) { - if (key == null) + return languageLoader[prefix].Keys().Contains(key.ToString()); + } + + public static string Translate(object key) + { + var typename = key.GetType().Name; + var enumKey = typename + "." + key; + if (HasKey("Core", enumKey)) { - return false; + return GetString("Core", enumKey); } - return HasKey(prefix + "." + key); - } - - /// - /// Check if a resource with key exists - /// - /// - /// true if available - public static bool HasKey(Enum key) - { - if (key == null) - { - return false; - } - return HasKey(key.ToString()); - } - - /// - /// Check if a resource with prefix.key exists - /// - /// - /// - /// true if available - public static bool HasKey(string prefix, string key) - { - return HasKey(prefix + "." + key); - } - - /// - /// Check if a resource with key exists - /// - /// - /// true if available - public static bool HasKey(string key) - { - if (key == null) - { - return false; - } - return Resources.ContainsKey(key); - } - - /// - /// TryGet method which combines HasKey & GetString - /// - /// - /// out string - /// - public static bool TryGetString(string key, out string languageString) - { - return Resources.TryGetValue(key, out languageString); + return key.ToString(); } /// @@ -657,48 +95,71 @@ namespace Greenshot.Addons.Core /// string with prefix /// string with key /// out string - /// + /// bool public static bool TryGetString(string prefix, string key, out string languageString) { - return Resources.TryGetValue(prefix + "." + key, out languageString); + if (languageLoader.Any(l => l.PrefixName() == prefix) && languageLoader[prefix].Keys().Contains(key)) + { + languageString = languageLoader[prefix][key]; + return true; + } + + languageString = null; + return false; } /// /// TryGet method which combines HasKey & GetString /// - /// string with prefix - /// Enum with key + /// string with key /// out string - /// - public static bool TryGetString(string prefix, Enum key, out string languageString) + /// bool + public static bool TryGetString(string key, out string languageString) { - return Resources.TryGetValue(prefix + "." + key, out languageString); + return TryGetString("Core", key, out languageString); } - - public static string Translate(object key) + /// + /// Get the resource for prefix.key + /// + /// + /// + /// resource or a "string ###prefix.key### not found" + public static string GetString(string prefix, string key) { - var typename = key.GetType().Name; - var enumKey = typename + "." + key; - if (HasKey(enumKey)) + if (key == null) { - return GetString(enumKey); + return null; } - return key.ToString(); + return languageLoader[prefix][key]; } /// /// Get the resource for key /// /// - /// resource or a "string ###key### not found" + /// resource or a "string ###prefix.key### not found" + public static string GetString(string key) + { + if (key == null) + { + return null; + } + return languageLoader["Core"][key]; + } + + /// + /// Get the resource for key + /// + /// Enum + /// resource or a "string ###prefix.key### not found" public static string GetString(Enum key) { if (key == null) { return null; } - return GetString(key.ToString()); + return languageLoader["Core"][key.ToString()]; } /// @@ -713,37 +174,7 @@ namespace Greenshot.Addons.Core { return null; } - return GetString(prefix + "." + key); - } - - /// - /// Get the resource for prefix.key - /// - /// - /// - /// resource or a "string ###prefix.key### not found" - public static string GetString(string prefix, string key) - { - return GetString(prefix + "." + key); - } - - /// - /// Get the resource for key - /// - /// - /// resource or a "string ###key### not found" - public static string GetString(string key) - { - if (key == null) - { - return null; - } - - if (!Resources.TryGetValue(key, out var returnValue)) - { - return "string ###" + key + "### not found"; - } - return returnValue; + return GetString(prefix, key.ToString()); } /// @@ -778,7 +209,12 @@ namespace Greenshot.Addons.Core /// formatted resource or a "string ###prefix.key### not found" public static string GetFormattedString(string prefix, string key, object param) { - return GetFormattedString(prefix + "." + key, param); + if (TryGetString(prefix, key, out var value)) + { + return string.Format(value, param); + } + + return $"string ###{prefix}.{key}### not found"; } /// @@ -789,83 +225,7 @@ namespace Greenshot.Addons.Core /// formatted resource or a "string ###key### not found" public static string GetFormattedString(string key, object param) { - if (!Resources.TryGetValue(key, out var returnValue)) - { - return "string ###" + key + "### not found"; - } - return string.Format(returnValue, param); - } - } - - /// - /// This class contains the information about a language file - /// - public class LanguageFile : IEquatable - { - public string Description { get; set; } - - public string Ietf { get; set; } - - public Version Version { get; set; } - - public string LanguageGroup { get; set; } - - public string Filepath { get; set; } - - public string Prefix { get; set; } - - /// - /// Overload equals so we can delete a entry from a collection - /// - /// - /// - public bool Equals(LanguageFile other) - { - if (Prefix != null) - { - if (other != null && !Prefix.Equals(other.Prefix)) - { - return false; - } - } - else if (other?.Prefix != null) - { - return false; - } - if (Ietf != null) - { - if (other != null && !Ietf.Equals(other.Ietf)) - { - return false; - } - } - else if (other?.Ietf != null) - { - return false; - } - if (Version != null) - { - if (other != null && !Version.Equals(other.Version)) - { - return false; - } - } - else if (other != null && other.Version != null) - { - return false; - } - if (Filepath != null) - { - if (other != null && !Filepath.Equals(other.Filepath)) - { - return false; - } - } - else if (other?.Filepath != null) - { - return false; - } - return true; + return GetFormattedString("Core", key, param); } } } \ No newline at end of file diff --git a/src/Greenshot.Addons/Core/PluginUtils.cs b/src/Greenshot.Addons/Core/PluginUtils.cs index 5244a65a9..b244dc8a3 100644 --- a/src/Greenshot.Addons/Core/PluginUtils.cs +++ b/src/Greenshot.Addons/Core/PluginUtils.cs @@ -34,7 +34,6 @@ using Dapplo.Log; using Dapplo.Windows.Icons; using Dapplo.Windows.Icons.Enums; using Greenshot.Addons.Interfaces.Forms; -using Greenshot.Addons.Interfaces.Plugin; using Microsoft.Win32; #endregion @@ -180,31 +179,6 @@ namespace Greenshot.Addons.Core return null; } - /// - /// Helper method to add a MenuItem to the File MenuItem of an ImageEditor - /// - /// - /// Image to display in the menu - /// Text to display in the menu - /// The TAG value - /// Keys which can be used as shortcut - /// The onclick handler - public static void AddToFileMenu(IImageEditor imageEditor, Image image, string text, object tag, Keys? shortcutKeys, EventHandler handler) - { - var item = new ToolStripMenuItem - { - Image = image, - Text = text, - Tag = tag - }; - if (shortcutKeys.HasValue) - { - item.ShortcutKeys = shortcutKeys.Value; - } - item.Click += handler; - AddToFileMenu(imageEditor, item); - } - /// /// Helper method to add a MenuItem to the File MenuItem of an ImageEditor /// @@ -231,74 +205,5 @@ namespace Greenshot.Addons.Core } } - /// - /// Helper method to add a MenuItem to the Plugin MenuItem of an ImageEditor - /// - /// - /// - public static void AddToPluginMenu(IImageEditor imageEditor, ToolStripMenuItem item) - { - var toolStripMenuItem = imageEditor.GetPluginMenuItem(); - var added = false; - for (var i = 0; i < toolStripMenuItem.DropDownItems.Count; i++) - { - if (toolStripMenuItem.DropDownItems[i].GetType() != typeof(ToolStripSeparator)) - { - continue; - } - - toolStripMenuItem.DropDownItems.Insert(i, item); - added = true; - break; - } - if (!added) - { - toolStripMenuItem.DropDownItems.Add(item); - } - } - - /// - /// 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! - var contextMenu = host.MainMenu; - var addedItem = false; - - // Try to find a separator, so we insert ourselves after it - for (var i = 0; i < contextMenu.Items.Count; i++) - { - if (contextMenu.Items[i].GetType() != typeof(ToolStripSeparator)) - { - continue; - } - - // Check if we need to add a new separator, which is done if the first found has a Tag with the value "PluginsAreAddedBefore" - if ("PluginsAreAddedBefore".Equals(contextMenu.Items[i].Tag)) - { - var separator = new ToolStripSeparator - { - Tag = "PluginsAreAddedAfter", - Size = new Size(305, 6) - }; - contextMenu.Items.Insert(i, separator); - } - else if (!"PluginsAreAddedAfter".Equals(contextMenu.Items[i].Tag)) - { - continue; - } - contextMenu.Items.Insert(i + 1, item); - addedItem = true; - break; - } - // If we didn't insert the item, we just add it... - if (!addedItem) - { - contextMenu.Items.Add(item); - } - } } } \ No newline at end of file diff --git a/src/Greenshot.Addons/Extensions/DestinationExtensions.cs b/src/Greenshot.Addons/Extensions/DestinationExtensions.cs index 2cb3654fa..a280c0657 100644 --- a/src/Greenshot.Addons/Extensions/DestinationExtensions.cs +++ b/src/Greenshot.Addons/Extensions/DestinationExtensions.cs @@ -25,7 +25,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; namespace Greenshot.Addons.Extensions { @@ -62,7 +62,7 @@ namespace Greenshot.Addons.Extensions /// IEnumerable of IDestination /// destination /// IDestination or null - public static IDestination Find(this IEnumerable> destinations, string destination) + public static IDestination Find(this IEnumerable> destinations, string destination) { return destinations.FirstOrDefault(p => p.Metadata.Designation == destination && p.Value.IsActive)?.Value; } @@ -73,7 +73,7 @@ namespace Greenshot.Addons.Extensions /// IEnumerable of IDestination /// destination type /// IDestination or null - public static IDestination Find(this IEnumerable> destinations, Type destinationType) + public static IDestination Find(this IEnumerable> destinations, Type destinationType) { return destinations.FirstOrDefault(p => p.Metadata.Designation == destinationType.GetDesignation() && p.Value.IsActive)?.Value; } diff --git a/src/Greenshot.Addons/Greenshot.Addons.csproj b/src/Greenshot.Addons/Greenshot.Addons.csproj index 668cfbd87..284aeb809 100644 --- a/src/Greenshot.Addons/Greenshot.Addons.csproj +++ b/src/Greenshot.Addons/Greenshot.Addons.csproj @@ -18,6 +18,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -31,29 +40,29 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -64,14 +73,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -154,7 +163,7 @@ - + @@ -164,6 +173,9 @@ + + + Form @@ -223,6 +235,7 @@ + @@ -245,12 +258,9 @@ - - - @@ -370,7 +380,7 @@ - + diff --git a/src/Greenshot.Addons/Interfaces/ICaptureDetails.cs b/src/Greenshot.Addons/Interfaces/ICaptureDetails.cs index 815176d2d..a327e5a05 100644 --- a/src/Greenshot.Addons/Interfaces/ICaptureDetails.cs +++ b/src/Greenshot.Addons/Interfaces/ICaptureDetails.cs @@ -25,7 +25,7 @@ using System; using System.Collections.Generic; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; #endregion diff --git a/src/Greenshot.Addons/ViewModels/FileConfigPartViewModel.cs b/src/Greenshot.Addons/ViewModels/FileConfigPartViewModel.cs index 4925dcb13..f816a8456 100644 --- a/src/Greenshot.Addons/ViewModels/FileConfigPartViewModel.cs +++ b/src/Greenshot.Addons/ViewModels/FileConfigPartViewModel.cs @@ -22,7 +22,6 @@ #endregion using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Windows; using Caliburn.Micro; using Greenshot.Addons.Core; @@ -34,19 +33,23 @@ namespace Greenshot.Addons.ViewModels /// /// A view model for showing the file configuration /// - [Export] - [PartCreationPolicy(CreationPolicy.NonShared)] public sealed class FileConfigPartViewModel : Screen { private IDestinationFileConfiguration _destinationFileConfiguration; private bool _useOwnSettings; - [Import] - public ICoreConfiguration CoreConfiguration { get; set; } + public ICoreConfiguration CoreConfiguration { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } + public FileConfigPartViewModel( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) + { + CoreConfiguration = coreConfiguration; + GreenshotLanguage = greenshotLanguage; + } /// /// A NPC wrapper for the UseOwnSettings in the IDestinationFileConfiguration, as this doesn't work when ITransactionalProperties is used diff --git a/src/Greenshot.Addons/ViewModels/UploadViewModel.cs b/src/Greenshot.Addons/ViewModels/UploadViewModel.cs index a117c23b2..c00d3c594 100644 --- a/src/Greenshot.Addons/ViewModels/UploadViewModel.cs +++ b/src/Greenshot.Addons/ViewModels/UploadViewModel.cs @@ -21,18 +21,16 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Caliburn.Micro; using Dapplo.CaliburnMicro.Extensions; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; namespace Greenshot.Addons.ViewModels { /// /// A view model for showing uploads /// - [Export] public sealed class UploadViewModel : Conductor.Collection.AllActive { /// @@ -40,8 +38,12 @@ namespace Greenshot.Addons.ViewModels /// private CompositeDisposable _disposables; - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } + + public UploadViewModel(IGreenshotLanguage greenshotLanguage) + { + GreenshotLanguage = greenshotLanguage; + } protected override void OnActivate() { diff --git a/src/Greenshot.Addons/app.config b/src/Greenshot.Addons/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Addons/app.config +++ b/src/Greenshot.Addons/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Addons/packages.config b/src/Greenshot.Addons/packages.config index a1b066b31..3d26a9c1b 100644 --- a/src/Greenshot.Addons/packages.config +++ b/src/Greenshot.Addons/packages.config @@ -1,22 +1,25 @@  + + + - - - - - - - - + + + + + + + + - + - + diff --git a/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj b/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj index c39606c68..299d388c8 100644 --- a/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj +++ b/src/Greenshot.Gfx.Experimental/Greenshot.Gfx.Experimental.csproj @@ -64,6 +64,7 @@ + diff --git a/src/Greenshot.Gfx.Experimental/Properties/AssemblyInfo.cs b/src/Greenshot.Gfx.Experimental/Properties/AssemblyInfo.cs index db231f7c2..5b43d1766 100644 --- a/src/Greenshot.Gfx.Experimental/Properties/AssemblyInfo.cs +++ b/src/Greenshot.Gfx.Experimental/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/src/Greenshot.Gfx.Experimental/app.config b/src/Greenshot.Gfx.Experimental/app.config new file mode 100644 index 000000000..5ad3f61fd --- /dev/null +++ b/src/Greenshot.Gfx.Experimental/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Greenshot.Gfx/Greenshot.Gfx.csproj b/src/Greenshot.Gfx/Greenshot.Gfx.csproj index 6642c1c22..c983db796 100644 --- a/src/Greenshot.Gfx/Greenshot.Gfx.csproj +++ b/src/Greenshot.Gfx/Greenshot.Gfx.csproj @@ -15,6 +15,15 @@ true + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll @@ -27,23 +36,26 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -162,6 +174,7 @@ + diff --git a/src/Greenshot.Gfx/SvgBitmap.cs b/src/Greenshot.Gfx/SvgBitmap.cs index f8aaa18ab..2308fa58d 100644 --- a/src/Greenshot.Gfx/SvgBitmap.cs +++ b/src/Greenshot.Gfx/SvgBitmap.cs @@ -48,8 +48,22 @@ namespace Greenshot.Gfx public SvgBitmap(Stream stream) { _svgDocument = SvgDocument.Open(stream); - Height = (int) _svgDocument.ViewBox.Height; - Width = (int) _svgDocument.ViewBox.Width; + if ((int) _svgDocument.ViewBox.Height == 0) + { + Height = (int)_svgDocument.Height; + } + else + { + Height = (int)_svgDocument.ViewBox.Height; + } + if ((int)_svgDocument.ViewBox.Width == 0) + { + Width = (int)_svgDocument.Width; + } + else + { + Width = (int)_svgDocument.ViewBox.Width; + } } /// diff --git a/src/Greenshot.Gfx/app.config b/src/Greenshot.Gfx/app.config index 01e79d74d..43fad85c0 100644 --- a/src/Greenshot.Gfx/app.config +++ b/src/Greenshot.Gfx/app.config @@ -6,6 +6,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Gfx/packages.config b/src/Greenshot.Gfx/packages.config index e329a5445..09c8ee0ae 100644 --- a/src/Greenshot.Gfx/packages.config +++ b/src/Greenshot.Gfx/packages.config @@ -1,14 +1,18 @@  + + + - - - - + + + + + - + diff --git a/src/Greenshot.PerformanceTests/App.config b/src/Greenshot.PerformanceTests/App.config index 43c6a05e4..219c43ebe 100644 --- a/src/Greenshot.PerformanceTests/App.config +++ b/src/Greenshot.PerformanceTests/App.config @@ -47,11 +47,11 @@ - + - + @@ -77,6 +77,10 @@ + + + + diff --git a/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj b/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj index 5a0254605..d2d4fdeea 100644 --- a/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj +++ b/src/Greenshot.PerformanceTests/Greenshot.PerformanceTests.csproj @@ -12,6 +12,15 @@ + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\BenchmarkDotNet.0.10.14\lib\net46\BenchmarkDotNet.dll @@ -33,23 +42,26 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -87,11 +99,11 @@ ..\packages\JeremyAnsel.ColorQuant.1.0.55\lib\net40\JeremyAnsel.ColorQuant.dll - - ..\packages\Microsoft.CodeAnalysis.Common.2.7.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll + + ..\packages\Microsoft.CodeAnalysis.Common.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.dll - - ..\packages\Microsoft.CodeAnalysis.CSharp.2.7.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll + + ..\packages\Microsoft.CodeAnalysis.CSharp.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll ..\packages\Microsoft.DotNet.InternalAbstractions.1.0.0\lib\net451\Microsoft.DotNet.InternalAbstractions.dll diff --git a/src/Greenshot.PerformanceTests/packages.config b/src/Greenshot.PerformanceTests/packages.config index 7c6204fe8..47a7226c3 100644 --- a/src/Greenshot.PerformanceTests/packages.config +++ b/src/Greenshot.PerformanceTests/packages.config @@ -1,17 +1,21 @@  + + + - - - - + + + + + - + @@ -25,8 +29,8 @@ - - + + diff --git a/src/Greenshot.Tests/Greenshot.Tests.csproj b/src/Greenshot.Tests/Greenshot.Tests.csproj index 57db137d6..b6573da54 100644 --- a/src/Greenshot.Tests/Greenshot.Tests.csproj +++ b/src/Greenshot.Tests/Greenshot.Tests.csproj @@ -38,6 +38,15 @@ latest + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\BenchmarkDotNet.0.10.14\lib\net46\BenchmarkDotNet.dll @@ -62,23 +71,26 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -113,11 +125,11 @@ ..\packages\Dapplo.Windows.User32.0.5.56\lib\net45\Dapplo.Windows.User32.dll - - ..\packages\Microsoft.CodeAnalysis.Common.2.7.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll + + ..\packages\Microsoft.CodeAnalysis.Common.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.dll - - ..\packages\Microsoft.CodeAnalysis.CSharp.2.7.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll + + ..\packages\Microsoft.CodeAnalysis.CSharp.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll ..\packages\Microsoft.DotNet.InternalAbstractions.1.0.0\lib\net451\Microsoft.DotNet.InternalAbstractions.dll @@ -296,6 +308,7 @@ + diff --git a/src/Greenshot.Tests/app.config b/src/Greenshot.Tests/app.config index c914d4292..129b46a54 100644 --- a/src/Greenshot.Tests/app.config +++ b/src/Greenshot.Tests/app.config @@ -44,11 +44,11 @@ - + - + @@ -74,6 +74,10 @@ + + + + \ No newline at end of file diff --git a/src/Greenshot.Tests/packages.config b/src/Greenshot.Tests/packages.config index 83f488bdf..ed3ce59cf 100644 --- a/src/Greenshot.Tests/packages.config +++ b/src/Greenshot.Tests/packages.config @@ -1,5 +1,8 @@  + + + @@ -7,12 +10,13 @@ - - - - + + + + + - + @@ -25,8 +29,8 @@ - - + + @@ -78,7 +82,7 @@ - + diff --git a/src/Greenshot/App.config b/src/Greenshot/App.config index e519ae72a..74e76b7d0 100644 --- a/src/Greenshot/App.config +++ b/src/Greenshot/App.config @@ -7,11 +7,16 @@ + - + + + + + diff --git a/src/Greenshot/Components/AuthenticationProvider.cs b/src/Greenshot/Components/AuthenticationProvider.cs index b10cc145d..54f77ad86 100644 --- a/src/Greenshot/Components/AuthenticationProvider.cs +++ b/src/Greenshot/Components/AuthenticationProvider.cs @@ -23,7 +23,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Linq; using Caliburn.Micro; using Dapplo.CaliburnMicro.Security; @@ -35,11 +34,15 @@ namespace Greenshot.Components /// This exports a IAuthenticationProvider which manages the rights in the configuration /// This is used to show or hide elements in the UI depending on the available rights /// - [Export(typeof(IAuthenticationProvider))] public class AuthenticationProvider : PropertyChangedBase, IAuthenticationProvider { - [Import] - private ICoreConfiguration CoreConfiguration { get; set; } + private readonly ICoreConfiguration _coreConfiguration; + + public AuthenticationProvider( + ICoreConfiguration coreConfiguration) + { + _coreConfiguration = coreConfiguration; + } public bool HasPermissions(IEnumerable neededPermissions, PermissionOperations permissionOperation = PermissionOperations.Or) { @@ -49,7 +52,7 @@ namespace Greenshot.Components throw new ArgumentNullException(nameof(neededPermissions)); } - if (CoreConfiguration.Permissions== null || CoreConfiguration.Permissions.Count == 0) + if (_coreConfiguration.Permissions== null || _coreConfiguration.Permissions.Count == 0) { return false; } @@ -59,9 +62,9 @@ namespace Greenshot.Components if (permissionOperation == PermissionOperations.Or) { - return permissionsToCompare.Any(permission => CoreConfiguration.Permissions.Contains(permission)); + return permissionsToCompare.Any(permission => _coreConfiguration.Permissions.Contains(permission)); } - return permissionsToCompare.All(permission => CoreConfiguration.Permissions.Contains(permission)); + return permissionsToCompare.All(permission => _coreConfiguration.Permissions.Contains(permission)); } /// @@ -75,7 +78,7 @@ namespace Greenshot.Components throw new ArgumentNullException(nameof(permission)); } var newPermission = permission.Trim().ToLowerInvariant(); - CoreConfiguration.Permissions.Add(newPermission); + _coreConfiguration.Permissions.Add(newPermission); NotifyOfPropertyChange(nameof(HasPermissions)); } @@ -90,7 +93,7 @@ namespace Greenshot.Components throw new ArgumentNullException(nameof(permission)); } var removingPermission = permission.Trim().ToLowerInvariant(); - CoreConfiguration.Permissions.Remove(removingPermission); + _coreConfiguration.Permissions.Remove(removingPermission); NotifyOfPropertyChange(nameof(HasPermissions)); } } diff --git a/src/Greenshot/Components/CommandlineParser.cs b/src/Greenshot/Components/CommandlineParser.cs index f6094e848..ed7fb19cb 100644 --- a/src/Greenshot/Components/CommandlineParser.cs +++ b/src/Greenshot/Components/CommandlineParser.cs @@ -28,7 +28,7 @@ using System.Text; using CommonServiceLocator; using Dapplo.Log; using Dapplo.Windows.Kernel32; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; namespace Greenshot.Components diff --git a/src/Greenshot/Components/FormsStartup.cs b/src/Greenshot/Components/FormsStartup.cs index d6a0fc3ee..734f2c47b 100644 --- a/src/Greenshot/Components/FormsStartup.cs +++ b/src/Greenshot/Components/FormsStartup.cs @@ -32,8 +32,8 @@ namespace Greenshot.Components /// /// This startup action starts Windows.Forms /// - [StartupAction(StartupOrder = (int)GreenshotStartupOrder.Forms)] - public class FormsStartup : IStartupAction + [ServiceOrder(GreenshotStartupOrder.Forms)] + public class FormsStartup : IStartup { private static readonly LogSource Log = new LogSource(); diff --git a/src/Greenshot/Components/GreenshotServer.cs b/src/Greenshot/Components/GreenshotServer.cs index 9b7d59de8..105a5ffda 100644 --- a/src/Greenshot/Components/GreenshotServer.cs +++ b/src/Greenshot/Components/GreenshotServer.cs @@ -24,8 +24,6 @@ #region Usings using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; using System.IO; using System.Linq; using System.Security.Principal; @@ -36,7 +34,7 @@ using System.Windows.Forms; using Dapplo.Addons; using Dapplo.Ini; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -52,14 +50,14 @@ namespace Greenshot.Components /// This startup action starts the Greenshot "server", which allows to open files etc. /// [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] - [StartupAction(StartupOrder = (int)GreenshotStartupOrder.Server), ShutdownAction] - public class GreenshotServerAction : IGreenshotContract, IAsyncStartupAction, IAsyncShutdownAction + [ServiceOrder(GreenshotStartupOrder.Server)] + public class GreenshotServerAction : IGreenshotContract, IStartupAsync, IShutdownAsync { private static readonly LogSource Log = new LogSource(); private readonly ICoreConfiguration _coreConfiguration; private readonly MainForm _mainForm; private readonly HotkeyHandler _hotkeyHandler; - private readonly IEnumerable _destinations; + private readonly DestinationHolder _destinationHolder; private ServiceHost _host; public static string Identity @@ -72,13 +70,16 @@ namespace Greenshot.Components } public static string EndPoint => $"net.pipe://localhost/Greenshot/Greenshot_{Identity}"; - [ImportingConstructor] - public GreenshotServerAction(ICoreConfiguration coreConfiguration, MainForm mainForm, HotkeyHandler hotkeyHandler, [ImportMany] IEnumerable destinations) + public GreenshotServerAction( + ICoreConfiguration coreConfiguration, + MainForm mainForm, + HotkeyHandler hotkeyHandler, + DestinationHolder destinationHolder) { _coreConfiguration = coreConfiguration; _mainForm = mainForm; _hotkeyHandler = hotkeyHandler; - _destinations = destinations; + _destinationHolder = destinationHolder; } public async Task StartAsync(CancellationToken cancellationToken = default) @@ -162,7 +163,7 @@ namespace Greenshot.Components // Fallback-Destination var designation = _coreConfiguration.OutputDestinations.FirstOrDefault(); - var destination = _destinations.FirstOrDefault(d => d.Designation == designation && d.IsActive); + var destination = _destinationHolder.SortedActiveDestinations.FirstOrDefault(d => d.Designation == designation); switch (captureMode.ToLower()) { diff --git a/src/Greenshot/Components/HotkeyHandler.cs b/src/Greenshot/Components/HotkeyHandler.cs index 4882e3d88..683f60353 100644 --- a/src/Greenshot/Components/HotkeyHandler.cs +++ b/src/Greenshot/Components/HotkeyHandler.cs @@ -22,7 +22,6 @@ #endregion using System; -using System.ComponentModel.Composition; using System.IO; using System.Linq; using System.Text; @@ -44,16 +43,14 @@ namespace Greenshot.Components /// /// This startup action registers the hotkeys /// - [UiStartupAction(StartupOrder = (int)GreenshotUiStartupOrder.Hotkeys), ShutdownAction(ShutdownOrder = int.MinValue)] - [Export] - public class HotkeyHandler : IUiStartupAction, IUiShutdownAction + [ServiceOrder(GreenshotUiStartupOrder.Hotkeys, int.MinValue)] + public class HotkeyHandler : IUiStartup, IUiShutdown { private static readonly LogSource Log = new LogSource(); private readonly ICoreConfiguration _coreConfiguration; private readonly WindowHandle _windowHandle; private static HotkeyHandler _instance; - [ImportingConstructor] public HotkeyHandler(ICoreConfiguration coreConfiguration, WindowHandle windowHandle) { _instance = this; diff --git a/src/Greenshot/Components/MainFormStartup.cs b/src/Greenshot/Components/MainFormStartup.cs index 4ce9b6e00..b85c438d3 100644 --- a/src/Greenshot/Components/MainFormStartup.cs +++ b/src/Greenshot/Components/MainFormStartup.cs @@ -23,9 +23,9 @@ #region Usings using System; -using System.ComponentModel.Composition; using System.Linq; using System.Windows.Forms; +using Dapplo.Addons; using Dapplo.CaliburnMicro; using Dapplo.Log; using Greenshot.Addons.Components; @@ -39,15 +39,14 @@ namespace Greenshot.Components /// /// This startup action starts the MainForm /// - [UiStartupAction(StartupOrder = (int)GreenshotUiStartupOrder.TrayIcon), UiShutdownAction] - public class MainFormStartup : IUiStartupAction, IUiShutdownAction + [ServiceOrder(GreenshotUiStartupOrder.TrayIcon)] + public class MainFormStartup : IUiStartup, IUiShutdown { private static readonly LogSource Log = new LogSource(); private readonly ICoreConfiguration _coreConfiguration; private readonly MainForm _mainForm; private readonly WindowHandle _windowHandle; - [ImportingConstructor] public MainFormStartup(ICoreConfiguration coreConfiguration, MainForm mainForm, WindowHandle windowHandle) { _coreConfiguration = coreConfiguration; diff --git a/src/Greenshot/Components/PluginLoader.cs b/src/Greenshot/Components/PluginLoader.cs deleted file mode 100644 index 4ba4f2f67..000000000 --- a/src/Greenshot/Components/PluginLoader.cs +++ /dev/null @@ -1,97 +0,0 @@ -#region Greenshot GNU General Public License - -// Greenshot - a free and open source screenshot tool -// Copyright (C) 2007-2018 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 . - -#endregion - -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.Linq; -using Dapplo.CaliburnMicro; -using Dapplo.Log; -using Greenshot.Addons.Addons; -using Greenshot.Addons.Core; -using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; - -namespace Greenshot.Components -{ - /// - /// This startup loads / initialized all the plugins - /// - [UiStartupAction(StartupOrder = (int)GreenshotUiStartupOrder.Plugins), UiShutdownAction] - public class PluginLoader : IUiStartupAction, IUiShutdownAction - { - private readonly ICoreConfiguration _coreConfiguration; - private readonly IEnumerable _plugins; - private readonly IEnumerable _destinations; - private readonly IEnumerable _processors; - private static readonly LogSource Log = new LogSource(); - - [ImportingConstructor] - public PluginLoader(ICoreConfiguration coreConfiguration, - [ImportMany] IEnumerable plugins, - [ImportMany] IEnumerable destinations, - [ImportMany] IEnumerable processors) - { - _coreConfiguration = coreConfiguration; - _plugins = plugins; - _destinations = destinations; - _processors = processors; - } - - public void Start() - { - Log.Debug().WriteLine("Starting plugins"); - - foreach (var greenshotPlugin in _plugins) - { - greenshotPlugin.Initialize(); - } - - // Check destinations, remove all that don't exist - foreach (var destination in _coreConfiguration.OutputDestinations.ToArray()) - { - if (_destinations.FirstOrDefault(p => p.Designation == destination && p.IsActive) == null) - { - _coreConfiguration.OutputDestinations.Remove(destination); - } - } - - // we should have at least one! - if (_coreConfiguration.OutputDestinations.Count == 0) - { - _coreConfiguration.OutputDestinations.Add("Editor"); - } - - Log.Debug().WriteLine("Started plugins"); - } - - public void Shutdown() - { - Log.Debug().WriteLine("Stopping plugins"); - - foreach (var greenshotPlugin in _plugins) - { - greenshotPlugin.Shutdown(); - } - } - } -} \ No newline at end of file diff --git a/src/Greenshot/Components/SoundHelper.cs b/src/Greenshot/Components/SoundHelper.cs index 821f57cd1..18369e479 100644 --- a/src/Greenshot/Components/SoundHelper.cs +++ b/src/Greenshot/Components/SoundHelper.cs @@ -24,7 +24,6 @@ #region Usings using System; -using System.ComponentModel.Composition; using System.IO; using System.Reflection; using System.Resources; @@ -42,8 +41,8 @@ namespace Greenshot.Components /// Create to fix the sometimes wrongly played sample, especially after first start from IDE /// See: http://www.codeproject.com/KB/audio-video/soundplayerbug.aspx?msg=2487569 /// - [StartupAction(StartupOrder = (int)GreenshotStartupOrder.Sound), ShutdownAction] - public class SoundHelper : IStartupAction, IShutdownAction + [ServiceOrder(GreenshotStartupOrder.Sound)] + public class SoundHelper : IStartup, IShutdown { private readonly ICoreConfiguration _coreConfiguration; private static readonly LogSource Log = new LogSource(); @@ -52,7 +51,6 @@ namespace Greenshot.Components private static SoundHelper _instance; - [ImportingConstructor] public SoundHelper(ICoreConfiguration coreConfiguration) { _coreConfiguration = coreConfiguration; diff --git a/src/Greenshot/Destinations/ClipboardDestination.cs b/src/Greenshot/Destinations/ClipboardDestination.cs index bd46bf6e5..ceca392f3 100644 --- a/src/Greenshot/Destinations/ClipboardDestination.cs +++ b/src/Greenshot/Destinations/ClipboardDestination.cs @@ -26,7 +26,8 @@ using System; using System.Drawing; using System.Windows.Forms; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Configuration; @@ -38,9 +39,16 @@ namespace Greenshot.Destinations /// /// Description of ClipboardDestination. /// - [Destination("Clipboard",2)] + [Destination("Clipboard", DestinationOrder.Clipboard)] public class ClipboardDestination : AbstractDestination { + public ClipboardDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { + } + public override string Description => GreenshotLanguage.SettingsDestinationClipboard; public override Keys EditorShortcutKeys => Keys.Control | Keys.Shift | Keys.C; @@ -58,7 +66,7 @@ namespace Greenshot.Destinations catch (Exception) { // TODO: Change to general logic in ProcessExport - surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString(LangKey.editor_clipboardfailed)); + surface.SendMessageEvent(this, SurfaceMessageTyp.Error, "Error"); //GreenshotLanguage.editorclipboardfailed); } ProcessExport(exportInformation, surface); return exportInformation; diff --git a/src/Greenshot/Destinations/EmailDestination.cs b/src/Greenshot/Destinations/EmailDestination.cs index 0598fca5d..76fc62f16 100644 --- a/src/Greenshot/Destinations/EmailDestination.cs +++ b/src/Greenshot/Destinations/EmailDestination.cs @@ -26,10 +26,10 @@ using System; using System.Drawing; using System.Windows.Forms; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; -using Greenshot.Configuration; using Greenshot.Helpers; #endregion @@ -39,7 +39,7 @@ namespace Greenshot.Destinations /// /// Description of EmailDestination. /// - [Destination("EMail", 3)] + [Destination("EMail", DestinationOrder.Email)] public class EmailDestination : AbstractDestination { private static readonly Bitmap MailIcon = GreenshotResources.GetBitmap("Email.Image"); @@ -61,7 +61,13 @@ namespace Greenshot.Destinations } } - public override string Description + public EmailDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage) : base(coreConfiguration, greenshotLanguage) + { + } + + public override string Description { get { diff --git a/src/Greenshot/Destinations/FileDestination.cs b/src/Greenshot/Destinations/FileDestination.cs index e89cd5429..fc7742c16 100644 --- a/src/Greenshot/Destinations/FileDestination.cs +++ b/src/Greenshot/Destinations/FileDestination.cs @@ -28,7 +28,8 @@ using System.Drawing; using System.IO; using System.Windows.Forms; using Dapplo.Log; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -41,12 +42,18 @@ namespace Greenshot.Destinations /// /// Description of FileSaveAsDestination. /// - [Destination("FileNoDialog", 0)] + [Destination("FileNoDialog", DestinationOrder.FileNoDialog)] public class FileDestination : AbstractDestination { private static readonly LogSource Log = new LogSource(); - public override string Description => GreenshotLanguage.QuicksettingsDestinationFile; + public FileDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage) : base(coreConfiguration, greenshotLanguage) + { + } + + public override string Description => GreenshotLanguage.QuicksettingsDestinationFile; public override Keys EditorShortcutKeys => Keys.Control | Keys.S; diff --git a/src/Greenshot/Destinations/FileWithDialogDestination.cs b/src/Greenshot/Destinations/FileWithDialogDestination.cs index 059d6143c..9ceb5dffd 100644 --- a/src/Greenshot/Destinations/FileWithDialogDestination.cs +++ b/src/Greenshot/Destinations/FileWithDialogDestination.cs @@ -23,10 +23,10 @@ #region Usings -using System.ComponentModel.Composition; using System.Drawing; using System.Windows.Forms; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Configuration; @@ -38,19 +38,17 @@ namespace Greenshot.Destinations /// /// Description of FileWithDialog. /// - [Destination("FileDialog", 0)] + [Destination("FileDialog", DestinationOrder.FileDialog)] public class FileWithDialogDestination : AbstractDestination { - private readonly ICoreConfiguration _coreConfiguration; - - [ImportingConstructor] - public FileWithDialogDestination(ICoreConfiguration coreConfiguration) + public FileWithDialogDestination(ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) { - _coreConfiguration = coreConfiguration; } - public override string Description => Language.GetString(LangKey.settings_destination_fileas); + public override string Description => Language.GetString(LangKey.settings_destination_fileas); public override Keys EditorShortcutKeys => Keys.Control | Keys.Shift | Keys.S; @@ -66,7 +64,7 @@ namespace Greenshot.Destinations exportInformation.ExportMade = true; exportInformation.Filepath = savedTo; captureDetails.Filename = savedTo; - _coreConfiguration.OutputFileAsFullpath = savedTo; + CoreConfiguration.OutputFileAsFullpath = savedTo; } ProcessExport(exportInformation, surface); return exportInformation; diff --git a/src/Greenshot/Destinations/PickerDestination.cs b/src/Greenshot/Destinations/PickerDestination.cs index 735bfef19..db9850dc6 100644 --- a/src/Greenshot/Destinations/PickerDestination.cs +++ b/src/Greenshot/Destinations/PickerDestination.cs @@ -23,15 +23,12 @@ #region Usings -using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Linq; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; -using Greenshot.Addons.Extensions; using Greenshot.Addons.Interfaces; -using Greenshot.Configuration; #endregion @@ -40,14 +37,21 @@ namespace Greenshot.Destinations /// /// The PickerDestination shows a context menu with all possible destinations, so the user can "pick" one /// - [Destination("Picker", 1)] + [Destination("Picker", DestinationOrder.Picker)] public class PickerDestination : AbstractDestination { - public override string Description => GreenshotLanguage.SettingsDestinationPicker; - private readonly string _pickerDesignation = typeof(PickerDestination).GetDesignation(); + private readonly DestinationHolder _destinationHolder; - [ImportMany(AllowRecomposition = true)] - private IEnumerable> _destinations = null; + public override string Description => GreenshotLanguage.SettingsDestinationPicker; + + public PickerDestination( + DestinationHolder destinationHolder, + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) : base(coreConfiguration, greenshotLanguage) + { + _destinationHolder = destinationHolder; + } /// /// Export the capture with the destination picker @@ -64,11 +68,8 @@ namespace Greenshot.Destinations { foreach (var outputDestination in CoreConfiguration.PickerDestinations) { - var pickerDestination = _destinations - .Where(destination => !"Picker".Equals(destination.Metadata.Designation)) - .Where(destination => destination.Value.IsActive) - .Where(destination => outputDestination == destination.Value.Designation) - .Select(d => d.Value).FirstOrDefault(); + var pickerDestination = _destinationHolder.SortedActiveDestinations + .FirstOrDefault(destination => outputDestination == destination.Designation); if (pickerDestination != null) { @@ -78,12 +79,8 @@ namespace Greenshot.Destinations } else { - foreach (var pickerDestination in _destinations - .Where(destination => !"Picker".Equals(destination.Metadata.Designation)) - .Where(destination => destination.Value.IsActive) - .OrderBy(destination => destination.Metadata.Priority) - .ThenBy(destination => destination.Value.Description) - .Select(d => d.Value)) + foreach (var pickerDestination in _destinationHolder.SortedActiveDestinations + .Where(destination => !"Picker".Equals(destination.Designation))) { pickerDestinations.Add(pickerDestination); } diff --git a/src/Greenshot/Destinations/PrinterDestination.cs b/src/Greenshot/Destinations/PrinterDestination.cs index 446438a2b..04ebcdd4f 100644 --- a/src/Greenshot/Destinations/PrinterDestination.cs +++ b/src/Greenshot/Destinations/PrinterDestination.cs @@ -28,7 +28,8 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; -using Greenshot.Addons.Addons; +using Greenshot.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; using Greenshot.Configuration; @@ -41,16 +42,21 @@ namespace Greenshot.Destinations /// /// Description of PrinterDestination. /// - [Destination("Printer", 2)] + [Destination("Printer", DestinationOrder.Printer)] public class PrinterDestination : AbstractDestination { private readonly string _printerName; - public PrinterDestination() + public PrinterDestination(ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ): base(coreConfiguration, greenshotLanguage) { } - public PrinterDestination(string printerName) + protected PrinterDestination( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + string printerName) : this(coreConfiguration, greenshotLanguage) { _printerName = printerName; } @@ -101,7 +107,7 @@ namespace Greenshot.Destinations }); foreach (var printer in printers) { - yield return new PrinterDestination(printer); + yield return new PrinterDestination(CoreConfiguration, GreenshotLanguage, printer); } } diff --git a/src/Greenshot/FodyWeavers.xml b/src/Greenshot/FodyWeavers.xml index 95147e215..d099b051c 100644 --- a/src/Greenshot/FodyWeavers.xml +++ b/src/Greenshot/FodyWeavers.xml @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/src/Greenshot/Forms/AboutForm.cs b/src/Greenshot/Forms/AboutForm.cs index 012a4f9ab..015e90c86 100644 --- a/src/Greenshot/Forms/AboutForm.cs +++ b/src/Greenshot/Forms/AboutForm.cs @@ -49,8 +49,9 @@ namespace Greenshot.Forms /// public sealed partial class AboutForm : AnimatingBaseForm { + private static readonly LogSource Log = new LogSource(); // Variables are used to define the location of the dots - private const int w = 13; + private const int w = 13; private const int p1 = 7; private const int p2 = p1 + w; private const int p3 = p2 + w; @@ -58,7 +59,6 @@ namespace Greenshot.Forms private const int p5 = p4 + w; private const int p6 = p5 + w; private const int p7 = p6 + w; - private static readonly LogSource Log = new LogSource(); private readonly Color _backColor = Color.FromArgb(61, 61, 61); private readonly ColorAnimator _backgroundAnimation; private readonly IList _colorFlow = new List(); diff --git a/src/Greenshot/Forms/LanguageDialog.cs b/src/Greenshot/Forms/LanguageDialog.cs index 28dcb55fd..7f311948b 100644 --- a/src/Greenshot/Forms/LanguageDialog.cs +++ b/src/Greenshot/Forms/LanguageDialog.cs @@ -24,6 +24,7 @@ #region Usings using System; +using System.Linq; using System.Threading; using System.Windows.Forms; using Dapplo.Log; @@ -90,7 +91,7 @@ namespace Greenshot.Forms return; } - comboBoxLanguage.SelectedValue = Language.SupportedLanguages[0].Ietf; + comboBoxLanguage.SelectedValue = Language.SupportedLanguages.Keys.FirstOrDefault(); Language.CurrentLanguage = SelectedLanguage; _properOkPressed = true; Close(); diff --git a/src/Greenshot/Forms/MainForm.cs b/src/Greenshot/Forms/MainForm.cs index d6e91fcae..43a944a65 100644 --- a/src/Greenshot/Forms/MainForm.cs +++ b/src/Greenshot/Forms/MainForm.cs @@ -26,7 +26,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.ComponentModel.Composition; using System.Diagnostics; using System.Drawing; using System.IO; @@ -34,6 +33,7 @@ using System.Linq; using System.Reflection; using System.Threading; using System.Windows.Forms; +using Autofac.Features.OwnedInstances; using Caliburn.Micro; using Dapplo.Ini; using Dapplo.Windows.Desktop; @@ -49,16 +49,14 @@ using Dapplo.Windows.DesktopWindowsManager; using Dapplo.Windows.Dpi.Enums; using Dapplo.Windows.Dpi.Forms; using Dapplo.Windows.Kernel32; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Core.Enums; using Greenshot.Addons.Extensions; using Greenshot.Addons.Interfaces; -using Greenshot.Addons.Interfaces.Plugin; using Greenshot.Gfx; using Greenshot.Ui.Configuration.ViewModels; -using Action = System.Action; using LangKey = Greenshot.Configuration.LangKey; using Message = System.Windows.Forms.Message; using Screen = System.Windows.Forms.Screen; @@ -70,35 +68,38 @@ namespace Greenshot.Forms /// /// Description of MainForm. /// - [Export(typeof(IGreenshotHost))] - [Export] - public partial class MainForm : BaseForm, IGreenshotHost + public partial class MainForm : BaseForm { private static readonly LogSource Log = new LogSource(); private readonly ICoreConfiguration _coreConfiguration; private readonly IWindowManager _windowManager; private readonly ConfigViewModel _configViewModel; - private readonly IEnumerable _destinations; // Timer for the double click test private readonly Timer _doubleClickTimer = new Timer(); // Make sure we have only one settings form - private readonly SettingsForm _settingsForm; - // Make sure we have only one about form - private AboutForm _aboutForm; + private readonly Func> _settingsFormFactory; + private readonly Func> _aboutFormFactory; + + private readonly DestinationHolder _destinationHolder; // Thumbnail preview private ThumbnailForm _thumbnailForm; public DpiHandler ContextMenuDpiHandler { get; private set; } - [ImportingConstructor] - public MainForm(ICoreConfiguration coreConfiguration, IWindowManager windowManager, ConfigViewModel configViewModel, SettingsForm settingsForm, [ImportMany] IEnumerable destinations) + public MainForm(ICoreConfiguration coreConfiguration, + IWindowManager windowManager, + ConfigViewModel configViewModel, + Func> settingsFormFactory, + Func> aboutFormFactory, + DestinationHolder destinationHolder) { _coreConfiguration = coreConfiguration; _windowManager = windowManager; _configViewModel = configViewModel; - _settingsForm = settingsForm; - _destinations = destinations; + _settingsFormFactory = settingsFormFactory; + _aboutFormFactory = aboutFormFactory; + _destinationHolder = destinationHolder; Instance = this; } @@ -110,7 +111,6 @@ namespace Greenshot.Forms // try { - _settingsForm.Initialize(); InitializeComponent(); SetupBitmapScaleHandler(); } @@ -168,15 +168,8 @@ namespace Greenshot.Forms public static MainForm Instance { get; set; } - public Form GreenshotForm => Instance; - public NotifyIcon NotifyIcon => notifyIcon; - /// - /// Main context menu - /// - public ContextMenuStrip MainMenu => contextMenu; - private void BalloonTipClicked(object sender, EventArgs e) { try @@ -286,7 +279,7 @@ namespace Greenshot.Forms if (File.Exists(_coreConfiguration.OutputFileAsFullpath)) { - CaptureHelper.CaptureFile(_coreConfiguration.OutputFileAsFullpath, _destinations.Find("Editor")); + CaptureHelper.CaptureFile(_coreConfiguration.OutputFileAsFullpath, _destinationHolder.SortedActiveDestinations.Find("Editor")); } break; case ClickActions.OPEN_SETTINGS: @@ -745,7 +738,7 @@ namespace Greenshot.Forms private void CaptureClipboardToolStripMenuItemClick(object sender, EventArgs e) { - BeginInvoke(new Action(() => CaptureHelper.CaptureClipboard())); + BeginInvoke(new System.Action(() => CaptureHelper.CaptureClipboard())); } private void OpenFileToolStripMenuItemClick(object sender, EventArgs e) @@ -856,19 +849,14 @@ namespace Greenshot.Forms _windowManager.ShowDialog(_configViewModel); } - if (Application.OpenForms.OfType().Any()) + using (var settingsForm = _settingsFormFactory()) { - // TODO: Await? - InteropWindowFactory.CreateFor(_settingsForm.Handle).ToForegroundAsync(); - } - else - { - if (_settingsForm.ShowDialog() == DialogResult.OK) + settingsForm.Value.Initialize(); + if (settingsForm.Value.ShowDialog() == DialogResult.OK) { InitializeQuickSettingsMenu(); } } - } /// @@ -883,24 +871,9 @@ namespace Greenshot.Forms public void ShowAbout() { - if (_aboutForm != null) + using (var aboutForm = _aboutFormFactory()) { - // TODO: Await? - InteropWindowFactory.CreateFor(_aboutForm.Handle).ToForegroundAsync(); - } - else - { - try - { - using (_aboutForm = new AboutForm()) - { - _aboutForm.ShowDialog(this); - } - } - finally - { - _aboutForm = null; - } + aboutForm.Value.ShowDialog(this); } } @@ -968,7 +941,7 @@ namespace Greenshot.Forms Text = Language.GetString(LangKey.settings_destination) }; // Working with IDestination: - foreach (var destination in _destinations) + foreach (var destination in _destinationHolder.SortedActiveDestinations) { selectList.AddItem(destination.Description, destination, _coreConfiguration.OutputDestinations.Contains(destination.Designation)); } diff --git a/src/Greenshot/Forms/SettingsForm.cs b/src/Greenshot/Forms/SettingsForm.cs index 6da3b26c0..e6e436934 100644 --- a/src/Greenshot/Forms/SettingsForm.cs +++ b/src/Greenshot/Forms/SettingsForm.cs @@ -25,7 +25,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Drawing; using System.Globalization; using System.IO; @@ -36,7 +35,7 @@ using System.Windows.Forms; using Dapplo.Log; using Dapplo.Windows.Common; using Dapplo.Windows.DesktopWindowsManager; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Controls; using Greenshot.Addons.Core; using Greenshot.Addons.Core.Enums; @@ -53,22 +52,20 @@ namespace Greenshot.Forms /// /// Description of SettingsForm. /// - [Export] public partial class SettingsForm : BaseForm { - private static readonly LogSource Log = new LogSource(); + private readonly DestinationHolder _destinationHolder; + private static readonly LogSource Log = new LogSource(); private readonly ToolTip _toolTip = new ToolTip(); private int _daysbetweencheckPreviousValue; private bool _inHotkey; - [ImportMany(AllowRecomposition = true)] - private IEnumerable> _destinations = null; - - public SettingsForm() - { - // Make sure the store isn't called to early, that's why we do it manually + public SettingsForm(DestinationHolder destinationHolder) + { + _destinationHolder = destinationHolder; + // Make sure the store isn't called to early, that's why we do it manually ManualStoreFields = true; - } + } public void Initialize() { @@ -374,9 +371,7 @@ namespace Greenshot.Forms var imageList = new ImageList(); listview_destinations.SmallImageList = imageList; var imageNr = -1; - foreach (var currentDestination in _destinations.Where(d => d.Value.IsActive) - .OrderBy(destination => destination.Metadata.Priority).ThenBy(d => d.Value.Description) - .Select(d => d.Value)) + foreach (var currentDestination in _destinationHolder.SortedActiveDestinations) { var destinationImage = currentDestination.GetDisplayIcon(DpiHandler.Dpi); if (destinationImage != null) diff --git a/src/Greenshot/Greenshot.csproj b/src/Greenshot/Greenshot.csproj index d44dbe983..25576fad8 100644 --- a/src/Greenshot/Greenshot.csproj +++ b/src/Greenshot/Greenshot.csproj @@ -18,8 +18,21 @@ 3.5 + latest + + ..\packages\Autofac.4.8.1\lib\net45\Autofac.dll + + + ..\packages\Autofac.Extras.AttributeMetadata.4.0.1\lib\net45\Autofac.Extras.AttributeMetadata.dll + + + ..\packages\Autofac.Extras.CommonServiceLocator.5.0.0\lib\net45\Autofac.Extras.CommonServiceLocator.dll + + + ..\packages\Autofac.Mef.4.0.0\lib\net45\Autofac.Integration.Mef.dll + ..\packages\Ben.Demystifier.0.1.1\lib\net45\Ben.Demystifier.dll @@ -41,35 +54,38 @@ ..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll - - ..\packages\Costura.Fody.2.0.0\lib\net452\Costura.dll + + ..\packages\Costura.Fody.2.0.1\lib\net452\Costura.dll - - ..\packages\Dapplo.Addons.0.5.56\lib\net45\Dapplo.Addons.dll + + ..\packages\Dapplo.Addons.1.0.44\lib\net45\Dapplo.Addons.dll - - ..\packages\Dapplo.Addons.Bootstrapper.0.5.56\lib\net45\Dapplo.Addons.Bootstrapper.dll + + ..\packages\Dapplo.Addons.Bootstrapper.1.0.44\lib\net45\Dapplo.Addons.Bootstrapper.dll - - ..\packages\Dapplo.CaliburnMicro.0.5.28\lib\net45\Dapplo.CaliburnMicro.dll + + ..\packages\Dapplo.Addons.Config.1.0.44\lib\net45\Dapplo.Addons.Config.dll - - ..\packages\Dapplo.CaliburnMicro.Configuration.0.5.28\lib\net45\Dapplo.CaliburnMicro.Configuration.dll + + ..\packages\Dapplo.CaliburnMicro.1.0.42\lib\net45\Dapplo.CaliburnMicro.dll - - ..\packages\Dapplo.CaliburnMicro.Dapp.0.5.28\lib\net45\Dapplo.CaliburnMicro.Dapp.dll + + ..\packages\Dapplo.CaliburnMicro.Configuration.1.0.42\lib\net45\Dapplo.CaliburnMicro.Configuration.dll - - ..\packages\Dapplo.CaliburnMicro.Menu.0.5.28\lib\net45\Dapplo.CaliburnMicro.Menu.dll + + ..\packages\Dapplo.CaliburnMicro.Dapp.1.0.42\lib\net45\Dapplo.CaliburnMicro.Dapp.dll - - ..\packages\Dapplo.CaliburnMicro.Metro.0.5.28\lib\net45\Dapplo.CaliburnMicro.Metro.dll + + ..\packages\Dapplo.CaliburnMicro.Menu.1.0.42\lib\net45\Dapplo.CaliburnMicro.Menu.dll - - ..\packages\Dapplo.CaliburnMicro.Security.0.5.28\lib\net45\Dapplo.CaliburnMicro.Security.dll + + ..\packages\Dapplo.CaliburnMicro.Metro.1.0.42\lib\net45\Dapplo.CaliburnMicro.Metro.dll - - ..\packages\Dapplo.CaliburnMicro.Translations.0.5.28\lib\net45\Dapplo.CaliburnMicro.Translations.dll + + ..\packages\Dapplo.CaliburnMicro.Security.1.0.42\lib\net45\Dapplo.CaliburnMicro.Security.dll + + + ..\packages\Dapplo.CaliburnMicro.Translations.1.0.42\lib\net45\Dapplo.CaliburnMicro.Translations.dll ..\packages\Dapplo.HttpExtensions.0.8.35\lib\net45\Dapplo.HttpExtensions.dll @@ -80,14 +96,14 @@ ..\packages\Dapplo.HttpExtensions.OAuth.0.8.35\lib\net45\Dapplo.HttpExtensions.OAuth.dll - - ..\packages\Dapplo.Ini.0.5.24\lib\net45\Dapplo.Ini.dll + + ..\packages\Dapplo.Ini.0.5.28\lib\net45\Dapplo.Ini.dll ..\packages\Dapplo.InterfaceImpl.0.2.12\lib\net45\Dapplo.InterfaceImpl.dll - - ..\packages\Dapplo.Language.0.5.24\lib\net45\Dapplo.Language.dll + + ..\packages\Dapplo.Language.0.5.28\lib\net45\Dapplo.Language.dll ..\packages\Dapplo.Log.1.2.1\lib\net45\Dapplo.Log.dll @@ -140,8 +156,8 @@ ..\packages\gong-wpf-dragdrop.1.1.0\lib\net45\GongSolutions.Wpf.DragDrop.dll - - ..\packages\MahApps.Metro.1.6.1\lib\net45\MahApps.Metro.dll + + ..\packages\MahApps.Metro.1.6.4\lib\net45\MahApps.Metro.dll ..\packages\MahApps.Metro.IconPacks.2.2.0\lib\net45\MahApps.Metro.IconPacks.dll @@ -202,7 +218,6 @@ - @@ -265,6 +280,7 @@ BugReportForm.cs + @@ -533,9 +549,9 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + - + \ No newline at end of file diff --git a/src/Greenshot/GreenshotAutofacModule.cs b/src/Greenshot/GreenshotAutofacModule.cs new file mode 100644 index 000000000..a96e877ff --- /dev/null +++ b/src/Greenshot/GreenshotAutofacModule.cs @@ -0,0 +1,111 @@ +#region Greenshot GNU General Public License + +// Greenshot - a free and open source screenshot tool +// Copyright (C) 2007-2018 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 . + +#endregion + +using Autofac; +using Dapplo.Addons; +using Dapplo.CaliburnMicro; +using Dapplo.CaliburnMicro.Configuration; +using Dapplo.CaliburnMicro.Security; +using Greenshot.Addons.Components; +using Greenshot.Components; +using Greenshot.Forms; +using Greenshot.Ui.Configuration.ViewModels; +using Greenshot.Ui.Misc.ViewModels; + +namespace Greenshot +{ + /// + public class GreenshotAutofacModule : AddonModule + { + protected override void Load(ContainerBuilder builder) + { + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + builder + .RegisterType() + .As() + .AsSelf() + .SingleInstance(); + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + + builder + .RegisterType() + .As() + .As() + .AsSelf() + .SingleInstance(); + + builder + .RegisterType() + .As() + .As() + .SingleInstance(); + + builder + .RegisterType() + .AsSelf(); + + // TODO: Should be removed + builder + .RegisterType() + .AsSelf(); + + // Configuration + builder + .RegisterAssemblyTypes(ThisAssembly) + .AssignableTo() + .As() + .SingleInstance(); + + // Startup and Shutdown + builder + .RegisterAssemblyTypes(ThisAssembly) + .AssignableTo() + .As() + .SingleInstance(); + + builder + .RegisterType() + .AsSelf(); + + builder + .RegisterType() + .AsSelf() + .SingleInstance(); + + // Destinations + builder + .RegisterAssemblyTypes(ThisAssembly) + .AssignableTo() + .As() + .SingleInstance(); + + base.Load(builder); + } + } +} diff --git a/src/Greenshot/Help/HelpFileLoader.cs b/src/Greenshot/Help/HelpFileLoader.cs index 49b2ff7de..9c1b48ec6 100644 --- a/src/Greenshot/Help/HelpFileLoader.cs +++ b/src/Greenshot/Help/HelpFileLoader.cs @@ -42,7 +42,7 @@ namespace Greenshot.Help public static void LoadHelp() { - var uri = FindOnlineHelpUrl(Language.CurrentLanguage) ?? Language.HelpFilePath; + var uri = FindOnlineHelpUrl(Language.CurrentLanguage);// ?? Language.HelpFilePath; Process.Start(uri); } diff --git a/src/Greenshot/Helpers/CaptureHelper.cs b/src/Greenshot/Helpers/CaptureHelper.cs index 3d3431c30..735f6365d 100644 --- a/src/Greenshot/Helpers/CaptureHelper.cs +++ b/src/Greenshot/Helpers/CaptureHelper.cs @@ -43,7 +43,7 @@ using Dapplo.Windows.Common.Structs; using Dapplo.Windows.DesktopWindowsManager; using Dapplo.Windows.Kernel32; using Dapplo.Windows.User32; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Addons.Core.Enums; using Greenshot.Addons.Extensions; @@ -71,14 +71,14 @@ namespace Greenshot.Helpers // TODO: when we get the screen capture code working correctly, this needs to be enabled //private static ScreenCaptureHelper screenCapture = null; private IList _windows = new List(); - private readonly IEnumerable _destinations; + private readonly DestinationHolder _destinationHolder; private readonly IEnumerable _processors; public CaptureHelper(CaptureMode captureMode) { _captureMode = captureMode; _capture = new Capture(); - _destinations = ServiceLocator.Current.GetAllInstances(); + _destinationHolder = ServiceLocator.Current.GetInstance(); _processors = ServiceLocator.Current.GetAllInstances(); } @@ -412,13 +412,13 @@ namespace Greenshot.Helpers if (_capture.CaptureDetails.HasDestination(typeof(PickerDestination).GetDesignation())) { _capture.CaptureDetails.ClearDestinations(); - _capture.CaptureDetails.AddDestination(_destinations.Find("Editor")); - _capture.CaptureDetails.AddDestination(_destinations.Find(typeof(PickerDestination))); + _capture.CaptureDetails.AddDestination(_destinationHolder.SortedActiveDestinations.Find("Editor")); + _capture.CaptureDetails.AddDestination(_destinationHolder.SortedActiveDestinations.Find(typeof(PickerDestination))); } else { _capture.CaptureDetails.ClearDestinations(); - _capture.CaptureDetails.AddDestination(_destinations.Find("Editor")); + _capture.CaptureDetails.AddDestination(_destinationHolder.SortedActiveDestinations.Find("Editor")); } HandleCapture(); } @@ -438,10 +438,10 @@ namespace Greenshot.Helpers if (filename.ToLower().EndsWith("." + OutputFormats.greenshot)) { - var surface = ImageOutput.SurfaceFactory.CreateExport().Value; + var surface = ImageOutput.SurfaceFactory(); surface = ImageOutput.LoadGreenshotSurface(filename, surface); surface.CaptureDetails = _capture.CaptureDetails; - _destinations.Find("Editor")?.ExportCaptureAsync(true, surface, _capture.CaptureDetails).Wait(); + _destinationHolder.SortedActiveDestinations.Find("Editor")?.ExportCaptureAsync(true, surface, _capture.CaptureDetails).Wait(); break; } } @@ -477,13 +477,13 @@ namespace Greenshot.Helpers if (_capture.CaptureDetails.HasDestination(typeof(PickerDestination).GetDesignation())) { _capture.CaptureDetails.ClearDestinations(); - _capture.CaptureDetails.AddDestination(_destinations.Find("Editor")); - _capture.CaptureDetails.AddDestination(_destinations.Find(typeof(PickerDestination))); + _capture.CaptureDetails.AddDestination(_destinationHolder.SortedActiveDestinations.Find("Editor")); + _capture.CaptureDetails.AddDestination(_destinationHolder.SortedActiveDestinations.Find(typeof(PickerDestination))); } else { _capture.CaptureDetails.ClearDestinations(); - _capture.CaptureDetails.AddDestination(_destinations.Find("Editor")); + _capture.CaptureDetails.AddDestination(_destinationHolder.SortedActiveDestinations.Find("Editor")); } HandleCapture(); } @@ -553,7 +553,7 @@ namespace Greenshot.Helpers { foreach (var destinationDesignation in CoreConfig.OutputDestinations) { - var destination = _destinations.Find(destinationDesignation); + var destination = _destinationHolder.SortedActiveDestinations.Find(destinationDesignation); if (destination != null) { _capture.CaptureDetails.AddDestination(destination); @@ -676,7 +676,7 @@ namespace Greenshot.Helpers } // Create Surface with capture, this way elements can be added automatically (like the mouse cursor) - var surface = ImageOutput.SurfaceFactory.CreateExport().Value; + var surface = ImageOutput.SurfaceFactory(); surface.SetCapture(_capture); surface.Modified = !outputMade; @@ -705,7 +705,7 @@ namespace Greenshot.Helpers if (captureDetails.HasDestination(typeof(PickerDestination).GetDesignation())) { - _destinations.Find(typeof(PickerDestination))?.ExportCaptureAsync(false, surface, captureDetails).Wait(); + _destinationHolder.SortedActiveDestinations.Find(typeof(PickerDestination))?.ExportCaptureAsync(false, surface, captureDetails).Wait(); captureDetails.CaptureDestinations.Clear(); canDisposeSurface = false; } diff --git a/src/Greenshot/Startup.cs b/src/Greenshot/Startup.cs index a56807fea..24b22ff9f 100644 --- a/src/Greenshot/Startup.cs +++ b/src/Greenshot/Startup.cs @@ -21,14 +21,18 @@ #endregion -#region Usings using System; using System.Diagnostics; using System.Drawing; using System.Text; using System.Windows; using System.Windows.Forms; +using Autofac; +using Autofac.Extras.CommonServiceLocator; +using Autofac.Features.OwnedInstances; using Caliburn.Micro; +using CommonServiceLocator; +using Dapplo.Addons.Bootstrapper; using Dapplo.CaliburnMicro.Dapp; using Dapplo.Ini.Converters; using Dapplo.Language; @@ -39,7 +43,7 @@ using Greenshot.Addons; using Greenshot.Addons.Core; using Greenshot.Ui.Misc.ViewModels; using Point = System.Drawing.Point; -#endregion + namespace Greenshot { @@ -52,7 +56,7 @@ namespace Greenshot /// Start Greenshot application /// [STAThread] - public static void Main(string[] arguments) + public static int Main(string[] arguments) { // TODO: Set via build StringEncryptionTypeConverter.RgbIv = "dlgjowejgogkklwj"; @@ -64,8 +68,13 @@ namespace Greenshot // Initialize a debug logger for Dapplo packages LogSettings.RegisterDefaultLogger(LogLevels.Verbose); #endif + var applicationConfig = ApplicationConfig.Create() + .WithApplicationName("Greenshot") + .WithMutex("F48E86D3-E34C-4DB7-8F8F-9A0EA55F0D08") + .WithAssemblyNames("Dapplo.Addons.Config") + .WithAssemblyPatterns("Greenshot.Addon*"); - var application = new Dapplication("Greenshot", "F48E86D3-E34C-4DB7-8F8F-9A0EA55F0D08") + var application = new Dapplication(applicationConfig) { ShutdownMode = ShutdownMode.OnExplicitShutdown }; @@ -77,17 +86,18 @@ namespace Greenshot ShowInstances(); // Don't start the dapplication, exit with 0 application.Shutdown(0); - return; + return -1; } RegisterErrorHandlers(application); - // Load the assemblies, and run the application - application.Bootstrapper.FindAndLoadAssemblies("Dapplo.*"); - // Make sure the non-plugin DLLs are also loaded, so exports are available. - application.Bootstrapper.FindAndLoadAssemblies("Greenshot*"); - application.Bootstrapper.FindAndLoadAssemblies("Greenshot*", extensions: new[] { "gsp" }); + application.Bootstrapper.OnContainerCreated += container => + { + var autofacServiceLocator = new AutofacServiceLocator(container); + ServiceLocator.SetLocatorProvider(() => autofacServiceLocator); + }; application.Run(); + return 0; } /// @@ -96,26 +106,29 @@ namespace Greenshot /// Dapplication private static void RegisterErrorHandlers(Dapplication application) { - application.OnUnhandledAppDomainException += (exception, b) => DisplayErrorViewModel(exception); - application.OnUnhandledDispatcherException += DisplayErrorViewModel; - application.OnUnhandledTaskException += DisplayErrorViewModel; + application.OnUnhandledAppDomainException += (exception, b) => DisplayErrorViewModel(application, exception); + application.OnUnhandledDispatcherException += exception => DisplayErrorViewModel(application, exception); + application.OnUnhandledTaskException += exception => DisplayErrorViewModel(application, exception); } /// /// Show the exception /// + /// Dapplication /// Exception - private static void DisplayErrorViewModel(Exception exception) + private static void DisplayErrorViewModel(Dapplication application, Exception exception) { - var windowManager = Dapplication.Current.Bootstrapper.GetExport().Value; - var errorViewModel = Dapplication.Current.Bootstrapper.GetExport().Value; - if (windowManager == null || errorViewModel == null) + var windowManager = application.Bootstrapper.Container.Resolve(); + using (var errorViewModel = application.Bootstrapper.Container.Resolve>()) { - return; + if (windowManager == null || errorViewModel == null) + { + return; + } + errorViewModel.Value.SetExceptionToDisplay(exception); + windowManager.ShowDialog(errorViewModel.Value); } - errorViewModel.SetExceptionToDisplay(exception); - windowManager.ShowWindow(errorViewModel); } /// diff --git a/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigNodeViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigNodeViewModel.cs index 08273ffcf..e8279d5c6 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigNodeViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigNodeViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; using Greenshot.Addons; @@ -32,12 +31,10 @@ namespace Greenshot.Ui.Configuration.ViewModels /// /// This represents a node in the config /// - [Export(typeof(IConfigScreen))] public sealed class CaptureConfigNodeViewModel : ConfigNode { public IGreenshotLanguage GreenshotLanguage { get; } - [ImportingConstructor] public CaptureConfigNodeViewModel(IGreenshotLanguage greenshotLanguage) { GreenshotLanguage = greenshotLanguage; diff --git a/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigViewModel.cs index bdbd5de39..00c7b14bc 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/CaptureConfigViewModel.cs @@ -22,7 +22,6 @@ #endregion using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -35,7 +34,6 @@ using Greenshot.Configuration; namespace Greenshot.Ui.Configuration.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class CaptureConfigViewModel : SimpleConfigScreen { /// @@ -43,14 +41,20 @@ namespace Greenshot.Ui.Configuration.ViewModels /// private CompositeDisposable _disposables; - [Import] - public ICoreConfiguration CoreConfiguration { get; set; } + public ICoreConfiguration CoreConfiguration { get; } - [Import] - public IConfigTranslations ConfigTranslations { get; set; } + public IConfigTranslations ConfigTranslations { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } + + public CaptureConfigViewModel(ICoreConfiguration coreConfiguration, + IConfigTranslations configTranslations, + IGreenshotLanguage greenshotLanguage) + { + CoreConfiguration = coreConfiguration; + ConfigTranslations = configTranslations; + GreenshotLanguage = greenshotLanguage; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot/Ui/Configuration/ViewModels/ConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/ConfigViewModel.cs index 5dcc1ed1a..8921fa75f 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/ConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/ConfigViewModel.cs @@ -23,7 +23,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Composition; using System.Reactive.Disposables; using System.Windows; using System.Windows.Controls; @@ -40,7 +39,6 @@ namespace Greenshot.Ui.Configuration.ViewModels /// The settings view model is, well... for the settings :) /// It is a conductor where only one item is active. /// - [Export] public sealed class ConfigViewModel : Config, IHaveIcon { /// @@ -63,9 +61,8 @@ namespace Greenshot.Ui.Configuration.ViewModels /// public IConfigTranslations ConfigTranslations { get; } - [ImportingConstructor] public ConfigViewModel( - [ImportMany] IEnumerable> configScreens, + IEnumerable> configScreens, IGreenshotLanguage greenshotLanguage, IConfigTranslations configTranslations) { diff --git a/src/Greenshot/Ui/Configuration/ViewModels/DestinationPickerConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/DestinationPickerConfigViewModel.cs index 01f5bbf85..b95477ee7 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/DestinationPickerConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/DestinationPickerConfigViewModel.cs @@ -21,40 +21,46 @@ #endregion -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel.Composition; using System.Linq; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; using Greenshot.Addons; -using Greenshot.Addons.Addons; +using Greenshot.Addons.Components; using Greenshot.Addons.Core; using Greenshot.Configuration; namespace Greenshot.Ui.Configuration.ViewModels { - [Export(typeof(IConfigScreen))] + /// + /// The ViewModel for the DestinationPicket configuration + /// public sealed class DestinationPickerConfigViewModel : SimpleConfigScreen { + private readonly DestinationHolder _destinationHolder; + /// /// Here all disposables are registered, so we can clean the up /// private CompositeDisposable _disposables; - [Import] - public ICoreConfiguration CoreConfiguration { get; set; } + public ICoreConfiguration CoreConfiguration { get; } + public IConfigTranslations ConfigTranslations { get; } + public IGreenshotLanguage GreenshotLanguage { get; } - [Import] - public IConfigTranslations ConfigTranslations { get; set; } - - [ImportMany(AllowRecomposition = true)] - private IEnumerable> AllDestinations = null; - - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public DestinationPickerConfigViewModel( + ICoreConfiguration coreConfiguration, + IConfigTranslations configTranslations, + IGreenshotLanguage greenshotLanguage, + DestinationHolder destinationHolder + ) + { + _destinationHolder = destinationHolder; + ConfigTranslations = configTranslations; + GreenshotLanguage = greenshotLanguage; + CoreConfiguration = coreConfiguration; + } public override void Initialize(IConfig config) { @@ -78,11 +84,9 @@ namespace Greenshot.Ui.Configuration.ViewModels { foreach (var outputDestination in CoreConfiguration.PickerDestinations) { - var pickerDestination = AllDestinations - .Where(destination => !"Picker".Equals(destination.Metadata.Designation)) - .Where(destination => destination.Value.IsActive) - .Where(destination => outputDestination == destination.Value.Designation) - .Select(d => d.Value).FirstOrDefault(); + var pickerDestination = _destinationHolder.SortedActiveDestinations + .Where(destination => !"Picker".Equals(destination.Designation)) + .FirstOrDefault(destination => outputDestination == destination.Designation); if (pickerDestination != null) { @@ -92,23 +96,16 @@ namespace Greenshot.Ui.Configuration.ViewModels } else { - foreach (var pickerDestination in AllDestinations - .Where(destination => !"Picker".Equals(destination.Metadata.Designation)) - .Where(destination => destination.Value.IsActive) - .OrderBy(destination => destination.Metadata.Priority) - .ThenBy(destination => destination.Value.Description) - .Select(d => d.Value)) + foreach (var pickerDestination in _destinationHolder.SortedActiveDestinations + .Where(destination => !"Picker".Equals(destination.Designation))) { UsedDestinations.Add(pickerDestination); } } AvailableDestinations.Clear(); - foreach (var destination in AllDestinations - .Where(destination => !"Picker".Equals(destination.Metadata.Designation)) - .Where(destination => destination.Value.IsActive) - .Where(destination => UsedDestinations.All(pickerDestination => pickerDestination.Designation != destination.Value.Designation)) - .OrderBy(destination => destination.Metadata.Priority).ThenBy(destination => destination.Value.Description) - .Select(d => d.Value)) + foreach (var destination in _destinationHolder.SortedActiveDestinations + .Where(destination => !"Picker".Equals(destination.Designation)) + .Where(destination => UsedDestinations.All(pickerDestination => pickerDestination.Designation != destination.Designation))) { AvailableDestinations.Add(destination); } diff --git a/src/Greenshot/Ui/Configuration/ViewModels/DestinationsConfigNodeViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/DestinationsConfigNodeViewModel.cs index 200b16399..bbe3048c0 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/DestinationsConfigNodeViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/DestinationsConfigNodeViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; using Greenshot.Addons; @@ -32,12 +31,10 @@ namespace Greenshot.Ui.Configuration.ViewModels /// /// This represents a node in the config /// - [Export(typeof(IConfigScreen))] public sealed class DestinationsConfigNodeViewModel : ConfigNode { public IGreenshotLanguage GreenshotLanguage { get; } - [ImportingConstructor] public DestinationsConfigNodeViewModel(IGreenshotLanguage greenshotLanguage) { GreenshotLanguage = greenshotLanguage; diff --git a/src/Greenshot/Ui/Configuration/ViewModels/GeneralConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/GeneralConfigViewModel.cs index a27e9e230..163ffdc0b 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/GeneralConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/GeneralConfigViewModel.cs @@ -21,18 +21,15 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; -using Dapplo.CaliburnMicro.Security; using Greenshot.Addons; using Greenshot.Addons.Core; using Greenshot.Components; namespace Greenshot.Ui.Configuration.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class GeneralConfigViewModel : SimpleConfigScreen { /// @@ -40,14 +37,22 @@ namespace Greenshot.Ui.Configuration.ViewModels /// private CompositeDisposable _disposables; - [Import] - public ICoreConfiguration CoreConfiguration { get; set; } + public ICoreConfiguration CoreConfiguration { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } - [Import(typeof(IAuthenticationProvider))] - public AuthenticationProvider AuthenticationProvider { get; set; } + public AuthenticationProvider AuthenticationProvider { get; } + + public GeneralConfigViewModel( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + AuthenticationProvider authenticationProvider + ) + { + CoreConfiguration = coreConfiguration; + GreenshotLanguage = greenshotLanguage; + AuthenticationProvider = authenticationProvider; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot/Ui/Configuration/ViewModels/NetworkConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/NetworkConfigViewModel.cs index cfa38ee6e..fc53cecdf 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/NetworkConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/NetworkConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using System.Windows; using Dapplo.CaliburnMicro.Configuration; @@ -32,7 +31,6 @@ using Greenshot.Addons.Core; namespace Greenshot.Ui.Configuration.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class NetworkConfigViewModel : AuthenticatedConfigNode { /// @@ -40,11 +38,18 @@ namespace Greenshot.Ui.Configuration.ViewModels /// private CompositeDisposable _disposables; - [Import] - public INetworkConfiguration NetworkConfiguration { get; set; } + public INetworkConfiguration NetworkConfiguration { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } + + public NetworkConfigViewModel( + INetworkConfiguration networkConfiguration, + IGreenshotLanguage greenshotLanguage + ) + { + NetworkConfiguration = networkConfiguration; + GreenshotLanguage = greenshotLanguage; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot/Ui/Configuration/ViewModels/OutputConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/OutputConfigViewModel.cs index 92bc6aaa6..57f9a1fc1 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/OutputConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/OutputConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -31,7 +30,6 @@ using Greenshot.Addons.ViewModels; namespace Greenshot.Ui.Configuration.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class OutputConfigViewModel : SimpleConfigScreen { /// @@ -39,15 +37,22 @@ namespace Greenshot.Ui.Configuration.ViewModels /// private CompositeDisposable _disposables; - [Import] public ICoreConfiguration CoreConfiguration { get; set; } - [Import] public IGreenshotLanguage GreenshotLanguage { get; set; } - [Import] public FileConfigPartViewModel FileConfigPartViewModel { get; set; } + public OutputConfigViewModel( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + FileConfigPartViewModel fileConfigPartViewModel) + { + CoreConfiguration = coreConfiguration; + GreenshotLanguage = greenshotLanguage; + FileConfigPartViewModel = fileConfigPartViewModel; + } + public override void Initialize(IConfig config) { // Prepare disposables diff --git a/src/Greenshot/Ui/Configuration/ViewModels/PrintConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/PrintConfigViewModel.cs index a43cb96de..97957303f 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/PrintConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/PrintConfigViewModel.cs @@ -21,7 +21,6 @@ #endregion -using System.ComponentModel.Composition; using System.Reactive.Disposables; using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Extensions; @@ -30,7 +29,6 @@ using Greenshot.Addons.Core; namespace Greenshot.Ui.Configuration.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class PrintConfigViewModel : SimpleConfigScreen { /// @@ -38,11 +36,18 @@ namespace Greenshot.Ui.Configuration.ViewModels /// private CompositeDisposable _disposables; - [Import] - public ICoreConfiguration CoreConfiguration { get; set; } + public ICoreConfiguration CoreConfiguration { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } + + public PrintConfigViewModel( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage + ) + { + CoreConfiguration = coreConfiguration; + GreenshotLanguage = greenshotLanguage; + } public override void Initialize(IConfig config) { diff --git a/src/Greenshot/Ui/Configuration/ViewModels/UiConfigViewModel.cs b/src/Greenshot/Ui/Configuration/ViewModels/UiConfigViewModel.cs index 976b4064e..730ed2301 100644 --- a/src/Greenshot/Ui/Configuration/ViewModels/UiConfigViewModel.cs +++ b/src/Greenshot/Ui/Configuration/ViewModels/UiConfigViewModel.cs @@ -24,7 +24,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel.Composition; using System.Linq; using System.Reactive.Disposables; using Caliburn.Micro; @@ -39,7 +38,6 @@ using Greenshot.Configuration; namespace Greenshot.Ui.Configuration.ViewModels { - [Export(typeof(IConfigScreen))] public sealed class UiConfigViewModel : SimpleConfigScreen { /// @@ -69,20 +67,31 @@ namespace Greenshot.Ui.Configuration.ViewModels public bool CanChangeLanguage => !string.IsNullOrWhiteSpace(CoreConfiguration.Language) && CoreConfiguration.Language != LanguageLoader.Current.CurrentLanguage; - [Import] - public IMetroConfiguration MetroConfiguration { get; set; } + public IMetroConfiguration MetroConfiguration { get; } - [Import] - public IConfigTranslations ConfigTranslations { get; set; } + public IConfigTranslations ConfigTranslations { get; } - [Import] - public ICoreConfiguration CoreConfiguration { get; set; } + public ICoreConfiguration CoreConfiguration { get; } - [Import] - public IGreenshotLanguage GreenshotLanguage { get; set; } + public IGreenshotLanguage GreenshotLanguage { get; } - [Import(typeof(IWindowManager))] - private MetroWindowManager MetroWindowManager { get; set; } + private MetroWindowManager MetroWindowManager { get; } + + public UiConfigViewModel( + ICoreConfiguration coreConfiguration, + IGreenshotLanguage greenshotLanguage, + IConfigTranslations configTranslations, + IMetroConfiguration metroConfiguration, + MetroWindowManager metroWindowManager + + ) + { + CoreConfiguration = coreConfiguration; + GreenshotLanguage = greenshotLanguage; + ConfigTranslations = configTranslations; + MetroConfiguration = metroConfiguration; + MetroWindowManager = metroWindowManager; + } public override void Commit() { diff --git a/src/Greenshot/Ui/Misc/ViewModels/ErrorViewModel.cs b/src/Greenshot/Ui/Misc/ViewModels/ErrorViewModel.cs index 67ac43bc5..6d7d44d0d 100644 --- a/src/Greenshot/Ui/Misc/ViewModels/ErrorViewModel.cs +++ b/src/Greenshot/Ui/Misc/ViewModels/ErrorViewModel.cs @@ -24,7 +24,6 @@ #region Usings using System; -using System.ComponentModel.Composition; using System.Diagnostics; using Caliburn.Micro; using Dapplo.CaliburnMicro; @@ -37,16 +36,13 @@ namespace Greenshot.Ui.Misc.ViewModels /// /// /// - [Export] public class ErrorViewModel : Screen { public IGreenshotLanguage GreenshotLanguage { get; } public IVersionProvider VersionProvider { get; } - [ImportingConstructor] public ErrorViewModel(IGreenshotLanguage greenshotLanguage, - [Import(AllowDefault = true)] - IVersionProvider versionProvider) + IVersionProvider versionProvider = null) { GreenshotLanguage = greenshotLanguage; VersionProvider = versionProvider; diff --git a/src/Greenshot/Ui/Misc/ViewModels/SplashViewModel.cs b/src/Greenshot/Ui/Misc/ViewModels/SplashViewModel.cs index 031bde6b1..deb221f1a 100644 --- a/src/Greenshot/Ui/Misc/ViewModels/SplashViewModel.cs +++ b/src/Greenshot/Ui/Misc/ViewModels/SplashViewModel.cs @@ -23,22 +23,19 @@ #region Usings -using System.ComponentModel.Composition; using Caliburn.Micro; using Dapplo.CaliburnMicro; -using Greenshot.Addons.Interfaces.Plugin; +using Greenshot.Forms; #endregion namespace Greenshot.Ui.Misc.ViewModels { - //[Export(typeof(IShell))] public class SplashViewModel : Screen, IShell { - private readonly IGreenshotHost _mainForm; + private readonly MainForm _mainForm; - [ImportingConstructor] - public SplashViewModel(IGreenshotHost mainForm) + public SplashViewModel(MainForm mainForm) { _mainForm = mainForm; } @@ -46,7 +43,7 @@ namespace Greenshot.Ui.Misc.ViewModels protected override void OnActivate() { base.OnActivate(); - _mainForm.GreenshotForm.Show(); + _mainForm.Show(); } } } diff --git a/src/Greenshot/packages.config b/src/Greenshot/packages.config index 33abdd5de..df62fa510 100644 --- a/src/Greenshot/packages.config +++ b/src/Greenshot/packages.config @@ -1,27 +1,32 @@  + + + + - - - - - - - - - - + + + + + + + + + + + - + - + @@ -40,7 +45,7 @@ - + diff --git a/src/GreenshotOCRCommand/GreenshotOCRCommand.csproj b/src/GreenshotOCRCommand/GreenshotOCRCommand.csproj index 44bef236f..fc419ccad 100644 --- a/src/GreenshotOCRCommand/GreenshotOCRCommand.csproj +++ b/src/GreenshotOCRCommand/GreenshotOCRCommand.csproj @@ -80,9 +80,9 @@ -mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\GreenshotOCRPlugin" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\GreenshotOCRPlugin" -copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName).config" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\GreenshotOCRPlugin" +mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\Greenshot.Addon.OCR" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\Greenshot.Addon.OCR" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName).config" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\Greenshot.Addon.OCR diff --git a/src/NuGet.Config b/src/NuGet.Config new file mode 100644 index 000000000..739aab3f5 --- /dev/null +++ b/src/NuGet.Config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file