Skip to content

Commit

Permalink
Expand index report for searched hashtags (#1711)
Browse files Browse the repository at this point in the history
* Expand index report for searched hashtags
#1649

* tranlated title
  • Loading branch information
stevencohn authored Dec 18, 2024
1 parent 0fd76ff commit b6fbd6c
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 67 deletions.
45 changes: 0 additions & 45 deletions OneMore/Commands/Search/SearchServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,51 +66,6 @@ public async Task CopyPages(IEnumerable<string> pageIds)
}


public async Task IndexPages(IEnumerable<string> pageIds)
{
string indexId = null;

using (var progress = new UI.ProgressDialog())
{
progress.SetMaximum(pageIds.Count());
progress.Show();

// create a new page to get a new ID
one.CreatePage(sectionId, out indexId);
var indexPage = await one.GetPage(indexId);

indexPage.Title = "Page Index";

var container = indexPage.EnsureContentContainer();

foreach (var pageId in pageIds)
{
// get the page to copy
var page = await one.GetPage(pageId);
var ns = page.Namespace;

progress.SetMessage(page.Title);
progress.Increment();

var link = one.GetHyperlink(page.PageId, string.Empty);

container.Add(new XElement(ns + "OE",
new XElement(ns + "T",
new XCData($"<a href=\"{link}\">{page.Title}</a>"))
));
}

await one.Update(indexPage);
}

// navigate after progress dialog is closed otherwise it will hang!
if (indexId != null)
{
await one.NavigateTo(indexId);
}
}


public async Task MovePages(IEnumerable<string> pageIds)
{
var sections = new Dictionary<string, XElement>();
Expand Down
102 changes: 87 additions & 15 deletions OneMore/Commands/Tagging/HashtagCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ namespace River.OneMoreAddIn.Commands
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using Resx = Properties.Resources;


internal class HashtagCommand : Command
{
private HashtagDialog.Commands command;
private IEnumerable<string> pageIds;
private IEnumerable<HashtagContext> selectedPages;
private string query;

private static HashtagDialog dialog;

Expand Down Expand Up @@ -64,7 +66,8 @@ public override async Task Execute(params object[] args)
if (d.DialogResult == DialogResult.OK)
{
command = d.Command;
pageIds = d.SelectedPages.ToList();
selectedPages = d.SelectedPages;
query = d.Query;

var msg = command switch
{
Expand Down Expand Up @@ -136,26 +139,28 @@ private async Task Callback(string sectionId)
return;
}

logger.Start($"..{command} {pageIds.Count()} pages");
logger.Start($"..{command} {selectedPages.Count()} pages");

try
{
await using var one = new OneNote();
var service = new SearchServices(one, sectionId);

switch (command)
if (command == HashtagDialog.Commands.Index)
{
await IndexTaggedPages(sectionId);
}
else
{
case HashtagDialog.Commands.Index:
await service.IndexPages(pageIds);
break;
await using var one = new OneNote();
var service = new SearchServices(one, sectionId);
var pageIds = selectedPages.Select(p => p.PageID).ToList();

case HashtagDialog.Commands.Copy:
if (command == HashtagDialog.Commands.Copy)
{
await service.CopyPages(pageIds);
break;

case HashtagDialog.Commands.Move:
}
else
{
await service.MovePages(pageIds);
break;
}
}
}
catch (Exception exc)
Expand All @@ -167,5 +172,72 @@ private async Task Callback(string sectionId)
logger.End();
}
}


private async Task IndexTaggedPages(string sectionId)
{
await using var one = new OneNote();
string parentId = null;

using (var progress = new UI.ProgressDialog())
{
progress.SetMaximum(selectedPages.Count());
progress.Show();

// create a new page to get a new ID
one.CreatePage(sectionId, out parentId);
var parent = await one.GetPage(parentId);

var ns = parent.Namespace;
PageNamespace.Set(ns);

parent.Title = Resx.HashtagCommand_indexTitle;

var container = parent.EnsureContentContainer();

var h1Index = parent.GetQuickStyle(Styles.StandardStyles.Heading1).Index;
var todoIndex = parent.AddTagDef("3", "To Do", 4);

container.Add(new Paragraph(query).SetQuickStyle(h1Index));

var content = new XElement(ns + "OEChildren");
container.Add(new Paragraph(content));

foreach (var context in selectedPages
.OrderBy(c => c.HierarchyPath)
.ThenBy(c => c.PageTitle))
{
progress.SetMessage(context.PageTitle);
progress.Increment();

var link = one.GetHyperlink(context.PageID,
string.IsNullOrWhiteSpace(context.TitleID) ? string.Empty : context.TitleID);

var text = $"{context.HierarchyPath}/{context.PageTitle}";

content.Add(new Paragraph(
new Tag(todoIndex, false),
new XElement(ns + "T",
new XCData($"<a href=\"{link}\">{text}</a>"))
));

var bullets = new ContentList(ns);
foreach (var snippet in context.Snippets)
{
link = one.GetHyperlink(context.PageID, snippet.ObjectID);
bullets.Add(new Bullet($"<a href=\"{link}\">{snippet.Snippet}</a>"));
}

content.Add(new Paragraph(bullets));
content.Add(new Paragraph(string.Empty));
}

await one.Update(parent);
parentId = parent.PageId;
}

// navigate after progress dialog is closed otherwise it will hang!
await one.NavigateTo(parentId);
}
}
}
2 changes: 2 additions & 0 deletions OneMore/Commands/Tagging/HashtagContextControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public HashtagContextControl(HashtagContext item)
{
Height += snippetsPanel.Height - height;
}

Tag = item;
}


Expand Down
21 changes: 14 additions & 7 deletions OneMore/Commands/Tagging/HashtagDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal partial class HashtagDialog : MoreForm
private readonly string moreID;
private readonly MoreAutoCompleteList palette;
private readonly bool experimental;
private readonly List<string> selections;
private readonly List<HashtagContext> selections;


public enum Commands
Expand Down Expand Up @@ -63,7 +63,7 @@ public HashtagDialog()

DefaultControl = tagBox;

selections = new List<string>();
selections = new List<HashtagContext>();

palette = new MoreAutoCompleteList
{
Expand Down Expand Up @@ -114,7 +114,10 @@ public HashtagDialog(string moreID)
public Commands Command { get; private set; }


public IEnumerable<string> SelectedPages => selections;
public string Query { get; private set; }


public IEnumerable<HashtagContext> SelectedPages => selections;


public bool ShowOfflineNotebooks { get; private set; }
Expand Down Expand Up @@ -227,6 +230,8 @@ private async Task SearchTags(object sender, EventArgs e)
return;
}

Query = where;

await using var one = new OneNote();

var loadedBookIDs = (await one.GetNotebooks()).Elements()
Expand Down Expand Up @@ -348,13 +353,15 @@ private void ScanDiscovered(object sender, LinkLabelLinkClickedEventArgs e)
private void Control_Checked(object sender, EventArgs e)
{
var control = sender as HashtagContextControl;
var context = (HashtagContext)control.Tag;
var enabled = control.IsChecked;

if (!enabled)
{
if (selections.Contains(control.PageID))
var index = selections.FindIndex(s => s.PageID == context.PageID);
if (index >= 0)
{
selections.Remove(control.PageID);
selections.RemoveAt(index);
}

for (int i = 0; i < contextPanel.Controls.Count; i++)
Expand All @@ -366,9 +373,9 @@ private void Control_Checked(object sender, EventArgs e)
}
}
}
else if (!selections.Contains(control.PageID))
else if (!selections.Any(s => s.PageID == context.PageID))
{
selections.Add(control.PageID);
selections.Add(context);
}

indexButton.Enabled = moveButton.Enabled = copyButton.Enabled = enabled;
Expand Down
9 changes: 9 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.

4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.ar-SA.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@
<data name="HasActiveMedia" xml:space="preserve">
<value>لا يمكن استدعاء أوامر OneMore أثناء وجود تسجيل نشط. الرجاء إيقاف التسجيل وحاول مرة أخرى.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>الصفحات الموسومة</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>يقوم OneMore حاليًا بإنشاء كتالوج الهاشتاج الخاص بك.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@ Dunkel</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>OneMore-Befehle können nicht aufgerufen werden, während eine Aufzeichnung aktiv ist. Bitte stoppen Sie die Aufnahme und versuchen Sie es erneut.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>Mit Tags versehene Seiten</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore erstellt derzeit Ihren Hashtag-Katalog.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.es-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@ Oscuro</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>No se pueden invocar los comandos de OneMore mientras hay una grabación activa. Detenga la grabación y vuelva a intentarlo.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>Páginas etiquetadas</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore está creando actualmente su catálogo de hashtags.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,10 @@ Sombre</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>Impossible d'invoquer les commandes OneMore pendant qu'il y a un enregistrement actif. Veuillez arrêter l'enregistrement et réessayer.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>Pages marquées</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore crée actuellement votre catalogue de hashtags.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.he-IL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,10 @@ Total Row Font
<data name="HasActiveMedia" xml:space="preserve">
<value>לא יכול להפעיל פקודות של OneMore בזמן שיש הקלטה פעילה. אנא הפסק את ההקלטה ונסה שוב.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>דפים מתויגים</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore יוצר כעת את קטלוג ההאשטאג שלך.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,10 @@ OneNoteファイル (*.one)</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>アクティブな録画中にOneMoreコマンドを呼び出すことはできません。録画を停止してから再試行してください。</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>タグ付きページ</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMoreが現在ハッシュタグカタログを作成しています。

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.nl-NL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,10 @@ Donker</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>Kan OneMore-opdrachten niet aanroepen terwijl er een actieve opname is. Stop de opname en probeer het opnieuw.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>Getagde pagina's</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore is momenteel uw hashtagcatalogus aan het maken.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.pl-PL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,10 @@ Ciemny</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>Nie można wywołać poleceń OneMore, gdy aktywne jest nagrywanie. Zatrzymaj nagrywanie i spróbuj ponownie.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>Oznaczone strony</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore tworzy obecnie Twój katalog hashtagów.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,10 @@ Escuro</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>Não é possível invocar comandos OneMore enquanto houver uma gravação ativa. Pare a gravação e tente novamente.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>Páginas marcadas</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore está atualmente criando seu catálogo de hashtags.

Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,10 @@ Dark</value>
<data name="HasActiveMedia" xml:space="preserve">
<value>Cannot invoke OneMore commands while there is an active recording. Please stop the recording and try again.</value>
</data>
<data name="HashtagCommand_indexTitle" xml:space="preserve">
<value>Tagged Pages</value>
<comment>page title</comment>
</data>
<data name="HashtagCommand_scanning" xml:space="preserve">
<value>OneMore is currently creating your hashtag catalog.

Expand Down
Loading

0 comments on commit b6fbd6c

Please sign in to comment.