Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arrange containers when no containers #1266

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions OneMore/Commands/Page/ArrangeContainersCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace River.OneMoreAddIn.Commands
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Resx = Properties.Resources;


/// <summary>
Expand All @@ -35,26 +36,34 @@ public ArrangeContainersCommand()

public override async Task Execute(params object[] args)
{
using var one = new OneNote(out page, out ns);

if (!page.Root.Elements(ns + "Outline").Any())
{
UIHelper.ShowInfo(Resx.ArrangeContainersCommand_noContainers);
return;
}

using var dialog = new ArrangeContainersDialog();
if (dialog.ShowDialog(owner) != System.Windows.Forms.DialogResult.OK)
{
return;
}

using var one = new OneNote(out page, out ns);

FindTopMargin();

if (dialog.Vertical)
var updated = dialog.Vertical
? ArrangeVertical(dialog.PageWidth)
: ArrangeFlow(dialog.Columns, dialog.PageWidth);

if (updated)
{
ArrangeVertical(dialog.PageWidth);
await one.Update(page);
}
else
{
ArrangeFlow(dialog.Columns, dialog.PageWidth);
UIHelper.ShowInfo(Resx.ArrangeContainersCommand_noContainers);
}

await one.Update(page);
}


Expand All @@ -79,10 +88,15 @@ private void FindTopMargin()
}


private void ArrangeVertical(int pageWidth)
private bool ArrangeVertical(int pageWidth)
{
var containers = CollectContainers(page, ns);

if (!containers.Any())
{
return false;
}

// find the topmost container position
var yoffset = Math.Min(
topMargin,
Expand All @@ -106,13 +120,20 @@ private void ArrangeVertical(int pageWidth)
var height = size.GetAttributeDouble("height");
yoffset += height + BottomMargin;
}

return true;
}


private void ArrangeFlow(int columns, int pageWidth)
private bool ArrangeFlow(int columns, int pageWidth)
{
var containers = CollectContainers(page, ns);

if (!containers.Any())
{
return false;
}

var xoffset = LeftMargin;

// find the topmost container position
Expand Down Expand Up @@ -161,6 +182,8 @@ private void ArrangeFlow(int columns, int pageWidth)
xoffset += Math.Max(width, colwidth) + RightMargin;
col++;
}

return true;
}


Expand Down
3 changes: 3 additions & 0 deletions OneMore/Commands/Tagging/HashtagScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public void Dispose()
dirtyPages++;
}
}

// throttle the workload to give breathing room to OneNote UI
await Task.Delay(100);
}

provider.DeletePhantoms(pids, sectionID, sectionPath);
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 @@ -288,6 +288,10 @@
<value>أرشفة الموقع</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>لم يتم العثور على حاويات في هذه الصفحة</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>ترتيب الحاويات</value>
<comment>dialog title</comment>
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 @@ -285,6 +285,10 @@
<value>Archivstandort</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>Auf dieser Seite wurden keine Container gefunden</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>Container anordnen</value>
<comment>dialog title</comment>
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 @@ -288,6 +288,10 @@ OneNote se cerrará automáticamente</value>
<value>Ubicación del archivo</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>No se encontraron contenedores en esta página.</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>Organizar contenedores</value>
<comment>dialog title</comment>
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 @@ -285,6 +285,10 @@
<value>Emplacement des archives</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>Aucun conteneur trouvé sur cette page</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>Organiser les conteneurs</value>
<comment>dialog title</comment>
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 @@ -299,6 +299,10 @@ OneNote ייסגר אוטומטית</value>
<value>מיקום ארכיון</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>לא נמצאו מיכלים בדף זה</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>מסדרים מיכלים</value>
<comment>dialog title</comment>
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 @@ -289,6 +289,10 @@ OneNote wordt automatisch gesloten</value>
<value>Archieflocatie</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>Er zijn geen containers gevonden op deze pagina</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>Containers schikken</value>
<comment>dialog title</comment>
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 @@ -297,6 +297,10 @@ OneNote zamknie się automatycznie</value>
<value>Lokalizacja archiwum.</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>Na tej stronie nie znaleziono kontenerów</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>Ułóż pojemniki</value>
<comment>dialog title</comment>
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 @@ -289,6 +289,10 @@ OneNote fechará automaticamente</value>
<value>Localização do arquivo</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>Nenhum contêiner encontrado nesta página</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>Organizar recipientes</value>
<comment>dialog title</comment>
Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ OneNote will close automatically</value>
<value>Archive Location</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>No containers found on this page</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>Arrange Containers</value>
<comment>dialog title</comment>
Expand Down
4 changes: 4 additions & 0 deletions OneMore/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ OneNote 将自动关闭</value>
<value>档案位置</value>
<comment>archive dialog title</comment>
</data>
<data name="ArrangeContainersCommand_noContainers" xml:space="preserve">
<value>该页面未找到容器</value>
<comment>message</comment>
</data>
<data name="ArrangeContainersDialog.Text" xml:space="preserve">
<value>排列容器</value>
<comment>dialog title</comment>
Expand Down