Skip to content

Commit 983c441

Browse files
committed
Add new shortcuts
Create a new item without opening it in OneNote Shortcut to the Create & Open button in new page preview panel Tweaks and reformats.
1 parent 4fd333e commit 983c441

File tree

4 files changed

+77
-54
lines changed

4 files changed

+77
-54
lines changed

Flow.Launcher.Plugin.OneNote/Main.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
6464
return searchManager.Query(query);
6565
}
6666

67-
public static void ForceReQuery()
68-
{
69-
instance.context.API.ChangeQuery(instance.currentQuery.RawQuery, true);
70-
}
67+
public static void ForceReQuery() => instance.context.API.ChangeQuery(instance.currentQuery.RawQuery, true);
7168

7269
public List<Result> LoadContextMenus(Result selectedResult)
7370
{

Flow.Launcher.Plugin.OneNote/ResultCreator.cs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ private string GetTitle(IOneNoteItem item, List<int> highlightData)
4747
highlightData[i] += BulletPoint.Length;
4848
}
4949
return title;
50-
5150
}
5251

5352
private string GetAutoCompleteText(IOneNoteItem item)
@@ -234,7 +233,6 @@ await Task.Run(() =>
234233
};
235234
}
236235

237-
238236
public Result CreatePageResult(OneNotePage page, string query)
239237
=> CreateOneNoteItemResult(page, false, string.IsNullOrWhiteSpace(query) ? null : context.API.FuzzySearch(query, page.Name).MatchData);
240238

@@ -256,12 +254,17 @@ public Result CreateNewPageResult(string newPageName, OneNoteSection section)
256254
AutoCompleteText = $"{GetAutoCompleteText(section)}{newPageName}",
257255
IcoPath = iconProvider.NewPage,
258256
PreviewPanel = GetNewPagePreviewPanel(section, newPageName),
259-
Action = _ =>
257+
Action = c =>
260258
{
261-
OneNoteApplication.CreatePage(section, newPageName, true);
259+
bool showOneNote = !c.SpecialKeyState.CtrlPressed;
260+
261+
OneNoteApplication.CreatePage(section, newPageName, showOneNote);
262262
Main.ForceReQuery();
263-
WindowHelper.FocusOneNote();
264-
return true;
263+
264+
if(showOneNote)
265+
WindowHelper.FocusOneNote();
266+
267+
return showOneNote;
265268
},
266269
};
267270
}
@@ -279,26 +282,30 @@ public Result CreateNewSectionResult(string newSectionName, IOneNoteItem parent)
279282
: $"Section names cannot contain: {string.Join(' ', OneNoteApplication.InvalidSectionChars)}",
280283
AutoCompleteText = $"{GetAutoCompleteText(parent)}{newSectionName}",
281284
IcoPath = iconProvider.NewSection,
282-
Action = _ =>
285+
Action = c =>
283286
{
284287
if (!validTitle)
285288
{
286289
return false;
287290
}
288291

292+
bool showOneNote = !c.SpecialKeyState.CtrlPressed;
293+
289294
switch (parent)
290295
{
291296
case OneNoteNotebook notebook:
292-
OneNoteApplication.CreateSection(notebook, newSectionName, true);
297+
OneNoteApplication.CreateSection(notebook, newSectionName, showOneNote);
293298
break;
294299
case OneNoteSectionGroup sectionGroup:
295-
OneNoteApplication.CreateSection(sectionGroup, newSectionName, true);
300+
OneNoteApplication.CreateSection(sectionGroup, newSectionName, showOneNote);
296301
break;
297302
}
298-
303+
299304
Main.ForceReQuery();
300-
WindowHelper.FocusOneNote();
301-
return true;
305+
if(showOneNote)
306+
WindowHelper.FocusOneNote();
307+
308+
return showOneNote;
302309
},
303310
};
304311
}
@@ -316,26 +323,30 @@ public Result CreateNewSectionGroupResult(string newSectionGroupName, IOneNoteIt
316323
: $"Section group names cannot contain: {string.Join(' ', OneNoteApplication.InvalidSectionGroupChars)}",
317324
AutoCompleteText = $"{GetAutoCompleteText(parent)}{newSectionGroupName}",
318325
IcoPath = iconProvider.NewSectionGroup,
319-
Action = _ =>
326+
Action = c =>
320327
{
321328
if (!validTitle)
322329
{
323330
return false;
324331
}
325332

333+
bool showOneNote = !c.SpecialKeyState.CtrlPressed;
334+
326335
switch (parent)
327336
{
328337
case OneNoteNotebook notebook:
329-
OneNoteApplication.CreateSectionGroup(notebook, newSectionGroupName, true);
338+
OneNoteApplication.CreateSectionGroup(notebook, newSectionGroupName, showOneNote);
330339
break;
331340
case OneNoteSectionGroup sectionGroup:
332-
OneNoteApplication.CreateSectionGroup(sectionGroup, newSectionGroupName, true);
341+
OneNoteApplication.CreateSectionGroup(sectionGroup, newSectionGroupName, showOneNote);
333342
break;
334343
}
335344

336345
Main.ForceReQuery();
337-
WindowHelper.FocusOneNote();
338-
return true;
346+
if(showOneNote)
347+
WindowHelper.FocusOneNote();
348+
349+
return showOneNote;
339350
},
340351
};
341352
}
@@ -353,17 +364,22 @@ public Result CreateNewNotebookResult(string newNotebookName)
353364
: $"Notebook names cannot contain: {string.Join(' ', OneNoteApplication.InvalidNotebookChars)}",
354365
AutoCompleteText = $"{ActionKeyword} {settings.Keywords.NotebookExplorer}{newNotebookName}",
355366
IcoPath = iconProvider.NewNotebook,
356-
Action = _ =>
367+
Action = c =>
357368
{
358369
if (!validTitle)
359370
{
360371
return false;
361372
}
362-
363-
OneNoteApplication.CreateNotebook(newNotebookName, true);
373+
374+
bool showOneNote = !c.SpecialKeyState.CtrlPressed;
375+
376+
OneNoteApplication.CreateNotebook(newNotebookName, showOneNote);
364377
Main.ForceReQuery();
365-
WindowHelper.FocusOneNote();
366-
return true;
378+
379+
if (showOneNote)
380+
WindowHelper.FocusOneNote();
381+
382+
return showOneNote;
367383
},
368384
};
369385
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
d:DataContext="{d:DesignInstance Type=vm:NewOneNotePageViewModel}"
1010
d:DesignHeight="300"
1111
d:DesignWidth="300"
12+
PreviewKeyDown="OnKeyDown"
13+
IsVisibleChanged="NewOneNotePagePreviewPanel_IsVisibleChanged"
1214
Loaded="NewOneNotePagePreviewPanel_OnLoaded"
1315
mc:Ignorable="d">
1416
<UserControl.Resources>
@@ -20,6 +22,7 @@
2022
</UserControl.Resources>
2123
<UserControl.InputBindings>
2224
<KeyBinding Command="{Binding CreateCommand}" Gesture="CTRL+S" />
25+
<KeyBinding Command="{Binding CreateAndOpenCommand}" Gesture="CTRL+O" />
2326
</UserControl.InputBindings>
2427
<DockPanel Margin="10,5,5,5" LastChildFill="True">
2528
<DockPanel>
@@ -38,7 +41,7 @@
3841
HorizontalAlignment="Right"
3942
Source="{Binding NewPageUri}" />-->
4043
</Grid>
41-
<Grid PreviewKeyDown="OnKeyDown">
44+
<Grid>
4245
<Grid.RowDefinitions>
4346
<RowDefinition Height="Auto" />
4447
<RowDefinition Height="5" />
@@ -73,17 +76,15 @@
7376
Command="{Binding CreateCommand}"
7477
Content="Create"
7578
Style="{DynamicResource SettingButton}"
76-
ToolTip="Creates a page in OneNote (CTRL+S)" />
79+
ToolTip="Creates a page in OneNote&#x0a;(CTRL+S)" />
7780
<Button
7881
x:Name="ButtonCreateAndOpen"
7982
Width="70"
8083
Margin="25,0,4,0"
8184
Command="{Binding CreateAndOpenCommand}"
8285
Style="{DynamicResource SettingButton}"
83-
ToolTip="Creates a page in OneNote and opens it">
84-
<TextBlock TextAlignment="Center">
85-
Create<LineBreak />
86-
&amp; Open</TextBlock>
86+
ToolTip="Creates a page in OneNote and opens it&#x0a;(CTRL+O)">
87+
<TextBlock Text="Create&#x0a;&amp; Open" TextAlignment="Center" />
8788
</Button>
8889
</WrapPanel>
8990
</Grid>

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,42 @@
44
using Flow.Launcher.Plugin.OneNote.UI.ViewModels;
55
using Odotocodot.OneNote.Linq;
66

7-
namespace Flow.Launcher.Plugin.OneNote.UI.Views;
8-
9-
public partial class NewOneNotePagePreviewPanel : UserControl
7+
namespace Flow.Launcher.Plugin.OneNote.UI.Views
108
{
11-
public NewOneNotePagePreviewPanel(PluginInitContext context, OneNoteSection section, string pageTitle)
12-
{
13-
DataContext = new NewOneNotePageViewModel(context, section, pageTitle);
14-
InitializeComponent();
15-
}
16-
private void NewOneNotePagePreviewPanel_OnLoaded(object sender, RoutedEventArgs e)
9+
public partial class NewOneNotePagePreviewPanel : UserControl
1710
{
18-
TextBoxPageTitle.Focus();
19-
}
11+
public NewOneNotePagePreviewPanel(PluginInitContext context, OneNoteSection section, string pageTitle)
12+
{
13+
DataContext = new NewOneNotePageViewModel(context, section, pageTitle);
14+
InitializeComponent();
15+
}
16+
private void NewOneNotePagePreviewPanel_OnLoaded(object sender, RoutedEventArgs e)
17+
{
18+
TextBoxPageTitle.Focus();
19+
}
20+
21+
private void NewOneNotePagePreviewPanel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
22+
{
23+
if((bool)e.NewValue)
24+
{
25+
TextBoxPageTitle.Focus();
26+
}
27+
}
2028

21-
private void OnKeyDown(object sender, KeyEventArgs e)
22-
{
23-
if (e.Key != Key.Tab)
24-
return;
29+
private void OnKeyDown(object sender, KeyEventArgs e)
30+
{
31+
if (e.Key != Key.Tab)
32+
return;
2533

26-
if (e.Source is not (TextBox or Button))
27-
return;
34+
if (e.Source is not (TextBox or Button))
35+
return;
2836

29-
var focusNavigationDirection = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)
30-
? FocusNavigationDirection.Previous
31-
: FocusNavigationDirection.Next;
32-
((UIElement)Keyboard.FocusedElement)?.MoveFocus(new TraversalRequest(focusNavigationDirection));
37+
var focusNavigationDirection = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)
38+
? FocusNavigationDirection.Previous
39+
: FocusNavigationDirection.Next;
40+
((UIElement)Keyboard.FocusedElement)?.MoveFocus(new TraversalRequest(focusNavigationDirection));
3341

34-
e.Handled = true;
42+
e.Handled = true;
43+
}
3544
}
3645
}

0 commit comments

Comments
 (0)