Small changes reducing code, and to make the export window a bit nicer.

This commit is contained in:
Robin 2018-08-07 14:42:30 +02:00
commit 4fae9d3d89
33 changed files with 198 additions and 217 deletions

View file

@ -56,6 +56,7 @@ namespace Greenshot.Addon.Box
public class BoxDestination : AbstractDestination
{
private static readonly LogSource Log = new LogSource();
private readonly ExportNotification _exportNotification;
private readonly IBoxConfiguration _boxConfiguration;
private readonly IBoxLanguage _boxLanguage;
private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory;
@ -73,8 +74,9 @@ namespace Greenshot.Addon.Box
IBoxLanguage boxLanguage,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory,
INetworkConfiguration networkConfiguration,
IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage, exportNotification)
IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_boxConfiguration = boxConfiguration;
_boxLanguage = boxLanguage;
_pleaseWaitFormFactory = pleaseWaitFormFactory;
@ -125,7 +127,7 @@ namespace Greenshot.Addon.Box
exportInformation.ExportMade = true;
exportInformation.Uri = uploadUrl;
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -86,7 +86,7 @@ namespace Greenshot.Addon.Confluence
IConfluenceConfiguration confluenceConfiguration,
IConfluenceLanguage confluenceLanguage,
Func<Owned<PleaseWaitForm>> pleaseWaitFormFactory
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_confluenceConfiguration = confluenceConfiguration;
@ -180,7 +180,7 @@ namespace Greenshot.Addon.Confluence
exportInformation.ErrorMessage = errorMessage;
}
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -63,6 +63,7 @@ namespace Greenshot.Addon.Dropbox
private readonly IDropboxConfiguration _dropboxPluginConfiguration;
private readonly IDropboxLanguage _dropboxLanguage;
private readonly IResourceProvider _resourceProvider;
private readonly ExportNotification _exportNotification;
private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory;
private OAuth2Settings _oAuth2Settings;
private IHttpBehaviour _oAuthHttpBehaviour;
@ -76,11 +77,12 @@ namespace Greenshot.Addon.Dropbox
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_dropboxPluginConfiguration = dropboxPluginConfiguration;
_dropboxLanguage = dropboxLanguage;
_resourceProvider = resourceProvider;
_exportNotification = exportNotification;
_pleaseWaitFormFactory = pleaseWaitFormFactory;
_oAuth2Settings = new OAuth2Settings
@ -140,7 +142,7 @@ namespace Greenshot.Addon.Dropbox
}
}
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -50,16 +50,18 @@ namespace Greenshot.Addon.ExternalCommand
private readonly ExternalCommandDefinition _externalCommandDefinition;
private readonly IExternalCommandConfiguration _externalCommandConfiguration;
private readonly ExportNotification _exportNotification;
public ExternalCommandDestination(ExternalCommandDefinition defintion,
IExternalCommandConfiguration externalCommandConfiguration,
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_externalCommandDefinition = defintion;
_externalCommandConfiguration = externalCommandConfiguration;
_exportNotification = exportNotification;
}
/// <inheritdoc />
@ -108,7 +110,7 @@ namespace Greenshot.Addon.ExternalCommand
}
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -64,6 +64,7 @@ namespace Greenshot.Addon.Flickr
private readonly IFlickrConfiguration _flickrConfiguration;
private readonly IFlickrLanguage _flickrLanguage;
private readonly IResourceProvider _resourceProvider;
private readonly ExportNotification _exportNotification;
private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory;
private readonly OAuth1Settings _oAuthSettings;
private readonly OAuth1HttpBehaviour _oAuthHttpBehaviour;
@ -88,11 +89,12 @@ namespace Greenshot.Addon.Flickr
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_flickrConfiguration = flickrConfiguration;
_flickrLanguage = flickrLanguage;
_resourceProvider = resourceProvider;
_exportNotification = exportNotification;
_pleaseWaitFormFactory = pleaseWaitFormFactory;
_oAuthSettings = new OAuth1Settings
@ -147,7 +149,7 @@ namespace Greenshot.Addon.Flickr
ExportMade = flickrUri != null,
Uri = flickrUri
};
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -59,6 +59,7 @@ namespace Greenshot.Addon.GooglePhotos
private readonly IGooglePhotosLanguage _googlePhotosLanguage;
private readonly INetworkConfiguration _networkConfiguration;
private readonly IResourceProvider _resourceProvider;
private readonly ExportNotification _exportNotification;
private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory;
private readonly OAuth2Settings _oAuth2Settings;
@ -71,12 +72,13 @@ namespace Greenshot.Addon.GooglePhotos
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_googlePhotosConfiguration = googlePhotosConfiguration;
_googlePhotosLanguage = googlePhotosLanguage;
_networkConfiguration = networkConfiguration;
_resourceProvider = resourceProvider;
_exportNotification = exportNotification;
_pleaseWaitFormFactory = pleaseWaitFormFactory;
_oAuth2Settings = new OAuth2Settings
@ -123,7 +125,7 @@ namespace Greenshot.Addon.GooglePhotos
exportInformation.ExportMade = true;
exportInformation.Uri = uploadUrl;
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -54,6 +54,7 @@ namespace Greenshot.Addon.Imgur
public class ImgurDestination : AbstractDestination
{
private static readonly LogSource Log = new LogSource();
private readonly ExportNotification _exportNotification;
private readonly IImgurConfiguration _imgurConfiguration;
private readonly IImgurLanguage _imgurLanguage;
private readonly ImgurApi _imgurApi;
@ -70,8 +71,9 @@ namespace Greenshot.Addon.Imgur
ImgurApi imgurApi,
ImgurHistoryViewModel imgurHistoryViewModel,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory,
IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage, exportNotification)
IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_imgurConfiguration = imgurConfiguration;
_imgurLanguage = imgurLanguage;
_imgurApi = imgurApi;
@ -103,7 +105,7 @@ namespace Greenshot.Addon.Imgur
ExportMade = uploadUrl != null,
Uri = uploadUrl?.AbsoluteUri
};
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -74,7 +74,7 @@ namespace Greenshot.Addon.Jira
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_jiraConfiguration = jiraConfiguration;
_jiraLanguage = jiraLanguage;
@ -239,7 +239,7 @@ namespace Greenshot.Addon.Jira
}
}
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -59,7 +59,7 @@ namespace Greenshot.Addon.LegacyEditor
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification,
EditorFactory editorFactory,
IEditorLanguage editorLanguage) : base(coreConfiguration, greenshotLanguage, exportNotification)
IEditorLanguage editorLanguage) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_editorFactory = editorFactory;
@ -130,7 +130,7 @@ namespace Greenshot.Addon.LegacyEditor
exportInformation.ExportMade = true;
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
// Workaround for the modified flag when using the editor.
surface.Modified = modified;
return exportInformation;

