Added a way to call the configuration directly out of the export notification.

This commit is contained in:
Robin 2018-08-07 16:17:40 +02:00
commit b0827c7db2
8 changed files with 62 additions and 9 deletions

View file

@ -53,6 +53,7 @@ namespace Greenshot.Addon.Imgur
builder builder
.RegisterType<ImgurConfigViewModel>() .RegisterType<ImgurConfigViewModel>()
.As<IConfigScreen>() .As<IConfigScreen>()
.AsSelf()
.SingleInstance(); .SingleInstance();
builder builder
.RegisterType<ImgurHistoryViewModel>() .RegisterType<ImgurHistoryViewModel>()

View file

@ -59,6 +59,7 @@ namespace Greenshot.Addon.Imgur
private readonly IImgurLanguage _imgurLanguage; private readonly IImgurLanguage _imgurLanguage;
private readonly ImgurApi _imgurApi; private readonly ImgurApi _imgurApi;
private readonly ImgurHistoryViewModel _imgurHistoryViewModel; private readonly ImgurHistoryViewModel _imgurHistoryViewModel;
private readonly ImgurConfigViewModel _imgurConfigViewModel;
private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory; private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory;
private readonly IResourceProvider _resourceProvider; private readonly IResourceProvider _resourceProvider;
@ -70,6 +71,7 @@ namespace Greenshot.Addon.Imgur
IImgurLanguage imgurLanguage, IImgurLanguage imgurLanguage,
ImgurApi imgurApi, ImgurApi imgurApi,
ImgurHistoryViewModel imgurHistoryViewModel, ImgurHistoryViewModel imgurHistoryViewModel,
ImgurConfigViewModel imgurConfigViewModel,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory, Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory,
IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage) IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage)
{ {
@ -78,7 +80,8 @@ namespace Greenshot.Addon.Imgur
_imgurLanguage = imgurLanguage; _imgurLanguage = imgurLanguage;
_imgurApi = imgurApi; _imgurApi = imgurApi;
_imgurHistoryViewModel = imgurHistoryViewModel; _imgurHistoryViewModel = imgurHistoryViewModel;
_pleaseWaitFormFactory = pleaseWaitFormFactory; _imgurConfigViewModel = imgurConfigViewModel;
_pleaseWaitFormFactory = pleaseWaitFormFactory;
_resourceProvider = resourceProvider; _resourceProvider = resourceProvider;
} }
@ -105,7 +108,7 @@ namespace Greenshot.Addon.Imgur
ExportMade = uploadUrl != null, ExportMade = uploadUrl != null,
Uri = uploadUrl?.AbsoluteUri Uri = uploadUrl?.AbsoluteUri
}; };
_exportNotification.NotifyOfExport(this, exportInformation, surface); _exportNotification.NotifyOfExport(this, exportInformation, surface, _imgurConfigViewModel);
return exportInformation; return exportInformation;
} }

View file

@ -24,6 +24,7 @@
using System; using System;
using Autofac.Features.OwnedInstances; using Autofac.Features.OwnedInstances;
using Caliburn.Micro; using Caliburn.Micro;
using Dapplo.CaliburnMicro.Configuration;
using Dapplo.Log; using Dapplo.Log;
using Greenshot.Addons.Core; using Greenshot.Addons.Core;
using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces;
@ -39,12 +40,12 @@ namespace Greenshot.Addons.Components
private static readonly LogSource Log = new LogSource(); private static readonly LogSource Log = new LogSource();
private readonly ICoreConfiguration _coreConfiguration; private readonly ICoreConfiguration _coreConfiguration;
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly Func<IDestination, ExportInformation, ISurface, Owned<ExportNotificationViewModel>> _toastFactory; private readonly Func<IDestination, ExportInformation, ISurface, IConfigScreen, Owned<ExportNotificationViewModel>> _toastFactory;
public ExportNotification( public ExportNotification(
ICoreConfiguration coreConfiguration, ICoreConfiguration coreConfiguration,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
Func<IDestination, ExportInformation, ISurface, Owned<ExportNotificationViewModel>> toastFactory) Func<IDestination, ExportInformation, ISurface, IConfigScreen, Owned<ExportNotificationViewModel>> toastFactory)
{ {
_coreConfiguration = coreConfiguration; _coreConfiguration = coreConfiguration;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
@ -57,7 +58,8 @@ namespace Greenshot.Addons.Components
/// <param name="source">IDestination</param> /// <param name="source">IDestination</param>
/// <param name="exportInformation">ExportInformation</param> /// <param name="exportInformation">ExportInformation</param>
/// <param name="exportedSurface">ISurface</param> /// <param name="exportedSurface">ISurface</param>
public void NotifyOfExport(IDestination source, ExportInformation exportInformation, ISurface exportedSurface) /// <param name="configScreen">IConfigScreen option to specify which IConfigScreen belongs to the destination</param>
public void NotifyOfExport(IDestination source, ExportInformation exportInformation, ISurface exportedSurface, IConfigScreen configScreen = null)
{ {
if (exportInformation == null || !_coreConfiguration.ShowTrayNotification) if (exportInformation == null || !_coreConfiguration.ShowTrayNotification)
{ {
@ -65,7 +67,7 @@ namespace Greenshot.Addons.Components
return; return;
} }
// Create the ViewModel "part" // 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 // Prepare to dispose the view model parts automatically if it's finished
void DisposeHandler(object sender, DeactivationEventArgs args) void DisposeHandler(object sender, DeactivationEventArgs args)
{ {

View file

@ -40,6 +40,9 @@
<Reference Include="CommonServiceLocator, Version=2.0.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL"> <Reference Include="CommonServiceLocator, Version=2.0.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll</HintPath> <HintPath>..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference> </Reference>
<Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll</HintPath>
</Reference>
<Reference Include="CustomMarshalers" /> <Reference Include="CustomMarshalers" />
<Reference Include="Dapplo.Addons, Version=1.0.71.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Dapplo.Addons, Version=1.0.71.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Addons.1.0.71\lib\net461\Dapplo.Addons.dll</HintPath> <HintPath>..\packages\Dapplo.Addons.1.0.71\lib\net461\Dapplo.Addons.dll</HintPath>
@ -134,6 +137,9 @@
<Reference Include="Dapplo.Windows.User32, Version=0.5.104.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Dapplo.Windows.User32, Version=0.5.104.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Windows.User32.0.5.104\lib\net461\Dapplo.Windows.User32.dll</HintPath> <HintPath>..\packages\Dapplo.Windows.User32.0.5.104\lib\net461\Dapplo.Windows.User32.dll</HintPath>
</Reference> </Reference>
<Reference Include="MahApps.Metro.IconPacks, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net46\MahApps.Metro.IconPacks.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualBasic" /> <Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@ -159,7 +165,7 @@
<Reference Include="System.Windows" /> <Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Caliburn.Micro.3.2.0\lib\net45\System.Windows.Interactivity.dll</HintPath> <HintPath>..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />

View file

@ -24,6 +24,8 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Media; using System.Windows.Media;
using Caliburn.Micro;
using Dapplo.CaliburnMicro.Configuration;
using Dapplo.CaliburnMicro.Toasts.ViewModels; using Dapplo.CaliburnMicro.Toasts.ViewModels;
using Dapplo.Log; using Dapplo.Log;
using Dapplo.Windows.Extensions; using Dapplo.Windows.Extensions;
@ -36,9 +38,21 @@ namespace Greenshot.Addons.ViewModels
/// <inheritdoc /> /// <inheritdoc />
public class ExportNotificationViewModel : ToastBaseViewModel public class ExportNotificationViewModel : ToastBaseViewModel
{ {
private readonly IWindowManager _windowManager;
private readonly Config<IConfigScreen> _configViewModel;
private readonly IConfigScreen _configScreen;
private static readonly LogSource Log = new LogSource(); 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<IConfigScreen> configViewModel,
IConfigScreen configScreen = null)
{ {
_windowManager = windowManager;
_configViewModel = configViewModel;
_configScreen = configScreen;
Information = exportInformation; Information = exportInformation;
Source = source; Source = source;
@ -56,6 +70,22 @@ namespace Greenshot.Addons.ViewModels
public ExportInformation Information { get; } public ExportInformation Information { get; }
public bool CanConfigure => _configScreen != null;
public void Configure()
{
if (!CanConfigure)
{
return;
}
_configViewModel.CurrentConfigScreen = _configScreen;
if (!_configViewModel.IsActive)
{
_windowManager.ShowDialog(_configViewModel);
}
}
/// <summary> /// <summary>
/// Handle the click /// Handle the click
/// </summary> /// </summary>

View file

@ -6,6 +6,7 @@
xmlns:toastNotifications="clr-namespace:ToastNotifications.Core;assembly=ToastNotifications" xmlns:toastNotifications="clr-namespace:ToastNotifications.Core;assembly=ToastNotifications"
xmlns:viewModels="clr-namespace:Greenshot.Addons.ViewModels" xmlns:viewModels="clr-namespace:Greenshot.Addons.ViewModels"
xmlns:cal="http://www.caliburnproject.org" 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" mc:Ignorable="d" Background="{DynamicResource AccentBaseColorBrush}" Width="300" Height="256" Padding="5"
d:DataContext="{d:DesignInstance viewModels:ExportNotificationViewModel,IsDesignTimeCreatable=False}" d:DataContext="{d:DesignInstance viewModels:ExportNotificationViewModel,IsDesignTimeCreatable=False}"
d:DesignHeight="100" d:DesignWidth="200" HorizontalContentAlignment="Stretch" HorizontalAlignment="Right"> d:DesignHeight="100" d:DesignWidth="200" HorizontalContentAlignment="Stretch" HorizontalAlignment="Right">
@ -16,6 +17,7 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="32" /> <RowDefinition Height="32" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="32" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="32" /> <ColumnDefinition Width="32" />
@ -28,8 +30,14 @@
<TextBlock Text="{Binding Information.DestinationDesignation}" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Light" Foreground="{DynamicResource IdealForegroundColorBrush}" TextWrapping="WrapWithOverflow" Grid.Row="0" Grid.Column="1" /> <TextBlock Text="{Binding Information.DestinationDesignation}" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Light" Foreground="{DynamicResource IdealForegroundColorBrush}" TextWrapping="WrapWithOverflow" Grid.Row="0" Grid.Column="1" />
<Image Source="{Binding Source.DisplayIconWpf}" Stretch="Uniform" RenderOptions.BitmapScalingMode="Fant" UseLayoutRounding="True" VerticalAlignment="Top" Grid.Row="0" Grid.Column="2"/> <Image Source="{Binding Source.DisplayIconWpf}" Stretch="Uniform" RenderOptions.BitmapScalingMode="Fant" UseLayoutRounding="True" VerticalAlignment="Top" Grid.Row="0" Grid.Column="2"/>
<!-- Bottom row --> <!-- Middle row -->
<TextBlock Text="{Binding Information.ErrorMessage}" VerticalAlignment="Center" FontWeight="Bold" Visibility="{Binding Information.IsError, Converter={StaticResource BooleanToVisibility}}" Foreground="Red" TextWrapping="WrapWithOverflow" Grid.Row="1" Grid.Column="1" /> <TextBlock Text="{Binding Information.ErrorMessage}" VerticalAlignment="Center" FontWeight="Bold" Visibility="{Binding Information.IsError, Converter={StaticResource BooleanToVisibility}}" Foreground="Red" TextWrapping="WrapWithOverflow" Grid.Row="1" Grid.Column="1" />
<Image cal:Message.Attach="[Event MouseDown] = [Action OpenExport()]" Source="{Binding ExportBitmapSource}" Visibility="{Binding Information.IsOk, Converter={StaticResource BooleanToVisibility}}" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Uniform" RenderOptions.BitmapScalingMode="Fant" UseLayoutRounding="True" Grid.Row="1" Grid.Column="1"/> <Image cal:Message.Attach="[Event MouseDown] = [Action OpenExport()]" Source="{Binding ExportBitmapSource}" Visibility="{Binding Information.IsOk, Converter={StaticResource BooleanToVisibility}}" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Uniform" RenderOptions.BitmapScalingMode="Fant" UseLayoutRounding="True" Grid.Row="1" Grid.Column="1"/>
<!-- Bottom row -->
<TextBlock Text="{Binding Information.DestinationDescription}" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Light" Foreground="{DynamicResource IdealForegroundColorBrush}" TextWrapping="WrapWithOverflow" Grid.Row="2" Grid.Column="1" />
<Button x:Name="Configure" ToolTip="Configure" Style="{DynamicResource SquareButtonStyle}" Grid.Row="2" Grid.Column="2" >
<iconPacks:PackIconMaterial Kind="Settings" />
</Button>
</Grid> </Grid>
</toastNotifications:NotificationDisplayPart> </toastNotifications:NotificationDisplayPart>

View file

@ -6,6 +6,7 @@
<package id="Caliburn.Micro" version="3.2.0" targetFramework="net461" /> <package id="Caliburn.Micro" version="3.2.0" targetFramework="net461" />
<package id="Caliburn.Micro.Core" version="3.2.0" targetFramework="net461" /> <package id="Caliburn.Micro.Core" version="3.2.0" targetFramework="net461" />
<package id="CommonServiceLocator" version="2.0.3" targetFramework="net461" /> <package id="CommonServiceLocator" version="2.0.3" targetFramework="net461" />
<package id="ControlzEx" version="3.0.2.4" targetFramework="net461" />
<package id="Dapplo.Addons" version="1.0.71" targetFramework="net461" /> <package id="Dapplo.Addons" version="1.0.71" targetFramework="net461" />
<package id="Dapplo.Addons.Bootstrapper" version="1.0.71" targetFramework="net461" /> <package id="Dapplo.Addons.Bootstrapper" version="1.0.71" targetFramework="net461" />
<package id="Dapplo.CaliburnMicro" version="1.0.64" targetFramework="net461" /> <package id="Dapplo.CaliburnMicro" version="1.0.64" targetFramework="net461" />
@ -37,6 +38,7 @@
<package id="Dapplo.Windows.Messages" version="0.5.104" targetFramework="net461" /> <package id="Dapplo.Windows.Messages" version="0.5.104" targetFramework="net461" />
<package id="Dapplo.Windows.Shell32" version="0.5.104" targetFramework="net461" /> <package id="Dapplo.Windows.Shell32" version="0.5.104" targetFramework="net461" />
<package id="Dapplo.Windows.User32" version="0.5.104" targetFramework="net461" /> <package id="Dapplo.Windows.User32" version="0.5.104" targetFramework="net461" />
<package id="MahApps.Metro.IconPacks" version="2.3.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" /> <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="Svg" version="2.3.0" targetFramework="net461" /> <package id="Svg" version="2.3.0" targetFramework="net461" />
<package id="System.Reactive" version="4.0.0" targetFramework="net461" /> <package id="System.Reactive" version="4.0.0" targetFramework="net461" />

View file

@ -57,6 +57,7 @@ namespace Greenshot
builder builder
.RegisterType<ConfigViewModel>() .RegisterType<ConfigViewModel>()
.As<Config<IConfigScreen>>()
.AsSelf(); .AsSelf();
builder builder