Changed IDestination, added a manuallyInitiated so the destination can change its behavior depending on the flag. An example use-case would be the word exporter: if the flag is false, which it would be if the word destination is set as THE destination, it would add to the current document if one is available otherwise create a new. This makes it possible to have a kind of session behavior.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1749 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-04 13:46:14 +00:00
parent c092712561
commit eb616472c4
24 changed files with 68 additions and 47 deletions

View file

@ -57,7 +57,7 @@ namespace GreenshotOCR {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
OcrPlugin.DoOCR(surface); OcrPlugin.DoOCR(surface);
return true; return true;
} }

View file

@ -70,7 +70,7 @@ namespace Greenshot.Destinations {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
try { try {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
ClipboardHelper.SetClipboardData(image); ClipboardHelper.SetClipboardData(image);

View file

@ -90,8 +90,8 @@ namespace Greenshot.Destinations {
yield return new EditorDestination(editor); yield return new EditorDestination(editor);
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
if (editor == null) { if (editor == null) {
// Make sure we collect the garbage before opening the screenshot // Make sure we collect the garbage before opening the screenshot
GC.Collect(); GC.Collect();

View file

@ -175,7 +175,7 @@ namespace Greenshot.Destinations {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
if (!isOutlookUsed) { if (!isOutlookUsed) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
MapiMailMessage.SendImage(image, captureDetails); MapiMailMessage.SendImage(image, captureDetails);

View file

@ -109,8 +109,8 @@ namespace Greenshot.Destinations {
yield return new ExcelDestination(workbookName); yield return new ExcelDestination(workbookName);
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
string tmpFile = captureDetails.Filename; string tmpFile = captureDetails.Filename;
if (tmpFile == null || surface.Modified) { if (tmpFile == null || surface.Modified) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {

View file

@ -70,7 +70,7 @@ namespace Greenshot.Destinations {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
bool outputMade = false; bool outputMade = false;
string pattern = conf.OutputFileFilenamePattern; string pattern = conf.OutputFileFilenamePattern;
if (string.IsNullOrEmpty(pattern)) { if (string.IsNullOrEmpty(pattern)) {

View file

@ -70,8 +70,8 @@ namespace Greenshot.Destinations {
return GreenshotPlugin.Core.GreenshotResources.getImage("Save.Image"); return GreenshotPlugin.Core.GreenshotResources.getImage("Save.Image");
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
string savedTo = null; string savedTo = null;
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
// Bug #2918756 don't overwrite path if SaveWithDialog returns null! // Bug #2918756 don't overwrite path if SaveWithDialog returns null!

View file

@ -108,8 +108,8 @@ namespace Greenshot.Destinations {
yield return new OneNoteDestination(page); yield return new OneNoteDestination(page);
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
if (page != null) { if (page != null) {
try { try {

View file

@ -65,7 +65,7 @@ namespace Greenshot.Destinations {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ContextMenuStrip menu = new ContextMenuStrip(); ContextMenuStrip menu = new ContextMenuStrip();
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) { menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason); LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
@ -94,7 +94,7 @@ namespace Greenshot.Destinations {
} }
// Make sure the menu is closed // Make sure the menu is closed
menu.Close(); menu.Close();
bool result = clickedDestination.ExportCapture(surface, captureDetails); bool result = clickedDestination.ExportCapture(true, surface, captureDetails);
// TODO: Find some better way to detect that we exported to the editor // TODO: Find some better way to detect that we exported to the editor
if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) { if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) {
LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result); LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result);

View file

@ -110,8 +110,8 @@ namespace Greenshot.Destinations {
yield return new PowerpointDestination(presentationName); yield return new PowerpointDestination(presentationName);
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
string tmpFile = captureDetails.Filename; string tmpFile = captureDetails.Filename;
Size imageSize = Size.Empty; Size imageSize = Size.Empty;
if (tmpFile == null || surface.Modified) { if (tmpFile == null || surface.Modified) {

View file

@ -71,8 +71,8 @@ namespace Greenshot.Destinations {
return GreenshotPlugin.Core.GreenshotResources.getImage("Printer.Image"); return GreenshotPlugin.Core.GreenshotResources.getImage("Printer.Image");
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
PrinterSettings printerSettings = null; PrinterSettings printerSettings = null;
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog(); printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog();

View file

@ -111,8 +111,8 @@ namespace Greenshot.Destinations {
yield return new WordDestination(wordCaption); yield return new WordDestination(wordCaption);
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
string tmpFile = captureDetails.Filename; string tmpFile = captureDetails.Filename;
if (tmpFile == null || surface.Modified) { if (tmpFile == null || surface.Modified) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
@ -122,7 +122,19 @@ namespace Greenshot.Destinations {
if (documentCaption != null) { if (documentCaption != null) {
WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile); WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
} else { } else {
WordExporter.InsertIntoNewDocument(tmpFile); bool exported = false;
if (!manuallyInitiated) {
// Insert into current document, if only one is open!
List<string> currentDocuments = WordExporter.GetWordDocuments();
if (currentDocuments.Count == 1) {
WordExporter.InsertIntoExistingDocument(currentDocuments[0], tmpFile);
exported = true;
}
}
if (!exported) {
WordExporter.InsertIntoNewDocument(tmpFile);
}
} }
surface.SendMessageEvent(this, SurfaceMessageTyp.Info, lang.GetFormattedString(LangKey.exported_to, Description)); surface.SendMessageEvent(this, SurfaceMessageTyp.Info, lang.GetFormattedString(LangKey.exported_to, Description));
surface.Modified = false; surface.Modified = false;

View file

@ -181,12 +181,12 @@ namespace Greenshot {
defaultItem.Tag = toolstripDestination; defaultItem.Tag = toolstripDestination;
defaultItem.Image = toolstripDestination.DisplayIcon; defaultItem.Image = toolstripDestination.DisplayIcon;
defaultItem.Click += delegate { defaultItem.Click += delegate {
toolstripDestination.ExportCapture(surface, surface.CaptureDetails); toolstripDestination.ExportCapture(true, surface, surface.CaptureDetails);
}; };
// The ButtonClick, this is for the icon, gets the current default item // The ButtonClick, this is for the icon, gets the current default item
destinationButton.ButtonClick += delegate(object sender, EventArgs e) { destinationButton.ButtonClick += delegate(object sender, EventArgs e) {
toolstripDestination.ExportCapture(surface, surface.CaptureDetails); toolstripDestination.ExportCapture(true, surface, surface.CaptureDetails);
}; };
// Generate the entries for the drop down // Generate the entries for the drop down
@ -204,7 +204,7 @@ namespace Greenshot {
destinationMenuItem.Tag = closureFixedDestination; destinationMenuItem.Tag = closureFixedDestination;
destinationMenuItem.Image = closureFixedDestination.DisplayIcon; destinationMenuItem.Image = closureFixedDestination.DisplayIcon;
destinationMenuItem.Click += delegate { destinationMenuItem.Click += delegate {
closureFixedDestination.ExportCapture(surface, surface.CaptureDetails); closureFixedDestination.ExportCapture(true, surface, surface.CaptureDetails);
}; };
destinationButton.DropDownItems.Add(destinationMenuItem); destinationButton.DropDownItems.Add(destinationMenuItem);
} }
@ -221,7 +221,7 @@ namespace Greenshot {
destinationButton.Text = toolstripDestination.Description; destinationButton.Text = toolstripDestination.Description;
destinationButton.Image = toolstripDestination.DisplayIcon; destinationButton.Image = toolstripDestination.DisplayIcon;
destinationButton.Click += delegate(object sender, EventArgs e) { destinationButton.Click += delegate(object sender, EventArgs e) {
toolstripDestination.ExportCapture(surface, surface.CaptureDetails); toolstripDestination.ExportCapture(true, surface, surface.CaptureDetails);
}; };
} }
} }
@ -474,17 +474,17 @@ namespace Greenshot {
if (surface.LastSaveFullPath == null) { if (surface.LastSaveFullPath == null) {
destinationDesignation = Destinations.FileWithDialogDestination.DESIGNATION; destinationDesignation = Destinations.FileWithDialogDestination.DESIGNATION;
} }
DestinationHelper.ExportCapture(destinationDesignation, surface, surface.CaptureDetails); DestinationHelper.ExportCapture(true, destinationDesignation, surface, surface.CaptureDetails);
} }
void BtnClipboardClick(object sender, EventArgs e) { void BtnClipboardClick(object sender, EventArgs e) {
DestinationHelper.ExportCapture(Destinations.ClipboardDestination.DESIGNATION, surface, surface.CaptureDetails); DestinationHelper.ExportCapture(true, Destinations.ClipboardDestination.DESIGNATION, surface, surface.CaptureDetails);
} }
void BtnPrintClick(object sender, EventArgs e) { void BtnPrintClick(object sender, EventArgs e) {
// The BeginInvoke is a solution for the printdialog not having focus // The BeginInvoke is a solution for the printdialog not having focus
this.BeginInvoke((MethodInvoker) delegate { this.BeginInvoke((MethodInvoker) delegate {
DestinationHelper.ExportCapture(Destinations.PrinterDestination.DESIGNATION, surface, surface.CaptureDetails); DestinationHelper.ExportCapture(true, Destinations.PrinterDestination.DESIGNATION, surface, surface.CaptureDetails);
}); });
} }
@ -1105,7 +1105,7 @@ namespace Greenshot {
clickedDestination = (IDestination)clickedMenuItem.Tag; clickedDestination = (IDestination)clickedMenuItem.Tag;
} }
if (clickedDestination != null) { if (clickedDestination != null) {
if (clickedDestination.ExportCapture(surface, surface.CaptureDetails)) { if (clickedDestination.ExportCapture(true, surface, surface.CaptureDetails)) {
surface.Modified = false; surface.Modified = false;
} }
} }

View file

@ -484,7 +484,7 @@ namespace Greenshot.Helpers {
bool canDisposeSurface = true; bool canDisposeSurface = true;
if (captureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION)) { if (captureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION)) {
DestinationHelper.ExportCapture(Destinations.PickerDestination.DESIGNATION, surface, captureDetails); DestinationHelper.ExportCapture(false, Destinations.PickerDestination.DESIGNATION, surface, captureDetails);
captureDetails.CaptureDestinations.Clear(); captureDetails.CaptureDestinations.Clear();
canDisposeSurface = false; canDisposeSurface = false;
} }
@ -505,7 +505,7 @@ namespace Greenshot.Helpers {
} }
LOG.InfoFormat("Calling destination {0}", destination.Description); LOG.InfoFormat("Calling destination {0}", destination.Description);
bool destinationOk = destination.ExportCapture(surface, captureDetails); bool destinationOk = destination.ExportCapture(false, surface, captureDetails);
if (Destinations.EditorDestination.DESIGNATION.Equals(destination.Designation) && destinationOk) { if (Destinations.EditorDestination.DESIGNATION.Equals(destination.Designation) && destinationOk) {
canDisposeSurface = false; canDisposeSurface = false;
} }

View file

@ -112,11 +112,11 @@ namespace Greenshot.Helpers {
/// <param name="designation"></param> /// <param name="designation"></param>
/// <param name="surface"></param> /// <param name="surface"></param>
/// <param name="captureDetails"></param> /// <param name="captureDetails"></param>
public static void ExportCapture(string designation, ISurface surface, ICaptureDetails captureDetails) { public static void ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) {
if (RegisteredDestinations.ContainsKey(designation)) { if (RegisteredDestinations.ContainsKey(designation)) {
IDestination destination = RegisteredDestinations[designation]; IDestination destination = RegisteredDestinations[designation];
if (destination.isActive) { if (destination.isActive) {
if (destination.ExportCapture(surface, captureDetails)) { if (destination.ExportCapture(manuallyInitiated, surface, captureDetails)) {
// Export worked, set the modified flag // Export worked, set the modified flag
surface.Modified = false; surface.Modified = false;
} }

View file

@ -106,7 +106,7 @@ namespace GreenshotConfluencePlugin {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
// force password check to take place before the pages load // force password check to take place before the pages load
if (!ConfluencePlugin.ConfluenceConnector.isLoggedIn) { if (!ConfluencePlugin.ConfluenceConnector.isLoggedIn) {
return false; return false;

View file

@ -72,7 +72,7 @@ namespace ExternalCommand {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
string fullPath = captureDetails.Filename; string fullPath = captureDetails.Filename;
if (fullPath == null) { if (fullPath == null) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {

View file

@ -65,7 +65,7 @@ namespace GreenshotImgurPlugin {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
using (Image image = surface.GetImageForExport()) { using (Image image = surface.GetImageForExport()) {
bool uploaded = plugin.Upload(captureDetails, image); bool uploaded = plugin.Upload(captureDetails, image);
if (uploaded) { if (uploaded) {

View file

@ -60,6 +60,9 @@ namespace Greenshot.Interop.Office {
LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message); LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
} }
} }
wordDocument.Application.Activate();
wordDocument.Activate();
wordDocument.ActiveWindow.Activate();
return true; return true;
} }
return false; return false;
@ -67,22 +70,24 @@ namespace Greenshot.Interop.Office {
private static void AddPictureToSelection(ISelection selection, string tmpFile) { private static void AddPictureToSelection(ISelection selection, string tmpFile) {
selection.InlineShapes.AddPicture(tmpFile, Type.Missing, Type.Missing, Type.Missing); selection.InlineShapes.AddPicture(tmpFile, Type.Missing, Type.Missing, Type.Missing);
//selection.InsertAfter("blablub\r\n"); selection.InsertAfter("\r\n");
} }
public static void InsertIntoNewDocument(string tmpFile) { public static void InsertIntoNewDocument(string tmpFile) {
using (IWordApplication wordApplication = COMWrapper.GetOrCreateInstance<IWordApplication>()) { using (IWordApplication wordApplication = COMWrapper.GetOrCreateInstance<IWordApplication>()) {
if (wordApplication != null) { if (wordApplication != null) {
wordApplication.Visible = true; wordApplication.Visible = true;
wordApplication.Activate();
// Create new Document // Create new Document
object template = string.Empty; object template = string.Empty;
object newTemplate = false; object newTemplate = false;
object documentType = 0; object documentType = 0;
object documentVisible = true; object documentVisible = true;
wordApplication.Documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible); IWordDocument wordDocument = wordApplication.Documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible);
// Add Picture // Add Picture
AddPictureToSelection(wordApplication.Selection, tmpFile); AddPictureToSelection(wordApplication.Selection, tmpFile);
wordDocument.Activate();
wordDocument.ActiveWindow.Activate();
} }
} }
} }

View file

@ -30,23 +30,26 @@ namespace Greenshot.Interop.Office {
ISelection Selection { get; } ISelection Selection { get; }
IDocuments Documents { get; } IDocuments Documents { get; }
bool Visible { get; set; } bool Visible { get; set; }
void Activate();
} }
// See: http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.documents_members(v=office.11).aspx // See: http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.documents_members(v=office.11).aspx
public interface IDocuments : Common, Collection { public interface IDocuments : Common, Collection {
void Add(ref object Template, ref object NewTemplate, ref object DocumentType, ref object Visible); IWordDocument Add(ref object Template, ref object NewTemplate, ref object DocumentType, ref object Visible);
IWordDocument item(int index); IWordDocument item(int index);
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.document.aspx // See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.document.aspx
public interface IWordDocument : Common { public interface IWordDocument : Common {
void Activate();
IWordApplication Application { get; } IWordApplication Application { get; }
Window ActiveWindow { get; } WordWindow ActiveWindow { get; }
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.window_members.aspx // See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.window_members.aspx
public interface Window : Common { public interface WordWindow : Common {
Pane ActivePane { get; } Pane ActivePane { get; }
void Activate();
string Caption { string Caption {
get; get;
} }

View file

@ -98,8 +98,8 @@ namespace GreenshotJiraPlugin {
} }
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails)); string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails));
byte[] buffer; byte[] buffer;
if (jira != null) { if (jira != null) {

View file

@ -172,7 +172,7 @@ namespace GreenshotPlugin.Core {
} }
} }
public abstract bool ExportCapture(ISurface surface, ICaptureDetails captureDetails); public abstract bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);
public override string ToString() { public override string ToString() {
return Description; return Description;

View file

@ -92,9 +92,10 @@ namespace Greenshot.Plugin {
/// <summary> /// <summary>
/// If a capture is made, and the destination is enabled, this method is called. /// If a capture is made, and the destination is enabled, this method is called.
/// </summary> /// </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="surface"></param>
/// <param name="captureDetails"></param> /// <param name="captureDetails"></param>
/// <returns>true if the destination has "exported" the capture</returns> /// <returns>true if the destination has "exported" the capture</returns>
bool ExportCapture(ISurface surface, ICaptureDetails captureDetails); bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);
} }
} }

View file

@ -61,7 +61,7 @@ namespace PluginExample {
} }
} }
public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails) { public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>(); CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
string file = host.GetFilename(OutputFormat.png, null); string file = host.GetFilename(OutputFormat.png, null);
string filePath = Path.Combine(config.OutputFilePath, file); string filePath = Path.Combine(config.OutputFilePath, file);