Skip to content

Commit

Permalink
Add open to filter out tags from offline notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Jul 22, 2024
1 parent 91a2078 commit 941bb40
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 7 deletions.
25 changes: 20 additions & 5 deletions OneMore/Commands/Tagging/HashtagDialog.Designer.cs

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

57 changes: 55 additions & 2 deletions OneMore/Commands/Tagging/HashtagDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace River.OneMoreAddIn.Commands

internal partial class HashtagDialog : MoreForm
{
private const string SettingsKey = "Hashtags";

private const string T0 = "0001-01-01T00:00:00.0000Z";

private readonly MoreAutoCompleteList palette;
Expand Down Expand Up @@ -78,6 +80,10 @@ public HashtagDialog()
.GetCollection("GeneralSheet").Get<bool>("experimental");

ShowScanTimes();

ShowOfflineNotebooks = new SettingsProvider()
.GetCollection(SettingsKey)
.Get("showOffline", true);
}


Expand All @@ -87,6 +93,9 @@ public HashtagDialog()
public IEnumerable<string> SelectedPages => selections;


public bool ShowOfflineNotebooks { get; private set; } = true;


private void ShowScanTimes()
{
var scan = new HashtagProvider().ReadScanTime();
Expand Down Expand Up @@ -149,9 +158,10 @@ private async void DoKeyDown(object sender, KeyEventArgs e)
}


private void DoSearchTags(object sender, EventArgs e)
private async void DoSearchTags(object sender, EventArgs e)
{
Task.Run(async () => { await SearchTags(sender, e); });
await SearchTags(sender, e);
//Task.Run(async () => { await SearchTags(sender, e); });
}


Expand All @@ -178,6 +188,14 @@ private async Task SearchTags(object sender, EventArgs e)
_ => provider.SearchTags(where, out parsed)
};

if (!ShowOfflineNotebooks)
{
// must be ToList?!
var loaded = tags.Where(t => loadedBookIDs.Contains(t.NotebookID)).ToList();
tags.Clear();
tags.AddRange(loaded);
}

logger.Verbose($"found {tags.Count} tags using [{parsed}]");

var width = contextPanel.ClientSize.Width -
Expand Down Expand Up @@ -408,10 +426,45 @@ private async void ScanNow(object sender, EventArgs e)
}


private void PrepareContextMenu(object sender, System.EventArgs e)
{
if (ShowOfflineNotebooks)
{
offlineNotebooksButton.Image = Resx.e_CheckMark;
offlineNotebooksButton.Text = "Show Offline Notebooks"; // Resx.HashtagDialog_showOfflineMenuItem;
}
else
{
offlineNotebooksButton.Image = null;
offlineNotebooksButton.Text = "Hide Offline Notebooks"; // Resx.HashtagDialog_hideOfflineMenuItem;
}
}


private void ToggleOfflineNotebooks(object sender, EventArgs e)
{
ShowOfflineNotebooks = !ShowOfflineNotebooks;
}


private void DoCancel(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}


private void SaveSettings(object sender, FormClosingEventArgs e)
{
var provider = new SettingsProvider();
var settings = provider.GetCollection(SettingsKey);
settings.Add("showOffline", ShowOfflineNotebooks);

if (settings.IsModified)
{
provider.SetCollection(settings);
provider.Save();
}
}
}
}

0 comments on commit 941bb40

Please sign in to comment.