View file

@ -49,6 +49,7 @@ namespace Greenshot.Addon.Lutim {
private readonly ILutimLanguage _lutimLanguage;
private readonly LutimApi _lutimApi;
private readonly IResourceProvider _resourceProvider;
private readonly ExportNotification _exportNotification;
private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory;
public LutimDestination(ILutimConfiguration lutimConfiguration,
@ -59,12 +60,13 @@ namespace Greenshot.Addon.Lutim {
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_lutimConfiguration = lutimConfiguration;
_lutimLanguage = lutimLanguage;
_lutimApi = lutimApi;
_resourceProvider = resourceProvider;
_exportNotification = exportNotification;
_pleaseWaitFormFactory = pleaseWaitFormFactory;
}
@ -89,7 +91,7 @@ namespace Greenshot.Addon.Lutim {
ExportMade = uploadUrl != null,
Uri = uploadUrl
};
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -59,7 +59,7 @@ namespace Greenshot.Addon.OCR
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_ocrConfiguration = ocrConfiguration;

View file

@ -54,7 +54,7 @@ namespace Greenshot.Addon.Office.Destinations
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_exePath = PluginUtils.GetExePath("EXCEL.EXE");
@ -111,7 +111,7 @@ namespace Greenshot.Addon.Office.Destinations
ExcelExporter.InsertIntoNewWorkbook(imageFile, surface.Screenshot.Size);
}
exportInformation.ExportMade = true;
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
// Cleanup imageFile if we created it here, so less tmp-files are generated and left
if (createdFile)
{

View file

@ -54,7 +54,7 @@ namespace Greenshot.Addon.Office.Destinations
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_exePath = PluginUtils.GetExePath("ONENOTE.EXE");

View file

@ -65,7 +65,7 @@ namespace Greenshot.Addon.Office.Destinations
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_officeConfiguration = officeConfiguration;
_exportNotification = exportNotification;
@ -198,7 +198,7 @@ namespace Greenshot.Addon.Office.Destinations
_officeConfiguration.EmailBCC, null);
}
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -57,7 +57,7 @@ namespace Greenshot.Addon.Office.Destinations
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_exePath = PluginUtils.GetExePath("POWERPNT.EXE");
@ -144,7 +144,7 @@ namespace Greenshot.Addon.Office.Destinations
exportInformation.ExportMade = PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
}
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -58,7 +58,7 @@ namespace Greenshot.Addon.Office.Destinations
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
_exePath = PluginUtils.GetExePath("WINWORD.EXE");
@ -162,7 +162,7 @@ namespace Greenshot.Addon.Office.Destinations
}
}
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -63,6 +63,7 @@ namespace Greenshot.Addon.OneDrive
private readonly IOneDriveLanguage _oneDriveLanguage;
private readonly IResourceProvider _resourceProvider;
private readonly Func<CancellationTokenSource, Owned<PleaseWaitForm>> _pleaseWaitFormFactory;
private readonly ExportNotification _exportNotification;
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");
@ -79,12 +80,13 @@ namespace Greenshot.Addon.OneDrive
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_oneDriveConfiguration = oneDriveConfiguration;
_oneDriveLanguage = oneDriveLanguage;
_resourceProvider = resourceProvider;
_pleaseWaitFormFactory = pleaseWaitFormFactory;
_exportNotification = exportNotification;
// Configure the OAuth2 settings for OneDrive communication
_oauth2Settings = new OAuth2Settings
{
@ -136,7 +138,7 @@ namespace Greenshot.Addon.OneDrive
ExportMade = uploadUrl != null,
Uri = uploadUrl?.AbsoluteUri
};
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
@ -239,9 +241,11 @@ namespace Greenshot.Addon.OneDrive
var localBehaviour = _oneDriveHttpBehaviour.ShallowClone();
var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);
oauthHttpBehaviour.MakeCurrent();
var body = new OneDriveGetLinkRequest();
body.Scope = oneDriveLinkType == OneDriveLinkType.@public ? "anonymous" : "organization";
body.Type = "view";
var body = new OneDriveGetLinkRequest
{
Scope = oneDriveLinkType == OneDriveLinkType.@public ? "anonymous" : "organization",
Type = "view"
};
return await sharableLink.PostAsync<OneDriveGetLinkResponse>(body);
}
}

