mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Fixed some problems exporting to word & powerpoint
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1751 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
c6099649f6
commit
1e436b69ee
9 changed files with 90 additions and 38 deletions
|
@ -39,7 +39,7 @@ namespace Greenshot.Destinations {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PickerDestination));
|
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PickerDestination));
|
||||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
public const string DESIGNATION = "Picker";
|
public const string DESIGNATION = "Picker";
|
||||||
private ILanguage lang = Language.GetInstance();
|
private static ILanguage lang = Language.GetInstance();
|
||||||
|
|
||||||
public override string Designation {
|
public override string Designation {
|
||||||
get {
|
get {
|
||||||
|
@ -65,7 +65,7 @@ namespace Greenshot.Destinations {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) {
|
||||||
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);
|
||||||
|
@ -73,16 +73,9 @@ namespace Greenshot.Destinations {
|
||||||
eventArgs.Cancel = true;
|
eventArgs.Cancel = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
foreach (IDestination destination in destinations) {
|
||||||
foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {
|
|
||||||
if ("Picker".Equals(destination.Designation)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!destination.isActive) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Fix foreach loop variable for the delegate
|
// Fix foreach loop variable for the delegate
|
||||||
ToolStripMenuItem item = destination.GetMenuItem(
|
ToolStripMenuItem item = destination.GetMenuItem(addDynamics,
|
||||||
delegate(object sender, EventArgs e) {
|
delegate(object sender, EventArgs e) {
|
||||||
ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
|
ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
|
||||||
if (toolStripMenuItem == null) {
|
if (toolStripMenuItem == null) {
|
||||||
|
@ -107,7 +100,6 @@ namespace Greenshot.Destinations {
|
||||||
menu.Items.Add(item);
|
menu.Items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close
|
// Close
|
||||||
menu.Items.Add(new ToolStripSeparator());
|
menu.Items.Add(new ToolStripSeparator());
|
||||||
ToolStripMenuItem closeItem = new ToolStripMenuItem(lang.GetString(LangKey.editor_close));
|
ToolStripMenuItem closeItem = new ToolStripMenuItem(lang.GetString(LangKey.editor_close));
|
||||||
|
@ -119,10 +111,15 @@ namespace Greenshot.Destinations {
|
||||||
surface.Dispose();
|
surface.Dispose();
|
||||||
};
|
};
|
||||||
menu.Items.Add(closeItem);
|
menu.Items.Add(closeItem);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ShowMenuAtCursor(ContextMenuStrip menu) {
|
||||||
// find a suitable location
|
// find a suitable location
|
||||||
Point location = Cursor.Position;
|
Point location = Cursor.Position;
|
||||||
Rectangle menuRectangle = new Rectangle(location, menu.Size);
|
Rectangle menuRectangle = new Rectangle(location, menu.Size);
|
||||||
|
|
||||||
menuRectangle.Intersect(WindowCapture.GetScreenBounds());
|
menuRectangle.Intersect(WindowCapture.GetScreenBounds());
|
||||||
if (menuRectangle.Height < menu.Height) {
|
if (menuRectangle.Height < menu.Height) {
|
||||||
location.Offset(-40, -(menuRectangle.Height - menu.Height));
|
location.Offset(-40, -(menuRectangle.Height - menu.Height));
|
||||||
|
@ -131,6 +128,22 @@ namespace Greenshot.Destinations {
|
||||||
}
|
}
|
||||||
menu.Show(location);
|
menu.Show(location);
|
||||||
menu.Focus();
|
menu.Focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||||
|
List<IDestination> destinations = new List<IDestination>();
|
||||||
|
foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {
|
||||||
|
if ("Picker".Equals(destination.Designation)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!destination.isActive) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
destinations.Add(destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextMenuStrip menu = CreatePickerMenu(true, surface, captureDetails, destinations);
|
||||||
|
ShowMenuAtCursor(menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,16 @@ namespace Greenshot.Destinations {
|
||||||
yield return new PowerpointDestination(presentationName);
|
yield return new PowerpointDestination(presentationName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Helper method for adding the normal "empty" PowerpointDestination
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private IEnumerable<IDestination> AllDynamicDestinations() {
|
||||||
|
yield return new PowerpointDestination();
|
||||||
|
foreach (string presentationName in PowerpointExporter.GetPowerpointPresentations()) {
|
||||||
|
yield return new PowerpointDestination(presentationName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||||
string tmpFile = captureDetails.Filename;
|
string tmpFile = captureDetails.Filename;
|
||||||
|
@ -123,7 +133,13 @@ namespace Greenshot.Destinations {
|
||||||
if (presentationName != null) {
|
if (presentationName != null) {
|
||||||
PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title);
|
PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title);
|
||||||
} else {
|
} else {
|
||||||
PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
|
if (manuallyInitiated) {
|
||||||
|
PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
|
||||||
|
} else {
|
||||||
|
ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, AllDynamicDestinations());
|
||||||
|
PickerDestination.ShowMenuAtCursor(menu);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|
|
@ -112,6 +112,17 @@ namespace Greenshot.Destinations {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper method for adding the normal "empty" WordDestination
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private IEnumerable<IDestination> AllDynamicDestinations() {
|
||||||
|
yield return new WordDestination();
|
||||||
|
foreach (string wordCaption in WordExporter.GetWordDocuments()) {
|
||||||
|
yield return new WordDestination(wordCaption);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override bool ExportCapture(bool manuallyInitiated, 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) {
|
||||||
|
@ -122,19 +133,13 @@ namespace Greenshot.Destinations {
|
||||||
if (documentCaption != null) {
|
if (documentCaption != null) {
|
||||||
WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
|
WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
|
||||||
} else {
|
} else {
|
||||||
bool exported = false;
|
if (manuallyInitiated) {
|
||||||
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);
|
WordExporter.InsertIntoNewDocument(tmpFile);
|
||||||
|
} else {
|
||||||
|
ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, AllDynamicDestinations());
|
||||||
|
PickerDestination.ShowMenuAtCursor(menu);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|
|
@ -242,7 +242,7 @@ namespace Greenshot {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolStripMenuItem item = destination.GetMenuItem(new EventHandler(DestinationToolStripMenuItemClick));
|
ToolStripMenuItem item = destination.GetMenuItem(true, new EventHandler(DestinationToolStripMenuItemClick));
|
||||||
item.ShortcutKeys = destination.EditorShortcutKeys;
|
item.ShortcutKeys = destination.EditorShortcutKeys;
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
fileStripMenuItem.DropDownItems.Add(item);
|
fileStripMenuItem.DropDownItems.Add(item);
|
||||||
|
|
|
@ -116,6 +116,8 @@ namespace Greenshot.Interop.Office {
|
||||||
LOG.WarnFormat("Problem setting the title to a text-range: {0}", ex.Message);
|
LOG.WarnFormat("Problem setting the title to a text-range: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
presentation.Application.ActiveWindow.View.GotoSlide(slide.SlideNumber);
|
||||||
|
presentation.Application.Activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +127,7 @@ namespace Greenshot.Interop.Office {
|
||||||
powerpointApplication.Visible = true;
|
powerpointApplication.Visible = true;
|
||||||
IPresentation presentation = powerpointApplication.Presentations.Add(MsoTriState.msoTrue);
|
IPresentation presentation = powerpointApplication.Presentations.Add(MsoTriState.msoTrue);
|
||||||
AddPictureToPresentation(presentation, tmpFile, imageSize, title);
|
AddPictureToPresentation(presentation, tmpFile, imageSize, title);
|
||||||
|
presentation.Application.Activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ namespace Greenshot.Interop.Office {
|
||||||
IPresentation ActivePresentation { get; }
|
IPresentation ActivePresentation { get; }
|
||||||
IPresentations Presentations { get; }
|
IPresentations Presentations { get; }
|
||||||
bool Visible { get; set; }
|
bool Visible { get; set; }
|
||||||
|
void Activate();
|
||||||
|
IPowerpointWindow ActiveWindow { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.slides_members.aspx
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.slides_members.aspx
|
||||||
|
@ -39,10 +41,22 @@ namespace Greenshot.Interop.Office {
|
||||||
ISlide Add(int Index, int layout);
|
ISlide Add(int Index, int layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.documentwindow.view.aspx
|
||||||
|
public interface IPowerpointWindow : Common {
|
||||||
|
void Activate();
|
||||||
|
IPowerpointView View { get; }
|
||||||
|
}
|
||||||
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.view_members.aspx
|
||||||
|
public interface IPowerpointView : Common {
|
||||||
|
IZoom Zoom { get; }
|
||||||
|
void GotoSlide(int index);
|
||||||
|
}
|
||||||
|
|
||||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.presentation_members.aspx
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.presentation_members.aspx
|
||||||
public interface IPresentation : Common {
|
public interface IPresentation : Common {
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
ISlides Slides { get; }
|
ISlides Slides { get; }
|
||||||
|
IPowerpointApplication Application { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.presentations_members.aspx
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.presentations_members.aspx
|
||||||
|
|
|
@ -43,12 +43,12 @@ namespace Greenshot.Interop.Office {
|
||||||
public interface IWordDocument : Common {
|
public interface IWordDocument : Common {
|
||||||
void Activate();
|
void Activate();
|
||||||
IWordApplication Application { get; }
|
IWordApplication Application { get; }
|
||||||
WordWindow ActiveWindow { get; }
|
IWordWindow 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 WordWindow : Common {
|
public interface IWordWindow : Common {
|
||||||
Pane ActivePane { get; }
|
IPane ActivePane { get; }
|
||||||
void Activate();
|
void Activate();
|
||||||
string Caption {
|
string Caption {
|
||||||
get;
|
get;
|
||||||
|
@ -56,17 +56,17 @@ namespace Greenshot.Interop.Office {
|
||||||
}
|
}
|
||||||
|
|
||||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pane_members.aspx
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pane_members.aspx
|
||||||
public interface Pane : Common {
|
public interface IPane : Common {
|
||||||
View View { get; }
|
IWordView View { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.view_members.aspx
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.view_members.aspx
|
||||||
public interface View : Common {
|
public interface IWordView : Common {
|
||||||
Zoom Zoom { get; }
|
IZoom Zoom { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.zoom_members.aspx
|
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.zoom_members.aspx
|
||||||
public interface Zoom : Common {
|
public interface IZoom : Common {
|
||||||
int Percentage { get; set; }
|
int Percentage { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,13 +112,13 @@ namespace GreenshotPlugin.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="destinationClickHandler"></param>
|
/// <param name="destinationClickHandler"></param>
|
||||||
/// <returns>ToolStripMenuItem</returns>
|
/// <returns>ToolStripMenuItem</returns>
|
||||||
public virtual ToolStripMenuItem GetMenuItem(EventHandler destinationClickHandler) {
|
public virtual ToolStripMenuItem GetMenuItem(bool addDynamics, EventHandler destinationClickHandler) {
|
||||||
ToolStripMenuItem basisMenuItem;
|
ToolStripMenuItem basisMenuItem;
|
||||||
basisMenuItem = new ToolStripMenuItem(Description);
|
basisMenuItem = new ToolStripMenuItem(Description);
|
||||||
basisMenuItem.Image = DisplayIcon;
|
basisMenuItem.Image = DisplayIcon;
|
||||||
basisMenuItem.Tag = this;
|
basisMenuItem.Tag = this;
|
||||||
basisMenuItem.Text = Description;
|
basisMenuItem.Text = Description;
|
||||||
if (isDynamic) {
|
if (isDynamic && addDynamics) {
|
||||||
basisMenuItem.DropDownOpening += delegate (object source, EventArgs eventArgs) {
|
basisMenuItem.DropDownOpening += delegate (object source, EventArgs eventArgs) {
|
||||||
if (basisMenuItem.DropDownItems.Count == 0) {
|
if (basisMenuItem.DropDownItems.Count == 0) {
|
||||||
List<IDestination> subDestinations = new List<IDestination>();
|
List<IDestination> subDestinations = new List<IDestination>();
|
||||||
|
|
|
@ -66,9 +66,10 @@ namespace Greenshot.Plugin {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a menu item
|
/// Return a menu item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="destinationClickHandler"></param>
|
/// <param name="addDynamics">Resolve the dynamic destinations too?</param>
|
||||||
|
/// <param name="destinationClickHandler">Handler which is called when clicked</param>
|
||||||
/// <returns>ToolStripMenuItem</returns>
|
/// <returns>ToolStripMenuItem</returns>
|
||||||
ToolStripMenuItem GetMenuItem(EventHandler destinationClickHandler);
|
ToolStripMenuItem GetMenuItem(bool addDynamics, EventHandler destinationClickHandler);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the ShortcutKeys for the Editor
|
/// Gets the ShortcutKeys for the Editor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue