From b0827c7db218d62821cdf183d83d493bee11a585 Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 7 Aug 2018 16:17:40 +0200 Subject: [PATCH] Added a way to call the configuration directly out of the export notification. --- src/Greenshot.Addon.Imgur/ImgurAddonModule.cs | 1 + src/Greenshot.Addon.Imgur/ImgurDestination.cs | 7 ++-- .../Components/ExportNotification.cs | 10 +++--- src/Greenshot.Addons/Greenshot.Addons.csproj | 8 ++++- .../ViewModels/ExportNotificationViewModel.cs | 32 ++++++++++++++++++- .../Views/ExportNotificationView.xaml | 10 +++++- src/Greenshot.Addons/packages.config | 2 ++ src/Greenshot/GreenshotAutofacModule.cs | 1 + 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/Greenshot.Addon.Imgur/ImgurAddonModule.cs b/src/Greenshot.Addon.Imgur/ImgurAddonModule.cs index 716000f94..5715462de 100644 --- a/src/Greenshot.Addon.Imgur/ImgurAddonModule.cs +++ b/src/Greenshot.Addon.Imgur/ImgurAddonModule.cs @@ -53,6 +53,7 @@ namespace Greenshot.Addon.Imgur builder .RegisterType() .As() + .AsSelf() .SingleInstance(); builder .RegisterType() diff --git a/src/Greenshot.Addon.Imgur/ImgurDestination.cs b/src/Greenshot.Addon.Imgur/ImgurDestination.cs index 2da0334be..b5dec259d 100644 --- a/src/Greenshot.Addon.Imgur/ImgurDestination.cs +++ b/src/Greenshot.Addon.Imgur/ImgurDestination.cs @@ -59,6 +59,7 @@ namespace Greenshot.Addon.Imgur private readonly IImgurLanguage _imgurLanguage; private readonly ImgurApi _imgurApi; private readonly ImgurHistoryViewModel _imgurHistoryViewModel; + private readonly ImgurConfigViewModel _imgurConfigViewModel; private readonly Func> _pleaseWaitFormFactory; private readonly IResourceProvider _resourceProvider; @@ -70,6 +71,7 @@ namespace Greenshot.Addon.Imgur IImgurLanguage imgurLanguage, ImgurApi imgurApi, ImgurHistoryViewModel imgurHistoryViewModel, + ImgurConfigViewModel imgurConfigViewModel, Func> pleaseWaitFormFactory, IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage) { @@ -78,7 +80,8 @@ namespace Greenshot.Addon.Imgur _imgurLanguage = imgurLanguage; _imgurApi = imgurApi; _imgurHistoryViewModel = imgurHistoryViewModel; - _pleaseWaitFormFactory = pleaseWaitFormFactory; + _imgurConfigViewModel = imgurConfigViewModel; + _pleaseWaitFormFactory = pleaseWaitFormFactory; _resourceProvider = resourceProvider; } @@ -105,7 +108,7 @@ namespace Greenshot.Addon.Imgur ExportMade = uploadUrl != null, Uri = uploadUrl?.AbsoluteUri }; - _exportNotification.NotifyOfExport(this, exportInformation, surface); + _exportNotification.NotifyOfExport(this, exportInformation, surface, _imgurConfigViewModel); return exportInformation; } diff --git a/src/Greenshot.Addons/Components/ExportNotification.cs b/src/Greenshot.Addons/Components/ExportNotification.cs index 81fa54532..e0cd02d76 100644 --- a/src/Greenshot.Addons/Components/ExportNotification.cs +++ b/src/Greenshot.Addons/Components/ExportNotification.cs @@ -24,6 +24,7 @@ using System; using Autofac.Features.OwnedInstances; using Caliburn.Micro; +using Dapplo.CaliburnMicro.Configuration; using Dapplo.Log; using Greenshot.Addons.Core; using Greenshot.Addons.Interfaces; @@ -39,12 +40,12 @@ namespace Greenshot.Addons.Components private static readonly LogSource Log = new LogSource(); private readonly ICoreConfiguration _coreConfiguration; private readonly IEventAggregator _eventAggregator; - private readonly Func> _toastFactory; + private readonly Func> _toastFactory; public ExportNotification( ICoreConfiguration coreConfiguration, IEventAggregator eventAggregator, - Func> toastFactory) + Func> toastFactory) { _coreConfiguration = coreConfiguration; _eventAggregator = eventAggregator; @@ -57,7 +58,8 @@ namespace Greenshot.Addons.Components /// IDestination /// ExportInformation /// ISurface - public void NotifyOfExport(IDestination source, ExportInformation exportInformation, ISurface exportedSurface) + /// IConfigScreen option to specify which IConfigScreen belongs to the destination + public void NotifyOfExport(IDestination source, ExportInformation exportInformation, ISurface exportedSurface, IConfigScreen configScreen = null) { if (exportInformation == null || !_coreConfiguration.ShowTrayNotification) { @@ -65,7 +67,7 @@ namespace Greenshot.Addons.Components return; } // Create the ViewModel "part" - var message = _toastFactory(source, exportInformation, exportedSurface); + var message = _toastFactory(source, exportInformation, exportedSurface, configScreen); // Prepare to dispose the view model parts automatically if it's finished void DisposeHandler(object sender, DeactivationEventArgs args) { diff --git a/src/Greenshot.Addons/Greenshot.Addons.csproj b/src/Greenshot.Addons/Greenshot.Addons.csproj index dcdf06c8d..28e1a8bc7 100644 --- a/src/Greenshot.Addons/Greenshot.Addons.csproj +++ b/src/Greenshot.Addons/Greenshot.Addons.csproj @@ -40,6 +40,9 @@ ..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll + + ..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll + ..\packages\Dapplo.Addons.1.0.71\lib\net461\Dapplo.Addons.dll @@ -134,6 +137,9 @@ ..\packages\Dapplo.Windows.User32.0.5.104\lib\net461\Dapplo.Windows.User32.dll + + ..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net46\MahApps.Metro.IconPacks.dll + @@ -159,7 +165,7 @@ - ..\packages\Caliburn.Micro.3.2.0\lib\net45\System.Windows.Interactivity.dll + ..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll diff --git a/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs b/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs index ebdeb0ff2..4a0829520 100644 --- a/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs +++ b/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs @@ -24,6 +24,8 @@ using System; using System.Diagnostics; using System.Windows.Media; +using Caliburn.Micro; +using Dapplo.CaliburnMicro.Configuration; using Dapplo.CaliburnMicro.Toasts.ViewModels; using Dapplo.Log; using Dapplo.Windows.Extensions; @@ -36,9 +38,21 @@ namespace Greenshot.Addons.ViewModels /// public class ExportNotificationViewModel : ToastBaseViewModel { + private readonly IWindowManager _windowManager; + private readonly Config _configViewModel; + private readonly IConfigScreen _configScreen; private static readonly LogSource Log = new LogSource(); - public ExportNotificationViewModel(IDestination source, ExportInformation exportInformation, ISurface exportedSurface) + public ExportNotificationViewModel( + IDestination source, + ExportInformation exportInformation, + ISurface exportedSurface, + IWindowManager windowManager, + Config configViewModel, + IConfigScreen configScreen = null) { + _windowManager = windowManager; + _configViewModel = configViewModel; + _configScreen = configScreen; Information = exportInformation; Source = source; @@ -56,6 +70,22 @@ namespace Greenshot.Addons.ViewModels public ExportInformation Information { get; } + public bool CanConfigure => _configScreen != null; + + public void Configure() + { + if (!CanConfigure) + { + return; + } + + _configViewModel.CurrentConfigScreen = _configScreen; + if (!_configViewModel.IsActive) + { + _windowManager.ShowDialog(_configViewModel); + } + } + /// /// Handle the click /// diff --git a/src/Greenshot.Addons/Views/ExportNotificationView.xaml b/src/Greenshot.Addons/Views/ExportNotificationView.xaml index b63994dee..1cdfb5ac9 100644 --- a/src/Greenshot.Addons/Views/ExportNotificationView.xaml +++ b/src/Greenshot.Addons/Views/ExportNotificationView.xaml @@ -6,6 +6,7 @@ xmlns:toastNotifications="clr-namespace:ToastNotifications.Core;assembly=ToastNotifications" xmlns:viewModels="clr-namespace:Greenshot.Addons.ViewModels" xmlns:cal="http://www.caliburnproject.org" + xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" mc:Ignorable="d" Background="{DynamicResource AccentBaseColorBrush}" Width="300" Height="256" Padding="5" d:DataContext="{d:DesignInstance viewModels:ExportNotificationViewModel,IsDesignTimeCreatable=False}" d:DesignHeight="100" d:DesignWidth="200" HorizontalContentAlignment="Stretch" HorizontalAlignment="Right"> @@ -16,6 +17,7 @@ + @@ -28,8 +30,14 @@ - + + + + + diff --git a/src/Greenshot.Addons/packages.config b/src/Greenshot.Addons/packages.config index aaf8920ca..17f5cf972 100644 --- a/src/Greenshot.Addons/packages.config +++ b/src/Greenshot.Addons/packages.config @@ -6,6 +6,7 @@ + @@ -37,6 +38,7 @@ + diff --git a/src/Greenshot/GreenshotAutofacModule.cs b/src/Greenshot/GreenshotAutofacModule.cs index bf6255bdf..cbf43592c 100644 --- a/src/Greenshot/GreenshotAutofacModule.cs +++ b/src/Greenshot/GreenshotAutofacModule.cs @@ -57,6 +57,7 @@ namespace Greenshot builder .RegisterType() + .As>() .AsSelf(); builder