Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.0.0 #14

Merged
merged 142 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
00fb46d
Update .gitignore
Odotocodot Mar 20, 2023
c387fc9
Remove references to OneNotePlugin
Odotocodot Mar 20, 2023
b2d9a5a
Fix NotebookExplorer references
Odotocodot Mar 20, 2023
179ae87
Import custom onenote to linq lib
Odotocodot Mar 24, 2023
7ed80d2
Custom OneNote Linq provider
Odotocodot Apr 2, 2023
b4f5214
Removed unused references
Odotocodot Apr 2, 2023
8302925
Improve when instance is found and released
Odotocodot Apr 2, 2023
b2917d5
Refactor
Odotocodot Apr 3, 2023
0dff055
Cleanup leftover resources on search
Odotocodot Apr 3, 2023
773ebcd
Pass in oneNote by reference for results
Odotocodot Apr 4, 2023
47b6e05
Show unread items
Odotocodot Apr 5, 2023
4b16716
Added scoped search
Odotocodot Apr 7, 2023
d57f21f
Refactor
Odotocodot Apr 8, 2023
c72aad4
Added search by title
Odotocodot Apr 10, 2023
f458235
Added section group icon
Odotocodot Apr 10, 2023
11a2538
Remove release on open
Odotocodot Apr 10, 2023
4ddeef1
Fix search by title
Odotocodot Apr 14, 2023
82f8088
Tweak onenote objects
Odotocodot Apr 15, 2023
1de9ab8
Create new section group icon
Odotocodot Apr 15, 2023
4ad4cc7
Clean up
Odotocodot Apr 16, 2023
1cb5577
Added basic settings
Odotocodot Apr 16, 2023
004922f
Basic implementation of fast mode
Odotocodot Apr 18, 2023
b973919
Simplified the acquisition of the OneNote COM Object
Odotocodot Apr 19, 2023
4bd83a8
Refactor and clean up
Odotocodot Apr 19, 2023
14827d2
Convert settings to MVVM
Odotocodot Apr 19, 2023
87adb40
Refactor
Odotocodot Apr 19, 2023
5a73c53
Implementing settings
Odotocodot Apr 19, 2023
4b9d9e7
Added validation to notebook/section/section group names
Odotocodot Apr 19, 2023
f434334
Update settings view
Odotocodot Apr 19, 2023
638f260
More settings view updates
Odotocodot Apr 20, 2023
7b98cd2
Refactor and code clean up
Odotocodot Apr 24, 2023
3e2966c
Improve Settings View
Odotocodot Apr 25, 2023
931a538
Format and improve settings
Odotocodot Apr 29, 2023
c884fe6
Improve Settings View
Odotocodot Apr 30, 2023
20919ee
Finished Settings View
Odotocodot Apr 30, 2023
2e88701
Tweaks
Odotocodot May 3, 2023
5b223c3
Small tweaks
Odotocodot May 21, 2023
3756d34
Update project version, net target and packages
Odotocodot May 21, 2023
73da982
Ground work for recycle bin types
Odotocodot May 21, 2023
a7fd8b6
Add comments and recyclebin api
Odotocodot May 24, 2023
805a3fe
Update comments and recycle bin api
Odotocodot May 24, 2023
e9fab7b
Rename property
Odotocodot May 26, 2023
36ee695
Refactor, update comments and parse recycle bin xml
Odotocodot May 27, 2023
b32c471
Remove some magic strings
Odotocodot May 27, 2023
3b289b7
More refactoring and comment updates
Odotocodot May 28, 2023
7f97cb0
smol refactor
Odotocodot May 28, 2023
ddd9436
Fix spelling errors
Odotocodot Jun 5, 2023
c5099d2
Remove fast mode setting
Odotocodot Jun 6, 2023
6529653
Added last modified to IOneNoteItem
Odotocodot Jun 7, 2023
90e9a42
Removed magic strings
Odotocodot Jun 7, 2023
976239f
Complete rework of xml parser/deserializer
Odotocodot Jun 10, 2023
d8464ca
Remove comments
Odotocodot Jun 10, 2023
509d353
Update Odocotodot.OneNote.Linq readme
Odotocodot Jun 10, 2023
3086d23
Fix small error
Odotocodot Jun 10, 2023
3f3f26b
Update OneNoteProvider
Odotocodot Jun 12, 2023
56c6cea
Replace Application with IApplication
Odotocodot Jun 13, 2023
dd25a13
Rename OneNoteProvider to OneNoteApplication
Odotocodot Jun 13, 2023
e653e8b
Add more of the OneNote API to OneNoteParse
Odotocodot Jun 13, 2023
3d33148
Refactored creating new OneNote items code
Odotocodot Jun 13, 2023
52aaa10
Update notebook explorer
Odotocodot Jun 14, 2023
5bd8bb2
Improve creation new OneNote items
Odotocodot Jun 15, 2023
99ea4f7
Clean up and tweaks
Odotocodot Jun 15, 2023
19d86db
Update ResultCreator
Odotocodot Jun 16, 2023
809d7ae
Refactor Result Creator
Odotocodot Jun 16, 2023
06d7263
Update settings
Odotocodot Jun 16, 2023
030a9ac
Improve exception throwing
Odotocodot Jun 17, 2023
3a2d178
Fix scoped search
Odotocodot Jun 18, 2023
4ab9682
Refactor and implemented recycle bin and encrypted sections settings
Odotocodot Jun 18, 2023
81d73a6
Update Settings UI
Odotocodot Jun 18, 2023
eb72285
Update Settings UI
Odotocodot Jun 19, 2023
6f9004b
Yet another update to Settings UI
Odotocodot Jun 19, 2023
47b0597
Add clear cached images settings
Odotocodot Jun 20, 2023
584d1f2
Clean up cached icons settings
Odotocodot Jun 21, 2023
9c93001
Compress images
Odotocodot Jun 23, 2023
413e5a3
Make OneNote settings match flow launcher design
Odotocodot Jun 23, 2023
e538266
Add finishing touchs to settings ui
Odotocodot Jun 24, 2023
e122c16
Add recycle bin icon
Odotocodot Jun 24, 2023
4d39747
Refactor notebook and section icons
Odotocodot Jun 25, 2023
57fa770
Remove ability to create in readonly items
Odotocodot Jun 25, 2023
d396d22
Refactor icons
Odotocodot Jun 25, 2023
e67286a
Refactor NotebookExplorer => SearchManager
Odotocodot Jun 27, 2023
3ccdc80
Refactor remove enum and use pattern matching
Odotocodot Jun 28, 2023
d1ffc6f
Change acquisition of COM object
Odotocodot Jul 1, 2023
e038e65
Rename keyword SearchByTitle to TitleSearch
Odotocodot Jul 1, 2023
5c8d90e
Add ability to open notebook/section icons folder to settings
Odotocodot Jul 3, 2023
d740917
Refactor base model
Odotocodot Jul 5, 2023
3f2e509
Create ActionKeyword.cs
Odotocodot Jul 5, 2023
f525d0a
Refactor Keywords to allow mutability
Odotocodot Jul 6, 2023
b8c1af0
Update SettingsView.xaml
Odotocodot Jul 7, 2023
3b45e76
Add ChangeKeywordWindow
Odotocodot Jul 8, 2023
18ff42d
Merge pull request #11 from Odotocodot/feature/customisable-keywords
Odotocodot Jul 8, 2023
e56bd20
Fix settings not being displayed
Odotocodot Jul 13, 2023
4ec2ee7
Small tweaks
Odotocodot Jul 13, 2023
5f8b195
Comment unused code
Odotocodot Jul 14, 2023
d9a92c6
Convert OneNoteApplication to static class
Odotocodot Jul 16, 2023
d293612
Bump Flow.Launcher.Plugin version to 4.1.0
Odotocodot Jul 17, 2023
aa23dde
Refactor OneNoteApplication
Odotocodot Jul 18, 2023
50fcefd
Rename searchString -> search
Odotocodot Jul 18, 2023
09d4979
Force save settings on keyword change
Odotocodot Jul 18, 2023
4d21888
Small code tweaks
Odotocodot Jul 21, 2023
a5b4c48
Change date formatting
Odotocodot Jul 21, 2023
29d5650
Add GetPageContent to API
Odotocodot Jul 25, 2023
fbd1c92
Convert GetRelativePath to property RelativePath
Odotocodot Jul 25, 2023
81ec6ac
Merge pull request #10 from Odotocodot/feature/v2
Odotocodot Jul 25, 2023
25463b5
Fix relative path
Odotocodot Aug 9, 2023
ded0769
Fix ChangeKeywordViewModel
Odotocodot Aug 9, 2023
9be7a21
Intermittent changes
Odotocodot Aug 10, 2023
68a55f8
Fix Keywords not saving
Odotocodot Aug 11, 2023
4afea79
Clean up settings view
Odotocodot Aug 11, 2023
713a21c
Fix multiple content dialogs
Odotocodot Aug 14, 2023
8cfbb22
Change COM -> Com
Odotocodot Aug 27, 2023
022b8fe
Refactor UI code
Odotocodot Aug 31, 2023
66cf629
More UI Refactoring
Odotocodot Sep 2, 2023
537b837
Remove comments
Odotocodot Sep 5, 2023
4ff72cb
Make OneNote init async
Odotocodot Sep 6, 2023
5814aaa
Split projects
Odotocodot Sep 7, 2023
9417d1a
Refactor UI folder structure
Odotocodot Sep 7, 2023
e96f67a
Update Odotocodot.OneNote.Linq.csproj
Odotocodot Sep 8, 2023
bb8e5d5
Update IOneNoteItemExtensions.cs
Odotocodot Sep 8, 2023
d57681e
Move parsing XML from constructors static class
Odotocodot Sep 8, 2023
780d1f1
Update documentation
Odotocodot Sep 11, 2023
2725975
Fix mutable chars
Odotocodot Sep 12, 2023
384a5b2
Refactor XName generation
Odotocodot Sep 13, 2023
dcb3e8a
Simplify invalid chars
Odotocodot Sep 14, 2023
e0b2aa1
Update documentation
Odotocodot Sep 17, 2023
cd0a084
Update documentation
Odotocodot Sep 18, 2023
baf9d6a
Update documentation
Odotocodot Sep 19, 2023
6aff73c
Add experimental rename method
Odotocodot Sep 19, 2023
9a10260
Small tweaks
Odotocodot Sep 20, 2023
af2d5a6
Clean settings ui
Odotocodot Sep 20, 2023
3c5f39b
Fix casting error
Odotocodot Sep 20, 2023
e92c22c
Clean up searchmanager
Odotocodot Sep 23, 2023
487c161
Refactor Main.cs and OneNoteApplication.cs
Odotocodot Sep 23, 2023
d197023
Update Readme.md
Odotocodot Sep 27, 2023
2054bdf
Update Readme.md
Odotocodot Sep 27, 2023
c288d3f
Update Readme.md
Odotocodot Sep 28, 2023
837d606
Update doc and readme
Odotocodot Sep 30, 2023
18ef544
Remove local Odotocodot.OneNote.Linq
Odotocodot Oct 1, 2023
885b21b
Add Odotocodot.OneNote.Linq as submodule
Odotocodot Oct 1, 2023
37b246f
Remove unused media
Odotocodot Oct 5, 2023
ae35244
Update Readme.md
Odotocodot Oct 5, 2023
b059367
Update links in readme
Odotocodot Oct 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,5 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

