Extended the ExportCapture with ExportInformation as a result object, this allows us to better and more consistently return & handle information from the export. Also it should be easier to extend the functionality. TODO: Still need to cleanup some messages, some are no longer needed

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2034 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-09-14 15:04:37 +00:00
commit be797ecf8a
27 changed files with 379 additions and 172 deletions

View file

@ -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);
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -175,16 +175,15 @@ 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);
exportInformation.ExportMade = true;
}
return true;
}
return exportInformation;
} else {
// Outlook logic
string tmpFile = captureDetails.Filename;
if (tmpFile == null || surface.Modified) {
@ -209,6 +208,7 @@ namespace Greenshot.Destinations {
if (outlookInspectorCaption != null) {
OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName);
exportInformation.ExportMade = true;
} else {
if (!manuallyInitiated) {
Dictionary<string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings);
@ -219,17 +219,14 @@ namespace Greenshot.Destinations {
destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
}
PickerDestination.ShowPickerMenu(false, surface, captureDetails, destinations);
return false;
}
}
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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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 {
/// <param name="surface">Surface to export</param>
/// <param name="captureDetails">Details of the capture</param>
/// <returns>true if export was made</returns>
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<IDestination> destinations = new List<IDestination>();
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;
}
}
}

View file

@ -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<string> 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;
}
}
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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectGuid>{CD642BF4-D815-4D67-A0B5-C69F0B8231AF}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -17,8 +17,27 @@
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<ApplicationManifest>greenshot.manifest</ApplicationManifest>
<TargetFrameworkProfile />
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
@ -31,7 +50,7 @@
<FileAlignment>4096</FileAlignment>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
@ -43,6 +62,29 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<FileAlignment>4096</FileAlignment>
<DebugType>Full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
<CodeAnalysisFailOnMissingRules>true</CodeAnalysisFailOnMissingRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<FileAlignment>4096</FileAlignment>
<DebugType>None</DebugType>
<PlatformTarget>x86</PlatformTarget>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>Lib\log4net.dll</HintPath>
@ -405,6 +447,23 @@
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
@ -412,11 +471,11 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PreBuildEvent>"$(MSBuildProjectDirectory)\tools\TortoiseSVN\SubWCRev.exe" "$(MSBuildProjectDirectory)\." "$(MSBuildProjectDirectory)\AssemblyInfo.cs.template" "$(MSBuildProjectDirectory)\AssemblyInfo.cs"
copy "$(ProjectDir)log4net.xml" "$(SolutionDir)bin\$(Configuration)\log4net.xml"</PreBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PreBuildEvent>"$(MSBuildProjectDirectory)\tools\TortoiseSVN\SubWCRev.exe" "$(MSBuildProjectDirectory)\." "$(MSBuildProjectDirectory)\AssemblyInfo.cs.template" "$(MSBuildProjectDirectory)\AssemblyInfo.cs"
copy "$(ProjectDir)log4net-debug.xml" "$(SolutionDir)bin\$(Configuration)\log4net.xml"</PreBuildEvent>
</PropertyGroup>

View file

@ -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;
}
}

View file

@ -128,18 +128,19 @@ namespace Greenshot.Helpers {
/// <param name="designation"></param>
/// <param name="surface"></param>
/// <param name="captureDetails"></param>
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)) {
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;
}
}
}

View file

@ -140,6 +140,17 @@ namespace Greenshot.Helpers {
get {return plugins;}
}
public IDestination GetDestination(string designation) {
return DestinationHelper.GetDestination(designation);
}
public List<IDestination> GetAllDestinations() {
return DestinationHelper.GetAllDestinations();
}
public ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) {
return DestinationHelper.ExportCapture(manuallyInitiated, designation, surface, captureDetails);
}
/// <summary>
/// Make Capture with specified Handler
/// </summary>

View file

@ -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) {
@ -146,17 +145,15 @@ namespace GreenshotConfluencePlugin {
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) {

View file

@ -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) {

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
return uploaded;
exportInformation.ExportMade = true;
exportInformation.Uri = uploadURL;
}
}
ProcessExport(exportInformation, surface);
return exportInformation;
}
}
}

View file

@ -68,17 +68,14 @@ namespace GreenshotPhotobucketPlugin {
config = IniConfig.GetIniSection<PhotobucketConfiguration>();
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;
}

View file

@ -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,7 +188,29 @@ namespace GreenshotPlugin.Core {
}
}
public abstract bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);
public abstract ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);
/// <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) {
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;

View file

@ -37,7 +37,7 @@ namespace Greenshot.Plugin {
FileSaved,
Error,
Info,
UploadedUrl
UploadedUri
}
public class SurfaceMessageEventArgs : EventArgs {

View file

@ -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;
}
}
}
/// <summary>
/// Description of IDestination.
/// </summary>
@ -90,13 +159,20 @@ namespace Greenshot.Plugin {
get;
}
/// <summary>
/// Returns true if this destination returns a link
/// </summary>
bool isLinkable {
get;
}
/// <summary>
/// If a capture is made, and the destination is enabled, this method is called.
/// </summary>
/// <param name="manuallyInitiated">true if the user selected this destination from a GUI, false if it was called as part of a process</param>
/// <param name="surface"></param>
/// <param name="captureDetails"></param>
/// <returns>true if the destination has "exported" the capture</returns>
bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);
/// <returns>DestinationExportInformation with information, like if the destination has "exported" the capture</returns>
ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);
}
}

View file

@ -175,6 +175,28 @@ namespace Greenshot.Plugin {
get;
}
/// <summary>
/// Get a destination by it's designation
/// </summary>
/// <param name="destination"></param>
/// <returns>IDestination</returns>
IDestination GetDestination(string designation);
/// <summary>
/// Get a list of all available destinations
/// </summary>
/// <returns>List<IDestination></returns>
List<IDestination> GetAllDestinations();
/// <summary>
/// Export a surface to the destination with has the supplied designation
/// </summary>
/// <param name="manuallyInitiated"></param>
/// <param name="designation"></param>
/// <param name="surface"></param>
/// <param name="captureDetails"></param>
ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails);
/// <summary>
/// Make region capture with specified Handler
/// </summary>