mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
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:
parent
c092712561
commit
eb616472c4
24 changed files with 68 additions and 47 deletions
|
@ -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);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
ClipboardHelper.SetClipboardData(image);
|
||||
|
|
|
@ -90,8 +90,8 @@ namespace Greenshot.Destinations {
|
|||
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) {
|
||||
// Make sure we collect the garbage before opening the screenshot
|
||||
GC.Collect();
|
||||
|
|
|
@ -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) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
MapiMailMessage.SendImage(image, captureDetails);
|
||||
|
|
|
@ -109,8 +109,8 @@ namespace Greenshot.Destinations {
|
|||
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;
|
||||
if (tmpFile == null || surface.Modified) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
|
|
|
@ -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;
|
||||
string pattern = conf.OutputFileFilenamePattern;
|
||||
if (string.IsNullOrEmpty(pattern)) {
|
||||
|
|
|
@ -70,8 +70,8 @@ namespace Greenshot.Destinations {
|
|||
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;
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
// Bug #2918756 don't overwrite path if SaveWithDialog returns null!
|
||||
|
|
|
@ -108,8 +108,8 @@ namespace Greenshot.Destinations {
|
|||
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()) {
|
||||
if (page != null) {
|
||||
try {
|
||||
|
|
|
@ -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();
|
||||
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
|
||||
LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
|
||||
|
@ -94,7 +94,7 @@ namespace Greenshot.Destinations {
|
|||
}
|
||||
// Make sure the menu is closed
|
||||
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
|
||||
if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) {
|
||||
LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result);
|
||||
|
|
|
@ -110,8 +110,8 @@ namespace Greenshot.Destinations {
|
|||
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;
|
||||
Size imageSize = Size.Empty;
|
||||
if (tmpFile == null || surface.Modified) {
|
||||
|
|
|
@ -71,8 +71,8 @@ namespace Greenshot.Destinations {
|
|||
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;
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog();
|
||||
|
|
|
@ -111,8 +111,8 @@ namespace Greenshot.Destinations {
|
|||
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;
|
||||
if (tmpFile == null || surface.Modified) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
|
@ -122,7 +122,19 @@ namespace Greenshot.Destinations {
|
|||
if (documentCaption != null) {
|
||||
WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
|
||||
} 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.Modified = false;
|
||||
|
|
|
@ -181,12 +181,12 @@ namespace Greenshot {
|
|||
defaultItem.Tag = toolstripDestination;
|
||||
defaultItem.Image = toolstripDestination.DisplayIcon;
|
||||
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
|
||||
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
|
||||
|
@ -204,7 +204,7 @@ namespace Greenshot {
|
|||
destinationMenuItem.Tag = closureFixedDestination;
|
||||
destinationMenuItem.Image = closureFixedDestination.DisplayIcon;
|
||||
destinationMenuItem.Click += delegate {
|
||||
closureFixedDestination.ExportCapture(surface, surface.CaptureDetails);
|
||||
closureFixedDestination.ExportCapture(true, surface, surface.CaptureDetails);
|
||||
};
|
||||
destinationButton.DropDownItems.Add(destinationMenuItem);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ namespace Greenshot {
|
|||
destinationButton.Text = toolstripDestination.Description;
|
||||
destinationButton.Image = toolstripDestination.DisplayIcon;
|
||||
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) {
|
||||
destinationDesignation = Destinations.FileWithDialogDestination.DESIGNATION;
|
||||
}
|
||||
DestinationHelper.ExportCapture(destinationDesignation, surface, surface.CaptureDetails);
|
||||
DestinationHelper.ExportCapture(true, destinationDesignation, surface, surface.CaptureDetails);
|
||||
}
|
||||
|
||||
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) {
|
||||
// The BeginInvoke is a solution for the printdialog not having focus
|
||||
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;
|
||||
}
|
||||
if (clickedDestination != null) {
|
||||
if (clickedDestination.ExportCapture(surface, surface.CaptureDetails)) {
|
||||
if (clickedDestination.ExportCapture(true, surface, surface.CaptureDetails)) {
|
||||
surface.Modified = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -484,7 +484,7 @@ namespace Greenshot.Helpers {
|
|||
bool canDisposeSurface = true;
|
||||
|
||||
if (captureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION)) {
|
||||
DestinationHelper.ExportCapture(Destinations.PickerDestination.DESIGNATION, surface, captureDetails);
|
||||
DestinationHelper.ExportCapture(false, Destinations.PickerDestination.DESIGNATION, surface, captureDetails);
|
||||
captureDetails.CaptureDestinations.Clear();
|
||||
canDisposeSurface = false;
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
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) {
|
||||
canDisposeSurface = false;
|
||||
}
|
||||
|
|
|
@ -112,11 +112,11 @@ namespace Greenshot.Helpers {
|
|||
/// <param name="designation"></param>
|
||||
/// <param name="surface"></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)) {
|
||||
IDestination destination = RegisteredDestinations[designation];
|
||||
if (destination.isActive) {
|
||||
if (destination.ExportCapture(surface, captureDetails)) {
|
||||
if (destination.ExportCapture(manuallyInitiated, surface, captureDetails)) {
|
||||
// Export worked, set the modified flag
|
||||
surface.Modified = false;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
if (!ConfluencePlugin.ConfluenceConnector.isLoggedIn) {
|
||||
return false;
|
||||
|
|
|
@ -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;
|
||||
if (fullPath == null) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
|
|
|
@ -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()) {
|
||||
bool uploaded = plugin.Upload(captureDetails, image);
|
||||
if (uploaded) {
|
||||
|
|
|
@ -60,6 +60,9 @@ namespace Greenshot.Interop.Office {
|
|||
LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
|
||||
}
|
||||
}
|
||||
wordDocument.Application.Activate();
|
||||
wordDocument.Activate();
|
||||
wordDocument.ActiveWindow.Activate();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -67,22 +70,24 @@ namespace Greenshot.Interop.Office {
|
|||
|
||||
private static void AddPictureToSelection(ISelection selection, string tmpFile) {
|
||||
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) {
|
||||
using (IWordApplication wordApplication = COMWrapper.GetOrCreateInstance<IWordApplication>()) {
|
||||
if (wordApplication != null) {
|
||||
wordApplication.Visible = true;
|
||||
|
||||
wordApplication.Activate();
|
||||
// Create new Document
|
||||
object template = string.Empty;
|
||||
object newTemplate = false;
|
||||
object documentType = 0;
|
||||
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
|
||||
AddPictureToSelection(wordApplication.Selection, tmpFile);
|
||||
wordDocument.Activate();
|
||||
wordDocument.ActiveWindow.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,23 +30,26 @@ namespace Greenshot.Interop.Office {
|
|||
ISelection Selection { get; }
|
||||
IDocuments Documents { get; }
|
||||
bool Visible { get; set; }
|
||||
void Activate();
|
||||
}
|
||||
|
||||
// See: http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.documents_members(v=office.11).aspx
|
||||
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);
|
||||
}
|
||||
|
||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.document.aspx
|
||||
public interface IWordDocument : Common {
|
||||
void Activate();
|
||||
IWordApplication Application { get; }
|
||||
Window ActiveWindow { get; }
|
||||
WordWindow ActiveWindow { get; }
|
||||
}
|
||||
|
||||
// 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; }
|
||||
void Activate();
|
||||
string Caption {
|
||||
get;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
byte[] buffer;
|
||||
if (jira != null) {
|
||||
|
|
|
@ -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() {
|
||||
return Description;
|
||||
|
|
|
@ -92,9 +92,10 @@ namespace Greenshot.Plugin {
|
|||
/// <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(ISurface surface, ICaptureDetails captureDetails);
|
||||
bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>();
|
||||
string file = host.GetFilename(OutputFormat.png, null);
|
||||
string filePath = Path.Combine(config.OutputFilePath, file);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue