Skip to content

Commit 8694387

Browse files
committed
migrate to LinqToOneNote [1/2]
1 parent 5429742 commit 8694387

11 files changed

Lines changed: 53 additions & 47 deletions

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Changelog
22

3-
## 3.0.0 - 2025-#-##
3+
## 3.0.0 - 2026-#-##
44
- **⚠ Now requires Flow Launcher version 2.0.0 or later.**
55
- Update Flow.Launcher.Plugin to 5.0.0
66
- Update to Net 9.0
77
- Refactored code
8+
- Migrate from `Odotocodot.OneNote.Linq 1.2.0` to `LinqToOneNote 2.0.0`
89

910

1011
## 2.1.2 - 2025-6-11

Flow.Launcher.Plugin.OneNote/Flow.Launcher.Plugin.OneNote.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageReference Include="Flow.Launcher.Plugin" Version="5.0.0" />
3232
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
3333
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
34-
<PackageReference Include="Odotocodot.OneNote.Linq" Version="1.2.0" />
34+
<PackageReference Include="LinqToOneNote" Version="2.0.0" />
3535
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
3636
</ItemGroup>
3737

Flow.Launcher.Plugin.OneNote/Icons/IconGeneratorInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Drawing;
2-
using Odotocodot.OneNote.Linq;
2+
using LinqToOneNote;
33