#Flow launcher specific
release.ps1
appveyor.yml
#VSCode
.vscode/
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "Odotocodot.OneNote.Linq"]
path = Odotocodot.OneNote.Linq
url = https://github.com/Odotocodot/Odotocodot.OneNote.Linq
branch = flow-plugin
24 changes: 0 additions & 24 deletions Constants.cs

This file was deleted.

39 changes: 39 additions & 0 deletions Flow.Launcher.Plugin.OneNote.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33712.159
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.OneNote", "Flow.Launcher.Plugin.OneNote\Flow.Launcher.Plugin.OneNote.csproj", "{3801047C-BEF0-4774-91DB-B64EEE874BB2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{65CCED4F-8513-4345-A2A8-14970B836C5F}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
Readme.md = Readme.md
release.ps1 = release.ps1
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Odotocodot.OneNote.Linq", "Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq.csproj", "{AB2CEDD9-15DB-4EAF-A675-10928E83918D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Release|Any CPU.Build.0 = Release|Any CPU
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CD75E0C8-C471-42DD-803A-C428D4B7622A}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<AssemblyName>Flow.Launcher.Plugin.OneNote</AssemblyName>
<PackageId>Flow.Launcher.Plugin.OneNote</PackageId>
<Authors>Odotocodot</Authors>
<PackageProjectUrl>https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote</PackageProjectUrl>
<RepositoryUrl>https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote</RepositoryUrl>
<PackageTags>flow-launcher flow-plugin</PackageTags>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand All @@ -23,10 +25,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Flow.Launcher.Plugin" Version="2.1.1" />
<PackageReference Include="Interop.Microsoft.Office.Interop.OneNote" Version="1.1.0.2" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="ScipBe.Common.Office.OneNote" Version="3.0.1" />
<PackageReference Include="Flow.Launcher.Plugin" Version="4.1.0" />
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -35,5 +36,7 @@
</Content>
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq.csproj" />
</ItemGroup>
</Project>
123 changes: 123 additions & 0 deletions Flow.Launcher.Plugin.OneNote/Icons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using Odotocodot.OneNote.Linq;
using System;
using System.IO;

namespace Flow.Launcher.Plugin.OneNote
{
public class Icons : BaseModel
{
public const string Logo = "Images/logo.png";
public const string Sync = "Images/refresh.png";
public const string Warning = "Images/warning.png";
public const string Search = Logo;
public const string RecycleBin = "Images/recycle_bin.png";
public const string Recent = "Images/recent.png";
public const string RecentPage = "Images/recent_page.png";

public const string Page = Logo;
public const string Section = "Images/section.png";
public const string SectionGroup = "Images/section_group.png";
public const string Notebook = "Images/notebook.png";

public const string NewPage = "Images/new_page.png";
public const string NewSection = "Images/new_section.png";
public const string NewSectionGroup = "Images/new_section_group.png";
public const string NewNotebook = "Images/new_notebook.png";

private OneNoteItemIcons notebookIcons;
private OneNoteItemIcons sectionIcons;
private Settings settings;

public int CachedIconCount => notebookIcons.IconCount + sectionIcons.IconCount;
public string CachedIconsFileSize => GetBytesReadable(notebookIcons.IconsFileSize + sectionIcons.IconsFileSize);
public static string NotebookIconDirectory { get; private set; }
public static string SectionIconDirectory { get; private set; }


private static readonly Lazy<Icons> lazy = new();
public static Icons Instance => lazy.Value;

public static void Init(PluginInitContext context, Settings settings)
{
NotebookIconDirectory = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, "Images", "NotebookIcons");
SectionIconDirectory = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, "Images", "SectionIcons");

Instance.notebookIcons = new OneNoteItemIcons(NotebookIconDirectory, Path.Combine(context.CurrentPluginMetadata.PluginDirectory, Notebook));
Instance.sectionIcons = new OneNoteItemIcons(SectionIconDirectory, Path.Combine(context.CurrentPluginMetadata.PluginDirectory, Section));


Instance.notebookIcons.PropertyChanged += Instance.IconCountChanged;
Instance.sectionIcons.PropertyChanged += Instance.IconCountChanged;

Instance.settings = settings;
}

public static void Close()
{
Instance.notebookIcons.PropertyChanged -= Instance.IconCountChanged;
Instance.sectionIcons.PropertyChanged -= Instance.IconCountChanged;
}
private void IconCountChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
OnPropertyChanged(nameof(CachedIconCount));
OnPropertyChanged(nameof(CachedIconsFileSize));
}

