Skip to content

Commit

Permalink
1226 select notebooks (#1355)
Browse files Browse the repository at this point in the history
* select notebooks
#1226
  • Loading branch information
stevencohn authored Apr 24, 2024
1 parent 25edf13 commit 061c641
Show file tree
Hide file tree
Showing 33 changed files with 1,128 additions and 132 deletions.
5 changes: 5 additions & 0 deletions OneMore/AddInCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ public async Task SaveSnippetCmd(IRibbonControl control)
=> await factory.Run<SaveSnippetCommand>();


[Command("ribScheduleHashtagScanButton_Label", Keys.None, "ribSearchMenu")]
public async Task ScheduleHashtagScanCmd(IRibbonControl control)
=> await factory.Run<HashtagScanCommand>();


[Command("ribSearchButton_Label", Keys.None, "ribSearchMenu")]
public async Task SearchCmd(IRibbonControl control)
=> await factory.Run<SearchCommand>();
Expand Down
69 changes: 50 additions & 19 deletions OneMore/Commands/Page/ArrangeContainersCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//************************************************************************************************
// Copyright © 2021 Steven M Cohn. All rights reserved.
// Copyright © 2021 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Commands
Expand Down Expand Up @@ -78,7 +78,7 @@ private void FindTopMargin()
.Select(e => e.Parent)
.FirstOrDefault();

if (bank == null)
if (bank is null)
{
topMargin = TopMargin;
}
Expand Down Expand Up @@ -190,35 +190,66 @@ private bool ArrangeFlow(int columns, int pageWidth)
}


// Collects a list of containers that have content, filtering out those with
// empty text runs. OneNote tends to append an empty container after Update regardless
// Collects a list of Outlines that have content, removing the last Outline if it
// only has a single line of whitespace. OneNote sometimes appends an empty container
// after Update for some reason.
private IEnumerable<XElement> CollectContainers(Page page, XNamespace ns)
{
var containers = page.Root.Elements(ns + "Outline")
var outlines = page.Root.Elements(ns + "Outline")
.Where(e => !e.Elements(ns + "Meta")
.Any(m => m.Attribute("name").Value == MetaNames.TaggingBank))
.ToList();

foreach (var container in containers)
if (outlines.Count < 2)
{
// zero or one Outline; don't leave the page entirely empty
return outlines;
}

// we only care about the last Outline...

var index = outlines.Count - 1;
var last = outlines[index];
var blocks = last.Descendants(ns + "HTMLBlock");
if (blocks.Any())
{
// HTMLBlock is content
return outlines;
}

var paragraphs = last.Descendants(ns + "OE");
if (!paragraphs.Any())
{
var runs = container.Descendants(ns + "T");
if (runs.Any())
// remove empty Outline
outlines.RemoveAt(index);
return outlines;
}

// if Outline contains exactly one paragraph
if (paragraphs.Count() == 1 &&
paragraphs.First() is XElement paragraph)
{
var descendants = paragraph.Descendants();

// contains Meta, Image, Table, or other non-text elements
if (descendants.Any(e => e.Name.LocalName != "T"))
{
var text = runs.Nodes().OfType<XCData>()
.Select(c => c.Value.Trim())
.Aggregate((a, b) => $"{a}{b}");

if (text.Length > 0)
{
yield return container;
}
return outlines;
}
else

var text = descendants
.Where(e => e.Name.LocalName == "T")
.Nodes().OfType<XCData>()
.Select(c => c.Value.Trim())
.Aggregate((a, b) => $"{a}{b}");

if (text?.Length == 0)
{
// likely contains an InsertedFile or image without text runs
yield return container;
outlines.RemoveAt(index);
}
}

return outlines;
}
}
}
5 changes: 2 additions & 3 deletions OneMore/Commands/Settings/ContextMenuSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ private MenuItemPanel(string name, string resID)
{
name = Resx.ResourceManager.GetString(resID, AddIn.Culture) ?? name;

using var graphics = Graphics.FromHwnd(IntPtr.Zero);
var textSize = graphics.MeasureString(name, Font);
Height = (int)(textSize.Height + 6);
var textSize = TextRenderer.MeasureText(name, Font);
Height = textSize.Height + 6;

box = new UI.MoreCheckBox
{
Expand Down
48 changes: 13 additions & 35 deletions OneMore/Commands/Settings/HashtagSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ namespace River.OneMoreAddIn.Settings
{
using River.OneMoreAddIn.Commands;
using River.OneMoreAddIn.Styles;
using System;
using System.Linq;
using System.Windows.Forms;
using Resx = Properties.Resources;


internal partial class HashtagSheet : SheetBase
{
private readonly HashtagScheduler scheduler;


public HashtagSheet(SettingsProvider provider) : base(provider)
{
Expand Down Expand Up @@ -77,8 +76,6 @@ public HashtagSheet(SettingsProvider provider) : base(provider)

filterBox.Checked = settings.Get<bool>("unfiltered");

upgradeLink.Enabled = !provider.GetCollection("tagging").Get("converted", false);

if (provider.GetCollection("GeneralSheet").Get("experimental", false))
{
delayBox.Value = settings.Get("delay", HashtagScanner.DefaultThrottle);
Expand All @@ -89,43 +86,24 @@ public HashtagSheet(SettingsProvider provider) : base(provider)
delayBox.Visible = false;
msLabel.Visible = false;
}

scheduler = new HashtagScheduler();
}


private async void ScheduleRebuild(object sender, LinkLabelLinkClickedEventArgs e)
protected override async void OnLoad(EventArgs e)
{
using var dialog =
scheduler.State == ScanningState.None ||
scheduler.State == ScanningState.Ready
? new ScheduleScanDialog()
: new ScheduleScanDialog(scheduler.StartTime);

if (scheduler.State != ScanningState.None &&
scheduler.State != ScanningState.Ready)
{
dialog.SetIntroText(string.Format(
Resx.HashtagSheet_prescheduled,
scheduler.StartTime.ToString("ddd, MMMM d, yyyy h:mm tt"))
);
}
else
{
dialog.SetIntroText(Resx.HashtagSheet_scanNotebooks);
}
base.OnLoad(e);

//
// FULL?
//
var converter = new LegacyTaggingConverter();
upgradeLink.Enabled = await converter.NeedsConversion();
}

var result = dialog.ShowDialog(this);
if (result == DialogResult.OK)
{
scheduler.StartTime = dialog.StartTime;
scheduler.State = ScanningState.PendingScan;
await scheduler.Activate();
}

private async void ScheduleRebuild(object sender, LinkLabelLinkClickedEventArgs e)
{
var cmd = new HashtagScanCommand();
cmd.SetLogger(logger);
cmd.SetOwner(this);
await cmd.Execute();
}


Expand Down
28 changes: 14 additions & 14 deletions OneMore/Commands/Tagging/HashtagCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.UI;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -78,30 +77,31 @@ private async Task<bool> ConfirmReady()

if (!HashtagProvider.DatabaseExists())
{
using var scheduleDialog = scheduler.State == ScanningState.None
? new ScheduleScanDialog()
: new ScheduleScanDialog(scheduler.StartTime);
using var sdialog = scheduler.State == ScanningState.None
? new ScheduleScanDialog(false)
: new ScheduleScanDialog(false, scheduler.StartTime);

var result = scheduleDialog.ShowDialog(owner);
var result = sdialog.ShowDialog(owner);
if (result == DialogResult.OK)
{
scheduler.StartTime = scheduleDialog.StartTime;
scheduler.Notebooks = sdialog.GetSelectedNotebooks();
scheduler.StartTime = sdialog.StartTime;
scheduler.State = ScanningState.PendingRebuild;
await scheduler.Activate();
}

return false;
}

if (scheduler.State != ScanningState.Ready)
{
var msg = scheduler.State == ScanningState.Scanning
? Resx.HashtagCommand_scanning
: string.Format(Resx.HashtagCommand_waiting, scheduler.StartTime.ToFriendlyString());
//if (scheduler.State != ScanningState.Ready)
//{
// var msg = scheduler.State == ScanningState.Scanning
// ? Resx.HashtagCommand_scanning
// : string.Format(Resx.HashtagCommand_waiting, scheduler.StartTime.ToFriendlyString());

MoreMessageBox.Show(owner, msg);
return false;
}
// MoreMessageBox.Show(owner, msg);
// return false;
//}

return true;
}
Expand Down
16 changes: 13 additions & 3 deletions OneMore/Commands/Tagging/HashtagDialog.Designer.cs

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

37 changes: 37 additions & 0 deletions OneMore/Commands/Tagging/HashtagDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,43 @@ private async Task SearchTags(object sender, EventArgs e)
}


private void DoScheduleScan(object sender, EventArgs e)
{
var scheduler = new HashtagScheduler();

using var dialog =
scheduler.State == ScanningState.None ||
scheduler.State == ScanningState.Ready
? new ScheduleScanDialog(true)
: new ScheduleScanDialog(true, scheduler.StartTime);

if (scheduler.State != ScanningState.None &&
scheduler.State != ScanningState.Ready)
{
dialog.SetIntroText(string.Format(
Resx.HashtagSheet_prescheduled,
scheduler.StartTime.ToString("ddd, MMMM d, yyyy h:mm tt"))
);
}
else
{
dialog.SetIntroText(Resx.HashtagSheet_scanNotebooks);
}

dialog.SetPreferredIDs(scheduler.Notebooks);

var result = dialog.ShowDialog(this);
if (result == DialogResult.OK)
{
scheduler.Notebooks = dialog.GetSelectedNotebooks();
scheduler.StartTime = dialog.StartTime;
scheduler.State = ScanningState.PendingScan;

Task.Run(async () => { await scheduler.Activate(); });
}
}


private void Control_Checked(object sender, EventArgs e)
{
var control = sender as HashtagContextControl;
Expand Down
Loading

0 comments on commit 061c641

Please sign in to comment.