44
namespace Flow.Launcher.Plugin.OneNote.Icons
55
{
@@ -12,18 +12,18 @@ public IconGeneratorInfo(IOneNoteItem item)
1212
{
1313
switch (item)
1414
{
15-
case OneNoteNotebook n:
15+
case Notebook n:
1616
prefix = IconConstants.Notebook;
1717
color = n.Color;
1818
break;
19-
case OneNoteSectionGroup sg:
19+
case SectionGroup sg:
2020
prefix = sg.IsRecycleBin ? IconConstants.RecycleBin : IconConstants.SectionGroup;
2121
break;
22-
case OneNoteSection s:
22+
case Section s:
2323
prefix = IconConstants.Section;
2424
color = s.Color;
2525
break;
26-
case OneNotePage:
26+
case Page:
2727
prefix = IconConstants.Page;
2828
break;
2929
}

Flow.Launcher.Plugin.OneNote/Main.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Flow.Launcher.Plugin.OneNote.Icons;
77
using Flow.Launcher.Plugin.OneNote.Search;
88
using Flow.Launcher.Plugin.OneNote.UI.Views;
9-
using Odotocodot.OneNote.Linq;
9+
using OneNoteApp = LinqToOneNote.OneNote;
1010
namespace Flow.Launcher.Plugin.OneNote
1111
{
1212
#nullable disable
@@ -39,21 +39,21 @@ private void OnVisibilityChanged(object _, VisibilityChangedEventArgs e)
3939
{
4040
if (context.CurrentPluginMetadata.Disabled || !e.IsVisible)
4141
{
42-
Task.Run(OneNoteApplication.ReleaseComObject);
42+
Task.Run(OneNoteApp.ReleaseComObject);
4343
}
4444
}
4545

4646
private static async Task OneNoteInitAsync(CancellationToken token)
4747
{
48-
if (OneNoteApplication.HasComObject)
48+
if (OneNoteApp.HasComObject)
4949
return;
5050

5151
if (!await semaphore.WaitAsync(0,token))
5252
return;
5353

5454
try
5555
{
56-
OneNoteApplication.InitComObject();
56+
OneNoteApp.InitComObject();
5757
}
5858
finally
5959
{
@@ -87,7 +87,7 @@ public void Dispose()
8787
{
8888
context.API.VisibilityChanged -= OnVisibilityChanged;
8989
semaphore.Dispose();
90-
OneNoteApplication.ReleaseComObject();
90+
OneNoteApp.ReleaseComObject();
9191
}
9292
}
9393
}

Flow.Launcher.Plugin.OneNote/Search/DefaultSearch.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Odotocodot.OneNote.Linq;
3+
using OneNoteApp = LinqToOneNote.OneNote;
44

55
namespace Flow.Launcher.Plugin.OneNote.Search
66
{
@@ -16,9 +16,9 @@ public override List<Result> GetResults(string query)
1616
return resultCreator.InvalidQuery();
1717
}
1818

19-
return OneNoteApplication.FindPages(query)
20-
.Select(pg => resultCreator.CreatePageResult(pg, query))
21-
.ToList();
19+
return OneNoteApp.FindPages(query)
20+
.Select(pg => resultCreator.CreatePageResult(pg, query))
21+
.ToList();
2222

2323
}
2424
}

Flow.Launcher.Plugin.OneNote/Search/NotebookExplorer.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Odotocodot.OneNote.Linq;
5-
using Odotocodot.OneNote.Linq.Abstractions;
4+
using LinqToOneNote;
5+
using LinqToOneNote.Abstractions;
6+
using OneNoteApp = LinqToOneNote.OneNote;
7+
68

79
namespace Flow.Launcher.Plugin.OneNote.Search
810
{
@@ -22,7 +24,7 @@ public override List<Result> GetResults(string query)
2224

2325
List<Result> results = search switch
2426
{
25-
{ } when search.StartsWithOrd(Keywords.TitleSearch) && parent is not OneNotePage => titleSearch.Filter(search, parent, collection),
27+
{ } when search.StartsWithOrd(Keywords.TitleSearch) && parent is not Page => titleSearch.Filter(search, parent, collection),
2628
{ } when search.StartsWithOrd(Keywords.ScopedSearch) && parent is INotebookOrSectionGroup => ScopedSearch(search, parent),
2729
{ } when !string.IsNullOrWhiteSpace(search) => Explorer(search, parent, collection),
2830
_ => ShowAll(parent, collection),
@@ -42,7 +44,7 @@ private bool ValidateSearch(string query, out string? lastSearch, out IOneNoteIt
4244
{
4345
lastSearch = null;
4446
parent = null;
45-
collection = OneNoteApplication.GetNotebooks();
47+
collection = OneNoteApp.GetFullHierarchy().Notebooks;
4648

4749
string search = query[(query.IndexOf(Keywords.NotebookExplorer, StringComparison.Ordinal) + Keywords.NotebookExplorer.Length)..];
4850
const string separator = Keywords.NotebookExplorerSeparator;
@@ -85,9 +87,9 @@ private List<Result> ScopedSearch(string query, IOneNoteItem parent)
8587

8688
string currentSearch = query[Keywords.TitleSearch.Length..];
8789

88-
var results = OneNoteApplication.FindPages(currentSearch, parent)
89-
.Select(pg => resultCreator.CreatePageResult(pg, currentSearch))
90-
.ToList();
90+
var results = OneNoteApp.FindPages(currentSearch, parent)
91+
.Select(pg => resultCreator.CreatePageResult(pg, currentSearch))
92+
.ToList();
9193

9294
return results.Any() ? results : ResultCreator.NoMatchesFound();
9395
}
@@ -100,7 +102,7 @@ private List<Result> Explorer(string search, IOneNoteItem? parent, IEnumerable<I
100102
.ToList();
101103

102104
// If parent is a section, pages inside can have the same name
103-
if (parent is not OneNoteSection && results.Any(result => string.Equals(search.Trim(), result.Title, StringComparison.OrdinalIgnoreCase)))
105+
if (parent is not Section && results.Any(result => string.Equals(search.Trim(), result.Title, StringComparison.OrdinalIgnoreCase)))
104106
return results;
105107

106108
if (parent?.IsInRecycleBin() == true)
@@ -116,7 +118,7 @@ private List<Result> Explorer(string search, IOneNoteItem? parent, IEnumerable<I
116118
results.Add(resultCreator.CreateNewSectionResult(search, x));
117119
results.Add(resultCreator.CreateNewSectionGroupResult(search, x));
118120
break;
119-
case OneNoteSection section:
121+
case Section section:
120122
if (!section.Locked)
121123
{
122124
results.Add(resultCreator.CreateNewPageResult(search, section));
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Odotocodot.OneNote.Linq;
3+
using LinqToOneNote;
4+
using OneNoteApp = LinqToOneNote.OneNote;
45

56
namespace Flow.Launcher.Plugin.OneNote.Search
67
{
@@ -16,13 +17,14 @@ public override List<Result> GetResults(string query)
1617
if (query.Length > keyword.Length && int.TryParse(query[keyword.Length..], out int userChosenCount))
1718
count = userChosenCount;
1819

19-
return OneNoteApplication.GetNotebooks()
20-
.GetPages()
21-
.FilterBySettings(settings)
22-
.OrderByDescending(pg => pg.LastModified)
23-
.Take(count)
24-
.Select(resultCreator.CreateRecentPageResult)
25-
.ToList();
20+
return OneNoteApp.GetFullHierarchy()
21+
.Notebooks
22+
.GetAllPages()
23+
.FilterBySettings(settings)
24+
.OrderByDescending(pg => pg.LastModified)
25+
.Take(count)
26+
.Select(resultCreator.CreateRecentPageResult)
27+
.ToList();
2628
}
2729
}
2830
}

Flow.Launcher.Plugin.OneNote/Search/SearchExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Flow.Launcher.Plugin.SharedModels;
4-
using Odotocodot.OneNote.Linq;
4+
using LinqToOneNote;
55

66
namespace Flow.Launcher.Plugin.OneNote.Search
77
{
@@ -24,7 +24,7 @@ public static IEnumerable<T> FilterBySettings<T>(this IEnumerable<T> source, Set
2424
foreach (var item in source)
2525
{
2626
var success = true;
27-
if (settings.ShowEncrypted && item is OneNoteSection section)
27+
if (settings.ShowEncrypted && item is Section section)
2828
{
2929
success = !section.Encrypted;
3030
}

Flow.Launcher.Plugin.OneNote/Search/TitleSearch.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using Odotocodot.OneNote.Linq;
3+
using LinqToOneNote;
4+
using OneNoteApp = LinqToOneNote.OneNote;
45

56
namespace Flow.Launcher.Plugin.OneNote.Search
67
{
@@ -9,7 +10,7 @@ public class TitleSearch : SearchBase
910
public TitleSearch(PluginInitContext context, Settings settings, ResultCreator resultCreator)
1011
: base(context, settings, resultCreator, settings.Keywords.TitleSearch) { }
1112

12-
public override List<Result> GetResults(string query) => Filter(query, null, OneNoteApplication.GetNotebooks());
13+
public override List<Result> GetResults(string query) => Filter(query, null, OneNoteApp.GetFullHierarchy().Notebooks);
1314

1415
public List<Result> Filter(string query, IOneNoteItem? parent, IEnumerable<IOneNoteItem> collection)
1516
{
@@ -18,7 +19,7 @@ public List<Result> Filter(string query, IOneNoteItem? parent, IEnumerable<IOneN
1819

1920
var currentSearch = query[keyword.Length..];
2021

21-
var results = collection.Traverse()
22+
var results = collection.Descendants()
2223
.FilterBySettings(settings)
2324
.FuzzySearch(currentSearch, context)
2425
.Select(x => resultCreator.CreateOneNoteItemResult(x.Item, false, x.HighlightData, x.Score))

Flow.Launcher.Plugin.OneNote/UI/ViewModels/NewOneNotePageViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using System;
22
using System.Windows.Input;
33
using Flow.Launcher.Plugin.OneNote.Icons;
4-
using Odotocodot.OneNote.Linq;
4+
using LinqToOneNote;
5+
using OneNoteApp = LinqToOneNote.OneNote;
56

67
namespace Flow.Launcher.Plugin.OneNote.UI.ViewModels
78
{
89
public class NewOneNotePageViewModel : Model
910
{
1011
private string? pageTitle = string.Empty;
1112
private string pageContent = string.Empty;
12-
private readonly OneNoteSection? section;
13+
private readonly Section? section;
1314
private readonly PluginInitContext context;
1415

15-
public NewOneNotePageViewModel(PluginInitContext context, OneNoteSection? section, string? pageTitle)
16+
public NewOneNotePageViewModel(PluginInitContext context, Section? section, string? pageTitle)
1617
{
1718
this.context = context;
1819
this.section = section;
@@ -23,16 +24,15 @@ public NewOneNotePageViewModel(PluginInitContext context, OneNoteSection? sectio
2324

2425
private void CreatePage(bool openImmediately)
2526
{
26-
var id = OneNoteApplication.CreatePage(section, PageTitle, false);
27-
var page = (OneNotePage)OneNoteItemExtensions.FindByID(id);
27+
var page = OneNoteApp.CreatePage(section, PageTitle);
2828
var pageContentXml = page.GetPageContent();
2929
var xmlWrap = $"<one:Outline><one:Position x=\"36.0\" y=\"86.4000015258789\" z=\"0\"/><one:Size width=\"72.0\" height=\"13.42771339416504\"/><one:OEChildren><one:OE alignment=\"left\"><one:T><![CDATA[{PageContent}]]></one:T></one:OE></one:OEChildren></one:Outline>";
3030
pageContentXml = pageContentXml.Insert(pageContentXml.IndexOf("</one:Page>", StringComparison.Ordinal), xmlWrap);
31-
OneNoteApplication.UpdatePageContent(pageContentXml);
31+
OneNoteApp.UpdatePageContent(pageContentXml);
3232
context.API.ReQuery();
3333
if (openImmediately)
3434
{
35-
page.OpenInOneNote();
35+
page.Open();
3636
context.API.HideMainWindow();
3737
WindowHelper.FocusOneNote();
3838
}

0 commit comments

Comments
 (0)