From 30d7d76850fe9808f13c5a6e3c3f6763d2dba0f9 Mon Sep 17 00:00:00 2001
From: Odotocodot <48138990+Odotocodot@users.noreply.github.com>
Date: Sat, 29 Jun 2024 16:04:27 +0100
Subject: [PATCH 1/7] Add smol comment
---
Flow.Launcher.Plugin.OneNote/UI/Styles.xaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Flow.Launcher.Plugin.OneNote/UI/Styles.xaml b/Flow.Launcher.Plugin.OneNote/UI/Styles.xaml
index bf94a1d..793f277 100644
--- a/Flow.Launcher.Plugin.OneNote/UI/Styles.xaml
+++ b/Flow.Launcher.Plugin.OneNote/UI/Styles.xaml
@@ -6,6 +6,7 @@
+ true
+ en
diff --git a/Flow.Launcher.Plugin.OneNote/SearchManager.NotebookExplorer.cs b/Flow.Launcher.Plugin.OneNote/SearchManager.NotebookExplorer.cs
new file mode 100644
index 0000000..c21b239
--- /dev/null
+++ b/Flow.Launcher.Plugin.OneNote/SearchManager.NotebookExplorer.cs
@@ -0,0 +1,173 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Odotocodot.OneNote.Linq;
+
+namespace Flow.Launcher.Plugin.OneNote
+{
+ public partial class SearchManager
+ {
+ private sealed class NotebookExplorer
+ {
+ private readonly SearchManager searchManager;
+ private readonly ResultCreator resultCreator;
+
+ private Keywords Keywords => searchManager.settings.Keywords;
+ internal NotebookExplorer(SearchManager searchManager, ResultCreator resultCreator)
+ {
+ this.searchManager = searchManager;
+ this.resultCreator = resultCreator;
+ }
+
+ internal List Query(Query query)
+ {
+ var results = new List();
+
+ string fullSearch = query.Search[(query.Search.IndexOf(Keywords.NotebookExplorer, StringComparison.Ordinal) + Keywords.NotebookExplorer.Length)..];
+
+ IOneNoteItem parent = null;
+ IEnumerable collection = OneNoteApplication.GetNotebooks();
+
+ string[] searches = fullSearch.Split(Keywords.NotebookExplorerSeparator, StringSplitOptions.None);
+
+ for (int i = -1; i < searches.Length - 1; i++)
+ {
+ if (i < 0)
+ {
+ continue;
+ }
+
+ parent = collection.FirstOrDefault(item => item.Name.Equals(searches[i]));
+ if (parent == null)
+ {
+ return results;
+ }
+
+ collection = parent.Children;
+ }
+
+ string lastSearch = searches[^1];
+
+ results = lastSearch switch
+ {
+ // Empty search so show all in collection
+ string search when string.IsNullOrWhiteSpace(search)
+ => EmptySearch(parent, collection),
+
+ // Search by title
+ string search when search.StartsWith(Keywords.TitleSearch) && parent is not OneNotePage
+ => searchManager.TitleSearch(search, parent, collection),
+
+ // Scoped search
+ string search when search.StartsWith(Keywords.ScopedSearch) && parent is OneNoteNotebook or OneNoteSectionGroup
+ => ScopedSearch(search, parent),
+
+ // Default search
+ _ => Explorer(lastSearch, parent, collection),
+ };
+
+ if (parent != null)
+ {
+ var result = resultCreator.CreateOneNoteItemResult(parent, false, score: 4000);
+ result.Title = $"Open \"{parent.Name}\" in OneNote";
+ result.SubTitle = lastSearch switch
+ {
+ string search when search.StartsWith(Keywords.TitleSearch)
+ => $"Now searching by title in \"{parent.Name}\"",
+
+ string search when search.StartsWith(Keywords.ScopedSearch)
+ => $"Now searching all pages in \"{parent.Name}\"",
+
+ _ => $"Use \'{Keywords.ScopedSearch}\' to search this item. Use \'{Keywords.TitleSearch}\' to search by title in this item",
+ };
+
+ results.Add(result);
+ }
+
+ return results;
+ }
+
+ private List EmptySearch(IOneNoteItem parent, IEnumerable collection)
+ {
+ List results = collection.Where(searchManager.SettingsCheck)
+ .Select(item => resultCreator.CreateOneNoteItemResult(item, true))
+ .ToList();
+ if (results.Any())
+ return results;
+ return resultCreator.NoItemsInCollection(results, parent);
+ }
+
+ private List ScopedSearch(string query, IOneNoteItem parent)
+ {
+ if (query.Length == Keywords.ScopedSearch.Length)
+ {
+ return ResultCreator.NoMatchesFound();
+ }
+
+ if (!char.IsLetterOrDigit(query[Keywords.ScopedSearch.Length]))
+ {
+ return resultCreator.InvalidQuery();
+ }
+
+ string currentSearch = query[Keywords.TitleSearch.Length..];
+
+ var results = OneNoteApplication.FindPages(currentSearch, parent)
+ .Select(pg => resultCreator.CreatePageResult(pg, currentSearch))
+ .ToList();
+
+ if (!results.Any())
+ {
+ results = ResultCreator.NoMatchesFound();
+ }
+
+ return results;
+ }
+#nullable enable
+ private List Explorer(string search, IOneNoteItem? parent, IEnumerable collection)
+ {
+ List? highlightData = null;
+ int score = 0;
+
+ var results = collection.Where(searchManager.SettingsCheck)
+ .Where(item => searchManager.FuzzySearch(item.Name, search, out highlightData, out score))
+ .Select(item => resultCreator.CreateOneNoteItemResult(item, true, highlightData, score))
+ .ToList();
+
+ AddCreateNewOneNoteItemResults(search, parent, results);
+ return results;
+ }
+
+ private void AddCreateNewOneNoteItemResults(string newItemName, IOneNoteItem? parent, List results)
+ {
+ if (results.Any(result => string.Equals(newItemName.Trim(), result.Title, StringComparison.OrdinalIgnoreCase)))
+ {
+ return;
+ }
+
+ if (parent?.IsInRecycleBin() == true)
+ {
+ return;
+ }
+
+ switch (parent)
+ {
+ case null:
+ results.Add(resultCreator.CreateNewNotebookResult(newItemName));
+ break;
+ case OneNoteNotebook:
+ case OneNoteSectionGroup:
+ results.Add(resultCreator.CreateNewSectionResult(newItemName, parent));
+ results.Add(resultCreator.CreateNewSectionGroupResult(newItemName, parent));
+ break;
+ case OneNoteSection section:
+ if (!section.Locked)
+ {
+ results.Add(resultCreator.CreateNewPageResult(newItemName, section));
+ }
+
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/Flow.Launcher.Plugin.OneNote/SearchManager.cs b/Flow.Launcher.Plugin.OneNote/SearchManager.cs
index 4e3c083..fbd7faa 100644
--- a/Flow.Launcher.Plugin.OneNote/SearchManager.cs
+++ b/Flow.Launcher.Plugin.OneNote/SearchManager.cs
@@ -1,11 +1,10 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using Odotocodot.OneNote.Linq;
namespace Flow.Launcher.Plugin.OneNote
{
- public class SearchManager
+ public partial class SearchManager
{
private readonly PluginInitContext context;
private readonly Settings settings;
@@ -73,10 +72,10 @@ private List TitleSearch(string query, IOneNoteItem parent, IEnumerable<
private List RecentPages(string query)
{
int count = settings.DefaultRecentsCount;
-
+
if (query.Length > settings.Keywords.RecentPages.Length && int.TryParse(query[settings.Keywords.RecentPages.Length..], out int userChosenCount))
count = userChosenCount;
-
+
return OneNoteApplication.GetNotebooks()
.GetPages()
.Where(SettingsCheck)
@@ -102,166 +101,5 @@ private bool SettingsCheck(IOneNoteItem item)
success = false;
return success;
}
- private sealed class NotebookExplorer
- {
- private readonly SearchManager searchManager;
- private readonly ResultCreator resultCreator;
-
- private Keywords Keywords => searchManager.settings.Keywords;
- internal NotebookExplorer(SearchManager searchManager, ResultCreator resultCreator)
- {
- this.searchManager = searchManager;
- this.resultCreator = resultCreator;
- }
-
- internal List Query(Query query)
- {
- var results = new List();
-
- string fullSearch = query.Search[(query.Search.IndexOf(Keywords.NotebookExplorer, StringComparison.Ordinal) + Keywords.NotebookExplorer.Length)..];
-
- IOneNoteItem parent = null;
- IEnumerable collection = OneNoteApplication.GetNotebooks();
-
- string[] searches = fullSearch.Split(Keywords.NotebookExplorerSeparator, StringSplitOptions.None);
-
- for (int i = -1; i < searches.Length - 1; i++)
- {
- if (i < 0)
- {
- continue;
- }
-
- parent = collection.FirstOrDefault(item => item.Name.Equals(searches[i]));
- if (parent == null)
- {
- return results;
- }
-
- collection = parent.Children;
- }
-
- string lastSearch = searches[^1];
-
- results = lastSearch switch
- {
- // Empty search so show all in collection
- string search when string.IsNullOrWhiteSpace(search)
- => EmptySearch(parent, collection),
-
- // Search by title
- string search when search.StartsWith(Keywords.TitleSearch) && parent is not OneNotePage
- => searchManager.TitleSearch(search, parent, collection),
-
- // Scoped search
- string search when search.StartsWith(Keywords.ScopedSearch) && parent is OneNoteNotebook or OneNoteSectionGroup
- => ScopedSearch(search, parent),
-
- // Default search
- _ => Explorer(lastSearch, parent, collection),
- };
-
- if (parent != null)
- {
- var result = resultCreator.CreateOneNoteItemResult(parent, false, score: 4000);
- result.Title = $"Open \"{parent.Name}\" in OneNote";
- result.SubTitle = lastSearch switch
- {
- string search when search.StartsWith(Keywords.TitleSearch)
- => $"Now searching by title in \"{parent.Name}\"",
-
- string search when search.StartsWith(Keywords.ScopedSearch)
- => $"Now searching all pages in \"{parent.Name}\"",
-
- _ => $"Use \'{Keywords.ScopedSearch}\' to search this item. Use \'{Keywords.TitleSearch}\' to search by title in this item",
- };
-
- results.Add(result);
- }
-
- return results;
- }
-
- private List EmptySearch(IOneNoteItem parent, IEnumerable collection)
- {
- List results = collection.Where(searchManager.SettingsCheck)
- .Select(item => resultCreator.CreateOneNoteItemResult(item, true))
- .ToList();
- if (results.Any())
- return results;
- return resultCreator.NoItemsInCollection(results, parent);
- }
-
- private List ScopedSearch(string query, IOneNoteItem parent)
- {
- if (query.Length == Keywords.ScopedSearch.Length)
- {
- return ResultCreator.NoMatchesFound();
- }
-
- if (!char.IsLetterOrDigit(query[Keywords.ScopedSearch.Length]))
- {
- return resultCreator.InvalidQuery();
- }
-
- string currentSearch = query[Keywords.TitleSearch.Length..];
- var results = new List();
-
- results = OneNoteApplication.FindPages(currentSearch, parent)
- .Select(pg => resultCreator.CreatePageResult(pg, currentSearch))
- .ToList();
-
- if (!results.Any())
- {
- results = ResultCreator.NoMatchesFound();
- }
-
- return results;
- }
-#nullable enable
- private List Explorer(string search, IOneNoteItem? parent, IEnumerable collection)
- {
- List? highlightData = null;
- int score = 0;
-
- var results = collection.Where(searchManager.SettingsCheck)
- .Where(item => searchManager.FuzzySearch(item.Name, search, out highlightData, out score))
- .Select(item => resultCreator.CreateOneNoteItemResult(item, true, highlightData, score))
- .ToList();
-
- AddCreateNewOneNoteItemResults(search, parent, results);
- return results;
- }
-
- private void AddCreateNewOneNoteItemResults(string newItemName, IOneNoteItem? parent, List results)
- {
- if (!results.Any(result => string.Equals(newItemName.Trim(), result.Title, StringComparison.OrdinalIgnoreCase)))
- {
- if (parent?.IsInRecycleBin() == true)
- {
- return;
- }
-
- switch (parent)
- {
- case null:
- results.Add(resultCreator.CreateNewNotebookResult(newItemName));
- break;
- case OneNoteNotebook:
- case OneNoteSectionGroup:
- results.Add(resultCreator.CreateNewSectionResult(newItemName, parent));
- results.Add(resultCreator.CreateNewSectionGroupResult(newItemName, parent));
- break;
- case OneNoteSection section:
- if (!section.Locked)
- {
- results.Add(resultCreator.CreateNewPageResult(newItemName, section));
- }
-
- break;
- }
- }
- }
- }
}
}
From 78d3dacee73da9d401225be3e66f86258d0aef54 Mon Sep 17 00:00:00 2001
From: Odotocodot <48138990+Odotocodot@users.noreply.github.com>
Date: Sat, 4 Jan 2025 17:08:10 +0000
Subject: [PATCH 5/7] Update plugin.json
---
Flow.Launcher.Plugin.OneNote/plugin.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Flow.Launcher.Plugin.OneNote/plugin.json b/Flow.Launcher.Plugin.OneNote/plugin.json
index 91d4e37..6f657d0 100644
--- a/Flow.Launcher.Plugin.OneNote/plugin.json
+++ b/Flow.Launcher.Plugin.OneNote/plugin.json
@@ -4,7 +4,7 @@
"Name": "OneNote",
"Description": "Search and create your OneNote notes",
"Author": "Odotocodot",
- "Version": "2.1.0",
+ "Version": "2.1.1",
"Language": "csharp",
"Website": "https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote",
"IcoPath": "Images/logo.png",
From 3026183118f703702794aab59df709ec99c93fb0 Mon Sep 17 00:00:00 2001
From: Odotocodot <48138990+Odotocodot@users.noreply.github.com>
Date: Sat, 4 Jan 2025 17:18:55 +0000
Subject: [PATCH 6/7] Update Readme.md
---
Readme.md | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/Readme.md b/Readme.md
index eb8bc87..53d4ca2 100644
--- a/Readme.md
+++ b/Readme.md
@@ -8,7 +8,15 @@
OneNote for Flow Launcher
-A [OneNote](https://www.microsoft.com/en-gb/microsoft-365/onenote/digital-note-taking-app) plugin for the [Flow launcher](https://github.com/Flow-Launcher/Flow.Launcher), allowing for the ability to quickly access and create notes.
+
+
+[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
+![GitHub Release](https://img.shields.io/github/v/release/odotocodot/Flow.Launcher.Plugin.OneNote)
+![Downloads](https://img.shields.io/github/downloads/odotocodot/Flow.Launcher.Plugin.OneNote/total)
+
+
+
+A [OneNote](https://www.microsoft.com/en-gb/microsoft-365/onenote/digital-note-taking-app) plugin for [Flow Launcher](https://github.com/Flow-Launcher/Flow.Launcher), allowing for the ability to quickly access and create notes.
## Contents
@@ -26,6 +34,7 @@ A [OneNote](https://www.microsoft.com/en-gb/microsoft-365/onenote/digital-note-t
- [Settings](#settings)
- [Keywords](#keywords)
- [Changelog](#changelog)
+- [Additional Information](#additional-information)
- [Acknowledgements](#acknowledgements)
## Installation
@@ -37,12 +46,10 @@ pm install OneNote
```
> [!IMPORTANT]
-> For [version 2.0+](#changelog) requires at Flow Launcher version 1.16+. For earlier versions see [releases](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/releases).
-
-
-> [!IMPORTANT]
-> This plugin is local only! It requires an installation of OneNote on you system!
-
+>
+> - [Versions 2.0+](Changelog.md#200---2023-10-05) requires Flow Launcher version 1.16+. For earlier versions see [releases](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/releases).
+> - This plugin is local only! It requires an installation of OneNote on you system!
+> - Some features require Windows/Microsoft Search to be enabled on your system. See more info [here](#additional-information).
## Features
@@ -215,7 +222,13 @@ All the keywords used can be changed according to user preference.
See [here](Changelog.md) for the full list of changes.
+## Additional Information
+
+In order to use [default](#default-search) and [scoped](#scoped-search) Windows/Microsoft Search must be enabled on your system. This is due to the [API](https://learn.microsoft.com/en-us/office/client-developer/onenote/application-interface-onenote#findpages-method) that these features rely on, requiring Windows Search.
+This will only be an issue if you have explicit turned off Windows Search.
+Other features should work as intended.
+
## Acknowledgements
- Made with [Linq2OneNote](https://github.com/Odotocodot/Linq2OneNote) a library for exposing the OneNote API also made by me :smiley:
-- Inspired by the OneNote plugin for [PowerToys](https://github.com/microsoft/PowerToys/tree/main/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.OneNote)
\ No newline at end of file
+- Inspired by the OneNote plugin for [PowerToys](https://github.com/microsoft/PowerToys/tree/main/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.OneNote)
From b72050d23c1f061999dcbe6cba2a63594aad00fe Mon Sep 17 00:00:00 2001
From: Odotocodot <48138990+Odotocodot@users.noreply.github.com>
Date: Sat, 4 Jan 2025 17:19:01 +0000
Subject: [PATCH 7/7] Update Changelog.md
---
Changelog.md | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/Changelog.md b/Changelog.md
index 180487f..2031a04 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,5 +1,18 @@
# Changelog
+## 2.1.1 - 2025-1-4
+
+### Changes
+
+- Indicated Windows/Microsoft Search is required for default and scoped search in readme. ([#24](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/issues/24))
+- Added some badges.
+- Updated OneNote page result tooltips.
+- Changed recent pages default keyword from `rcntpgs:` to `rp:`.
+
+### Fixes
+
+- Fixed spelling and grammar mistakes.
+
## 2.1.0 - 2024-6-24
### Added