Add SelectFile helper method & Improve code quality

This commit is contained in:
Jack251970 2025-09-18 11:58:38 +08:00
parent 647c55eaf7
commit dd07baff59
4 changed files with 20 additions and 29 deletions

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
@ -904,5 +904,19 @@ namespace Flow.Launcher.Infrastructure
}
#endregion
#region File / Folder Dialog
public static string SelectFile()
{
var dlg = new OpenFileDialog();
var result = dlg.ShowDialog();
if (result == true)
return dlg.FileName;
return string.Empty;
}
#endregion
}
}

View file

@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.ViewModel;
namespace Flow.Launcher
@ -31,7 +32,7 @@ namespace Flow.Launcher
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
{
var selectedFilePath = SelectFile();
var selectedFilePath = Win32Helper.SelectFile();
if (!string.IsNullOrEmpty(selectedFilePath))
{
@ -41,15 +42,5 @@ namespace Flow.Launcher
((Button)sender).Focus();
}
}
private static string SelectFile()
{
var dlg = new Microsoft.Win32.OpenFileDialog();
var result = dlg.ShowDialog();
if (result == true)
return dlg.FileName;
return string.Empty;
}
}
}

View file

@ -2,6 +2,7 @@
using System.Windows.Controls;
using System.Windows.Navigation;
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.ViewModel;
namespace Flow.Launcher
@ -32,13 +33,13 @@ namespace Flow.Launcher
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
_viewModel.OpenUrl(e.Uri.AbsoluteUri);
App.API.OpenUrl(e.Uri.AbsoluteUri);
e.Handled = true;
}
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
{
var selectedFilePath = _viewModel.SelectFile();
var selectedFilePath = Win32Helper.SelectFile();
if (!string.IsNullOrEmpty(selectedFilePath))
{

View file

@ -98,21 +98,6 @@ public partial class SelectFileManagerViewModel : BaseModel
}
}
internal void OpenUrl(string absoluteUri)
{
App.API.OpenUrl(absoluteUri);
}
internal string SelectFile()
{
var dlg = new Microsoft.Win32.OpenFileDialog();
var result = dlg.ShowDialog();
if (result == true)
return dlg.FileName;
return string.Empty;
}
[RelayCommand]
private void Add()
{