Skip to content

Commit bd74a03

Browse files
authored
Merge pull request #42 from Odotocodot/dev
Version 3.1.0 - ⭐ **Recent pages** is dead, long live **sort by last modified**. ([#32](#32)) - Using the **sort by last modified** keyword, as the name implies, allows you to sort results by last modified. But unlike **recent pages** you can now use it in multiple places, i.e. with **title search**, **scoped search** and **notebook explorer**. Note it must be placed after the aforementioned keywords. - Examples:\ (`#` = **sort by last modified** keyword, `*` = **title search** keyword, `nb:\` = **notebook explorer** keyword, `>` = **scoped search** keyword) - ```on #{your search query}``` - ```on *#{your search query}``` - ```on nb:\PathToItem\#{your search query}``` - ```on nb:\PathToItem\>#{your search query}``` - ```on nb:\PathToItem\*#{your search query}``` - Added a setting to allow users to always open items in a new OneNote window. ([#40](#40)) - Updated plugin logo.
2 parents c174f1a + 2fd0df5 commit bd74a03

25 files changed

Lines changed: 476 additions & 339 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,4 @@ MigrationBackup/
354354
#VSCode
355355
.vscode/
356356
.idea/
357+
*.lscache

Changelog.md

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

3+
## 3.1.0
4+
5+
- :star: **Recent pages** is dead, long live **sort by last modified**. ([#32](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/issues/32))
6+
- Using the **sort by last modified** keyword, as the name implies, allows you to sort results by last modified. But unlike **recent pages** you can now use it in multiple places, i.e. with **title search**, **scoped search** and **notebook explorer**. Note it must be placed after the aforementioned keywords.
7+
- Examples:\
8+
(`#` = **sort by last modified** keyword, `*` = **title search** keyword, `nb:\` = **notebook explorer** keyword, `>` = **scoped search** keyword)
9+
- ```on #{your search query}```
10+
- ```on *#{your search query}```
11+
- ```on nb:\PathToItem\#{your search query}```
12+
- ```on nb:\PathToItem\>#{your search query}```
13+
- ```on nb:\PathToItem\*#{your search query}```
14+
- Added a setting to allow users to always open items in a new OneNote window. ([#40](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/issues/40))
15+
316
## 3.0.1 - 2026-03-13
417

518
- Fix crash on quick note with empty title (Updated to `LinqToOneNote-2.1.1`)
619
- Fix incorrect **scope search** check
720
- Cache OneNote hierarchy when applicable
8-
- This brings the performance improvement for Notebook Explorer from last version to **recent pages** and **title search**
21+
- This brings the performance improvement from **notebook explorer** from last version to **recent pages** and **title search**
922

1023
## 3.0.0 - 2026-03-04
1124

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@
33

44
namespace Flow.Launcher.Plugin.OneNote.Icons
55
{
6-
public struct IconGeneratorInfo
6+
public readonly struct IconGeneratorInfo
77
{
88
public readonly string prefix = string.Empty;
99
public readonly Color? color;
10-
11-
public IconGeneratorInfo(IOneNoteItem item)
10+
11+
private IconGeneratorInfo(string prefix, Color? color = null)
12+
{
13+
this.prefix = prefix;
14+
this.color = color;
15+
}
16+
17+
public static IconGeneratorInfo Create(IOneNoteItem item)
1218
{
13-
switch (item)
19+
return item switch
1420
{
15-
case Notebook n:
16-
prefix = IconConstants.Notebook;
17-
color = n.Color;
18-
break;
19-
case SectionGroup sg:
20-
prefix = sg.IsRecycleBin ? IconConstants.RecycleBin : IconConstants.SectionGroup;
21-
break;
22-
case Section s:
23-
prefix = IconConstants.Section;
24-
color = s.Color;
25-
break;
26-
case Page:
27-
prefix = IconConstants.Page;
28-
break;
29-
}
21+
Notebook n => new (IconConstants.Notebook, n.Color),
22+
SectionGroup sg => new (sg.IsRecycleBin ? IconConstants.RecycleBin : IconConstants.SectionGroup),
23+
Section s => new (IconConstants.Section, s.Color),
24+
Page => new (IconConstants.Page),
25+
_ => new (),
26+
};
3027
}
3128
}
3229
}
31.1 KB
Loading

Flow.Launcher.Plugin.OneNote/Keywords.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ namespace Flow.Launcher.Plugin.OneNote
88
public class Keywords
99
{
1010
public const string NotebookExplorerSeparator = "\\";
11-
public Keyword NotebookExplorer { get; set; } = new($"nb:{NotebookExplorerSeparator}");
12-
public Keyword RecentPages { get; set; } = new ("rp:");
13-
public Keyword TitleSearch { get; set; } = new ("*");
14-
public Keyword ScopedSearch { get; set; } = new (">");
15-
11+
public Keyword NotebookExplorer { get; init; } = new($"nb:{NotebookExplorerSeparator}");
12+
[JsonPropertyName("RecentPages")]
13+
public Keyword SortByLastModified { get; init; } = new ("rp:");
14+
public Keyword TitleSearch { get; init; } = new ("*");
15+
public Keyword ScopedSearch { get; init; } = new (">");
16+
17+
private Keyword[]? keywords;
18+
[JsonIgnore]
19+
public Keyword[] All => keywords ??= [NotebookExplorer, SortByLastModified, TitleSearch, ScopedSearch];
1620
}
1721

1822
[JsonConverter(typeof(KeywordJsonConverter))]
19-
public class Keyword
23+
public class Keyword(string value)
2024
{
21-
public Keyword(string value) => Value = value;
22-
public string Value { get; private set; }
25+
public string Value { get; private set; } = value;
2326

2427
public void ChangeKeyword(string newValue) => Value = newValue;
2528

2629
public int Length => Value.Length;
2730
public static implicit operator string(Keyword keyword) => keyword.Value;
2831
public override string ToString() => Value;
29-
30-
public static Keyword Empty { get; } = new ("");
3132
}
3233

3334
//Needed for legacy as keywords where just saved as a string
@@ -39,5 +40,4 @@ public override Keyword Read(ref Utf8JsonReader reader, Type typeToConvert, Json
3940
public override void Write(Utf8JsonWriter writer, Keyword value, JsonSerializerOptions options)
4041
=> JsonSerializer.Serialize(writer, value.Value, options);
4142
}
42-
4343
}

Flow.Launcher.Plugin.OneNote/ResultCreator.cs

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,12 @@
1111

1212
namespace Flow.Launcher.Plugin.OneNote
1313
{
14-
public class ResultCreator
14+
public class ResultCreator(PluginInitContext context, Settings settings, IconProvider iconProvider)
1515
{
16-
private readonly PluginInitContext context;
17-
private readonly Settings settings;
18-
private readonly IconProvider iconProvider;
19-
2016
private const string PathSeparator = " > ";
2117
private const string BulletPoint = "\u2022 ";
2218
private const string TrianglePoint = "\u2023 ";
2319
private string ActionKeyword => context.CurrentPluginMetadata.ActionKeyword;
24-
public ResultCreator(PluginInitContext context, Settings settings, IconProvider iconProvider)
25-
{
26-
this.settings = settings;
27-
this.iconProvider = iconProvider;
28-
this.context = context;
29-
}
3020

3121
private static string GetNicePath(IOneNoteItem item, string separator = PathSeparator) => item.GetRelativePath(false, separator);
3222

@@ -84,14 +74,14 @@ public List<Result> EmptyQuery()
8474
new Result
8575
{
8676
Title = "See recent pages",
87-
SubTitle = $"Type \"{settings.Keywords.RecentPages}\" or select this option to see recently modified pages",
88-
AutoCompleteText = $"{ActionKeyword} {settings.Keywords.RecentPages}",
77+
SubTitle = $"Type \"{settings.Keywords.SortByLastModified}\" or select this option to see recently modified pages",
78+
AutoCompleteText = $"{ActionKeyword} {settings.Keywords.SortByLastModified}",
8979
IcoPath = iconProvider.Recent,
9080
AddSelectedCount = false,
9181
Score = -1000,
9282
Action = _ =>
9383
{
94-
context.API.ChangeQuery($"{ActionKeyword} {settings.Keywords.RecentPages}", true);
84+
context.API.ChangeQuery($"{ActionKeyword} {settings.Keywords.SortByLastModified}", true);
9585
return false;
9686
},
9787
},
@@ -104,7 +94,7 @@ public List<Result> EmptyQuery()
10494
PreviewPanel = GetNewPagePreviewPanel(null, null),
10595
Action = _ =>
10696
{
107-
OneNoteApp.CreateQuickNote(OpenMode.ExistingOrNewWindow);
97+
OneNoteApp.CreateQuickNote(settings.AlwaysOpenInNewWindow ? OpenMode.NewWindow : OpenMode.ExistingOrNewWindow);
10898
WindowHelper.FocusOneNote();
10999
return true;
110100
},
@@ -142,7 +132,7 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
142132
var toolTip = string.Empty;
143133
var subTitle = GetNicePath(item);
144134
var autoCompleteText = GetAutoCompleteText(item);
145-
var iconInfo = new IconGeneratorInfo(item);
135+
var iconInfo = IconGeneratorInfo.Create(item);
146136

147137
switch (item)
148138
{
@@ -213,27 +203,27 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
213203
await Task.Run(() =>
214204
{
215205
item.Sync();
216-
item.Open();
206+
OneNoteApp.Open(item, settings.AlwaysOpenInNewWindow);
217207
});
218208
WindowHelper.FocusOneNote();
219209
return true;
220210
},
221211
};
222212
}
223-
224-
public Result CreatePageResult(Page page, string query)
225-
=> CreateOneNoteItemResult(page, false, string.IsNullOrWhiteSpace(query) ? null : context.API.FuzzySearch(query, page.Name).MatchData);
226213

227-
public Result CreateRecentPageResult(Page page)
214+
public Result CreateRecentItemResult(IOneNoteItem item, bool actionIsAutoComplete, List<int>? highlightData = null)
228215
{
229-
var result = CreateOneNoteItemResult(page, false);
230-
result.SubTitle = $"{page.LastModified.Humanize()} | {result.SubTitle}";
231-
result.IcoPath = iconProvider.Recent;
216+
var result = CreateOneNoteItemResult(item, actionIsAutoComplete, highlightData);
217+
result.SubTitle = string.IsNullOrWhiteSpace(result.SubTitle)
218+
? $"{item.LastModified.Humanize()}"
219+
: $"{item.LastModified.Humanize()} | {result.SubTitle}";
220+
if(item is Page)
221+
result.IcoPath = iconProvider.Recent;
232222
result.AddSelectedCount = false;
233223
return result;
234224
}
235225

236-
//When name can have invalid chars
226+
//When new name can have invalid chars
237227
private Result CreateNewItemResult<TNew, TParent>(string newName, TParent? parent, string iconPath, Func<TParent?, string, OpenMode, TNew> createFunc)
238228
where TNew : IOneNoteItem, INameInvalidCharacters
239229
where TParent : IOneNoteItem
@@ -261,7 +251,10 @@ private Result CreateNewItemResult<TNew, TParent>(string newName, TParent? paren
261251
return false;
262252

263253
bool showOneNote = !c.SpecialKeyState.CtrlPressed;
264-
createFunc(parent, newName, showOneNote ? OpenMode.ExistingOrNewWindow : OpenMode.None);
254+
bool newWindow = settings.AlwaysOpenInNewWindow;
255+
256+
OpenMode openMode = showOneNote ? newWindow ? OpenMode.NewWindow : OpenMode.ExistingOrNewWindow : OpenMode.None;
257+
createFunc(parent, newName, openMode);
265258

266259
context.API.ReQuery();
267260

@@ -291,18 +284,27 @@ public List<Result> ContextMenu(Result selectedResult)
291284
var results = new List<Result>();
292285
if (selectedResult.ContextData is IOneNoteItem item)
293286
{
294-
var result = CreateOneNoteItemResult(item, false);
295-
result.Title = $"Open and sync \"{item.Name}\"";
296-
result.SubTitle = string.Empty;
297-
result.Score = 30;
298-
result.AddSelectedCount = false;
299-
result.ContextData = null;
300-
results.Add(result);
287+
Result.IconDelegate icon = iconProvider.GetIcon(IconGeneratorInfo.Create(item));
288+
results.Add(new Result
289+
{
290+
Title = $"Open and sync \"{item.Name}\"",
291+
Icon = icon,
292+
Score = 30,
293+
AddSelectedCount = false,
294+
Action = _ =>
295+
{
296+
OneNoteApp.Open(item);
297+
OneNoteApp.SyncItem(item);
298+
WindowHelper.FocusOneNote();
299+
return true;
300+
}
301+
});
302+
301303

302304
results.Add(new Result
303305
{
304306
Title = $"Open \"{item.Name}\" in new OneNote window",
305-
Icon = result.Icon,
307+
Icon = icon,
306308
Score = 20,
307309
AddSelectedCount = false,
308310
Action = _ =>
@@ -381,7 +383,7 @@ Result EmptyCollectionResult(string title, string iconPath, string? subTitle = n
381383
}
382384

383385
private Lazy<System.Windows.Controls.UserControl> GetNewPagePreviewPanel(Section? section, string? pageTitle)
384-
=> new(() => new NewOneNotePagePreviewPanel(context, section, pageTitle));
386+
=> new(() => new NewOneNotePagePreviewPanel(context, settings, section, pageTitle));
385387

386388
public static List<Result> NoMatchesFound()
387389
{

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)