Skip to content

Commit

Permalink
add option to pin Notes to top and Quick Notes to bottom when sorting…
Browse files Browse the repository at this point in the history
… sections
  • Loading branch information
stevenmcohn committed Mar 5, 2020
1 parent e78d9ed commit 1414ae2
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 22 deletions.
2 changes: 1 addition & 1 deletion AssemblyInfo.Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static partial class AssemblyInfo
public const string Company = "River Software";
public const string Copyright = "Copyright \u00a9 2016 Steven M Cohn. All rights reserved.";

public const string Version = "1.7.0";
public const string Version = "1.7.1";
public const string FileVersion = Version;

public const string Configuration =
Expand Down
48 changes: 38 additions & 10 deletions OneMoreAddIn/Commands/SortCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private class PageNode
private HierarchyScope scope;
private SortDialog.Sortings sorting;
private SortDialog.Directions direction;
private bool pinNotes;


public SortCommand() : base()
Expand All @@ -47,6 +48,7 @@ public void Execute()
scope = dialog.Scope;
sorting = dialog.Soring;
direction = dialog.Direction;
pinNotes = dialog.PinNotes;
}

if (result == DialogResult.OK)
Expand Down Expand Up @@ -77,7 +79,7 @@ public void Execute()
else
{
// sections will include all sections for the current notebook
root = SortSections(root, sorting, direction);
root = SortSections(root, sorting, direction, pinNotes);
}
}

Expand Down Expand Up @@ -106,12 +108,6 @@ private XElement SortPages(
* can be sorted correctly. Children are not sorted.
*/

string keyName;

if (sorting == SortDialog.Sortings.ByCreated) keyName = "dateTime";
else if (sorting == SortDialog.Sortings.ByModified) keyName = "lastModifiedTime";
else keyName = "name";

var ns = root.GetNamespaceOfPrefix("one");

var pages = new List<PageNode>();
Expand All @@ -130,6 +126,12 @@ private XElement SortPages(
}
}

string keyName;

if (sorting == SortDialog.Sortings.ByCreated) keyName = "dateTime";
else if (sorting == SortDialog.Sortings.ByModified) keyName = "lastModifiedTime";
else keyName = "name";

// sort all parents by chosen key.
// regex keeps only printable characters (so we don't sort on title emoticons!)
pages =
Expand Down Expand Up @@ -162,7 +164,7 @@ orderby key


private XElement SortSections(
XElement root, SortDialog.Sortings sorting, SortDialog.Directions direction)
XElement root, SortDialog.Sortings sorting, SortDialog.Directions direction, bool pinNotes)
{
/*
* <one:Notebooks xmlns:one="http://schemas.microsoft.com/office/onenote/2013/onenote">
Expand Down Expand Up @@ -214,20 +216,46 @@ orderby key
sections = sections.Reverse();
}

// .Remove will remove from "sections" IEnumerable so add to new list
XElement notes = null;
XElement quick = null;
var list = new List<XElement>();

// .Remove will remove from "sections" IEnumerable so add to new list
foreach (var section in sections)
{
list.Insert(0, section);
if (pinNotes && section.Attribute("name").Value.Equals("Notes"))
{
notes = section;
}
else if (pinNotes && section.Attribute("name").Value.Equals("Quick Notes"))
{
quick = section;
}
else
{
list.Insert(0, section);
}

section.Remove();
}

// re-insert sorted sections into notebook

if (quick != null)
{
notebook.AddFirst(quick);
}

foreach (var section in list)
{
notebook.AddFirst(section);
}

if (notes != null)
{
notebook.AddFirst(notes);
}

return root;
}

Expand Down
42 changes: 35 additions & 7 deletions OneMoreAddIn/Dialogs/SortDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions OneMoreAddIn/Dialogs/SortDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public HierarchyScope Scope
ascButton.Checked ? Directions.Ascending : Directions.Descending;


public bool PinNotes => pinNotesBox.Checked;


public Sortings Soring =>
nameButton.Checked ? Sortings.ByName
: (createdButton.Checked ? Sortings.ByCreated : Sortings.ByModified);
Expand Down Expand Up @@ -98,6 +101,9 @@ private void scopeBox_SelectedIndexChanged(object sender, EventArgs e)
nameButton.Checked = true;
}
}

pinNotesBox.Enabled = (scopeBox.SelectedIndex == 1);
quickLabel.Enabled = (scopeBox.SelectedIndex == 1);
}
}
}
4 changes: 0 additions & 4 deletions Roadmap.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# OneMore Roadmap

1. *Keep Notes at top after sorting* - OneNote keeps the Notes section first in the list
of sections. The Sort command will move this potentially. So should I add an option to
the Sort dialog to keep Notes at the top?

1. *Favorites Menu* - Manage links to favorite pages through either
a ribbon button in the OneMore group or a menu item off of the OneMore
menu. Simple add/remove functionality, alphabetized. No fancy management.
Expand Down

0 comments on commit 1414ae2

Please sign in to comment.