View file

@ -74,7 +74,7 @@ namespace Greenshot.Addon.Photobucket
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_photobucketConfiguration = photobucketConfiguration;
_photobucketLanguage = photobucketLanguage;
@ -230,7 +230,7 @@ namespace Greenshot.Addon.Photobucket
exportInformation.ExportMade = true;
exportInformation.Uri = uploaded.Original;
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -69,7 +69,7 @@ namespace Greenshot.Addon.Tfs
TfsClient tfsClient,
Func<CancellationTokenSource, Owned<PleaseWaitForm>> pleaseWaitFormFactory,
IResourceProvider resourceProvider,
ExportNotification exportNotification) : base(coreConfiguration, greenshotLanguage, exportNotification)
ExportNotification exportNotification) : base(coreConfiguration, greenshotLanguage)
{
_tfsConfiguration = tfsConfiguration;
_tfsLanguage = tfsLanguage;
@ -165,7 +165,7 @@ namespace Greenshot.Addon.Tfs
ExportMade = uploadUrl != null,
Uri = uploadUrl?.AbsoluteUri
};
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -39,12 +39,12 @@ namespace Greenshot.Addons.Components
private static readonly LogSource Log = new LogSource();
private readonly ICoreConfiguration _coreConfiguration;
private readonly IEventAggregator _eventAggregator;
private readonly Func<IDestination, ExportInformation, Owned<ExportNotificationViewModel>> _toastFactory;
private readonly Func<IDestination, ExportInformation, ISurface, Owned<ExportNotificationViewModel>> _toastFactory;
public ExportNotification(
ICoreConfiguration coreConfiguration,
IEventAggregator eventAggregator,
Func<IDestination, ExportInformation, Owned<ExportNotificationViewModel>> toastFactory)
Func<IDestination, ExportInformation, ISurface, Owned<ExportNotificationViewModel>> toastFactory)
{
_coreConfiguration = coreConfiguration;
_eventAggregator = eventAggregator;
@ -56,15 +56,16 @@ namespace Greenshot.Addons.Components
/// </summary>
/// <param name="source">IDestination</param>
/// <param name="exportInformation">ExportInformation</param>
public void NotifyOfExport(IDestination source, ExportInformation exportInformation)
/// <param name="exportedSurface">ISurface</param>
public void NotifyOfExport(IDestination source, ExportInformation exportInformation, ISurface exportedSurface)
{
if (exportInformation == null || !_coreConfiguration.ShowTrayNotification || !exportInformation.ExportMade)
if (exportInformation == null || !_coreConfiguration.ShowTrayNotification)
{
Log.Info().WriteLine("No notification due to ShowTrayNotification = {0} - or export made = {1}", _coreConfiguration.ShowTrayNotification, exportInformation?.ExportMade);
Log.Info().WriteLine("No notification due to ShowTrayNotification = {0} - or export made = {1}", _coreConfiguration.ShowTrayNotification);
return;
}
// Create the ViewModel "part"
var message = _toastFactory(source, exportInformation);
var message = _toastFactory(source, exportInformation, exportedSurface);
// Prepare to dispose the view model parts automatically if it's finished
void DisposeHandler(object sender, DeactivationEventArgs args)
{

View file

@ -31,8 +31,6 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using Autofac.Features.OwnedInstances;
using Caliburn.Micro;
using Dapplo.Log;
using Dapplo.Windows.Common.Extensions;
using Dapplo.Windows.Common.Structs;
@ -42,7 +40,6 @@ using Dapplo.Windows.Extensions;
using Greenshot.Addons.Components;
using Greenshot.Addons.Extensions;
using Greenshot.Addons.Interfaces;
using Greenshot.Addons.ViewModels;
using Greenshot.Gfx;
#endregion
@ -54,9 +51,6 @@ namespace Greenshot.Addons.Core
/// </summary>
public abstract class AbstractDestination : IDestination
{
private readonly ExportNotification _exportNotification;
private readonly IEventAggregator _eventAggregator;
private readonly Func<IDestination, Owned<ExportNotificationViewModel>> _toastFactory;
private static readonly LogSource Log = new LogSource();
protected IGreenshotLanguage GreenshotLanguage { get; }
@ -64,10 +58,8 @@ namespace Greenshot.Addons.Core
protected AbstractDestination(
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification)
IGreenshotLanguage greenshotLanguage)
{
_exportNotification = exportNotification;
CoreConfiguration = coreConfiguration;
GreenshotLanguage = greenshotLanguage;
Designation = GetType().GetDesignation();
@ -241,39 +233,6 @@ namespace Greenshot.Addons.Core
//if (disposing) {}
}
/// <summary>
/// A small helper method to perform some default destination actions, like inform the surface of the export
/// </summary>
/// <param name="exportInformation"></param>
/// <param name="surface"></param>
public void ProcessExport(ExportInformation exportInformation, ISurface surface)
{
_exportNotification.NotifyOfExport(this, exportInformation);
if (exportInformation != null && exportInformation.ExportMade)
{
if (!string.IsNullOrEmpty(exportInformation.Uri))
{
surface.UploadUrl = exportInformation.Uri;
surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUri, string.Format(GreenshotLanguage.ExportedTo, exportInformation.DestinationDescription));
}
else if (!string.IsNullOrEmpty(exportInformation.Filepath))
{
surface.LastSaveFullPath = exportInformation.Filepath;
surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, string.Format(GreenshotLanguage.ExportedTo, exportInformation.DestinationDescription));
}
else
{
surface.SendMessageEvent(this, SurfaceMessageTyp.Info, string.Format(GreenshotLanguage.ExportedTo, exportInformation.DestinationDescription));
}
surface.Modified = false;
}
else if (!string.IsNullOrEmpty(exportInformation?.ErrorMessage))
{
surface.SendMessageEvent(this, SurfaceMessageTyp.Error,
string.Format(GreenshotLanguage.ExportedTo, exportInformation.DestinationDescription) + " " + exportInformation.ErrorMessage);
}
}
public override string ToString()
{
return Description;

View file

@ -36,6 +36,12 @@ namespace Greenshot.Addons.Interfaces
ExportMade = exportMade;
}
public bool IsError => !string.IsNullOrEmpty(ErrorMessage);
public bool IsOk => string.IsNullOrEmpty(ErrorMessage);
public bool IsFileExport => !string.IsNullOrEmpty(Filepath);
public bool IsCloudExport => !string.IsNullOrEmpty(Uri);
public string DestinationDesignation { get; }
public string DestinationDescription { get; set; }

View file

@ -21,8 +21,14 @@
#endregion
using System;
using System.Diagnostics;
using System.Windows.Media;
using Dapplo.CaliburnMicro.Toasts.ViewModels;
using Dapplo.Log;
using Dapplo.Windows.Extensions;
using Greenshot.Addons.Components;
using Greenshot.Addons.Core;
using Greenshot.Addons.Interfaces;
namespace Greenshot.Addons.ViewModels
@ -30,13 +36,52 @@ namespace Greenshot.Addons.ViewModels
/// <inheritdoc />
public class ExportNotificationViewModel : ToastBaseViewModel
{
public ExportNotificationViewModel(IDestination source, ExportInformation exportInformation)
private static readonly LogSource Log = new LogSource();
public ExportNotificationViewModel(IDestination source, ExportInformation exportInformation, ISurface exportedSurface)
{
Information = exportInformation;
Source = source;
using (var bitmap = exportedSurface.GetBitmapForExport())
{
ExportBitmapSource = bitmap.ToBitmapSource();
}
}
public ImageSource GreenshotIcon => GreenshotResources.GreenshotIconAsBitmapSource();
public ImageSource ExportBitmapSource { get; }
public IDestination Source { get; }
public ExportInformation Information { get; }
/// <summary>
/// Handle the click
/// </summary>
public void OpenExport()
{
try
{
if (Information.IsFileExport)
{
ExplorerHelper.OpenInExplorer(Information.Filepath);
return;
}
if (Information.IsCloudExport)
{
Process.Start(Information.Uri);
}
}
catch (Exception ex)
{
Log.Error().WriteLine(ex,"While opening {0}", Information.Uri);
}
finally
{
Close();
}
}
}
}

