Skip to content

Commit 273e49f

Browse files
authored
Merge pull request #14 from Odotocodot/dev
Version 2.0.0
2 parents af29dad + b059367 commit 273e49f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2227
-937
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,5 @@ MigrationBackup/
351351
# Ionide (cross platform F# VS Code tools) working folder
352352
.ionide/
353353

354-
#Flow launcher specific
355-
release.ps1
356-
appveyor.yml
354+
#VSCode
355+
.vscode/

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "Odotocodot.OneNote.Linq"]
2+
path = Odotocodot.OneNote.Linq
3+
url = https://github.com/Odotocodot/Odotocodot.OneNote.Linq
4+
branch = flow-plugin

Constants.cs

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

Flow.Launcher.Plugin.OneNote.sln

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33712.159
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.OneNote", "Flow.Launcher.Plugin.OneNote\Flow.Launcher.Plugin.OneNote.csproj", "{3801047C-BEF0-4774-91DB-B64EEE874BB2}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{65CCED4F-8513-4345-A2A8-14970B836C5F}"
9+
ProjectSection(SolutionItems) = preProject
10+
.gitignore = .gitignore
11+
LICENSE = LICENSE
12+
Readme.md = Readme.md
13+
release.ps1 = release.ps1
14+
EndProjectSection
15+
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Odotocodot.OneNote.Linq", "Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq.csproj", "{AB2CEDD9-15DB-4EAF-A675-10928E83918D}"
17+
EndProject
18+
Global
19+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
20+
Debug|Any CPU = Debug|Any CPU
21+
Release|Any CPU = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24+
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{3801047C-BEF0-4774-91DB-B64EEE874BB2}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{AB2CEDD9-15DB-4EAF-A675-10928E83918D}.Release|Any CPU.Build.0 = Release|Any CPU
32+
EndGlobalSection
33+
GlobalSection(SolutionProperties) = preSolution
34+
HideSolutionNode = FALSE
35+
EndGlobalSection
36+
GlobalSection(ExtensibilityGlobals) = postSolution
37+
SolutionGuid = {CD75E0C8-C471-42DD-803A-C428D4B7622A}
38+
EndGlobalSection
39+
EndGlobal

Flow.Launcher.Plugin.OneNote.csproj renamed to Flow.Launcher.Plugin.OneNote/Flow.Launcher.Plugin.OneNote.csproj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0-windows</TargetFramework>
4+
<TargetFramework>net7.0-windows</TargetFramework>
55
<AssemblyName>Flow.Launcher.Plugin.OneNote</AssemblyName>
66
<PackageId>Flow.Launcher.Plugin.OneNote</PackageId>
77
<Authors>Odotocodot</Authors>
88
<PackageProjectUrl>https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote</PackageProjectUrl>
99
<RepositoryUrl>https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote</RepositoryUrl>
1010
<PackageTags>flow-launcher flow-plugin</PackageTags>
1111
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
12+
<UseWPF>true</UseWPF>
13+
<UseWindowsForms>true</UseWindowsForms>
1214
</PropertyGroup>
1315

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

2527
<ItemGroup>
26-
<PackageReference Include="Flow.Launcher.Plugin" Version="2.1.1" />
27-
<PackageReference Include="Interop.Microsoft.Office.Interop.OneNote" Version="1.1.0.2" />
28-
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
29-
<PackageReference Include="ScipBe.Common.Office.OneNote" Version="3.0.1" />
28+
<PackageReference Include="Flow.Launcher.Plugin" Version="4.1.0" />
29+
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
30+
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
3031
</ItemGroup>
3132

3233
<ItemGroup>
@@ -35,5 +36,7 @@
3536
</Content>
3637
</ItemGroup>
3738

38-
39+
<ItemGroup>
40+
<ProjectReference Include="..\Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq\Odotocodot.OneNote.Linq.csproj" />
41+
</ItemGroup>
3942
</Project>

Flow.Launcher.Plugin.OneNote/Icons.cs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using Odotocodot.OneNote.Linq;
2+
using System;
3+
using System.IO;
4+
5+
namespace Flow.Launcher.Plugin.OneNote
6+
{
7+
public class Icons : BaseModel
8+
{
9+
public const string Logo = "Images/logo.png";
10+
public const string Sync = "Images/refresh.png";
11+
public const string Warning = "Images/warning.png";
12+
public const string Search = Logo;
13+
public const string RecycleBin = "Images/recycle_bin.png";
14+
public const string Recent = "Images/recent.png";
15+
public const string RecentPage = "Images/recent_page.png";
16+
17+
public const string Page = Logo;
18+
public const string Section = "Images/section.png";
19+
public const string SectionGroup = "Images/section_group.png";
20+
public const string Notebook = "Images/notebook.png";
21+
22+
public const string NewPage = "Images/new_page.png";
23+
public const string NewSection = "Images/new_section.png";
24+
public const string NewSectionGroup = "Images/new_section_group.png";
25+
public const string NewNotebook = "Images/new_notebook.png";
26+
27+
private OneNoteItemIcons notebookIcons;
28+
private OneNoteItemIcons sectionIcons;
29+
private Settings settings;
30+
31+
public int CachedIconCount => notebookIcons.IconCount + sectionIcons.IconCount;
32+
public string CachedIconsFileSize => GetBytesReadable(notebookIcons.IconsFileSize + sectionIcons.IconsFileSize);
33+
public static string NotebookIconDirectory { get; private set; }
34+
public static string SectionIconDirectory { get; private set; }
35+
36+
37+
private static readonly Lazy<Icons> lazy = new();
38+
public static Icons Instance => lazy.Value;
39+
40+
public static void Init(PluginInitContext context, Settings settings)
41+
{
42+
NotebookIconDirectory = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, "Images", "NotebookIcons");
43+
SectionIconDirectory = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, "Images", "SectionIcons");
44+
45+
Instance.notebookIcons = new OneNoteItemIcons(NotebookIconDirectory, Path.Combine(context.CurrentPluginMetadata.PluginDirectory, Notebook));
46+
Instance.sectionIcons = new OneNoteItemIcons(SectionIconDirectory, Path.Combine(context.CurrentPluginMetadata.PluginDirectory, Section));
47+
48+
49+
Instance.notebookIcons.PropertyChanged += Instance.IconCountChanged;
50+
Instance.sectionIcons.PropertyChanged += Instance.IconCountChanged;
51+
52+
Instance.settings = settings;
53+
}
54+
55+
public static void Close()
56+
{
57+
Instance.notebookIcons.PropertyChanged -= Instance.IconCountChanged;
58+
Instance.sectionIcons.PropertyChanged -= Instance.IconCountChanged;
59+
}
60+
private void IconCountChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
61+
{
62+
OnPropertyChanged(nameof(CachedIconCount));
63+
OnPropertyChanged(nameof(CachedIconsFileSize));
64+
}
65+
66+
public static string GetIcon(IOneNoteItem item)
67+
{
68+
return item switch
69+
{
70+
OneNoteNotebook notebook => Instance.settings.CreateColoredIcons && notebook.Color.HasValue
71+
? Instance.notebookIcons.GetIcon(notebook.Color.Value)
72+
: Notebook,
73+
OneNoteSectionGroup sectionGroup => sectionGroup.IsRecycleBin
74+
? RecycleBin
75+
: SectionGroup,
76+
OneNoteSection section => Instance.settings.CreateColoredIcons && section.Color.HasValue
77+
? Instance.sectionIcons.GetIcon(section.Color.Value)
78+
: Section,
79+
OneNotePage => Page,
80+
_ => Warning,
81+
};
82+
}
83+
84+
public void ClearCachedIcons()
85+
{
86+
notebookIcons.ClearCachedIcons();
87+
sectionIcons.ClearCachedIcons();
88+
}
89+
90+
// Returns the human-readable file size for an arbitrary, 64-bit file size
91+
// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB"
92+
private static string GetBytesReadable(long i)
93+
{
94+
// Get absolute value
95+
long absolute_i = Math.Abs(i);
96+
// Determine the suffix and readable value
97+
string suffix;
98+
double readable;
99+
switch (absolute_i)
100+
{
101+
case >= 0x40000000: // Gigabyte
102+
suffix = "GB";
103+
readable = i >> 20;
104+
break;
105+
case >= 0x100000: // Megabyte
106+
suffix = "MB";
107+
readable = i >> 10;
108+
break;
109+
case >= 0x400:
110+
suffix = "KB"; // Kilobyte
111+
readable = i;
112+
break;
113+
default:
114+
return i.ToString("0 B"); // Byte
115+
}
116+
// Divide by 1024 to get fractional value
117+
readable /= 1024;
118+
// Return formatted number with suffix
119+
return readable.ToString("0.## ") + suffix;
120+
}
121+
122+
}
123+
}
3.82 KB
Loading
Loading
6.21 KB
Loading
Loading
Loading
298 Bytes
Loading
3.06 KB
Loading
Loading
Loading
3.09 KB
Loading
274 Bytes
Loading
Loading
1.82 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Flow.Launcher.Plugin.OneNote
2+
{
3+
public class Keywords
4+
{
5+
public const string NotebookExplorerSeparator = "\\";
6+
public string NotebookExplorer { get; set; } = $"nb:{NotebookExplorerSeparator}";
7+
public string RecentPages { get; set; } = "rcntpgs:";
8+
public string TitleSearch { get; set; } = "*";
9+
public string ScopedSearch { get; set; } = ">";
10+
}
11+
}

Flow.Launcher.Plugin.OneNote/Main.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using Odotocodot.OneNote.Linq;
6+
namespace Flow.Launcher.Plugin.OneNote
7+
{
8+
public class Main : IAsyncPlugin, IContextMenu, ISettingProvider, IDisposable
9+
{
10+
private PluginInitContext context;
11+
12+
private SearchManager searchManager;
13+
private Settings settings;
14+
15+
private static SemaphoreSlim semaphore;
16+
public Task InitAsync(PluginInitContext context)
17+
{
18+
this.context = context;
19+
settings = context.API.LoadSettingJsonStorage<Settings>();
20+
Icons.Init(context, settings);
21+
searchManager = new SearchManager(context, settings, new ResultCreator(context, settings));
22+
semaphore = new SemaphoreSlim(1,1);
23+
context.API.VisibilityChanged += OnVisibilityChanged;
24+
return Task.CompletedTask;
25+
}
26+
27+
public void OnVisibilityChanged(object _, VisibilityChangedEventArgs e)
28+
{
29+
if (context.CurrentPluginMetadata.Disabled || !e.IsVisible)
30+
{
31+
OneNoteApplication.ReleaseComObject();
32+
}
33+
}
34+
35+
private static async Task OneNoteInitAsync(CancellationToken token = default)
36+
{
37+
if (semaphore.CurrentCount == 0 || OneNoteApplication.HasComObject)
38+
return;
39+
40+
await semaphore.WaitAsync(token);
41+
OneNoteApplication.Init();
42+
semaphore.Release();
43+
}
44+
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
45+
{
46+
var init = OneNoteInitAsync(token);
47+
48+
if (string.IsNullOrEmpty(query.Search))
49+
return searchManager.EmptyQuery();
50+
51+
await init;
52+
53+
return query.FirstSearch switch
54+
{
55+
string fs when fs.StartsWith(settings.Keywords.RecentPages) => searchManager.RecentPages(fs),
56+
string fs when fs.StartsWith(settings.Keywords.NotebookExplorer) => searchManager.NotebookExplorer(query),
57+
string fs when fs.StartsWith(settings.Keywords.TitleSearch) => searchManager.TitleSearch(string.Join(' ', query.SearchTerms), OneNoteApplication.GetNotebooks()),
58+
_ => searchManager.DefaultSearch(query.Search)
59+
};
60+
}
61+
62+
public List<Result> LoadContextMenus(Result selectedResult)
63+
{
64+
return searchManager.ContextMenu(selectedResult);
65+
}
66+
67+
public System.Windows.Controls.Control CreateSettingPanel()
68+
{
69+
return new UI.Views.SettingsView(new UI.ViewModels.SettingsViewModel(context, settings));
70+
}
71+
72+
public void Dispose()
73+
{
74+
context.API.VisibilityChanged -= OnVisibilityChanged;
75+
semaphore.Dispose();
76+
Icons.Close();
77+
OneNoteApplication.ReleaseComObject();
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)