From 87f4d83fd2cd13a9d8d7a5cd04fa969319d988c6 Mon Sep 17 00:00:00 2001 From: RKrom Date: Tue, 29 Jul 2014 13:10:02 +0200 Subject: [PATCH] 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. --- .../Destinations/OneNoteDestination.cs | 19 +++++++---- .../OfficeExport/OneNoteExporter.cs | 32 +++++++++++++------ .../OfficeInterop/OneNoteInterop.cs | 1 + 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs b/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs index 6b8fa87b8..1b692183a 100644 --- a/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs +++ b/GreenshotOfficePlugin/Destinations/OneNoteDestination.cs @@ -109,14 +109,21 @@ namespace GreenshotOfficePlugin { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); + if (page != null) { - try { - OneNoteExporter.ExportToPage(surface, page); - exportInformation.ExportMade = true; - } catch (Exception ex) { - exportInformation.ErrorMessage = ex.Message; - LOG.Error(ex); + // No page selected, take the current + List pages = OneNoteExporter.GetPages(); + if(pages == null || pages.Count == 0) { + return exportInformation; } + page = pages[0]; + } + try { + OneNoteExporter.ExportToPage(surface, page); + exportInformation.ExportMade = true; + } catch (Exception ex) { + exportInformation.ErrorMessage = ex.Message; + LOG.Error(ex); } return exportInformation; } diff --git a/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs b/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs index 683f360b0..e96955f8f 100644 --- a/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs +++ b/GreenshotOfficePlugin/OfficeExport/OneNoteExporter.cs @@ -35,6 +35,7 @@ namespace Greenshot.Interop.Office { public class OneNotePage { public string PageName { get; set; } public string PageID { get; set; } + public bool IsCurrentlyViewed { get; set; } } public class 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()) { LOG.InfoFormat("Sending XML: {0}", pageChangesXml); 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; while (xmlReader.Read()) { if ("one:Page".Equals(xmlReader.Name)) { - if ("true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"))) { - OneNotePage page = new OneNotePage(); - page.PageName = xmlReader.GetAttribute("name"); - 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); + // Skip deleted items + if("true".Equals(xmlReader.GetAttribute("isInRecycleBin"))) { + continue; } + 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) { 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; } } diff --git a/GreenshotOfficePlugin/OfficeInterop/OneNoteInterop.cs b/GreenshotOfficePlugin/OfficeInterop/OneNoteInterop.cs index e28e2938a..7a7a49095 100644 --- a/GreenshotOfficePlugin/OfficeInterop/OneNoteInterop.cs +++ b/GreenshotOfficePlugin/OfficeInterop/OneNoteInterop.cs @@ -33,6 +33,7 @@ namespace Greenshot.Interop.Office { void GetHierarchy(string startNode, HierarchyScope scope, out string notebookXml, XMLSchema schema); void UpdatePageContent(string pageChangesXml, DateTime dateExpectedLastModified, XMLSchema schema, bool force); void GetPageContent(string pageId, out string pageXml, PageInfo pageInfoToExport, XMLSchema schema); + void NavigateTo(string hierarchyObjectID, string objectId, bool newWindow); } public enum PageInfo {