View file

@ -5,11 +5,31 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:toastNotifications="clr-namespace:ToastNotifications.Core;assembly=ToastNotifications"
xmlns:viewModels="clr-namespace:Greenshot.Addons.ViewModels"
mc:Ignorable="d" Background="{DynamicResource AccentColorBrush}" Width="200" Padding="5"
xmlns:cal="http://www.caliburnproject.org"
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">
<DockPanel LastChildFill="True">
<Image Source="{Binding Source.DisplayIconWpf}" Width="64" VerticalAlignment="Top"/>
<Label Content="{Binding Information.DestinationDescription}" VerticalAlignment="Center" FontWeight="Light" Foreground="White"/>
</DockPanel>
<toastNotifications:NotificationDisplayPart.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
</toastNotifications:NotificationDisplayPart.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="32" />
</Grid.ColumnDefinitions>
<!-- Top row -->
<Image Source="{Binding GreenshotIcon}" Stretch="Uniform" RenderOptions.BitmapScalingMode="Fant" UseLayoutRounding="True" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0"/>
<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"/>
<!-- Bottom 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" />
<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"/>
</Grid>
</toastNotifications:NotificationDisplayPart>

View file

@ -45,12 +45,15 @@ namespace Greenshot.Destinations
[Destination("Clipboard", DestinationOrder.Clipboard)]
public class ClipboardDestination : AbstractDestination
{
private readonly ExportNotification _exportNotification;
public ClipboardDestination(
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
}
public override string Description => GreenshotLanguage.SettingsDestinationClipboard;
@ -105,7 +108,7 @@ namespace Greenshot.Destinations
// TODO: Change to general logic in ProcessExport
surface.SendMessageEvent(this, SurfaceMessageTyp.Error, "Error"); //GreenshotLanguage.editorclipboardfailed);
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -42,6 +42,7 @@ namespace Greenshot.Destinations
[Destination("EMail", DestinationOrder.Email)]
public class EmailDestination : AbstractDestination
{
private readonly ExportNotification _exportNotification;
private static readonly Bitmap MailIcon = GreenshotResources.GetBitmap("Email.Image");
private static bool _isActiveFlag;
private static string _mapiClient;
@ -64,8 +65,9 @@ namespace Greenshot.Destinations
public EmailDestination(
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification) : base(coreConfiguration, greenshotLanguage, exportNotification)
ExportNotification exportNotification) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
}
public override string Description
@ -112,7 +114,7 @@ namespace Greenshot.Destinations
var exportInformation = new ExportInformation(Designation, Description);
MapiMailMessage.SendImage(surface, captureDetails);
exportInformation.ExportMade = true;
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -45,13 +45,15 @@ namespace Greenshot.Destinations
[Destination("FileNoDialog", DestinationOrder.FileNoDialog)]
public class FileDestination : AbstractDestination
{
private readonly ExportNotification _exportNotification;
private static readonly LogSource Log = new LogSource();
public FileDestination(
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification) : base(coreConfiguration, greenshotLanguage, exportNotification)
ExportNotification exportNotification) : base(coreConfiguration, greenshotLanguage)
{
_exportNotification = exportNotification;
}
public override string Description => GreenshotLanguage.QuicksettingsDestinationFile;
@ -125,7 +127,7 @@ namespace Greenshot.Destinations
CoreConfiguration.OutputFileAsFullpath = fullPath;
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}

View file

@ -42,13 +42,15 @@ namespace Greenshot.Destinations
public class FileWithDialogDestination : AbstractDestination
{
private readonly IGreenshotLanguage _greenshotLanguage;
private readonly ExportNotification _exportNotification;
public FileWithDialogDestination(ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_greenshotLanguage = greenshotLanguage;
_exportNotification = exportNotification;
}
public override string Description => _greenshotLanguage.SettingsDestinationFileas;
@ -69,7 +71,7 @@ namespace Greenshot.Destinations
captureDetails.Filename = savedTo;
CoreConfiguration.OutputFileAsFullpath = savedTo;
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -49,7 +49,7 @@ namespace Greenshot.Destinations
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_destinationHolder = destinationHolder;
}

View file

@ -54,7 +54,7 @@ namespace Greenshot.Destinations
IGreenshotLanguage greenshotLanguage,
ExportNotification exportNotification,
Func<ISurface, ICaptureDetails, Owned<PrintHelper>> printHelperFactory
) : base(coreConfiguration, greenshotLanguage, exportNotification)
) : base(coreConfiguration, greenshotLanguage)
{
_greenshotLanguage = greenshotLanguage;
_exportNotification = exportNotification;
@ -161,7 +161,7 @@ namespace Greenshot.Destinations
exportInformation.ExportMade = true;
}
ProcessExport(exportInformation, surface);
_exportNotification.NotifyOfExport(this, exportInformation, surface);
return exportInformation;
}
}

View file

@ -561,77 +561,6 @@ namespace Greenshot.Helpers
}
}
/// <summary>
/// If a balloon tip is show for a taken capture, this handles the click on it
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenCaptureOnClick(object sender, EventArgs e)
{
if (!(MainForm.Instance.NotifyIcon.Tag is SurfaceMessageEventArgs eventArgs))
{
Log.Warn().WriteLine("OpenCaptureOnClick called without SurfaceMessageEventArgs");
RemoveEventHandler(sender, e);
return;
}
var surface = eventArgs.Surface;
if (surface != null)
{
switch (eventArgs.MessageType)
{
case SurfaceMessageTyp.FileSaved:
ExplorerHelper.OpenInExplorer(surface.LastSaveFullPath);
break;
case SurfaceMessageTyp.UploadedUri:
Process.Start(surface.UploadUrl);
break;
}
}
Log.Debug().WriteLine("Deregistering the BalloonTipClicked");
RemoveEventHandler(sender, e);
}
private void RemoveEventHandler(object sender, EventArgs e)
{
MainForm.Instance.NotifyIcon.BalloonTipClicked -= OpenCaptureOnClick;
MainForm.Instance.NotifyIcon.BalloonTipClosed -= RemoveEventHandler;
MainForm.Instance.NotifyIcon.Tag = null;
}
/// <summary>
/// This is the SufraceMessageEvent receiver
/// </summary>
/// <param name="sender"></param>
/// <param name="eventArgs"></param>
private void SurfaceMessageReceived(object sender, SurfaceMessageEventArgs eventArgs)
{
if (string.IsNullOrEmpty(eventArgs?.Message))
{
return;
}
if (MainForm.Instance == null)
{
return;
}
switch (eventArgs.MessageType)
{
case SurfaceMessageTyp.Error:
MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Error);
break;
case SurfaceMessageTyp.Info:
MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info);
break;
case SurfaceMessageTyp.FileSaved:
case SurfaceMessageTyp.UploadedUri:
// Show a balloon and register an event handler to open the "capture" for if someone clicks the balloon.
MainForm.Instance.NotifyIcon.BalloonTipClicked += OpenCaptureOnClick;
MainForm.Instance.NotifyIcon.BalloonTipClosed += RemoveEventHandler;
// Store for later usage
MainForm.Instance.NotifyIcon.Tag = eventArgs;
MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info);
break;
}
}
/// <summary>
/// Process the actuall capture
@ -680,11 +609,6 @@ namespace Greenshot.Helpers
surface.SetCapture(_capture);
surface.Modified = !outputMade;
// Register notify events if this is wanted
if (CoreConfig.ShowTrayNotification && !CoreConfig.HideTrayicon)
{
surface.SurfaceMessage += SurfaceMessageReceived;
}
// Let the processors do their job
foreach (var processor in _processors)
{

View file

@ -50,8 +50,7 @@ namespace Greenshot.Ui.Notifications.ViewModels
public string Message => string.Format(_greenshotLanguage.UpdateFound, LatestVersion);
public ImageSource Icon => GreenshotResources.GreenshotIconAsBitmapSource();
public ImageSource GreenshotIcon => GreenshotResources.GreenshotIconAsBitmapSource();
/// <summary>
/// Handle the click

View file

@ -18,7 +18,7 @@
<ColumnDefinition Width="64" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding Icon}" Width="64" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0"/>
<Image Source="{Binding GreenshotIcon}" Width="64" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="{Binding Message}" VerticalAlignment="Center" FontWeight="Light" Foreground="{DynamicResource IdealForegroundColorBrush}" TextWrapping="WrapWithOverflow" Grid.Row="0" Grid.Column="1" />
<Button Style="{DynamicResource SquareButtonStyle}" Focusable="False" cal:Message.Attach="[Action OpenDownloads()]" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<TextBlock>