mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Enhancements to the OneNote exporter, this will now show a list of all pages and use the current viewed by default. After export we try to navigate to the page we exported to.
This commit is contained in:
parent
2b747650ae
commit
87f4d83fd2
3 changed files with 37 additions and 15 deletions
|
@ -109,14 +109,21 @@ namespace GreenshotOfficePlugin {
|
||||||
|
|
||||||
public override ExportInformation 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);
|
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
|
||||||
|
|
||||||
if (page != null) {
|
if (page != null) {
|
||||||
try {
|
// No page selected, take the current
|
||||||
OneNoteExporter.ExportToPage(surface, page);
|
List<OneNotePage> pages = OneNoteExporter.GetPages();
|
||||||
exportInformation.ExportMade = true;
|
if(pages == null || pages.Count == 0) {
|
||||||
} catch (Exception ex) {
|
return exportInformation;
|
||||||
exportInformation.ErrorMessage = ex.Message;
|
|
||||||
LOG.Error(ex);
|
|
||||||
}
|
}
|
||||||
|
page = pages[0];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
OneNoteExporter.ExportToPage(surface, page);
|
||||||
|
exportInformation.ExportMade = true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
exportInformation.ErrorMessage = ex.Message;
|
||||||
|
LOG.Error(ex);
|
||||||
}
|
}
|
||||||
return exportInformation;
|
return exportInformation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace Greenshot.Interop.Office {
|
||||||
public class OneNotePage {
|
public class OneNotePage {
|
||||||
public string PageName { get; set; }
|
public string PageName { get; set; }
|
||||||
public string PageID { get; set; }
|
public string PageID { get; set; }
|
||||||
|
public bool IsCurrentlyViewed { get; set; }
|
||||||
}
|
}
|
||||||
public class OneNoteExporter {
|
public class OneNoteExporter {
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OneNoteExporter));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OneNoteExporter));
|
||||||
|
@ -53,6 +54,11 @@ namespace Greenshot.Interop.Office {
|
||||||
using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance<IOneNoteApplication>()) {
|
using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance<IOneNoteApplication>()) {
|
||||||
LOG.InfoFormat("Sending XML: {0}", pageChangesXml);
|
LOG.InfoFormat("Sending XML: {0}", pageChangesXml);
|
||||||
oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false);
|
oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false);
|
||||||
|
try {
|
||||||
|
oneNoteApplication.NavigateTo(page.PageID, null, false);
|
||||||
|
} catch(Exception ex) {
|
||||||
|
LOG.Warn("Unable to navigate to the target page", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,16 +83,18 @@ namespace Greenshot.Interop.Office {
|
||||||
reader = null;
|
reader = null;
|
||||||
while (xmlReader.Read()) {
|
while (xmlReader.Read()) {
|
||||||
if ("one:Page".Equals(xmlReader.Name)) {
|
if ("one:Page".Equals(xmlReader.Name)) {
|
||||||
if ("true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"))) {
|
// Skip deleted items
|
||||||
OneNotePage page = new OneNotePage();
|
if("true".Equals(xmlReader.GetAttribute("isInRecycleBin"))) {
|
||||||
page.PageName = xmlReader.GetAttribute("name");
|
continue;
|
||||||
page.PageID = xmlReader.GetAttribute("ID");
|
|
||||||
pages.Add(page);
|
|
||||||
// For debugging
|
|
||||||
//string pageXml = "";
|
|
||||||
//oneNoteApplication.GetPageContent(page.PageID, out pageXml, PageInfo.piAll, XMLSchema.xs2010);
|
|
||||||
//LOG.DebugFormat("Page XML: {0}", pageXml);
|
|
||||||
}
|
}
|
||||||
|
OneNotePage page = new OneNotePage();
|
||||||
|
page.PageName = xmlReader.GetAttribute("name");
|
||||||
|
page.PageID = xmlReader.GetAttribute("ID");
|
||||||
|
if(page.PageID == null || page.PageName == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
page.IsCurrentlyViewed = "true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"));
|
||||||
|
pages.Add(page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,6 +109,12 @@ namespace Greenshot.Interop.Office {
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.Warn("Problem retrieving onenote destinations, ignoring: ", ex);
|
LOG.Warn("Problem retrieving onenote destinations, ignoring: ", ex);
|
||||||
}
|
}
|
||||||
|
pages.Sort(delegate(OneNotePage p1, OneNotePage p2) {
|
||||||
|
if(p1.IsCurrentlyViewed || p2.IsCurrentlyViewed) {
|
||||||
|
return p2.IsCurrentlyViewed.CompareTo(p1.IsCurrentlyViewed);
|
||||||
|
}
|
||||||
|
return p1.PageName.CompareTo(p2.PageName);
|
||||||
|
});
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace Greenshot.Interop.Office {
|
||||||
void GetHierarchy(string startNode, HierarchyScope scope, out string notebookXml, XMLSchema schema);
|
void GetHierarchy(string startNode, HierarchyScope scope, out string notebookXml, XMLSchema schema);
|
||||||
void UpdatePageContent(string pageChangesXml, DateTime dateExpectedLastModified, XMLSchema schema, bool force);
|
void UpdatePageContent(string pageChangesXml, DateTime dateExpectedLastModified, XMLSchema schema, bool force);
|
||||||
void GetPageContent(string pageId, out string pageXml, PageInfo pageInfoToExport, XMLSchema schema);
|
void GetPageContent(string pageId, out string pageXml, PageInfo pageInfoToExport, XMLSchema schema);
|
||||||
|
void NavigateTo(string hierarchyObjectID, string objectId, bool newWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PageInfo {
|
public enum PageInfo {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue