Skip to content

Commit d541fa7

Browse files
committed
Added setting to allow users to always open items in a new OneNote window.
Also refactor `IconGeneratorInfo`. Closes #40
1 parent 442ffc9 commit d541fa7

7 files changed

Lines changed: 100 additions & 75 deletions

File tree

Changelog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 3.1.0
44

5-
- :star: **Recent pages** is dead, long live **sort by last modified** ([#32](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/issues/32))
5+
- :star: **Recent pages** is dead, long live **sort by last modified**. ([#32](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/issues/32))
66
- Using the **sort by last modified** keyword, as the name implies, allows you to sort results by last modified. But unlike **recent pages** you can now use it in multiple places, i.e. with **title search**, **scoped search** and **notebook explorer**. Note it must be placed after the aforementioned keywords.
77
- Examples:\
88
(`#` = **sort by last modified** keyword, `*` = **title search** keyword, `nb:\` = **notebook explorer** keyword, `>` = **scoped search** keyword)
@@ -11,7 +11,7 @@
1111
- ```on: nb:\PathToItem\#{your search query}```
1212
- ```on: nb:\PathToItem\>#{your search query}```
1313
- ```on: nb:\PathToItem\*#{your search query}```
14-
14+
- Added a setting to allow users to always open items in a new OneNote window. ([#40](https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote/issues/40))
1515

1616
## 3.0.1 - 2026-03-13
1717

Flow.Launcher.Plugin.OneNote/Icons/IconGeneratorInfo.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@
33

44
namespace Flow.Launcher.Plugin.OneNote.Icons
55
{
6-
public struct IconGeneratorInfo
6+
public readonly struct IconGeneratorInfo
77
{
88
public readonly string prefix = string.Empty;
99
public readonly Color? color;
10-
11-
public IconGeneratorInfo(IOneNoteItem item)
10+
11+
private IconGeneratorInfo(string prefix, Color? color = null)
12+
{
13+
this.prefix = prefix;
14+
this.color = color;
15+
}
16+
17+
public static IconGeneratorInfo Create(IOneNoteItem item)
1218
{
13-
switch (item)
19+
return item switch
1420
{
15-
case Notebook n:
16-
prefix = IconConstants.Notebook;
17-
color = n.Color;
18-
break;
19-
case SectionGroup sg:
20-
prefix = sg.IsRecycleBin ? IconConstants.RecycleBin : IconConstants.SectionGroup;
21-
break;
22-
case Section s:
23-
prefix = IconConstants.Section;
24-
color = s.Color;
25-
break;
26-
case Page:
27-
prefix = IconConstants.Page;
28-
break;
29-
}
21+
Notebook n => new (IconConstants.Notebook, n.Color),
22+
SectionGroup sg => new (sg.IsRecycleBin ? IconConstants.RecycleBin : IconConstants.SectionGroup),
23+
Section s => new (IconConstants.Section, s.Color),
24+
Page => new (IconConstants.Page),
25+
_ => new (),
26+
};
3027
}
3128
}
3229
}

Flow.Launcher.Plugin.OneNote/ResultCreator.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,12 @@
1111

1212
namespace Flow.Launcher.Plugin.OneNote
1313
{
14-
public class ResultCreator
14+
public class ResultCreator(PluginInitContext context, Settings settings, IconProvider iconProvider)
1515
{
16-
private readonly PluginInitContext context;
17-
private readonly Settings settings;
18-
private readonly IconProvider iconProvider;
19-
2016
private const string PathSeparator = " > ";
2117
private const string BulletPoint = "\u2022 ";
2218
private const string TrianglePoint = "\u2023 ";
2319
private string ActionKeyword => context.CurrentPluginMetadata.ActionKeyword;
24-
public ResultCreator(PluginInitContext context, Settings settings, IconProvider iconProvider)
25-
{
26-
this.settings = settings;
27-
this.iconProvider = iconProvider;
28-
this.context = context;
29-
}
3020

3121
private static string GetNicePath(IOneNoteItem item, string separator = PathSeparator) => item.GetRelativePath(false, separator);
3222

@@ -104,7 +94,7 @@ public List<Result> EmptyQuery()
10494
PreviewPanel = GetNewPagePreviewPanel(null, null),
10595
Action = _ =>
10696
{
107-
OneNoteApp.CreateQuickNote(OpenMode.ExistingOrNewWindow);
97+
OneNoteApp.CreateQuickNote(settings.AlwaysOpenInNewWindow ? OpenMode.NewWindow : OpenMode.ExistingOrNewWindow);
10898
WindowHelper.FocusOneNote();
10999
return true;
110100
},
@@ -142,7 +132,7 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
142132
var toolTip = string.Empty;
143133
var subTitle = GetNicePath(item);
144134
var autoCompleteText = GetAutoCompleteText(item);
145-
var iconInfo = new IconGeneratorInfo(item);
135+
var iconInfo = IconGeneratorInfo.Create(item);
146136

147137
switch (item)
148138
{
@@ -213,7 +203,7 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
213203
await Task.Run(() =>
214204
{
215205
item.Sync();
216-
item.Open();
206+
OneNoteApp.Open(item, settings.AlwaysOpenInNewWindow);
217207
});
218208
WindowHelper.FocusOneNote();
219209
return true;
@@ -233,7 +223,7 @@ public Result CreateRecentItemResult(IOneNoteItem item, bool actionIsAutoComplet
233223
return result;
234224
}
235225

236-
//When name can have invalid chars
226+
//When new name can have invalid chars
237227
private Result CreateNewItemResult<TNew, TParent>(string newName, TParent? parent, string iconPath, Func<TParent?, string, OpenMode, TNew> createFunc)
238228
where TNew : IOneNoteItem, INameInvalidCharacters
239229
where TParent : IOneNoteItem
@@ -261,7 +251,10 @@ private Result CreateNewItemResult<TNew, TParent>(string newName, TParent? paren
261251
return false;
262252

263253
bool showOneNote = !c.SpecialKeyState.CtrlPressed;
264-
createFunc(parent, newName, showOneNote ? OpenMode.ExistingOrNewWindow : OpenMode.None);
254+
bool newWindow = settings.AlwaysOpenInNewWindow;
255+
256+
OpenMode openMode = showOneNote ? newWindow ? OpenMode.NewWindow : OpenMode.ExistingOrNewWindow : OpenMode.None;
257+
createFunc(parent, newName, openMode);
265258

266259
context.API.ReQuery();
267260

@@ -291,18 +284,27 @@ public List<Result> ContextMenu(Result selectedResult)
291284
var results = new List<Result>();
292285
if (selectedResult.ContextData is IOneNoteItem item)
293286
{
294-
var result = CreateOneNoteItemResult(item, false);
295-
result.Title = $"Open and sync \"{item.Name}\"";
296-
result.SubTitle = string.Empty;
297-
result.Score = 30;
298-
result.AddSelectedCount = false;
299-
result.ContextData = null;
300-
results.Add(result);
287+
Result.IconDelegate icon = iconProvider.GetIcon(IconGeneratorInfo.Create(item));
288+
results.Add(new Result
289+
{
290+
Title = $"Open and sync \"{item.Name}\"",
291+
Icon = icon,
292+
Score = 30,
293+
AddSelectedCount = false,
294+
Action = _ =>
295+
{
296+
OneNoteApp.Open(item);
297+
OneNoteApp.SyncItem(item);
298+
WindowHelper.FocusOneNote();
299+
return true;
300+
}
301+
});
302+
301303

302304
results.Add(new Result
303305
{
304306
Title = $"Open \"{item.Name}\" in new OneNote window",
305-
Icon = result.Icon,
307+
Icon = icon,
306308
Score = 20,
307309
AddSelectedCount = false,
308310
Action = _ =>
@@ -381,7 +383,7 @@ Result EmptyCollectionResult(string title, string iconPath, string? subTitle = n
381383
}
382384

383385
private Lazy<System.Windows.Controls.UserControl> GetNewPagePreviewPanel(Section? section, string? pageTitle)
384-
=> new(() => new NewOneNotePagePreviewPanel(context, section, pageTitle));
386+
=> new(() => new NewOneNotePagePreviewPanel(context, settings, section, pageTitle));
385387

386388
public static List<Result> NoMatchesFound()
387389
{

Flow.Launcher.Plugin.OneNote/Settings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Settings : UI.Model
1010
private bool createColoredIcons = true;
1111
private int maxResults = 30;
1212
private bool useMaxResults = true;
13+
private bool alwaysOpenInNewWindow = false;
1314
private IconTheme iconTheme = IconTheme.Color;
1415
public Keywords Keywords { get; init; } = new Keywords();
1516

@@ -54,5 +55,11 @@ public IconTheme IconTheme
5455
get => iconTheme;
5556
set => SetProperty(ref iconTheme, value);
5657
}
58+
59+
public bool AlwaysOpenInNewWindow
60+
{
61+
get => alwaysOpenInNewWindow;
62+
set => alwaysOpenInNewWindow = value;
63+
}
5764
}
5865
}

Flow.Launcher.Plugin.OneNote/UI/ViewModels/NewOneNotePageViewModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ public class NewOneNotePageViewModel : Model
1212
private string pageContent = string.Empty;
1313
private readonly Section? section;
1414
private readonly PluginInitContext context;
15+
private readonly Settings settings;
1516

16-
public NewOneNotePageViewModel(PluginInitContext context, Section? section, string? pageTitle)
17+
public NewOneNotePageViewModel(PluginInitContext context, Settings settings, Section? section, string? pageTitle)
1718
{
1819
this.context = context;
20+
this.settings = settings;
1921
this.section = section;
2022
PageTitle = pageTitle;
2123
CreateCommand = new RelayCommand(() => CreatePage(false));
@@ -33,6 +35,7 @@ private void CreatePage(bool openImmediately)
3335
{
3436
page = OneNoteApp.CreatePage(section, PageTitle);
3537
}
38+
3639
var xmlWrap = $"""
3740
<one:Outline>
3841
<one:Position x="36.0" y="86.4000015258789" z="0"/>
@@ -52,7 +55,7 @@ private void CreatePage(bool openImmediately)
5255
context.API.ReQuery();
5356
if (openImmediately)
5457
{
55-
page.Open();
58+
OneNoteApp.Open(page, settings.AlwaysOpenInNewWindow);
5659
context.API.HideMainWindow();
5760
WindowHelper.FocusOneNote();
5861
}

Flow.Launcher.Plugin.OneNote/UI/Views/NewOneNotePagePreviewPanel.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace Flow.Launcher.Plugin.OneNote.UI.Views
88
{
99
public partial class NewOneNotePagePreviewPanel : UserControl
1010
{
11-
public NewOneNotePagePreviewPanel(PluginInitContext context, Section? section, string? pageTitle)
11+
public NewOneNotePagePreviewPanel(PluginInitContext context, Settings settings, Section? section, string? pageTitle)
1212
{
13-
DataContext = new NewOneNotePageViewModel(context, section, pageTitle);
13+
DataContext = new NewOneNotePageViewModel(context, settings, section, pageTitle);
1414
InitializeComponent();
1515
}
1616
private void NewOneNotePagePreviewPanel_OnLoaded(object sender, RoutedEventArgs e)

Flow.Launcher.Plugin.OneNote/UI/Views/SettingsView.xaml

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,47 @@
7676
</Border>
7777
<!--#endregion-->
7878

79+
<!--#region Always Open In New Window-->
80+
<Border Style="{DynamicResource SettingGroupBox}">
81+
<ItemsControl Style="{StaticResource SettingGrid}">
82+
<StackPanel Style="{StaticResource TextPanel}">
83+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="Always open items in a new OneNote window" />
84+
</StackPanel>
85+
<ui:ToggleSwitch
86+
Grid.Column="2"
87+
IsOn="{Binding Settings.AlwaysOpenInNewWindow}"
88+
Style="{DynamicResource SideToggleSwitch}" />
89+
<ui:FontIcon Glyph="&#xe8a7;" Style="{StaticResource Glyph}" />
90+
</ItemsControl>
91+
</Border>
92+
<!--#endregion-->
93+
94+
<!--#region Max Results-->
95+
<Border Style="{DynamicResource SettingGroupBox}">
96+
<ItemsControl Style="{StaticResource SettingGrid}">
97+
<StackPanel Style="{StaticResource TextPanel}">
98+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="Limit the of results" />
99+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="The max number of results to show when searching, can improve performance. Turn off to always show all results" />
100+
</StackPanel>
101+
<StackPanel Grid.Column="2" Orientation="Horizontal">
102+
<ui:NumberBox
103+
Width="140"
104+
MinWidth="140"
105+
Margin="0,4,22,4"
106+
VerticalAlignment="Center"
107+
IsEnabled="{Binding Settings.UseMaxResults}"
108+
Maximum="100000"
109+
Minimum="1"
110+
SmallChange="5"
111+
SpinButtonPlacementMode="Compact"
112+
Value="{Binding Settings.MaxResults}" />
113+
<ui:ToggleSwitch IsOn="{Binding Settings.UseMaxResults}" Style="{DynamicResource SideToggleSwitch}" />
114+
</StackPanel>
115+
<ui:FontIcon Glyph="&#xe8fd;" Style="{StaticResource Glyph}" />
116+
</ItemsControl>
117+
</Border>
118+
<!--#endregion-->
119+
79120
<!--#region Coloured icons-->
80121
<Border Style="{DynamicResource SettingGroupBox}">
81122
<ItemsControl Style="{StaticResource SettingGrid}">
@@ -155,31 +196,6 @@
155196
</ItemsControl>
156197
</Border>
157198
<!--#endregion-->
158-
159-
<!--#region Max Results-->
160-
<Border Style="{DynamicResource SettingGroupBox}">
161-
<ItemsControl Style="{StaticResource SettingGrid}">
162-
<StackPanel Style="{StaticResource TextPanel}">
163-
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="Limit the of results" />
164-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="The max number of results to show when searching, can improve performance. Turn off to always show all results" />
165-
</StackPanel>
166-
<StackPanel Grid.Column="2" Orientation="Horizontal">
167-
<ui:NumberBox
168-
Width="140"
169-
MinWidth="140"
170-
Margin="0,4,22,4"
171-
IsEnabled="{Binding Settings.UseMaxResults}"
172-
Maximum="100000"
173-
Minimum="1"
174-
SmallChange="5"
175-
SpinButtonPlacementMode="Compact"
176-
Value="{Binding Settings.MaxResults}" />
177-
<ui:ToggleSwitch IsOn="{Binding Settings.UseMaxResults}" Style="{DynamicResource SideToggleSwitch}" />
178-
</StackPanel>
179-
<ui:FontIcon Glyph="&#xe8fd;" Style="{StaticResource Glyph}" />
180-
</ItemsControl>
181-
</Border>
182-
<!--#endregion-->
183199

184200
<!--#region Keywords-->
185201
<Border CornerRadius="0,0,9,9" Style="{DynamicResource SettingGroupBox}">

0 commit comments

Comments
 (0)