diff --git a/Greenshot-OCR-Plugin/OCRDestination.cs b/Greenshot-OCR-Plugin/OCRDestination.cs index 1155afa82..5021cabc3 100644 --- a/Greenshot-OCR-Plugin/OCRDestination.cs +++ b/Greenshot-OCR-Plugin/OCRDestination.cs @@ -50,9 +50,9 @@ namespace GreenshotOCR { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { OcrPlugin.DoOCR(surface); - return true; + return new ExportInformation(this.Designation, this.Description, true); } } } diff --git a/Greenshot/Destinations/ClipboardDestination.cs b/Greenshot/Destinations/ClipboardDestination.cs index c23cb69e9..79bcfe698 100644 --- a/Greenshot/Destinations/ClipboardDestination.cs +++ b/Greenshot/Destinations/ClipboardDestination.cs @@ -68,19 +68,19 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); try { using (Image image = surface.GetImageForExport()) { ClipboardHelper.SetClipboardData(image); - surface.Modified = false; + exportInformation.ExportMade = true; } - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetString(LangKey.editor_storedtoclipboard)); - return true; } catch (Exception) { + // TODO: Change to general logic in ProcessExport surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString(LangKey.editor_clipboardfailed)); } - - return false; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Destinations/EditorDestination.cs b/Greenshot/Destinations/EditorDestination.cs index a069343f8..a2174b5b4 100644 --- a/Greenshot/Destinations/EditorDestination.cs +++ b/Greenshot/Destinations/EditorDestination.cs @@ -90,7 +90,8 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); if (editor == null) { // Make sure we collect the garbage before opening the screenshot GC.Collect(); @@ -105,22 +106,24 @@ namespace Greenshot.Destinations { editorForm.Show(); editorForm.Activate(); LOG.Debug("Finished opening Editor"); - return true; + exportInformation.ExportMade = true; } catch (Exception e) { LOG.Error(e); + exportInformation.ErrorMessage = e.Message; } } else { try { using (Bitmap image = (Bitmap)surface.GetImageForExport()) { editor.Surface.AddBitmapContainer(image, 10, 10); } - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description)); - return true; + exportInformation.ExportMade = true; } catch (Exception e) { LOG.Error(e); - } + exportInformation.ErrorMessage = e.Message; + } } - return false; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs index 15fefa2e8..0b04a5d04 100644 --- a/Greenshot/Destinations/EmailDestination.cs +++ b/Greenshot/Destinations/EmailDestination.cs @@ -175,61 +175,58 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); if (!isOutlookUsed) { using (Image image = surface.GetImageForExport()) { MapiMailMessage.SendImage(image, captureDetails); - surface.Modified = false; - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to " + mapiClient); - } - return true; - } - - // Outlook logic - string tmpFile = captureDetails.Filename; - if (tmpFile == null || surface.Modified) { - using (Image image = surface.GetImageForExport()) { - tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings()); + exportInformation.ExportMade = true; } + return exportInformation; } else { - LOG.InfoFormat("Using already available file: {0}", tmpFile); - } - - // Create a attachment name for the image - string attachmentName = captureDetails.Title; - if (!string.IsNullOrEmpty(attachmentName)) { - attachmentName = attachmentName.Trim(); - } - // Set default if non is set - if (string.IsNullOrEmpty(attachmentName)) { - attachmentName = "Greenshot Capture"; - } - // Make sure it's "clean" so it doesn't corrupt the header - attachmentName = Regex.Replace(attachmentName, @"[^\x20\d\w]", ""); - - if (outlookInspectorCaption != null) { - OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName); - } else { - if (!manuallyInitiated) { - Dictionary inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings); - if (inspectorCaptions != null && inspectorCaptions.Count > 0) { - List destinations = new List(); - destinations.Add(new EmailDestination()); - foreach (string inspectorCaption in inspectorCaptions.Keys) { - destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption])); - } - PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations); - return false; + // Outlook logic + string tmpFile = captureDetails.Filename; + if (tmpFile == null || surface.Modified) { + using (Image image = surface.GetImageForExport()) { + tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings()); } + } else { + LOG.InfoFormat("Using already available file: {0}", tmpFile); + } + + // Create a attachment name for the image + string attachmentName = captureDetails.Title; + if (!string.IsNullOrEmpty(attachmentName)) { + attachmentName = attachmentName.Trim(); + } + // Set default if non is set + if (string.IsNullOrEmpty(attachmentName)) { + attachmentName = "Greenshot Capture"; + } + // Make sure it's "clean" so it doesn't corrupt the header + attachmentName = Regex.Replace(attachmentName, @"[^\x20\d\w]", ""); + + if (outlookInspectorCaption != null) { + OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName); + exportInformation.ExportMade = true; + } else { + if (!manuallyInitiated) { + Dictionary inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings); + if (inspectorCaptions != null && inspectorCaptions.Count > 0) { + List destinations = new List(); + destinations.Add(new EmailDestination()); + foreach (string inspectorCaption in inspectorCaptions.Keys) { + destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption])); + } + PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations); + } + } + OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC); } - OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC); } - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description)); - surface.Modified = false; - // Don't know how to handle a cancel in the email - return true; + return exportInformation; } } } \ No newline at end of file diff --git a/Greenshot/Destinations/ExcelDestination.cs b/Greenshot/Destinations/ExcelDestination.cs index 5cd87b4eb..7240f2a9b 100644 --- a/Greenshot/Destinations/ExcelDestination.cs +++ b/Greenshot/Destinations/ExcelDestination.cs @@ -110,7 +110,8 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string tmpFile = captureDetails.Filename; if (tmpFile == null || surface.Modified) { using (Image image = surface.GetImageForExport()) { @@ -122,9 +123,9 @@ namespace Greenshot.Destinations { } else { ExcelExporter.InsertIntoNewWorkbook(tmpFile); } - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description)); - surface.Modified = false; - return true; + exportInformation.ExportMade = true; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Destinations/FileDestination.cs b/Greenshot/Destinations/FileDestination.cs index d77c15234..0f2ad6c5a 100644 --- a/Greenshot/Destinations/FileDestination.cs +++ b/Greenshot/Destinations/FileDestination.cs @@ -69,7 +69,8 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); bool outputMade; bool overwrite; string fullPath; @@ -114,14 +115,12 @@ namespace Greenshot.Destinations { } // Don't overwite filename if no output is made if (outputMade) { - surface.LastSaveFullPath = fullPath; - surface.Modified = false; + exportInformation.ExportMade = outputMade; + exportInformation.Filepath = fullPath; captureDetails.Filename = fullPath; - surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath)); - } else { - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, ""); } - return outputMade; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Destinations/FileWithDialogDestination.cs b/Greenshot/Destinations/FileWithDialogDestination.cs index 155c31d38..bcb5fb878 100644 --- a/Greenshot/Destinations/FileWithDialogDestination.cs +++ b/Greenshot/Destinations/FileWithDialogDestination.cs @@ -69,19 +69,20 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string savedTo = null; using (Image image = surface.GetImageForExport()) { // Bug #2918756 don't overwrite path if SaveWithDialog returns null! savedTo = ImageOutput.SaveWithDialog(image, captureDetails); if (savedTo != null) { - surface.Modified = false; - surface.LastSaveFullPath = savedTo; + exportInformation.ExportMade = true; + exportInformation.Filepath = savedTo; captureDetails.Filename = savedTo; - surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath)); } } - return savedTo != null; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Destinations/OneNoteDestination.cs b/Greenshot/Destinations/OneNoteDestination.cs index 96a6c04be..78b8833e5 100644 --- a/Greenshot/Destinations/OneNoteDestination.cs +++ b/Greenshot/Destinations/OneNoteDestination.cs @@ -110,17 +110,20 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); using (Image image = surface.GetImageForExport()) { if (page != null) { try { OneNoteExporter.ExportToPage((Bitmap)image, page); + exportInformation.ExportMade = true; } catch (Exception ex) { + exportInformation.ErrorMessage = ex.Message; LOG.Error(ex); } } } - return true; + return exportInformation; } } } diff --git a/Greenshot/Destinations/PickerDestination.cs b/Greenshot/Destinations/PickerDestination.cs index d207fa5c4..2511d4aaf 100644 --- a/Greenshot/Destinations/PickerDestination.cs +++ b/Greenshot/Destinations/PickerDestination.cs @@ -102,10 +102,9 @@ namespace Greenshot.Destinations { menu.Hide(); // Export - bool result = clickedDestination.ExportCapture(true, surface, captureDetails); - LOG.InfoFormat("Destination was {0} and result {1}", clickedDestination.Designation, result); - if (result == true) { - LOG.Info("Export success, closing menu"); + ExportInformation exportInformation = clickedDestination.ExportCapture(true, surface, captureDetails); + if (exportInformation != null && exportInformation.ExportMade) { + LOG.InfoFormat("Export to {0} success, closing menu", exportInformation.DestinationDescription); // close menu if the destination wasn't the editor menu.Close(); @@ -115,7 +114,7 @@ namespace Greenshot.Destinations { surface = null; } } else { - LOG.Info("Export failed, showing menu again"); + LOG.Info("Export cancelled or failed, showing menu again"); // This prevents the problem that the context menu shows in the task-bar ShowMenuAtCursor(menu); } @@ -180,7 +179,8 @@ namespace Greenshot.Destinations { /// Surface to export /// Details of the capture /// true if export was made - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); List destinations = new List(); foreach(IDestination destination in DestinationHelper.GetAllDestinations()) { if ("Picker".Equals(destination.Designation)) { @@ -193,7 +193,9 @@ namespace Greenshot.Destinations { } ShowPickerMenu(true, surface, captureDetails, destinations); - return true; + exportInformation.ExportMade = true; + // No Processing! :) + return exportInformation; } } } diff --git a/Greenshot/Destinations/PowerpointDestination.cs b/Greenshot/Destinations/PowerpointDestination.cs index 95a7aea47..caffae3e6 100644 --- a/Greenshot/Destinations/PowerpointDestination.cs +++ b/Greenshot/Destinations/PowerpointDestination.cs @@ -111,7 +111,8 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string tmpFile = captureDetails.Filename; Size imageSize = Size.Empty; if (tmpFile == null || surface.Modified) { @@ -122,6 +123,7 @@ namespace Greenshot.Destinations { } if (presentationName != null) { PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title); + exportInformation.ExportMade = true; } else { if (!manuallyInitiated) { List presentations = PowerpointExporter.GetPowerpointPresentations(); @@ -132,14 +134,16 @@ namespace Greenshot.Destinations { destinations.Add(new PowerpointDestination(presentation)); } PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations); - return false; + exportInformation.ExportMade = true; } } - PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title); + if (!exportInformation.ExportMade) { + PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title); + exportInformation.ExportMade = true; + } } - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description)); - surface.Modified = false; - return true; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Destinations/PrinterDestination.cs b/Greenshot/Destinations/PrinterDestination.cs index 2357c15aa..72bac2c16 100644 --- a/Greenshot/Destinations/PrinterDestination.cs +++ b/Greenshot/Destinations/PrinterDestination.cs @@ -93,7 +93,8 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); PrinterSettings printerSettings = null; using (Image image = surface.GetImageForExport()) { if (!string.IsNullOrEmpty(printerName)) { @@ -105,12 +106,15 @@ namespace Greenshot.Destinations { printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog(); } if (printerSettings != null) { - surface.Modified = false; - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.editor_senttoprinter, printerSettings.PrinterName)); + printerName = printerSettings.PrinterName; + // Renew destination + exportInformation.DestinationDescription = this.Description; + exportInformation.ExportMade = true; } } - return printerSettings != null; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Destinations/WordDestination.cs b/Greenshot/Destinations/WordDestination.cs index 31851f11f..15a8ac49f 100644 --- a/Greenshot/Destinations/WordDestination.cs +++ b/Greenshot/Destinations/WordDestination.cs @@ -111,7 +111,8 @@ namespace Greenshot.Destinations { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string tmpFile = captureDetails.Filename; if (tmpFile == null || surface.Modified) { using (Image image = surface.GetImageForExport()) { @@ -121,13 +122,15 @@ namespace Greenshot.Destinations { if (documentCaption != null) { try { WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile); + exportInformation.ExportMade = true; } catch (Exception) { try { WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile); + exportInformation.ExportMade = true; } catch (Exception ex) { LOG.Error(ex); + // TODO: Change to general logic in ProcessExport surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description)); - return false; } } } else { @@ -140,25 +143,24 @@ namespace Greenshot.Destinations { destinations.Add(new WordDestination(document)); } PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations); - return false; } } try { WordExporter.InsertIntoNewDocument(tmpFile); + exportInformation.ExportMade = true; } catch(Exception) { try { WordExporter.InsertIntoNewDocument(tmpFile); + exportInformation.ExportMade = true; } catch (Exception ex) { LOG.Error(ex); + // TODO: Change to general logic in ProcessExport surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description)); - return false; } } } - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description)); - surface.Modified = false; - - return true; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index b9839f759..936a0bf47 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -302,7 +302,7 @@ namespace Greenshot { string dateTime = DateTime.Now.ToLongTimeString(); // TODO: Fix that we only open files, like in the tooltip //if (eventArgs.MessageType == SurfaceMessageTyp.FileSaved || eventArgs.MessageType == SurfaceMessageTyp.UploadedUrl) { - if (eventArgs.MessageType == SurfaceMessageTyp.FileSaved || eventArgs.MessageType == SurfaceMessageTyp.UploadedUrl) { + if (eventArgs.MessageType == SurfaceMessageTyp.FileSaved || eventArgs.MessageType == SurfaceMessageTyp.UploadedUri) { updateStatusLabel(dateTime + " - " + eventArgs.Message, fileSavedStatusContextMenu); } else { updateStatusLabel(dateTime + " - " + eventArgs.Message); @@ -1059,7 +1059,8 @@ namespace Greenshot { clickedDestination = (IDestination)clickedMenuItem.Tag; } if (clickedDestination != null) { - if (clickedDestination.ExportCapture(true, surface, surface.CaptureDetails)) { + ExportInformation exportInformation = clickedDestination.ExportCapture(true, surface, surface.CaptureDetails); + if (exportInformation != null && exportInformation.ExportMade) { surface.Modified = false; } } diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj index e7ec4b00d..1ad505077 100644 --- a/Greenshot/Greenshot.csproj +++ b/Greenshot/Greenshot.csproj @@ -1,5 +1,5 @@  - + {CD642BF4-D815-4D67-A0B5-C69F0B8231AF} Debug @@ -17,8 +17,27 @@ v2.0 greenshot.manifest + + + 3.5 + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true - + bin\Debug\ true Full @@ -31,7 +50,7 @@ 4096 DEBUG;TRACE - + bin\Release\ false None @@ -43,6 +62,29 @@ AnyCPU 4096 + + true + bin\x86\Debug\ + DEBUG;TRACE + true + true + 4096 + Full + x86 + Off + false + true + true + + + bin\x86\Release\ + true + true + 4096 + None + x86 + Off + Lib\log4net.dll @@ -405,6 +447,23 @@ Form + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + {5B924697-4DCD-4F98-85F1-105CB84B7341} @@ -412,11 +471,11 @@ - + "$(MSBuildProjectDirectory)\tools\TortoiseSVN\SubWCRev.exe" "$(MSBuildProjectDirectory)\." "$(MSBuildProjectDirectory)\AssemblyInfo.cs.template" "$(MSBuildProjectDirectory)\AssemblyInfo.cs" copy "$(ProjectDir)log4net.xml" "$(SolutionDir)bin\$(Configuration)\log4net.xml" - + "$(MSBuildProjectDirectory)\tools\TortoiseSVN\SubWCRev.exe" "$(MSBuildProjectDirectory)\." "$(MSBuildProjectDirectory)\AssemblyInfo.cs.template" "$(MSBuildProjectDirectory)\AssemblyInfo.cs" copy "$(ProjectDir)log4net-debug.xml" "$(SolutionDir)bin\$(Configuration)\log4net.xml" diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index 2b192c7ef..31b8e88cd 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -497,7 +497,7 @@ namespace Greenshot.Helpers { MainForm.instance.notifyIcon.ShowBalloonTip(10000, "Greenshot", eventArgs.Message, ToolTipIcon.Info); break; case SurfaceMessageTyp.FileSaved: - case SurfaceMessageTyp.UploadedUrl: + case SurfaceMessageTyp.UploadedUri: EventHandler balloonTipClickedHandler = null; EventHandler balloonTipClosedHandler = null; balloonTipClosedHandler = delegate(object sender, EventArgs e) { @@ -570,8 +570,8 @@ namespace Greenshot.Helpers { } LOG.InfoFormat("Calling destination {0}", destination.Description); - bool destinationOk = destination.ExportCapture(false, surface, captureDetails); - if (Destinations.EditorDestination.DESIGNATION.Equals(destination.Designation) && destinationOk) { + ExportInformation exportInformation = destination.ExportCapture(false, surface, captureDetails); + if (Destinations.EditorDestination.DESIGNATION.Equals(destination.Designation) && exportInformation.ExportMade) { canDisposeSurface = false; } } diff --git a/Greenshot/Helpers/DestinationHelper.cs b/Greenshot/Helpers/DestinationHelper.cs index c8fa7d65a..dd023df41 100644 --- a/Greenshot/Helpers/DestinationHelper.cs +++ b/Greenshot/Helpers/DestinationHelper.cs @@ -128,18 +128,19 @@ namespace Greenshot.Helpers { /// /// /// - public static void ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { - if (RegisteredDestinations.ContainsKey(designation)) { - IDestination destination = RegisteredDestinations[designation]; - if (destination.isActive) { - if (destination.ExportCapture(manuallyInitiated, surface, captureDetails)) { - // Export worked, set the modified flag to false if the export wasn't to the editor or picker - if (!EditorDestination.DESIGNATION.Equals(designation) && !PickerDestination.DESIGNATION.Equals(designation)) { - surface.Modified = false; - } + public static ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { + IDestination destination = GetDestination(designation); + if (destination != null && destination.isActive) { + ExportInformation exportInformation = destination.ExportCapture(manuallyInitiated, surface, captureDetails); + if (exportInformation != null && exportInformation.ExportMade) { + // Export worked, set the modified flag to false if the export wasn't to the editor or picker + if (!EditorDestination.DESIGNATION.Equals(designation) && !PickerDestination.DESIGNATION.Equals(designation)) { + surface.Modified = false; } } + return exportInformation; } + return null; } } } diff --git a/Greenshot/Helpers/PluginHelper.cs b/Greenshot/Helpers/PluginHelper.cs index 0730f28b0..e438928dc 100644 --- a/Greenshot/Helpers/PluginHelper.cs +++ b/Greenshot/Helpers/PluginHelper.cs @@ -140,6 +140,17 @@ namespace Greenshot.Helpers { get {return plugins;} } + public IDestination GetDestination(string designation) { + return DestinationHelper.GetDestination(designation); + } + public List GetAllDestinations() { + return DestinationHelper.GetAllDestinations(); + } + + public ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { + return DestinationHelper.ExportCapture(manuallyInitiated, designation, surface, captureDetails); + } + /// /// Make Capture with specified Handler /// diff --git a/GreenshotConfluencePlugin/ConfluenceDestination.cs b/GreenshotConfluencePlugin/ConfluenceDestination.cs index b725c1c59..771177da2 100644 --- a/GreenshotConfluencePlugin/ConfluenceDestination.cs +++ b/GreenshotConfluencePlugin/ConfluenceDestination.cs @@ -114,10 +114,11 @@ namespace GreenshotConfluencePlugin { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); // force password check to take place before the pages load if (!ConfluencePlugin.ConfluenceConnector.isLoggedIn) { - return false; + return exportInformation; } Page selectedPage = page; @@ -132,8 +133,6 @@ namespace GreenshotConfluencePlugin { openPage = false; } filename = confluenceUpload.Filename; - } else { - return false; } } if (selectedPage != null) { @@ -143,20 +142,18 @@ namespace GreenshotConfluencePlugin { if (uploaded) { if (openPage) { try { - Process.Start(selectedPage.Url); + Process.Start(selectedPage.Url); } catch { } } - surface.UploadURL = selectedPage.Url; - surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", Description)); - surface.Modified = false; - return true; + exportInformation.ExportMade = true; + exportInformation.Uri = selectedPage.Url; } else { - surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString("confluence", LangKey.upload_failure) + " " + errorMessage); + exportInformation.ErrorMessage = errorMessage; } } } - - return false; + ProcessExport(exportInformation, surface); + return exportInformation; } private bool upload(Image image, Page page, string filename, out string errorMessage) { diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs index 8ae381952..abdc978ed 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs @@ -66,7 +66,8 @@ namespace ExternalCommand { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); OutputSettings outputSettings = new OutputSettings(); string fullPath = captureDetails.Filename; @@ -82,10 +83,11 @@ namespace ExternalCommand { commandThread.Name = "Running " + presetCommand; commandThread.IsBackground = true; commandThread.Start(); - surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString("exported_to", Description)); - surface.Modified = false; + exportInformation.ExportMade = true; + //exportInformation.Uri = "file://" + fullPath; } - return true; + ProcessExport(exportInformation, surface); + return exportInformation; } private void CallExternalCommand(string commando, string fullPath) { diff --git a/GreenshotImgurPlugin/ImgurDestination.cs b/GreenshotImgurPlugin/ImgurDestination.cs index 6f3c6e8d2..3212e3bf1 100644 --- a/GreenshotImgurPlugin/ImgurDestination.cs +++ b/GreenshotImgurPlugin/ImgurDestination.cs @@ -62,17 +62,15 @@ namespace GreenshotImgurPlugin { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); using (Image image = surface.GetImageForExport()) { string uploadURL = null; - bool uploaded = plugin.Upload(captureDetails, image, out uploadURL); - if (uploaded) { - surface.UploadURL = uploadURL; - surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", Designation)); - surface.Modified = false; - } - return uploaded; + exportInformation.ExportMade = plugin.Upload(captureDetails, image, out uploadURL); + exportInformation.Uri = uploadURL; } + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/GreenshotJiraPlugin/JiraDestination.cs b/GreenshotJiraPlugin/JiraDestination.cs index 2dbfdc8a8..80923f4b9 100644 --- a/GreenshotJiraPlugin/JiraDestination.cs +++ b/GreenshotJiraPlugin/JiraDestination.cs @@ -101,7 +101,8 @@ namespace GreenshotJiraPlugin { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails)); byte[] buffer; OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors); @@ -121,10 +122,8 @@ namespace GreenshotJiraPlugin { } ); LOG.Debug("Uploaded to Jira."); - surface.UploadURL = jiraPlugin.JiraConnector.getURL(jira.Key); - surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", FormatUpload(jira))); - surface.Modified = false; - return true; + exportInformation.ExportMade = true; + exportInformation.Uri = surface.UploadURL; } catch (Exception e) { MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message); } @@ -150,17 +149,16 @@ namespace GreenshotJiraPlugin { } ); LOG.Debug("Uploaded to Jira."); - surface.UploadURL = jiraPlugin.JiraConnector.getURL(jiraForm.getJiraIssue().Key); - surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", FormatUpload(jiraForm.getJiraIssue()))); - surface.Modified = false; - return true; + exportInformation.ExportMade = true; + exportInformation.Uri = surface.UploadURL; } catch(Exception e) { MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message); } } } } - return false; + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/GreenshotPhotobucketPlugin/PhotobucketDestination.cs b/GreenshotPhotobucketPlugin/PhotobucketDestination.cs index 26833abe9..d363ade98 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketDestination.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketDestination.cs @@ -62,17 +62,18 @@ namespace GreenshotPhotobucketPlugin { } } - public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); using (Image image = surface.GetImageForExport()) { string uploadURL = null; bool uploaded = plugin.Upload(captureDetails, image, out uploadURL); if (uploaded) { - surface.UploadURL = uploadURL; - surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUrl, Language.GetFormattedString("exported_to", Designation)); - surface.Modified = false; + exportInformation.ExportMade = true; + exportInformation.Uri = uploadURL; } - return uploaded; } + ProcessExport(exportInformation, surface); + return exportInformation; } } } diff --git a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs index 2cd4d9b5c..4d8f27ab5 100644 --- a/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs +++ b/GreenshotPhotobucketPlugin/PhotobucketPlugin.cs @@ -68,17 +68,14 @@ namespace GreenshotPhotobucketPlugin { config = IniConfig.GetIniSection(); resources = new ComponentResourceManager(typeof(PhotobucketPlugin)); - ToolStripMenuItem itemPlugInRoot = new ToolStripMenuItem("Photobucket"); - itemPlugInRoot.Image = (Image)resources.GetObject("Photobucket"); - - ToolStripMenuItem itemPlugInConfig = new ToolStripMenuItem(Language.GetString("photobucket", LangKey.configure)); + ToolStripMenuItem itemPlugInConfig = new ToolStripMenuItem("Photobucket " + Language.GetString("photobucket", LangKey.configure)); itemPlugInConfig.Tag = host; itemPlugInConfig.Click += delegate { config.ShowConfigDialog(); }; - itemPlugInRoot.DropDownItems.Add(itemPlugInConfig); + itemPlugInConfig.Image = (Image)resources.GetObject("Photobucket"); - PluginUtils.AddToContextMenu(host, itemPlugInRoot); + PluginUtils.AddToContextMenu(host, itemPlugInConfig); return true; } diff --git a/GreenshotPlugin/Core/AbstractDestination.cs b/GreenshotPlugin/Core/AbstractDestination.cs index 62d85fb43..6a12a0ce9 100644 --- a/GreenshotPlugin/Core/AbstractDestination.cs +++ b/GreenshotPlugin/Core/AbstractDestination.cs @@ -173,6 +173,12 @@ namespace GreenshotPlugin.Core { } } + public virtual bool isLinkable { + get { + return false; + } + } + public virtual bool isActive { get { if (configuration.ExcludeDestinations != null && configuration.ExcludeDestinations.Contains(Designation)) { @@ -182,8 +188,30 @@ namespace GreenshotPlugin.Core { } } - public abstract bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails); - + public abstract ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails); + + /// + /// A small helper method to perform some default destination actions, like inform the surface of the export + /// + /// + /// + public void ProcessExport(ExportInformation exportInformation, ISurface surface) { + if (exportInformation != null && exportInformation.ExportMade) { + if (!string.IsNullOrEmpty(exportInformation.Uri)) { + surface.UploadURL = exportInformation.Uri; + surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUri, Language.GetFormattedString("exported_to", exportInformation.DestinationDescription)); + } else if (!string.IsNullOrEmpty(exportInformation.Filepath)) { + surface.LastSaveFullPath = exportInformation.Filepath; + surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString("exported_to", exportInformation.DestinationDescription)); + } else { + surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString("exported_to", exportInformation.DestinationDescription)); + } + surface.Modified = false; + } else if (exportInformation != null && !string.IsNullOrEmpty(exportInformation.ErrorMessage)) { + surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("exported_to_error", exportInformation.DestinationDescription) + " " + exportInformation.ErrorMessage); + } + } + public override string ToString() { return Description; } diff --git a/GreenshotPlugin/Interfaces/Generic.cs b/GreenshotPlugin/Interfaces/Generic.cs index ef1229248..fc3310495 100644 --- a/GreenshotPlugin/Interfaces/Generic.cs +++ b/GreenshotPlugin/Interfaces/Generic.cs @@ -37,7 +37,7 @@ namespace Greenshot.Plugin { FileSaved, Error, Info, - UploadedUrl + UploadedUri } public class SurfaceMessageEventArgs : EventArgs { diff --git a/GreenshotPlugin/Interfaces/IDestination.cs b/GreenshotPlugin/Interfaces/IDestination.cs index 23827fadb..cd54392ac 100644 --- a/GreenshotPlugin/Interfaces/IDestination.cs +++ b/GreenshotPlugin/Interfaces/IDestination.cs @@ -24,6 +24,75 @@ using System.Drawing; using System.Windows.Forms; namespace Greenshot.Plugin { + public class ExportInformation { + private string uri = null; + private string filepath = null; + + private bool exportMade = false; + private string destinationDesignation = null; + private string destinationDescription = null; + + private string errorMessage = null; + + public ExportInformation(string destinationDesignation, string destinationDescription) { + this.destinationDesignation = destinationDesignation; + this.destinationDescription = destinationDescription; + } + public ExportInformation(string destinationDesignation, string destinationDescription, bool exportMade): this(destinationDesignation, destinationDescription) { + this.exportMade = exportMade; + } + + public string DestinationDesignation { + get { + return destinationDesignation; + } + } + public string DestinationDescription { + get { + return destinationDescription; + } + set { + destinationDescription = value; + } + } + + public bool ExportMade { + get { + return exportMade; + } + set { + exportMade = value; + } + } + + public string Uri { + get { + return uri; + } + set { + uri = value; + } + } + + public string ErrorMessage { + get { + return errorMessage; + } + set { + errorMessage = value; + } + } + + public string Filepath { + get { + return filepath; + } + set { + filepath = value; + } + } + } + /// /// Description of IDestination. /// @@ -90,13 +159,20 @@ namespace Greenshot.Plugin { get; } + /// + /// Returns true if this destination returns a link + /// + bool isLinkable { + get; + } + /// /// If a capture is made, and the destination is enabled, this method is called. /// /// true if the user selected this destination from a GUI, false if it was called as part of a process /// /// - /// true if the destination has "exported" the capture - bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails); + /// DestinationExportInformation with information, like if the destination has "exported" the capture + ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails); } } diff --git a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs index 0741ff0f4..49f2f3240 100644 --- a/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs +++ b/GreenshotPlugin/Interfaces/Plugin/PluginInterfaces.cs @@ -174,7 +174,29 @@ namespace Greenshot.Plugin { IDictionary Plugins { get; } - + + /// + /// Get a destination by it's designation + /// + /// + /// IDestination + IDestination GetDestination(string designation); + + /// + /// Get a list of all available destinations + /// + /// List + List GetAllDestinations(); + + /// + /// Export a surface to the destination with has the supplied designation + /// + /// + /// + /// + /// + ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails); + /// /// Make region capture with specified Handler ///