public static string GetIcon(IOneNoteItem item)
{
return item switch
{
OneNoteNotebook notebook => Instance.settings.CreateColoredIcons && notebook.Color.HasValue
? Instance.notebookIcons.GetIcon(notebook.Color.Value)
: Notebook,
OneNoteSectionGroup sectionGroup => sectionGroup.IsRecycleBin
? RecycleBin
: SectionGroup,
OneNoteSection section => Instance.settings.CreateColoredIcons && section.Color.HasValue
? Instance.sectionIcons.GetIcon(section.Color.Value)
: Section,
OneNotePage => Page,
_ => Warning,
};
}

public void ClearCachedIcons()
{
notebookIcons.ClearCachedIcons();
sectionIcons.ClearCachedIcons();
}

// Returns the human-readable file size for an arbitrary, 64-bit file size
// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB"
private static string GetBytesReadable(long i)
{
// Get absolute value
long absolute_i = Math.Abs(i);
// Determine the suffix and readable value
string suffix;
double readable;
switch (absolute_i)
{
case >= 0x40000000: // Gigabyte
suffix = "GB";
readable = i >> 20;
break;
case >= 0x100000: // Megabyte
suffix = "MB";
readable = i >> 10;
break;
case >= 0x400:
suffix = "KB"; // Kilobyte
readable = i;
break;
default:
return i.ToString("0 B"); // Byte
}
// Divide by 1024 to get fractional value
readable /= 1024;
// Return formatted number with suffix
return readable.ToString("0.## ") + suffix;
}

}
}
Binary file added Flow.Launcher.Plugin.OneNote/Images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Flow.Launcher.Plugin.OneNote/Images/new_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Flow.Launcher.Plugin.OneNote/Images/notebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Flow.Launcher.Plugin.OneNote/Images/recent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Flow.Launcher.Plugin.OneNote/Images/refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Flow.Launcher.Plugin.OneNote/Images/section.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Flow.Launcher.Plugin.OneNote/Images/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Flow.Launcher.Plugin.OneNote/Keywords.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Flow.Launcher.Plugin.OneNote
{
public class Keywords
{
public const string NotebookExplorerSeparator = "\\";
public string NotebookExplorer { get; set; } = $"nb:{NotebookExplorerSeparator}";
public string RecentPages { get; set; } = "rcntpgs:";
public string TitleSearch { get; set; } = "*";
public string ScopedSearch { get; set; } = ">";
}
}
80 changes: 80 additions & 0 deletions Flow.Launcher.Plugin.OneNote/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Odotocodot.OneNote.Linq;
namespace Flow.Launcher.Plugin.OneNote
{
public class Main : IAsyncPlugin, IContextMenu, ISettingProvider, IDisposable
{
private PluginInitContext context;

private SearchManager searchManager;
private Settings settings;

private static SemaphoreSlim semaphore;
public Task InitAsync(PluginInitContext context)
{
this.context = context;
settings = context.API.LoadSettingJsonStorage<Settings>();
Icons.Init(context, settings);
searchManager = new SearchManager(context, settings, new ResultCreator(context, settings));
semaphore = new SemaphoreSlim(1,1);
context.API.VisibilityChanged += OnVisibilityChanged;
return Task.CompletedTask;
}

public void OnVisibilityChanged(object _, VisibilityChangedEventArgs e)
{
if (context.CurrentPluginMetadata.Disabled || !e.IsVisible)
{
OneNoteApplication.ReleaseComObject();
}
}

private static async Task OneNoteInitAsync(CancellationToken token = default)
{
if (semaphore.CurrentCount == 0 || OneNoteApplication.HasComObject)
return;

await semaphore.WaitAsync(token);
OneNoteApplication.Init();
semaphore.Release();
}
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
var init = OneNoteInitAsync(token);

if (string.IsNullOrEmpty(query.Search))
return searchManager.EmptyQuery();

await init;

return query.FirstSearch switch
{
string fs when fs.StartsWith(settings.Keywords.RecentPages) => searchManager.RecentPages(fs),
string fs when fs.StartsWith(settings.Keywords.NotebookExplorer) => searchManager.NotebookExplorer(query),
string fs when fs.StartsWith(settings.Keywords.TitleSearch) => searchManager.TitleSearch(string.Join(' ', query.SearchTerms), OneNoteApplication.GetNotebooks()),
_ => searchManager.DefaultSearch(query.Search)
};
}

public List<Result> LoadContextMenus(Result selectedResult)
{
return searchManager.ContextMenu(selectedResult);
}

public System.Windows.Controls.Control CreateSettingPanel()
{
return new UI.Views.SettingsView(new UI.ViewModels.SettingsViewModel(context, settings));
}

public void Dispose()
{
context.API.VisibilityChanged -= OnVisibilityChanged;
semaphore.Dispose();
Icons.Close();
OneNoteApplication.ReleaseComObject();
}
}
}
Loading
Loading