Skip to content

Commit

Permalink
Add NextUnreadPageCommand (stevencohn#1488)
Browse files Browse the repository at this point in the history
* Add NextUnreadPageCommand
stevencohn#1487

* update
  • Loading branch information
stevencohn authored and weissm committed Jul 29, 2024
1 parent 4b6bacb commit b74fb0f
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 0 deletions.
10 changes: 10 additions & 0 deletions OneMore/AddInCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,11 @@ public async Task NavigatorCmd(IRibbonControl control)
=> await factory.Run<NavigatorCommand>();


[Command("ribNextUnreadPageButton_Label", Keys.None, "ribSearchMenu")]
public async Task NextUnreadPageCmd(IRibbonControl control)
=> await factory.Run<NextUnreadPageCommand>();


[Command("ribNewStyleButton_Label", Keys.None)]
public async Task NewStyleCmd(IRibbonControl control)
=> await factory.Run<NewStyleCommand>();
Expand Down Expand Up @@ -673,6 +678,11 @@ public async Task PreviewMarkdownCmd(IRibbonControl control)
=> await factory.Run<PreviewMarkdownCommand>();


[Command("ribPreviousUnreadPageButton_Label", Keys.None, "ribSearchMenu")]
public async Task PreviousUnreadPageCmd(IRibbonControl control)
=> await factory.Run<PreviousUnreadPageCommand>();


[Command("ribPronunciateButton_Label", Keys.None, "ribEditMenu")]
public async Task PronunciateCmd(IRibbonControl control)
=> await factory.Run<PronunciateCommand>();
Expand Down
108 changes: 108 additions & 0 deletions OneMore/Commands/Navigator/NextUnreadPageCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//************************************************************************************************
// Copyright © 2024 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Commands
{
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Resx = Properties.Resources;


#region Wrapper
internal class PreviousUnreadPageCommand : NextUnreadPageCommand
{
public PreviousUnreadPageCommand() : base() { }
public override Task Execute(params object[] args)
{
return base.Execute(false);
}
}
#endregion Wrapper


/// <summary>
/// Navigate to the next or previous unread page if any.
/// </summary>
internal class NextUnreadPageCommand : Command
{
public NextUnreadPageCommand()
{
}


public override async Task Execute(params object[] args)
{
var forward = args.Length == 0 || (bool)args[0];

await using var one = new OneNote();
var notebooks = await one.GetNotebooks();
var ns = notebooks.GetNamespaceOfPrefix(OneNote.Prefix);

var books = notebooks.Elements(ns + "Notebook");
if (!forward)
{
books = books.Reverse();
}

// load and scan one notebook at a time in case any are huge...

XElement next = null;
foreach (var book in books)
{
var notebook = await one.GetNotebook(
book.Attribute("ID").Value, OneNote.Scope.Pages);

// create a new root with a flat list of pages so ElementsAfter/BeforeSelf
// can be used to easily scan...

var pages = new XElement(ns + "pages",
notebook.Descendants(ns + "Page").Where(e =>
e.Attribute("isCurrentlyViewed") is not null ||
e.Attribute("isUnread") is not null)
);

if (!pages.HasElements)
{
// must not be current notebook and has no unread pages
continue;
}

if (notebook.Attribute("isCurrentlyViewed") is not null)
{
// find the anchor point
var current = pages.Elements()
.First(e => e.Attribute("isCurrentlyViewed") is not null);

// find next unread in desired direction
next = forward
? current.ElementsAfterSelf()
.FirstOrDefault(e => e.Attribute("isUnread") is not null)
: current.ElementsBeforeSelf()
.FirstOrDefault(e => e.Attribute("isUnread") is not null);
}
else
{
// in other notebook, no current page, so blindly grab the first unread found
next = forward
? pages.Elements().First()
: pages.Elements().Last();
}

if (next is not null)
{
break;
}
}

if (next is null)
{
ShowInfo(Resx.NextUnreadPageCommand_nomore);
return;
}

await one.NavigateTo(next.Attribute("ID").Value);
}
}
}
1 change: 1 addition & 0 deletions OneMore/OneMore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<Compile Include="Commands\Edit\ConvertMarkdownCommand.cs" />
<Compile Include="Commands\Edit\CopyAsTextCommand.cs" />
<Compile Include="Commands\Images\SelectInkCommand.cs" />
<Compile Include="Commands\Navigator\NextUnreadPageCommand.cs" />
<Compile Include="Commands\Page\DuplicateLineCommand.cs" />
<Compile Include="Commands\Edit\PreviewMarkdownCommand.cs" />
<Compile Include="Commands\File\FileQuickNotesCommand.cs" />
Expand Down
45 changes: 45 additions & 0 deletions OneMore/Properties/Resources.Designer.cs

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

20 changes: 20 additions & 0 deletions OneMore/Properties/Resources.ar-SA.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,10 @@
<value>اتصال الشبكة غير متوفر</value>
<comment>error</comment>
</data>
<data name="NextUnreadPageCommand_nomore" xml:space="preserve">
<value>لم يتم العثور على صفحات غير مقروءة في هذا الاتجاه</value>
<comment>message</comment>
</data>
<data name="NumberingPage_Message" xml:space="preserve">
<value>صفحة الترقيم {0}</value>
<comment>progress status dialog</comment>
Expand Down Expand Up @@ -3511,6 +3515,14 @@ ISO-code then comma then language name</comment>
<value>قم بإنشاء نمط جديد من التحديد الحالي</value>
<comment>ribbon styles</comment>
</data>
<data name="ribNextUnreadPageButton_Label" xml:space="preserve">
<value>الصفحة التالية غير المقروءة</value>
<comment>ribbon search</comment>
</data>
<data name="ribNextUnreadPageButton_Screentip" xml:space="preserve">
<value>الانتقال إلى الصفحة التالية غير المقروءة</value>
<comment>ribbon search</comment>
</data>
<data name="ribNoSpellCheckButton_Screentip" xml:space="preserve">
<value>تعطيل التدقيق الإملائي للصفحة بأكملها (F4)</value>
<comment>Ribbon OneMore menu item, no spell check on this page</comment>
Expand Down Expand Up @@ -3642,6 +3654,14 @@ ISO-code then comma then language name</comment>
<value>معاينة الصفحة أو النص المحدد كتخفيض</value>
<comment>ribbon edit</comment>
</data>
<data name="ribPreviousUnreadPageButton_Label" xml:space="preserve">
<value>الصفحة السابقة غير المقروءة</value>
<comment>ribbon search</comment>
</data>
<data name="ribPreviousUnreadPageButton_Screentip" xml:space="preserve">
<value>الانتقال إلى الصفحة غير المقروءة السابقة</value>
<comment>ribbon search</comment>
</data>
<data name="ribPronunciateButton_Label" xml:space="preserve">
<value>أدخل النطق</value>
<comment>Ribbon OneMore menu item</comment>
Expand Down
20 changes: 20 additions & 0 deletions OneMore/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,10 @@ Benutzerdefinierte Überschrift 3</value>
<value>Netzwerkverbindung ist nicht verfügbar</value>
<comment>error</comment>
</data>
<data name="NextUnreadPageCommand_nomore" xml:space="preserve">
<value>In dieser Richtung wurden keine ungelesenen Seiten gefunden</value>
<comment>message</comment>
</data>
<data name="NumberingPage_Message" xml:space="preserve">
<value>Nummerierungsseite {0}</value>
<comment>progress status dialog</comment>
Expand Down Expand Up @@ -3511,6 +3515,14 @@ Nach der letzten Gruppe</value>
<value>Erstellt einen neuen Stil aus der aktuellen Auswahl</value>
<comment>ribbon styles</comment>
</data>
<data name="ribNextUnreadPageButton_Label" xml:space="preserve">
<value>Nächste ungelesene Seite</value>
<comment>ribbon search</comment>
</data>
<data name="ribNextUnreadPageButton_Screentip" xml:space="preserve">
<value>Gehen Sie zur nächsten ungelesenen Seite</value>
<comment>ribbon search</comment>
</data>
<data name="ribNoSpellCheckButton_Screentip" xml:space="preserve">
<value>Rechtschreibprüfung für ganze Seite deaktivieren (F4)</value>
<comment>Ribbon OneMore menu item, no spell check on this page</comment>
Expand Down Expand Up @@ -3634,6 +3646,14 @@ Nach der letzten Gruppe</value>
<value>Vorschau der Seite oder des ausgewählten Texts als Markdown</value>
<comment>ribbon edit</comment>
</data>
<data name="ribPreviousUnreadPageButton_Label" xml:space="preserve">
<value>Vorherige ungelesene Seite</value>
<comment>ribbon search</comment>
</data>
<data name="ribPreviousUnreadPageButton_Screentip" xml:space="preserve">
<value>Zur vorherigen ungelesenen Seite wechseln</value>
<comment>ribbon search</comment>
</data>
<data name="ribPronunciateButton_Label" xml:space="preserve">
<value>Aussprache einfügen</value>
<comment>Ribbon OneMore menu item</comment>
Expand Down
20 changes: 20 additions & 0 deletions OneMore/Properties/Resources.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,10 @@ Título personalizado 3</value>
<value>La conexión de red no está disponible</value>
<comment>error</comment>
</data>
<data name="NextUnreadPageCommand_nomore" xml:space="preserve">
<value>No se encontraron páginas no leídas en esa dirección.</value>
<comment>message</comment>
</data>
<data name="NumberingPage_Message" xml:space="preserve">
<value>Página de numeración {0}</value>
<comment>progress status dialog</comment>
Expand Down Expand Up @@ -3511,6 +3515,14 @@ Después del último grupo</value>
<value>Crear un nuevo estilo a partir de la selección actual</value>
<comment>ribbon styles</comment>
</data>
<data name="ribNextUnreadPageButton_Label" xml:space="preserve">
<value>Siguiente página no leída</value>
<comment>ribbon search</comment>
</data>
<data name="ribNextUnreadPageButton_Screentip" xml:space="preserve">
<value>Pasar a la siguiente página no leída</value>
<comment>ribbon search</comment>
</data>
<data name="ribNoSpellCheckButton_Screentip" xml:space="preserve">
<value>Desactivar el corrector ortográfico para toda la página (F4)</value>
<comment>Ribbon OneMore menu item, no spell check on this page</comment>
Expand Down Expand Up @@ -3642,6 +3654,14 @@ Después del último grupo</value>
<value>Vista previa de la página o texto seleccionado como rebaja</value>
<comment>ribbon edit</comment>
</data>
<data name="ribPreviousUnreadPageButton_Label" xml:space="preserve">
<value>Página anterior no leída</value>
<comment>ribbon search</comment>
</data>
<data name="ribPreviousUnreadPageButton_Screentip" xml:space="preserve">
<value>Ir a la página anterior no leída</value>
<comment>ribbon search</comment>
</data>
<data name="ribPronunciateButton_Label" xml:space="preserve">
<value>Insertar pronunciación</value>
<comment>Ribbon OneMore menu item</comment>
Expand Down
20 changes: 20 additions & 0 deletions OneMore/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,10 @@ Titre personnalisé 3</value>
<value>La connexion réseau n'est pas disponible</value>
<comment>error</comment>
</data>
<data name="NextUnreadPageCommand_nomore" xml:space="preserve">
<value>Aucune page non lue trouvée dans cette direction</value>
<comment>message</comment>
</data>
<data name="NumberingPage_Message" xml:space="preserve">
<value>Page de numérotation {0}</value>
<comment>progress status dialog</comment>
Expand Down Expand Up @@ -3510,6 +3514,14 @@ Après le dernier groupe</value>
<value>Créer un nouveau style à partir de la sélection actuelle</value>
<comment>ribbon styles</comment>
</data>
<data name="ribNextUnreadPageButton_Label" xml:space="preserve">
<value>Page suivante non lue</value>
<comment>ribbon search</comment>
</data>
<data name="ribNextUnreadPageButton_Screentip" xml:space="preserve">
<value>Passer à la page suivante non lue</value>
<comment>ribbon search</comment>
</data>
<data name="ribNoSpellCheckButton_Screentip" xml:space="preserve">
<value>Désactiver la vérification orthographique pour toute la page (F4)</value>
<comment>Ribbon OneMore menu item, no spell check on this page</comment>
Expand Down Expand Up @@ -3641,6 +3653,14 @@ Après le dernier groupe</value>
<value>Aperçu de la page ou du texte sélectionné sous forme de démarque</value>
<comment>ribbon edit</comment>
</data>
<data name="ribPreviousUnreadPageButton_Label" xml:space="preserve">
<value>Page précédente non lue</value>
<comment>ribbon search</comment>
</data>
<data name="ribPreviousUnreadPageButton_Screentip" xml:space="preserve">
<value>Passer à la page précédente non lue</value>
<comment>ribbon search</comment>
</data>
<data name="ribPronunciateButton_Label" xml:space="preserve">
<value>Insérer la prononciation</value>
<comment>Ribbon OneMore menu item</comment>
Expand Down
Loading

0 comments on commit b74fb0f

Please sign in to comment.