diff --git a/src/Greenshot.Addon.Box/BoxDestination.cs b/src/Greenshot.Addon.Box/BoxDestination.cs index 7eb0b4f1e..1e8f0bfc5 100644 --- a/src/Greenshot.Addon.Box/BoxDestination.cs +++ b/src/Greenshot.Addon.Box/BoxDestination.cs @@ -56,7 +56,8 @@ namespace Greenshot.Addon.Box public class BoxDestination : AbstractDestination { private static readonly LogSource Log = new LogSource(); - private readonly IBoxConfiguration _boxConfiguration; + private readonly ExportNotification _exportNotification; + private readonly IBoxConfiguration _boxConfiguration; private readonly IBoxLanguage _boxLanguage; private readonly Func> _pleaseWaitFormFactory; private readonly INetworkConfiguration _networkConfiguration; @@ -73,8 +74,9 @@ namespace Greenshot.Addon.Box IBoxLanguage boxLanguage, Func> 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; } diff --git a/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs b/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs index f86d17c91..a93daddf0 100644 --- a/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs +++ b/src/Greenshot.Addon.Confluence/ConfluenceDestination.cs @@ -86,7 +86,7 @@ namespace Greenshot.Addon.Confluence IConfluenceConfiguration confluenceConfiguration, IConfluenceLanguage confluenceLanguage, Func> pleaseWaitFormFactory - ) : base(coreConfiguration, greenshotLanguage, exportNotification) + ) : base(coreConfiguration, greenshotLanguage) { _exportNotification = exportNotification; _confluenceConfiguration = confluenceConfiguration; @@ -180,8 +180,8 @@ namespace Greenshot.Addon.Confluence exportInformation.ErrorMessage = errorMessage; } } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } private bool Upload(ISurface surfaceToUpload, Content page, string filename, out string errorMessage) diff --git a/src/Greenshot.Addon.Dropbox/DropboxDestination.cs b/src/Greenshot.Addon.Dropbox/DropboxDestination.cs index 77b029481..dd5cb9b89 100644 --- a/src/Greenshot.Addon.Dropbox/DropboxDestination.cs +++ b/src/Greenshot.Addon.Dropbox/DropboxDestination.cs @@ -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> _pleaseWaitFormFactory; private OAuth2Settings _oAuth2Settings; private IHttpBehaviour _oAuthHttpBehaviour; @@ -76,11 +77,12 @@ namespace Greenshot.Addon.Dropbox IGreenshotLanguage greenshotLanguage, ExportNotification exportNotification, Func> 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; } diff --git a/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs b/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs index bcf6f5de1..bece4adc2 100644 --- a/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs +++ b/src/Greenshot.Addon.ExternalCommand/ExternalCommandDestination.cs @@ -50,17 +50,19 @@ 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; + } /// public override string Designation => "External " + _externalCommandDefinition.Name.Replace(',', '_'); @@ -108,8 +110,8 @@ namespace Greenshot.Addon.ExternalCommand } } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot.Addon.Flickr/FlickrDestination.cs b/src/Greenshot.Addon.Flickr/FlickrDestination.cs index 143525dcb..7285d85f6 100644 --- a/src/Greenshot.Addon.Flickr/FlickrDestination.cs +++ b/src/Greenshot.Addon.Flickr/FlickrDestination.cs @@ -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> _pleaseWaitFormFactory; private readonly OAuth1Settings _oAuthSettings; private readonly OAuth1HttpBehaviour _oAuthHttpBehaviour; @@ -88,11 +89,12 @@ namespace Greenshot.Addon.Flickr IGreenshotLanguage greenshotLanguage, ExportNotification exportNotification, Func> pleaseWaitFormFactory - ) : base(coreConfiguration, greenshotLanguage, exportNotification) + ) : base(coreConfiguration, greenshotLanguage) { _flickrConfiguration = flickrConfiguration; _flickrLanguage = flickrLanguage; _resourceProvider = resourceProvider; + _exportNotification = exportNotification; _pleaseWaitFormFactory = pleaseWaitFormFactory; _oAuthSettings = new OAuth1Settings @@ -147,8 +149,8 @@ namespace Greenshot.Addon.Flickr ExportMade = flickrUri != null, Uri = flickrUri }; - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } diff --git a/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs b/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs index 5fbf1cd77..a2da655c9 100644 --- a/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs +++ b/src/Greenshot.Addon.GooglePhotos/GooglePhotosDestination.cs @@ -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> _pleaseWaitFormFactory; private readonly OAuth2Settings _oAuth2Settings; @@ -71,12 +72,13 @@ namespace Greenshot.Addon.GooglePhotos IGreenshotLanguage greenshotLanguage, ExportNotification exportNotification, Func> pleaseWaitFormFactory - ) : base(coreConfiguration, greenshotLanguage, exportNotification) + ) : base(coreConfiguration, greenshotLanguage) { _googlePhotosConfiguration = googlePhotosConfiguration; _googlePhotosLanguage = googlePhotosLanguage; _networkConfiguration = networkConfiguration; _resourceProvider = resourceProvider; + _exportNotification = exportNotification; _pleaseWaitFormFactory = pleaseWaitFormFactory; _oAuth2Settings = new OAuth2Settings @@ -123,8 +125,8 @@ namespace Greenshot.Addon.GooglePhotos exportInformation.ExportMade = true; exportInformation.Uri = uploadUrl; } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } private async Task Upload(ISurface surfaceToUpload) diff --git a/src/Greenshot.Addon.Imgur/ImgurDestination.cs b/src/Greenshot.Addon.Imgur/ImgurDestination.cs index 244ed61de..2da0334be 100644 --- a/src/Greenshot.Addon.Imgur/ImgurDestination.cs +++ b/src/Greenshot.Addon.Imgur/ImgurDestination.cs @@ -54,7 +54,8 @@ namespace Greenshot.Addon.Imgur public class ImgurDestination : AbstractDestination { private static readonly LogSource Log = new LogSource(); - private readonly IImgurConfiguration _imgurConfiguration; + private readonly ExportNotification _exportNotification; + private readonly IImgurConfiguration _imgurConfiguration; private readonly IImgurLanguage _imgurLanguage; private readonly ImgurApi _imgurApi; private readonly ImgurHistoryViewModel _imgurHistoryViewModel; @@ -70,9 +71,10 @@ namespace Greenshot.Addon.Imgur ImgurApi imgurApi, ImgurHistoryViewModel imgurHistoryViewModel, Func> pleaseWaitFormFactory, - IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage, exportNotification) - { - _imgurConfiguration = imgurConfiguration; + IResourceProvider resourceProvider) : base(coreConfiguration, greenshotLanguage) + { + _exportNotification = exportNotification; + _imgurConfiguration = imgurConfiguration; _imgurLanguage = imgurLanguage; _imgurApi = imgurApi; _imgurHistoryViewModel = imgurHistoryViewModel; @@ -103,8 +105,8 @@ namespace Greenshot.Addon.Imgur ExportMade = uploadUrl != null, Uri = uploadUrl?.AbsoluteUri }; - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } /// diff --git a/src/Greenshot.Addon.Jira/JiraDestination.cs b/src/Greenshot.Addon.Jira/JiraDestination.cs index 4018a3f40..3e72477f6 100644 --- a/src/Greenshot.Addon.Jira/JiraDestination.cs +++ b/src/Greenshot.Addon.Jira/JiraDestination.cs @@ -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,8 +239,8 @@ namespace Greenshot.Addon.Jira } } } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs b/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs index d2841fe39..417676afc 100644 --- a/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs +++ b/src/Greenshot.Addon.LegacyEditor/EditorDestination.cs @@ -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; @@ -129,10 +129,10 @@ namespace Greenshot.Addon.LegacyEditor _editorFactory.CreateOrReuse(surface, captureDetails); exportInformation.ExportMade = true; } - - ProcessExport(exportInformation, surface); - // Workaround for the modified flag when using the editor. - surface.Modified = modified; + + _exportNotification.NotifyOfExport(this, exportInformation, surface); + // Workaround for the modified flag when using the editor. + surface.Modified = modified; return exportInformation; } } diff --git a/src/Greenshot.Addon.Lutim/LutimDestination.cs b/src/Greenshot.Addon.Lutim/LutimDestination.cs index aa902cebf..62a396451 100644 --- a/src/Greenshot.Addon.Lutim/LutimDestination.cs +++ b/src/Greenshot.Addon.Lutim/LutimDestination.cs @@ -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> _pleaseWaitFormFactory; public LutimDestination(ILutimConfiguration lutimConfiguration, @@ -59,12 +60,13 @@ namespace Greenshot.Addon.Lutim { IGreenshotLanguage greenshotLanguage, ExportNotification exportNotification, Func> pleaseWaitFormFactory - ) : base(coreConfiguration, greenshotLanguage, exportNotification) + ) : base(coreConfiguration, greenshotLanguage) { _lutimConfiguration = lutimConfiguration; _lutimLanguage = lutimLanguage; _lutimApi = lutimApi; _resourceProvider = resourceProvider; + _exportNotification = exportNotification; _pleaseWaitFormFactory = pleaseWaitFormFactory; } @@ -89,8 +91,8 @@ namespace Greenshot.Addon.Lutim { ExportMade = uploadUrl != null, Uri = uploadUrl }; - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } diff --git a/src/Greenshot.Addon.OCR/OCRDestination.cs b/src/Greenshot.Addon.OCR/OCRDestination.cs index 70b834582..e131198d7 100644 --- a/src/Greenshot.Addon.OCR/OCRDestination.cs +++ b/src/Greenshot.Addon.OCR/OCRDestination.cs @@ -59,8 +59,8 @@ namespace Greenshot.Addon.OCR ICoreConfiguration coreConfiguration, IGreenshotLanguage greenshotLanguage, ExportNotification exportNotification - ) : base(coreConfiguration, greenshotLanguage, exportNotification) - { + ) : base(coreConfiguration, greenshotLanguage) + { _ocrConfiguration = ocrConfiguration; var ocrDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); diff --git a/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs b/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs index 3a09e2a0a..4ea0f7e83 100644 --- a/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/ExcelDestination.cs @@ -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,9 +111,9 @@ namespace Greenshot.Addon.Office.Destinations ExcelExporter.InsertIntoNewWorkbook(imageFile, surface.Screenshot.Size); } exportInformation.ExportMade = true; - ProcessExport(exportInformation, surface); - // Cleanup imageFile if we created it here, so less tmp-files are generated and left - if (createdFile) + _exportNotification.NotifyOfExport(this, exportInformation, surface); + // Cleanup imageFile if we created it here, so less tmp-files are generated and left + if (createdFile) { ImageOutput.DeleteNamedTmpFile(imageFile); } diff --git a/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs b/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs index dd65d2cd7..423ede2e5 100644 --- a/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/OneNoteDestination.cs @@ -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"); diff --git a/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs b/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs index 3da02dc5c..794791f71 100644 --- a/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/OutlookDestination.cs @@ -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,8 +198,8 @@ namespace Greenshot.Addon.Office.Destinations _officeConfiguration.EmailBCC, null); } } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs b/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs index 324c54a95..dd340f482 100644 --- a/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/PowerpointDestination.cs @@ -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,8 +144,8 @@ namespace Greenshot.Addon.Office.Destinations exportInformation.ExportMade = PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title); } } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot.Addon.Office/Destinations/WordDestination.cs b/src/Greenshot.Addon.Office/Destinations/WordDestination.cs index 0aafcbe97..38bf104fe 100644 --- a/src/Greenshot.Addon.Office/Destinations/WordDestination.cs +++ b/src/Greenshot.Addon.Office/Destinations/WordDestination.cs @@ -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,8 +162,8 @@ namespace Greenshot.Addon.Office.Destinations } } } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs b/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs index 576b2cbda..6e5822927 100644 --- a/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs +++ b/src/Greenshot.Addon.OneDrive/OneDriveDestination.cs @@ -63,6 +63,7 @@ namespace Greenshot.Addon.OneDrive private readonly IOneDriveLanguage _oneDriveLanguage; private readonly IResourceProvider _resourceProvider; private readonly Func> _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(body); } } diff --git a/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs b/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs index 60d7cb9cd..cb1544f27 100644 --- a/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs +++ b/src/Greenshot.Addon.Photobucket/PhotobucketDestination.cs @@ -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,8 +230,8 @@ namespace Greenshot.Addon.Photobucket exportInformation.ExportMade = true; exportInformation.Uri = uploaded.Original; } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } diff --git a/src/Greenshot.Addon.Tfs/TfsDestination.cs b/src/Greenshot.Addon.Tfs/TfsDestination.cs index 7c3acb2c5..7749fae36 100644 --- a/src/Greenshot.Addon.Tfs/TfsDestination.cs +++ b/src/Greenshot.Addon.Tfs/TfsDestination.cs @@ -69,7 +69,7 @@ namespace Greenshot.Addon.Tfs TfsClient tfsClient, Func> 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; } diff --git a/src/Greenshot.Addons/Components/ExportNotification.cs b/src/Greenshot.Addons/Components/ExportNotification.cs index 05274b227..81fa54532 100644 --- a/src/Greenshot.Addons/Components/ExportNotification.cs +++ b/src/Greenshot.Addons/Components/ExportNotification.cs @@ -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> _toastFactory; + private readonly Func> _toastFactory; public ExportNotification( ICoreConfiguration coreConfiguration, IEventAggregator eventAggregator, - Func> toastFactory) + Func> toastFactory) { _coreConfiguration = coreConfiguration; _eventAggregator = eventAggregator; @@ -56,15 +56,16 @@ namespace Greenshot.Addons.Components /// /// IDestination /// ExportInformation - public void NotifyOfExport(IDestination source, ExportInformation exportInformation) + /// ISurface + 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) { diff --git a/src/Greenshot.Addons/Core/AbstractDestination.cs b/src/Greenshot.Addons/Core/AbstractDestination.cs index 75bd9a415..45acadd62 100644 --- a/src/Greenshot.Addons/Core/AbstractDestination.cs +++ b/src/Greenshot.Addons/Core/AbstractDestination.cs @@ -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 /// public abstract class AbstractDestination : IDestination { - private readonly ExportNotification _exportNotification; - private readonly IEventAggregator _eventAggregator; - private readonly Func> _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) {} } - /// - /// A small helper method to perform some default destination actions, like inform the surface of the export - /// - /// - /// - 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; diff --git a/src/Greenshot.Addons/Interfaces/ExportInformation.cs b/src/Greenshot.Addons/Interfaces/ExportInformation.cs index 12327fa20..876d990a7 100644 --- a/src/Greenshot.Addons/Interfaces/ExportInformation.cs +++ b/src/Greenshot.Addons/Interfaces/ExportInformation.cs @@ -36,7 +36,13 @@ namespace Greenshot.Addons.Interfaces ExportMade = exportMade; } - public string DestinationDesignation { get; } + 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; } diff --git a/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs b/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs index 2756f616b..ebdeb0ff2 100644 --- a/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs +++ b/src/Greenshot.Addons/ViewModels/ExportNotificationViewModel.cs @@ -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 /// 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; } + + /// + /// Handle the click + /// + 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(); + } + } } } diff --git a/src/Greenshot.Addons/Views/ExportNotificationView.xaml b/src/Greenshot.Addons/Views/ExportNotificationView.xaml index efdd0ac4b..b63994dee 100644 --- a/src/Greenshot.Addons/Views/ExportNotificationView.xaml +++ b/src/Greenshot.Addons/Views/ExportNotificationView.xaml @@ -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"> - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Greenshot/Destinations/ClipboardDestination.cs b/src/Greenshot/Destinations/ClipboardDestination.cs index 973ae82f6..f45a9c594 100644 --- a/src/Greenshot/Destinations/ClipboardDestination.cs +++ b/src/Greenshot/Destinations/ClipboardDestination.cs @@ -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,8 +108,8 @@ namespace Greenshot.Destinations // TODO: Change to general logic in ProcessExport surface.SendMessageEvent(this, SurfaceMessageTyp.Error, "Error"); //GreenshotLanguage.editorclipboardfailed); } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot/Destinations/EmailDestination.cs b/src/Greenshot/Destinations/EmailDestination.cs index ce8717108..c06590e21 100644 --- a/src/Greenshot/Destinations/EmailDestination.cs +++ b/src/Greenshot/Destinations/EmailDestination.cs @@ -42,7 +42,8 @@ namespace Greenshot.Destinations [Destination("EMail", DestinationOrder.Email)] public class EmailDestination : AbstractDestination { - private static readonly Bitmap MailIcon = GreenshotResources.GetBitmap("Email.Image"); + 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,8 +114,8 @@ namespace Greenshot.Destinations var exportInformation = new ExportInformation(Designation, Description); MapiMailMessage.SendImage(surface, captureDetails); exportInformation.ExportMade = true; - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot/Destinations/FileDestination.cs b/src/Greenshot/Destinations/FileDestination.cs index 04d8baaa5..970126d56 100644 --- a/src/Greenshot/Destinations/FileDestination.cs +++ b/src/Greenshot/Destinations/FileDestination.cs @@ -45,13 +45,15 @@ namespace Greenshot.Destinations [Destination("FileNoDialog", DestinationOrder.FileNoDialog)] public class FileDestination : AbstractDestination { - private static readonly LogSource Log = new LogSource(); + 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,8 +127,8 @@ namespace Greenshot.Destinations CoreConfiguration.OutputFileAsFullpath = fullPath; } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } private string CreateNewFilename(ICaptureDetails captureDetails) diff --git a/src/Greenshot/Destinations/FileWithDialogDestination.cs b/src/Greenshot/Destinations/FileWithDialogDestination.cs index 82a1f34ef..261fb3c2f 100644 --- a/src/Greenshot/Destinations/FileWithDialogDestination.cs +++ b/src/Greenshot/Destinations/FileWithDialogDestination.cs @@ -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,8 +71,8 @@ namespace Greenshot.Destinations captureDetails.Filename = savedTo; CoreConfiguration.OutputFileAsFullpath = savedTo; } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot/Destinations/PickerDestination.cs b/src/Greenshot/Destinations/PickerDestination.cs index 91b285516..05f2e8a5c 100644 --- a/src/Greenshot/Destinations/PickerDestination.cs +++ b/src/Greenshot/Destinations/PickerDestination.cs @@ -49,7 +49,7 @@ namespace Greenshot.Destinations ICoreConfiguration coreConfiguration, IGreenshotLanguage greenshotLanguage, ExportNotification exportNotification - ) : base(coreConfiguration, greenshotLanguage, exportNotification) + ) : base(coreConfiguration, greenshotLanguage) { _destinationHolder = destinationHolder; } diff --git a/src/Greenshot/Destinations/PrinterDestination.cs b/src/Greenshot/Destinations/PrinterDestination.cs index c8fd2e666..0efe4c392 100644 --- a/src/Greenshot/Destinations/PrinterDestination.cs +++ b/src/Greenshot/Destinations/PrinterDestination.cs @@ -54,8 +54,8 @@ namespace Greenshot.Destinations IGreenshotLanguage greenshotLanguage, ExportNotification exportNotification, Func> printHelperFactory - ) : base(coreConfiguration, greenshotLanguage, exportNotification) - { + ) : base(coreConfiguration, greenshotLanguage) + { _greenshotLanguage = greenshotLanguage; _exportNotification = exportNotification; _printHelperFactory = printHelperFactory; @@ -161,8 +161,8 @@ namespace Greenshot.Destinations exportInformation.ExportMade = true; } - ProcessExport(exportInformation, surface); - return exportInformation; + _exportNotification.NotifyOfExport(this, exportInformation, surface); + return exportInformation; } } } \ No newline at end of file diff --git a/src/Greenshot/Helpers/CaptureHelper.cs b/src/Greenshot/Helpers/CaptureHelper.cs index 99d921d7d..ef1d8eeb1 100644 --- a/src/Greenshot/Helpers/CaptureHelper.cs +++ b/src/Greenshot/Helpers/CaptureHelper.cs @@ -560,78 +560,7 @@ namespace Greenshot.Helpers } } } - - /// - /// If a balloon tip is show for a taken capture, this handles the click on it - /// - /// - /// - 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; - } - - /// - /// This is the SufraceMessageEvent receiver - /// - /// - /// - 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; - } - } + /// /// 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) { diff --git a/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs b/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs index bd2c9d886..39ce40c0a 100644 --- a/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs +++ b/src/Greenshot/Ui/Notifications/ViewModels/UpdateNotificationViewModel.cs @@ -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(); /// /// Handle the click diff --git a/src/Greenshot/Ui/Notifications/Views/UpdateNotificationView.xaml b/src/Greenshot/Ui/Notifications/Views/UpdateNotificationView.xaml index 908555db4..5f6535e8c 100644 --- a/src/Greenshot/Ui/Notifications/Views/UpdateNotificationView.xaml +++ b/src/Greenshot/Ui/Notifications/Views/UpdateNotificationView.xaml @@ -18,7 +18,7 @@ - +