move code to viewmodel

This commit is contained in:
Jeremy 2025-05-21 21:39:46 +10:00
parent e2d50cd80b
commit 41b9cd496b
3 changed files with 15 additions and 6 deletions

View file

@ -31,12 +31,12 @@ namespace Flow.Launcher
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
{
var dlg = new Microsoft.Win32.OpenFileDialog();
var result = dlg.ShowDialog();
if (result == true)
var selectedFilePath = _viewModel.SelectFile();
if (!string.IsNullOrEmpty(selectedFilePath))
{
var path = (TextBox)(((FrameworkElement)sender).Parent as FrameworkElement).FindName("PathTextBox");
path.Text = dlg.FileName;
path.Text = selectedFilePath;
path.Focus();
((Button)sender).Focus();
}

View file

@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
@ -40,6 +41,16 @@ public partial class SelectBrowserViewModel : BaseModel
return true;
}
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()
{

View file

@ -108,9 +108,7 @@ public partial class SelectFileManagerViewModel : BaseModel
var dlg = new Microsoft.Win32.OpenFileDialog();
var result = dlg.ShowDialog();
if (result == true)
{
return dlg.FileName;
}
return string.Empty;
}