Skip to content

Commit

Permalink
add source page hier info env vars (stevencohn#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored and weissm committed Sep 7, 2024
1 parent d169fcb commit 2cf6044
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions OneMore/Commands/File/RunPluginCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class RunPluginCommand : Command
private Plugin plugin;
private ProgressDialog progress = null;
private Page page;
private OneNote.HierarchyInfo hierarchyInfo;
private string workpath;
private bool trialRun;

Expand Down Expand Up @@ -150,6 +151,9 @@ private async Task<string> PreparePageCache()
return null;
}

hierarchyInfo = await one.GetPageInfo(page.PageId);
hierarchyInfo.PageId = page.PageId;

return content;
}

Expand Down Expand Up @@ -229,6 +233,9 @@ private async Task<string> PrepareHierarchyCache()
return null;
}

hierarchyInfo = await one.GetPageInfo();
hierarchyInfo.PageId = one.CurrentPageId;

return content;
}

Expand Down Expand Up @@ -284,6 +291,13 @@ private async Task<bool> ExecuteWorker(ProgressDialog progress, CancellationToke
info.Environment["PLUGIN_PAGENAME"] = plugin.PageName;
info.Environment["PLUGIN_ASCHILD"] = plugin.AsChildPage.ToString();

info.Environment["PLUGIN_SOURCE_PAGEID"] = hierarchyInfo.PageId;
info.Environment["PLUGIN_SOURCE_SECTIONID"] = hierarchyInfo.SectionId;
info.Environment["PLUGIN_SOURCE_NOTEBOOKID"] = hierarchyInfo.NotebookId;
info.Environment["PLUGIN_SOURCE_PAGENAME"] = hierarchyInfo.Name;
info.Environment["PLUGIN_SOURCE_PAGEPATH"] = hierarchyInfo.Path;
info.Environment["PLUGIN_SOURCE_PAGEURL"] = hierarchyInfo.Link;

process = new Process
{
StartInfo = info,
Expand Down Expand Up @@ -424,12 +438,12 @@ private async Task CreatePage(OneNote one, XElement childRoot)
childRoot.Attribute("ID").Value = pageId;
var child = new Page(childRoot);

// every new page adds hashes so need to remove them
child.OptimizeForSave(true);

var childTitle = child.Title.Trim();
var parentTitle = page.Title.Trim();

// every new page adds hashes so need to remove them
child.OptimizeForSave(true);

// if plugin has modified the page title then accept that
// otherwise apply the name template defined by this plugin...
if (childTitle == parentTitle)
Expand Down

0 comments on commit 2cf6044

Please sign in to comment.