Skip to content

Commit

Permalink
Merge pull request #1177 from stevencohn/463-hashtags
Browse files Browse the repository at this point in the history
463 hashtags
  • Loading branch information
stevencohn authored Nov 20, 2023
2 parents 31a7216 + 482f7c8 commit d3862da
Show file tree
Hide file tree
Showing 43 changed files with 1,742 additions and 75 deletions.
3 changes: 3 additions & 0 deletions OneMore/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ public void OnStartupComplete(ref Array custom)
// navigation listener
new Commands.NavigationService().Startup();

// hashtags scanner
new Commands.HashtagService().Startup();

// update check
Task.Run(async () => { await SetGeneralOptions(); });

Expand Down
30 changes: 18 additions & 12 deletions OneMore/Commands/Navigator/NavigationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace River.OneMoreAddIn.Commands
{
using Newtonsoft.Json;
using River.OneMoreAddIn.Settings;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -171,23 +170,27 @@ public async Task<bool> RecordHistory(string pageID, int depth)
if (index < 0)
{
record = Resolve(pageID);
log.History.Insert(0, record);
updated = true;
if (record != null)
{
log.History.Insert(0, record);
updated = true;
}
}
else
{
record = log.History[index];
UpdateTitle(record);

if (index >= 0)
if (UpdateTitle(record))
{
log.History.RemoveAt(index);
log.History.Insert(0, record);
updated = true;
}
}

if (updated)
// record might be null if page is still loading after previously
// clearing the notebook cache...

if (updated && (record != null))
{
record.Visited = DateTime.Now.GetTickSeconds();

Expand Down Expand Up @@ -216,9 +219,9 @@ private HistoryRecord Resolve(string pageID)
using var one = new OneNote { FallThrough = true };
return one.GetPageInfo(pageID);
}
catch (System.Runtime.InteropServices.COMException)
catch (System.Runtime.InteropServices.COMException exc)
{
logger.WriteLine($"navigator resolve skipping broken page {pageID}");
logger.WriteLine($"navigator resolve skipping broken or unloaded page {pageID}", exc);
}
catch (Exception exc)
{
Expand All @@ -229,22 +232,25 @@ private HistoryRecord Resolve(string pageID)
}


private void UpdateTitle(HistoryRecord record)
private bool UpdateTitle(HistoryRecord record)
{
try
{
using var one = new OneNote { FallThrough = true };
var page = one.GetPage(record.PageId, OneNote.PageDetail.Basic);
record.Name = page.Title;
return true;
}
catch (System.Runtime.InteropServices.COMException)
catch (System.Runtime.InteropServices.COMException exc)
{
logger.WriteLine($"navigator update title skipping broken page {record.PageId}");
logger.WriteLine($"navigator update title skipping broken or unloaded page {record.PageId}", exc);
}
catch (Exception exc)
{
logger.WriteLine($"navigator can't udpate title for page {record.PageId}", exc);
}

return false;
}


Expand Down
161 changes: 161 additions & 0 deletions OneMore/Commands/Settings/HashtagSheet .Designer.cs

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

61 changes: 61 additions & 0 deletions OneMore/Commands/Settings/HashtagSheet .cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//************************************************************************************************
// Copyright © 2023 teven M. Cohn. All Rights Reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Settings
{
using River.OneMoreAddIn.Commands;
using Resx = Properties.Resources;


internal partial class HashtagSheet : SheetBase
{

public HashtagSheet(SettingsProvider provider) : base(provider)
{
InitializeComponent();

Name = nameof(HashtagSheet);
Title = Resx.HashtagSheet_Title;

if (NeedsLocalizing())
{
Localize(new string[]
{
"introBox",
"intervalLabel",
"minLabel=word_Minutes",
"advancedGroup=phrase_AdvancedOptions",
"disabledBox"
});
}

var settings = provider.GetCollection(Name);

intervalBox.Value = settings.Get("interval", HashtagService.DefaultPollingInterval);

disabledBox.Checked = settings.Get("disabled", false);
}


public override bool CollectSettings()
{
// general...

var settings = provider.GetCollection(Name);

var updated = settings.Add("interval", (int)intervalBox.Value);

updated = disabledBox.Checked
? settings.Add("disabled", true) || updated
: settings.Remove("disabled") || updated;

if (updated)
{
provider.SetCollection(settings);
}

return updated;
}
}
}
Loading

0 comments on commit d3862da

Please sign in to comment.