Skip to content

Commit dd07baf

Browse files
committed
Add SelectFile helper method & Improve code quality
1 parent 647c55e commit dd07baf

File tree

4 files changed

+20
-29
lines changed

4 files changed

+20
-29
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Diagnostics;
@@ -904,5 +904,19 @@ public static void EnableWin32DarkMode(string colorScheme)
904904
}
905905

906906
#endregion
907+
908+
#region File / Folder Dialog
909+
910+
public static string SelectFile()
911+
{
912+
var dlg = new OpenFileDialog();
913+
var result = dlg.ShowDialog();
914+
if (result == true)
915+
return dlg.FileName;
916+
917+
return string.Empty;
918+
}
919+
920+
#endregion
907921
}
908922
}

Flow.Launcher/SelectBrowserWindow.xaml.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Windows;
22
using System.Windows.Controls;
33
using CommunityToolkit.Mvvm.DependencyInjection;
4+
using Flow.Launcher.Infrastructure;
45
using Flow.Launcher.ViewModel;
56

67
namespace Flow.Launcher
@@ -31,7 +32,7 @@ private void btnDone_Click(object sender, RoutedEventArgs e)
3132

3233
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
3334
{
34-
var selectedFilePath = SelectFile();
35+
var selectedFilePath = Win32Helper.SelectFile();
3536

3637
if (!string.IsNullOrEmpty(selectedFilePath))
3738
{
@@ -41,15 +42,5 @@ private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
4142
((Button)sender).Focus();
4243
}
4344
}
44-
45-
private static string SelectFile()
46-
{
47-
var dlg = new Microsoft.Win32.OpenFileDialog();
48-
var result = dlg.ShowDialog();
49-
if (result == true)
50-
return dlg.FileName;
51-
52-
return string.Empty;
53-
}
5445
}
5546
}

Flow.Launcher/SelectFileManagerWindow.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Windows.Controls;
33
using System.Windows.Navigation;
44
using CommunityToolkit.Mvvm.DependencyInjection;
5+
using Flow.Launcher.Infrastructure;
56
using Flow.Launcher.ViewModel;
67

78
namespace Flow.Launcher
@@ -32,13 +33,13 @@ private void btnDone_Click(object sender, RoutedEventArgs e)
3233

3334
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
3435
{
35-
_viewModel.OpenUrl(e.Uri.AbsoluteUri);
36+
App.API.OpenUrl(e.Uri.AbsoluteUri);
3637
e.Handled = true;
3738
}
3839

3940
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
4041
{
41-
var selectedFilePath = _viewModel.SelectFile();
42+
var selectedFilePath = Win32Helper.SelectFile();
4243

4344
if (!string.IsNullOrEmpty(selectedFilePath))
4445
{

Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,6 @@ private static bool IsFileManagerValid(string path)
9898
}
9999
}
100100

101-
internal void OpenUrl(string absoluteUri)
102-
{
103-
App.API.OpenUrl(absoluteUri);
104-
}
105-
106-
internal string SelectFile()
107-
{
108-
var dlg = new Microsoft.Win32.OpenFileDialog();
109-
var result = dlg.ShowDialog();
110-
if (result == true)
111-
return dlg.FileName;
112-
113-
return string.Empty;
114-
}
115-
116101
[RelayCommand]
117102
private void Add()
118103
{

0 commit comments

Comments
 (0)