67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
|
|
namespace DrillTools
|
|
{
|
|
/// <summary>
|
|
/// 参数文件选择窗口,列出指定目录下所有 .txt 文件供用户选择。
|
|
/// </summary>
|
|
public partial class ParameterFileSelectionWindow : Window
|
|
{
|
|
/// <summary>
|
|
/// 用户选中的文件完整路径;若取消则为 null。
|
|
/// </summary>
|
|
public string? SelectedFilePath { get; private set; }
|
|
|
|
public ParameterFileSelectionWindow(string paramDirectory)
|
|
{
|
|
InitializeComponent();
|
|
|
|
if (Directory.Exists(paramDirectory))
|
|
{
|
|
var files = Directory.GetFiles(paramDirectory, "*.txt")
|
|
.Select(f => new FileInfo(f))
|
|
.OrderBy(f => f.Name)
|
|
.ToList();
|
|
|
|
FileListBox.ItemsSource = files;
|
|
}
|
|
|
|
OkButton.IsEnabled = false;
|
|
FileListBox.SelectionChanged += (_, _) =>
|
|
{
|
|
OkButton.IsEnabled = FileListBox.SelectedItem != null;
|
|
};
|
|
|
|
// 双击直接确认
|
|
FileListBox.MouseDoubleClick += (_, _) =>
|
|
{
|
|
if (FileListBox.SelectedItem is FileInfo file)
|
|
{
|
|
SelectedFilePath = file.FullName;
|
|
DialogResult = true;
|
|
Close();
|
|
}
|
|
};
|
|
}
|
|
|
|
private void OkButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (FileListBox.SelectedItem is FileInfo file)
|
|
{
|
|
SelectedFilePath = file.FullName;
|
|
DialogResult = true;
|
|
Close();
|
|
}
|
|
}
|
|
|
|
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
DialogResult = false;
|
|
Close();
|
|
}
|
|
}
|
|
}
|