|
1 |
| -using System; |
2 |
| -using System.IO; |
3 |
| -using System.Windows; |
4 |
| -using System.Windows.Input; |
5 |
| -using System.Windows.Interop; |
6 |
| -using System.Windows.Navigation; |
7 |
| -using Microsoft.Win32; |
| 1 | +using Flow.Launcher.Core.ExternalPlugins; |
8 | 2 | using Flow.Launcher.Core.Plugin;
|
9 | 3 | using Flow.Launcher.Core.Resource;
|
| 4 | +using Flow.Launcher.Helper; |
10 | 5 | using Flow.Launcher.Infrastructure;
|
11 | 6 | using Flow.Launcher.Infrastructure.UserSettings;
|
12 | 7 | using Flow.Launcher.Plugin;
|
13 | 8 | using Flow.Launcher.Plugin.SharedCommands;
|
14 | 9 | using Flow.Launcher.ViewModel;
|
15 |
| -using Flow.Launcher.Helper; |
16 |
| -using System.Windows.Controls; |
17 |
| -using Flow.Launcher.Core.ExternalPlugins; |
18 |
| -using System.Runtime.InteropServices; |
| 10 | +using Microsoft.Win32; |
| 11 | +using ModernWpf; |
| 12 | +using System; |
| 13 | +using System.IO; |
| 14 | +using System.Windows; |
| 15 | +using System.Windows.Forms; |
| 16 | +using System.Windows.Input; |
| 17 | +using System.Windows.Interop; |
| 18 | +using System.Windows.Navigation; |
| 19 | +using Button = System.Windows.Controls.Button; |
| 20 | +using Control = System.Windows.Controls.Control; |
| 21 | +using MessageBox = System.Windows.MessageBox; |
| 22 | +using TextBox = System.Windows.Controls.TextBox; |
19 | 23 | using ThemeManager = ModernWpf.ThemeManager;
|
20 |
| -using ApplicationTheme = ModernWpf.ApplicationTheme; |
21 | 24 |
|
22 | 25 | namespace Flow.Launcher
|
23 | 26 | {
|
@@ -62,39 +65,30 @@ private void OnAutoStartupUncheck(object sender, RoutedEventArgs e)
|
62 | 65 |
|
63 | 66 | public static void SetStartup()
|
64 | 67 | {
|
65 |
| - using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true)) |
66 |
| - { |
67 |
| - key?.SetValue(Infrastructure.Constant.FlowLauncher, Infrastructure.Constant.ExecutablePath); |
68 |
| - } |
| 68 | + using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true); |
| 69 | + key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath); |
69 | 70 | }
|
70 | 71 |
|
71 | 72 | private void RemoveStartup()
|
72 | 73 | {
|
73 |
| - using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true)) |
74 |
| - { |
75 |
| - key?.DeleteValue(Infrastructure.Constant.FlowLauncher, false); |
76 |
| - } |
| 74 | + using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true); |
| 75 | + key?.DeleteValue(Constant.FlowLauncher, false); |
77 | 76 | }
|
78 | 77 |
|
79 | 78 | public static bool StartupSet()
|
80 | 79 | {
|
81 |
| - using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true)) |
| 80 | + using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true); |
| 81 | + var path = key?.GetValue(Constant.FlowLauncher) as string; |
| 82 | + if (path != null) |
82 | 83 | {
|
83 |
| - var path = key?.GetValue(Infrastructure.Constant.FlowLauncher) as string; |
84 |
| - if (path != null) |
85 |
| - { |
86 |
| - return path == Infrastructure.Constant.ExecutablePath; |
87 |
| - } |
88 |
| - else |
89 |
| - { |
90 |
| - return false; |
91 |
| - } |
| 84 | + return path == Constant.ExecutablePath; |
92 | 85 | }
|
| 86 | + return false; |
93 | 87 | }
|
94 | 88 |
|
95 | 89 | private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e)
|
96 | 90 | {
|
97 |
| - var dlg = new System.Windows.Forms.FolderBrowserDialog |
| 91 | + var dlg = new FolderBrowserDialog |
98 | 92 | {
|
99 | 93 | SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
|
100 | 94 | };
|
@@ -223,7 +217,7 @@ private void OnPluginNameClick(object sender, MouseButtonEventArgs e)
|
223 | 217 | var uri = new Uri(website);
|
224 | 218 | if (Uri.CheckSchemeName(uri.Scheme))
|
225 | 219 | {
|
226 |
| - SearchWeb.NewTabInBrowser(website); |
| 220 | + website.NewTabInBrowser(); |
227 | 221 | }
|
228 | 222 | }
|
229 | 223 | }
|
@@ -257,7 +251,7 @@ private async void OnCheckUpdates(object sender, RoutedEventArgs e)
|
257 | 251 |
|
258 | 252 | private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
259 | 253 | {
|
260 |
| - SearchWeb.NewTabInBrowser(e.Uri.AbsoluteUri); |
| 254 | + e.Uri.AbsoluteUri.NewTabInBrowser(); |
261 | 255 | e.Handled = true;
|
262 | 256 | }
|
263 | 257 |
|
@@ -296,74 +290,63 @@ private void OnExternalPluginInstallClick(object sender, RoutedEventArgs e)
|
296 | 290 | if(sender is Button { DataContext: UserPlugin plugin })
|
297 | 291 | {
|
298 | 292 | var pluginsManagerPlugin = PluginManager.GetPluginForId("9f8f9b14-2518-4907-b211-35ab6290dee7");
|
299 |
| - var actionKeywrod = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0]; |
300 |
| - API.ChangeQuery($"{actionKeywrod} install {plugin.Name}"); |
| 293 | + var actionKeyword = pluginsManagerPlugin.Metadata.ActionKeywords.Count == 0 ? "" : pluginsManagerPlugin.Metadata.ActionKeywords[0]; |
| 294 | + API.ChangeQuery($"{actionKeyword} install {plugin.Name}"); |
301 | 295 | API.ShowMainWindow();
|
302 | 296 | }
|
303 | 297 | }
|
304 | 298 |
|
305 | 299 | private void window_MouseDown(object sender, MouseButtonEventArgs e) /* for close hotkey popup */
|
306 | 300 | {
|
307 |
| - TextBox textBox = Keyboard.FocusedElement as TextBox; |
308 |
| - if (textBox != null) |
| 301 | + if (Keyboard.FocusedElement is not TextBox textBox) |
309 | 302 | {
|
310 |
| - TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next); |
311 |
| - textBox.MoveFocus(tRequest); |
| 303 | + return; |
312 | 304 | }
|
| 305 | + var tRequest = new TraversalRequest(FocusNavigationDirection.Next); |
| 306 | + textBox.MoveFocus(tRequest); |
313 | 307 | }
|
314 | 308 |
|
315 |
| - private void DarkModeSelectedIndexChanged(object sender, EventArgs e) |
| 309 | + private void DarkModeSelectedIndexChanged(object sender, EventArgs e) => ThemeManager.Current.ApplicationTheme = settings.DarkMode switch |
316 | 310 | {
|
317 |
| - if (settings.DarkMode == "Light") |
318 |
| - { |
319 |
| - ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Light; |
320 |
| - } |
321 |
| - else if (settings.DarkMode == "Dark") |
322 |
| - { |
323 |
| - ModernWpf.ThemeManager.Current.ApplicationTheme = ModernWpf.ApplicationTheme.Dark; |
324 |
| - } |
325 |
| - } |
| 311 | + "Light" => ApplicationTheme.Light, |
| 312 | + "Dark" => ApplicationTheme.Dark, |
| 313 | + "System" => null, |
| 314 | + _ => ThemeManager.Current.ApplicationTheme |
| 315 | + }; |
326 | 316 |
|
327 | 317 | /* Custom TitleBar */
|
328 | 318 |
|
329 | 319 | private void OnMinimizeButtonClick(object sender, RoutedEventArgs e)
|
330 | 320 | {
|
331 |
| - this.WindowState = WindowState.Minimized; |
| 321 | + WindowState = WindowState.Minimized; |
332 | 322 | }
|
333 | 323 |
|
334 | 324 | private void OnMaximizeRestoreButtonClick(object sender, RoutedEventArgs e)
|
335 | 325 | {
|
336 |
| - if (this.WindowState == WindowState.Maximized) |
337 |
| - { |
338 |
| - this.WindowState = WindowState.Normal; |
339 |
| - } |
340 |
| - else |
341 |
| - { |
342 |
| - this.WindowState = WindowState.Maximized; |
343 |
| - } |
| 326 | + WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; |
344 | 327 | }
|
345 | 328 |
|
346 | 329 | private void OnCloseButtonClick(object sender, RoutedEventArgs e)
|
347 | 330 | {
|
348 |
| - this.Close(); |
| 331 | + Close(); |
349 | 332 | }
|
350 | 333 |
|
351 | 334 | private void RefreshMaximizeRestoreButton()
|
352 | 335 | {
|
353 |
| - if (this.WindowState == WindowState.Maximized) |
| 336 | + if (WindowState == WindowState.Maximized) |
354 | 337 | {
|
355 |
| - this.maximizeButton.Visibility = Visibility.Collapsed; |
356 |
| - this.restoreButton.Visibility = Visibility.Visible; |
| 338 | + maximizeButton.Visibility = Visibility.Collapsed; |
| 339 | + restoreButton.Visibility = Visibility.Visible; |
357 | 340 | }
|
358 | 341 | else
|
359 | 342 | {
|
360 |
| - this.maximizeButton.Visibility = Visibility.Visible; |
361 |
| - this.restoreButton.Visibility = Visibility.Collapsed; |
| 343 | + maximizeButton.Visibility = Visibility.Visible; |
| 344 | + restoreButton.Visibility = Visibility.Collapsed; |
362 | 345 | }
|
363 | 346 | }
|
364 | 347 | private void Window_StateChanged(object sender, EventArgs e)
|
365 | 348 | {
|
366 |
| - this.RefreshMaximizeRestoreButton(); |
| 349 | + RefreshMaximizeRestoreButton(); |
367 | 350 | }
|
368 | 351 |
|
369 | 352 | }
|
|
0 commit comments