-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Odotocodot/dev
Version 2.0.0
- Loading branch information
Showing
70 changed files
with
2,227 additions
and
937 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} |
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } = ">"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.