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:
RKrom 2014-07-29 13:10:02 +02:00
commit 87f4d83fd2
3 changed files with 37 additions and 15 deletions

View file

@ -109,7 +109,15 @@ 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) {
// No page selected, take the current
List<OneNotePage> pages = OneNoteExporter.GetPages();
if(pages == null || pages.Count == 0) {
return exportInformation;
}
page = pages[0];
}
try { try {
OneNoteExporter.ExportToPage(surface, page); OneNoteExporter.ExportToPage(surface, page);
exportInformation.ExportMade = true; exportInformation.ExportMade = true;
@ -117,7 +125,6 @@ namespace GreenshotOfficePlugin {
exportInformation.ErrorMessage = ex.Message; exportInformation.ErrorMessage = ex.Message;
LOG.Error(ex); LOG.Error(ex);
} }
}
return exportInformation; return exportInformation;
} }
} }

View file

@ -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
if("true".Equals(xmlReader.GetAttribute("isInRecycleBin"))) {
continue;
}
OneNotePage page = new OneNotePage(); OneNotePage page = new OneNotePage();
page.PageName = xmlReader.GetAttribute("name"); page.PageName = xmlReader.GetAttribute("name");
page.PageID = xmlReader.GetAttribute("ID"); page.PageID = xmlReader.GetAttribute("ID");
pages.Add(page); if(page.PageID == null || page.PageName == null) {
// For debugging continue;
//string pageXml = "";
//oneNoteApplication.GetPageContent(page.PageID, out pageXml, PageInfo.piAll, XMLSchema.xs2010);
//LOG.DebugFormat("Page XML: {0}", pageXml);
} }
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;
} }
} }

View file

@ -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 {