mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Added the possibility to have a link to e.g. the original website when exporting to Outlook or Word.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2444 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
00a01236e0
commit
609075f8d1
5 changed files with 91 additions and 19 deletions
|
@ -186,7 +186,7 @@ namespace GreenshotOfficePlugin {
|
|||
return ShowPickerMenu(false, surface, captureDetails, destinations);
|
||||
}
|
||||
} else {
|
||||
exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC);
|
||||
exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC, null);
|
||||
}
|
||||
}
|
||||
ProcessExport(exportInformation, surface);
|
||||
|
|
|
@ -142,12 +142,12 @@ namespace GreenshotOfficePlugin {
|
|||
}
|
||||
}
|
||||
try {
|
||||
WordExporter.InsertIntoNewDocument(tmpFile);
|
||||
WordExporter.InsertIntoNewDocument(tmpFile, null);
|
||||
exportInformation.ExportMade = true;
|
||||
} catch(Exception) {
|
||||
// Retry once, just in case
|
||||
try {
|
||||
WordExporter.InsertIntoNewDocument(tmpFile);
|
||||
WordExporter.InsertIntoNewDocument(tmpFile, null);
|
||||
exportInformation.ExportMade = true;
|
||||
} catch (Exception ex) {
|
||||
LOG.Error(ex);
|
||||
|
|
|
@ -289,7 +289,7 @@ namespace Greenshot.Interop.Office {
|
|||
/// <param name="outlookApplication"></param>
|
||||
/// <param name="tmpFile"></param>
|
||||
/// <param name="captureDetails"></param>
|
||||
private static void ExportToNewEmail(IOutlookApplication outlookApplication, EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string CC, string BCC) {
|
||||
private static void ExportToNewEmail(IOutlookApplication outlookApplication, EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string CC, string BCC, string url) {
|
||||
Item newItem = outlookApplication.CreateItem(OlItemType.olMailItem);
|
||||
if (newItem == null) {
|
||||
return;
|
||||
|
@ -342,7 +342,13 @@ namespace Greenshot.Interop.Office {
|
|||
}
|
||||
|
||||
newMail.BodyFormat = OlBodyFormat.olFormatHTML;
|
||||
string htmlImgEmbedded = "<BR/><IMG border=0 hspace=0 alt=\"" + attachmentName + "\" align=baseline src=\"cid:" + contentID + "\"><BR/>";
|
||||
string href = "";
|
||||
string hrefEnd = "";
|
||||
if (!string.IsNullOrEmpty(url)) {
|
||||
href = string.Format("<A HREF=\"{0}\">", url);
|
||||
hrefEnd = "</A>";
|
||||
}
|
||||
string htmlImgEmbedded = string.Format("<BR/>{0}<IMG border=0 hspace=0 alt=\"{1}\" align=baseline src=\"cid:{2}\"><BR/>", href, attachmentName, contentID, hrefEnd);
|
||||
string fallbackBody = "<HTML><BODY>" + htmlImgEmbedded + "</BODY></HTML>";
|
||||
if (bodyString == null) {
|
||||
bodyString = fallbackBody;
|
||||
|
@ -376,12 +382,12 @@ namespace Greenshot.Interop.Office {
|
|||
/// </summary>
|
||||
/// <param name="tmpfile">The file to send, do not delete the file right away!</param>
|
||||
/// <returns>true if it worked, false if not</returns>
|
||||
public static bool ExportToOutlook(EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string CC, string BCC) {
|
||||
public static bool ExportToOutlook(EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string CC, string BCC, string url) {
|
||||
bool exported = false;
|
||||
try {
|
||||
using (IOutlookApplication outlookApplication = GetOrCreateOutlookApplication()) {
|
||||
if (outlookApplication != null) {
|
||||
ExportToNewEmail(outlookApplication, format, tmpFile, subject, attachmentName, to, CC, BCC);
|
||||
ExportToNewEmail(outlookApplication, format, tmpFile, subject, attachmentName, to, CC, BCC, url);
|
||||
exported = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,10 +62,25 @@ namespace Greenshot.Interop.Office {
|
|||
/// <param name="wordApplication"></param>
|
||||
/// <param name="wordDocument"></param>
|
||||
/// <param name="tmpFile"></param>
|
||||
/// <param name="adress">link for the image</param>
|
||||
/// <param name="tooltip">tooltip of the image</param>
|
||||
/// <returns></returns>
|
||||
internal static bool InsertIntoExistingDocument(IWordApplication wordApplication, IWordDocument wordDocument, string tmpFile) {
|
||||
internal static bool InsertIntoExistingDocument(IWordApplication wordApplication, IWordDocument wordDocument, string tmpFile, string address, string tooltip) {
|
||||
if (wordApplication.Selection != null) {
|
||||
AddPictureToSelection(wordApplication.Selection, tmpFile);
|
||||
// Add Picture
|
||||
using (IInlineShape shape = AddPictureToSelection(wordApplication.Selection, tmpFile)) {
|
||||
if (!string.IsNullOrEmpty(address)) {
|
||||
object screentip = Type.Missing;
|
||||
if (!string.IsNullOrEmpty(tooltip)) {
|
||||
screentip = tooltip;
|
||||
}
|
||||
try {
|
||||
wordDocument.Hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
|
||||
} catch (Exception e) {
|
||||
LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
wordDocument.ActiveWindow.ActivePane.View.Zoom.Percentage = 100;
|
||||
} catch (Exception e) {
|
||||
|
@ -89,12 +104,13 @@ namespace Greenshot.Interop.Office {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static void AddPictureToSelection(ISelection selection, string tmpFile) {
|
||||
selection.InlineShapes.AddPicture(tmpFile, false, true, Type.Missing);
|
||||
private static IInlineShape AddPictureToSelection(ISelection selection, string tmpFile) {
|
||||
IInlineShape shape = selection.InlineShapes.AddPicture(tmpFile, false, true, Type.Missing);
|
||||
selection.InsertAfter("\r\n");
|
||||
return shape;
|
||||
}
|
||||
|
||||
public static void InsertIntoNewDocument(string tmpFile) {
|
||||
public static void InsertIntoNewDocument(string tmpFile, string address, string tooltip) {
|
||||
using (IWordApplication wordApplication = COMWrapper.GetOrCreateInstance<IWordApplication>()) {
|
||||
if (wordApplication != null) {
|
||||
wordApplication.Visible = true;
|
||||
|
@ -106,7 +122,19 @@ namespace Greenshot.Interop.Office {
|
|||
object documentVisible = true;
|
||||
IWordDocument wordDocument = wordApplication.Documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible);
|
||||
// Add Picture
|
||||
AddPictureToSelection(wordApplication.Selection, tmpFile);
|
||||
using (IInlineShape shape = AddPictureToSelection(wordApplication.Selection, tmpFile)) {
|
||||
if (!string.IsNullOrEmpty(address)) {
|
||||
object screentip = Type.Missing;
|
||||
if (!string.IsNullOrEmpty(tooltip)) {
|
||||
screentip = tooltip;
|
||||
}
|
||||
try {
|
||||
wordDocument.Hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
|
||||
} catch (Exception e) {
|
||||
LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
wordDocument.Activate();
|
||||
wordDocument.ActiveWindow.Activate();
|
||||
}
|
||||
|
|
|
@ -37,18 +37,23 @@ namespace Greenshot.Interop.Office {
|
|||
IWordDocument item(int index);
|
||||
}
|
||||
|
||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.document.aspx
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.document%28v=office.14%29.aspx
|
||||
/// </summary>
|
||||
public interface IWordDocument : Common {
|
||||
void Activate();
|
||||
IWordApplication Application { get; }
|
||||
IWordWindow ActiveWindow { get; }
|
||||
bool ReadOnly { get; }
|
||||
IHyperlinks Hyperlinks { get; }
|
||||
|
||||
// Only 2007 and later!
|
||||
bool Final { get; set; }
|
||||
}
|
||||
|
||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.window_members.aspx
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.window_members.aspx
|
||||
/// </summary>
|
||||
public interface IWordWindow : Common {
|
||||
IPane ActivePane { get; }
|
||||
void Activate();
|
||||
|
@ -57,12 +62,16 @@ namespace Greenshot.Interop.Office {
|
|||
}
|
||||
}
|
||||
|
||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pane_members.aspx
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pane_members.aspx
|
||||
/// </summary>
|
||||
public interface IPane : Common {
|
||||
IWordView View { get; }
|
||||
}
|
||||
|
||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.view_members.aspx
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.view_members.aspx
|
||||
/// </summary>
|
||||
public interface IWordView : Common {
|
||||
IZoom Zoom { get; }
|
||||
}
|
||||
|
@ -72,13 +81,42 @@ namespace Greenshot.Interop.Office {
|
|||
int Percentage { get; set; }
|
||||
}
|
||||
|
||||
// See: http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.selection_members(v=office.11).aspx
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/de-de/library/microsoft.office.interop.word.selection_members(v=office.11).aspx
|
||||
/// </summary>
|
||||
public interface ISelection : Common {
|
||||
IInlineShapes InlineShapes { get; }
|
||||
void InsertAfter(string text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/ms263866%28v=office.14%29.aspx
|
||||
/// </summary>
|
||||
public interface IInlineShapes : Common {
|
||||
object AddPicture(string FileName, object LinkToFile, object SaveWithDocument, object Range);
|
||||
IInlineShape AddPicture(string FileName, object LinkToFile, object SaveWithDocument, object Range);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.inlineshape_members%28v=office.14%29.aspx
|
||||
/// </summary>
|
||||
public interface IInlineShape : Common {
|
||||
IHyperlink Hyperlink { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.hyperlink_members%28v=office.14%29.aspx
|
||||
/// </summary>
|
||||
public interface IHyperlink : Common {
|
||||
string Address {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.hyperlinks%28v=office.14%29.aspx
|
||||
/// </summary>
|
||||
public interface IHyperlinks : Common, Collection {
|
||||
IHyperlink Add(object Anchor, object Address, object SubAddress, object ScreenTip, object TextToDisplay, object Target);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue