Skip to content

Commit

Permalink
Merge pull request #14 from Odotocodot/dev
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
Odotocodot committed Oct 7, 2023
2 parents af29dad + b059367 commit 273e49f
Show file tree
Hide file tree
Showing 70 changed files with 2,227 additions and 937 deletions.
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

0 comments on commit 273e49f

Please sign in to comment.