mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add SelectFile helper method & Improve code quality
This commit is contained in:
parent
647c55eaf7
commit
dd07baff59
4 changed files with 20 additions and 29 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
@ -904,5 +904,19 @@ namespace Flow.Launcher.Infrastructure
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||||
|
using Flow.Launcher.Infrastructure;
|
||||||
using Flow.Launcher.ViewModel;
|
using Flow.Launcher.ViewModel;
|
||||||
|
|
||||||
namespace Flow.Launcher
|
namespace Flow.Launcher
|
||||||
|
|
@ -31,7 +32,7 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
|
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var selectedFilePath = SelectFile();
|
var selectedFilePath = Win32Helper.SelectFile();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(selectedFilePath))
|
if (!string.IsNullOrEmpty(selectedFilePath))
|
||||||
{
|
{
|
||||||
|
|
@ -41,15 +42,5 @@ namespace Flow.Launcher
|
||||||
((Button)sender).Focus();
|
((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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||||
|
using Flow.Launcher.Infrastructure;
|
||||||
using Flow.Launcher.ViewModel;
|
using Flow.Launcher.ViewModel;
|
||||||
|
|
||||||
namespace Flow.Launcher
|
namespace Flow.Launcher
|
||||||
|
|
@ -32,13 +33,13 @@ namespace Flow.Launcher
|
||||||
|
|
||||||
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||||
{
|
{
|
||||||
_viewModel.OpenUrl(e.Uri.AbsoluteUri);
|
App.API.OpenUrl(e.Uri.AbsoluteUri);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
|
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var selectedFilePath = _viewModel.SelectFile();
|
var selectedFilePath = Win32Helper.SelectFile();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(selectedFilePath))
|
if (!string.IsNullOrEmpty(selectedFilePath))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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]
|
[RelayCommand]
|
||||||
private void Add()
|
private void Add()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue