Skip to content

Commit dc170ca

Browse files
committed
Add ForceReQuery method to Main.cs
Also, an assortment of tweaks
1 parent 8892d5c commit dc170ca

File tree

7 files changed

+32
-21
lines changed

7 files changed

+32
-21
lines changed

Flow.Launcher.Plugin.OneNote/Main.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class Main : IAsyncPlugin, IContextMenu, ISettingProvider, IDisposable
1818
private IconProvider iconProvider;
1919

2020
private static SemaphoreSlim semaphore;
21+
private static Main instance;
22+
23+
private Query currentQuery;
2124
public Task InitAsync(PluginInitContext context)
2225
{
2326
this.context = context;
@@ -27,6 +30,7 @@ public Task InitAsync(PluginInitContext context)
2730
searchManager = new SearchManager(context, settings, resultCreator);
2831
semaphore = new SemaphoreSlim(1,1);
2932
context.API.VisibilityChanged += OnVisibilityChanged;
33+
instance = this;
3034
return Task.CompletedTask;
3135
}
3236

@@ -49,6 +53,7 @@ private static async Task OneNoteInitAsync(CancellationToken token = default)
4953
}
5054
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
5155
{
56+
currentQuery = query;
5257
var init = OneNoteInitAsync(token);
5358

5459
if (string.IsNullOrEmpty(query.Search))
@@ -59,6 +64,11 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
5964
return searchManager.Query(query);
6065
}
6166

67+
public static void ForceReQuery()
68+
{
69+
instance.context.API.ChangeQuery(instance.currentQuery.RawQuery, true);
70+
}
71+
6272
public List<Result> LoadContextMenus(Result selectedResult)
6373
{
6474
return resultCreator.ContextMenu(selectedResult);

Flow.Launcher.Plugin.OneNote/ResultCreator.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,8 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
208208
}
209209

210210

211-
public Result CreatePageResult(OneNotePage page, string query)
212-
{
213-
return CreateOneNoteItemResult(page, false, string.IsNullOrWhiteSpace(query) ? null : context.API.FuzzySearch(query, page.Name).MatchData);
214-
}
211+
public Result CreatePageResult(OneNotePage page, string query)
212+
=> CreateOneNoteItemResult(page, false, string.IsNullOrWhiteSpace(query) ? null : context.API.FuzzySearch(query, page.Name).MatchData);
215213

216214
public Result CreateRecentPageResult(OneNotePage page)
217215
{
@@ -233,6 +231,7 @@ public Result CreateNewPageResult(string newPageName, OneNoteSection section)
233231
Action = c =>
234232
{
235233
OneNoteApplication.CreatePage(section, newPageName, true);
234+
Main.ForceReQuery();
236235
return true;
237236
},
238237
};
@@ -268,7 +267,7 @@ public Result CreateNewSectionResult(string newSectionName, IOneNoteItem parent)
268267
break;
269268
}
270269

271-
context.API.ChangeQuery(ActionKeyword, true);
270+
Main.ForceReQuery();
272271
return true;
273272
},
274273
};
@@ -304,7 +303,7 @@ public Result CreateNewSectionGroupResult(string newSectionGroupName, IOneNoteIt
304303
break;
305304
}
306305

307-
context.API.ChangeQuery(ActionKeyword, true);
306+
Main.ForceReQuery();
308307
return true;
309308
},
310309
};
@@ -331,7 +330,7 @@ public Result CreateNewNotebookResult(string newNotebookName)
331330
}
332331

333332
OneNoteApplication.CreateNotebook(newNotebookName, true);
334-
context.API.ChangeQuery(ActionKeyword, true);
333+
Main.ForceReQuery();
335334
return true;
336335
},
337336
};
@@ -368,6 +367,7 @@ public List<Result> ContextMenu(Result selectedResult)
368367
}
369368
public List<Result> NoItemsInCollection(List<Result> results, IOneNoteItem parent)
370369
{
370+
// parent can be null if the collection only contains notebooks.
371371
switch (parent)
372372
{
373373
case OneNoteNotebook:

Flow.Launcher.Plugin.OneNote/SearchManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ private List<Result> EmptySearch(IOneNoteItem parent, IEnumerable<IOneNoteItem>
189189
.ToList();
190190
if (results.Any())
191191
return results;
192-
// parent can be null if the collection only contains notebooks.
193192
return resultCreator.NoItemsInCollection(results, parent);
194193
}
195194

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public SettingsViewModel(PluginInitContext context, Settings settings, IconProvi
3838
CommandManager.InvalidateRequerySuggested();
3939
}
4040
};
41+
settings.PropertyChanged += (_, args) =>
42+
{
43+
if (args.PropertyName == nameof(Settings.IconTheme))
44+
{
45+
Main.ForceReQuery();
46+
}
47+
};
4148
SelectedKeyword = Keywords[0];
4249
}
4350
public ICommand EditCommand { get; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
d:DataContext="{d:DesignInstance Type=vm:ChangeKeywordViewModel}"
1111
Background="{DynamicResource PopuBGColor}"
1212
Foreground="{DynamicResource PopupTextColor}"
13-
Loaded="WindowLoaded"
13+
FocusManager.FocusedElement="{Binding ElementName=TextBox_NewKeyword}"
1414
ResizeMode="NoResize"
1515
SizeToContent="Height"
1616
WindowStartupLocation="CenterScreen"

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,5 @@ public ChangeKeywordWindow(SettingsViewModel viewModel, PluginInitContext contex
1010
InitializeComponent();
1111
DataContext = new ChangeKeywordViewModel(viewModel, context, Close);
1212
}
13-
14-
private void WindowLoaded(object sender, RoutedEventArgs e)
15-
{
16-
TextBox_NewKeyword.Focus();
17-
}
1813
}
1914
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,18 @@
126126
<Grid x:Name="GridImages">
127127
<Image
128128
Width="32"
129-
UseLayoutRounding="True"
130-
SnapsToDevicePixels="True"
131129
Height="32"
132-
Source="{Binding ImageUri}" />
130+
SnapsToDevicePixels="True"
131+
Source="{Binding ImageUri}"
132+
UseLayoutRounding="True" />
133133
<Image
134134
Width="32"
135-
UseLayoutRounding="True"
136-
SnapsToDevicePixels="True"
137135
Height="32"
138-
Source="{Binding ImageUri2}">
136+
SnapsToDevicePixels="True"
137+
Source="{Binding ImageUri2}"
138+
UseLayoutRounding="True">
139139
<Image.Clip>
140-
<RectangleGeometry Rect="14,0,18,32"></RectangleGeometry>
140+
<RectangleGeometry Rect="14,0,18,32" />
141141
</Image.Clip>
142142
</Image>
143143
</Grid>

0 commit comments

Comments
 (0)