Skip to content

Commit ece36f5

Browse files
authored
Merge pull request #26 from Odotocodot/dev
Version 2.1.1
2 parents 5f56aa8 + b72050d commit ece36f5

10 files changed

+225
-186
lines changed

Changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 2.1.1 - 2025-1-4
4+
5+
### Changes
6+
7+
- Indicated Windows/Microsoft Search is required for default and scoped search in readme. ([#24](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/issues/24))
8+
- Added some badges.
9+
- Updated OneNote page result tooltips.
10+
- Changed recent pages default keyword from `rcntpgs:` to `rp:`.
11+
12+
### Fixes
13+
14+
- Fixed spelling and grammar mistakes.
15+
316
## 2.1.0 - 2024-6-24
417

518
### Added

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1212
<UseWPF>true</UseWPF>
1313
<UseWindowsForms>true</UseWindowsForms>
14-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <!-- Required for bringing OneNote to front -->
14+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <!-- Required for bringing OneNote to front -->
15+
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
1516
</PropertyGroup>
1617

1718
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

Flow.Launcher.Plugin.OneNote/Keywords.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class Keywords
44
{
55
public const string NotebookExplorerSeparator = "\\";
66
public string NotebookExplorer { get; set; } = $"nb:{NotebookExplorerSeparator}";
7-
public string RecentPages { get; set; } = "rcntpgs:";
7+
public string RecentPages { get; set; } = "rp:";
88
public string TitleSearch { get; set; } = "*";
99
public string ScopedSearch { get; set; } = ">";
1010
}

Flow.Launcher.Plugin.OneNote/ResultCreator.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public List<Result> EmptyQuery()
6868
new Result
6969
{
7070
Title = "View notebook explorer",
71-
SubTitle = $"Type \"{settings.Keywords.NotebookExplorer}\" or select this option to search by notebook structure ",
71+
SubTitle = $"Type \"{settings.Keywords.NotebookExplorer}\" or select this option to search by notebook structure",
7272
AutoCompleteText = $"{ActionKeyword} {settings.Keywords.NotebookExplorer}",
7373
IcoPath = iconProvider.NotebookExplorer,
7474
Score = 2000,
@@ -194,9 +194,10 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
194194

195195
subTitle = subTitle[..^(page.Name.Length + PathSeparator.Length)];
196196
toolTip =
197-
$"Created:\t\t{page.Created:F}\n" +
198-
$"Last Modified:\t{page.LastModified:F}";
199-
197+
$"""
198+
{"Created:",-15} {page.Created:F}
199+
{"Last Modified:",-15} {page.LastModified:F}
200+
""";
200201
iconInfo = new IconGeneratorInfo(page);
201202
break;
202203
default:
@@ -239,7 +240,7 @@ public Result CreatePageResult(OneNotePage page, string query)
239240
public Result CreateRecentPageResult(OneNotePage page)
240241
{
241242
var result = CreateOneNoteItemResult(page, false, null);
242-
result.SubTitle = $"{page.LastModified.Humanize()}\t{result.SubTitle}";
243+
result.SubTitle = $"{page.LastModified.Humanize()} | {result.SubTitle}";
243244
result.IcoPath = iconProvider.Recent;
244245
return result;
245246
}
@@ -454,7 +455,7 @@ private Lazy<UserControl> GetNewPagePreviewPanel(OneNoteSection section, string
454455
public static List<Result> NoMatchesFound()
455456
{
456457
return SingleResult("No matches found",
457-
"Try searching something else, or syncing your notebooks.",
458+
"Try searching something else, or syncing your notebooks",
458459
IconProvider.Logo);
459460
}
460461
public List<Result> InvalidQuery()
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Odotocodot.OneNote.Linq;
5+
6+
namespace Flow.Launcher.Plugin.OneNote
7+
{
8+
public partial class SearchManager
9+
{
10+
private sealed class NotebookExplorer
11+
{
12+
private readonly SearchManager searchManager;
13+
private readonly ResultCreator resultCreator;
14+
15+
private Keywords Keywords => searchManager.settings.Keywords;
16+
internal NotebookExplorer(SearchManager searchManager, ResultCreator resultCreator)
17+
{
18+
this.searchManager = searchManager;
19+
this.resultCreator = resultCreator;
20+
}
21+
22+
internal List<Result> Query(Query query)
23+
{
24+
var results = new List<Result>();
25+
26+
string fullSearch = query.Search[(query.Search.IndexOf(Keywords.NotebookExplorer, StringComparison.Ordinal) + Keywords.NotebookExplorer.Length)..];
27+
28+
IOneNoteItem parent = null;
29+
IEnumerable<IOneNoteItem> collection = OneNoteApplication.GetNotebooks();
30+
31+
string[] searches = fullSearch.Split(Keywords.NotebookExplorerSeparator, StringSplitOptions.None);
32+
33+
for (int i = -1; i < searches.Length - 1; i++)
34+
{
35+
if (i < 0)
36+
{
37+
continue;
38+
}
39+
40+
parent = collection.FirstOrDefault(item => item.Name.Equals(searches[i]));
41+
if (parent == null)
42+
{
43+
return results;
44+
}
45+
46+
collection = parent.Children;
47+
}
48+
49+
string lastSearch = searches[^1];
50+
51+
results = lastSearch switch
52+
{
53+
// Empty search so show all in collection
54+
string search when string.IsNullOrWhiteSpace(search)
55+
=> EmptySearch(parent, collection),
56+
57+
// Search by title
58+
string search when search.StartsWith(Keywords.TitleSearch) && parent is not OneNotePage
59+
=> searchManager.TitleSearch(search, parent, collection),
60+
61+
// Scoped search
62+
string search when search.StartsWith(Keywords.ScopedSearch) && parent is OneNoteNotebook or OneNoteSectionGroup
63+
=> ScopedSearch(search, parent),
64+
65+
// Default search
66+
_ => Explorer(lastSearch, parent, collection),
67+
};
68+
69+
if (parent != null)
70+
{
71+
var result = resultCreator.CreateOneNoteItemResult(parent, false, score: 4000);
72+
result.Title = $"Open \"{parent.Name}\" in OneNote";
73+
result.SubTitle = lastSearch switch
74+
{
75+
string search when search.StartsWith(Keywords.TitleSearch)
76+
=> $"Now searching by title in \"{parent.Name}\"",
77+
78+
string search when search.StartsWith(Keywords.ScopedSearch)
79+
=> $"Now searching all pages in \"{parent.Name}\"",
80+
81+
_ => $"Use \'{Keywords.ScopedSearch}\' to search this item. Use \'{Keywords.TitleSearch}\' to search by title in this item",
82+
};
83+
84+
results.Add(result);
85+
}
86+
87+
return results;
88+
}
89+
90+
private List<Result> EmptySearch(IOneNoteItem parent, IEnumerable<IOneNoteItem> collection)
91+
{
92+
List<Result> results = collection.Where(searchManager.SettingsCheck)
93+
.Select(item => resultCreator.CreateOneNoteItemResult(item, true))
94+
.ToList();
95+
if (results.Any())
96+
return results;
97+
return resultCreator.NoItemsInCollection(results, parent);
98+
}
99+
100+
private List<Result> ScopedSearch(string query, IOneNoteItem parent)
101+
{
102+
if (query.Length == Keywords.ScopedSearch.Length)
103+
{
104+
return ResultCreator.NoMatchesFound();
105+
}
106+
107+
if (!char.IsLetterOrDigit(query[Keywords.ScopedSearch.Length]))
108+
{
109+
return resultCreator.InvalidQuery();
110+
}
111+
112+
string currentSearch = query[Keywords.TitleSearch.Length..];
113+
114+
var results = OneNoteApplication.FindPages(currentSearch, parent)
115+
.Select(pg => resultCreator.CreatePageResult(pg, currentSearch))
116+
.ToList();
117+
118+
if (!results.Any())
119+
{
120+
results = ResultCreator.NoMatchesFound();
121+
}
122+
123+
return results;
124+
}
125+
#nullable enable
126+
private List<Result> Explorer(string search, IOneNoteItem? parent, IEnumerable<IOneNoteItem> collection)
127+
{
128+
List<int>? highlightData = null;
129+
int score = 0;
130+
131+
var results = collection.Where(searchManager.SettingsCheck)
132+
.Where(item => searchManager.FuzzySearch(item.Name, search, out highlightData, out score))
133+
.Select(item => resultCreator.CreateOneNoteItemResult(item, true, highlightData, score))
134+
.ToList();
135+
136+
AddCreateNewOneNoteItemResults(search, parent, results);
137+
return results;
138+
}
139+
140+
private void AddCreateNewOneNoteItemResults(string newItemName, IOneNoteItem? parent, List<Result> results)
141+
{
142+
if (results.Any(result => string.Equals(newItemName.Trim(), result.Title, StringComparison.OrdinalIgnoreCase)))
143+
{
144+
return;
145+
}
146+
147+
if (parent?.IsInRecycleBin() == true)
148+
{
149+
return;
150+
}
151+
152+
switch (parent)
153+
{
154+
case null:
155+
results.Add(resultCreator.CreateNewNotebookResult(newItemName));
156+
break;
157+
case OneNoteNotebook:
158+
case OneNoteSectionGroup:
159+
results.Add(resultCreator.CreateNewSectionResult(newItemName, parent));
160+
results.Add(resultCreator.CreateNewSectionGroupResult(newItemName, parent));
161+
break;
162+
case OneNoteSection section:
163+
if (!section.Locked)
164+
{
165+
results.Add(resultCreator.CreateNewPageResult(newItemName, section));
166+
}
167+
168+
break;
169+
}
170+
}
171+
}
172+
}
173+
}

0 commit comments

Comments
 (0)