新增窗口置顶功能并优化sort.txt读取方式
新增窗口“置顶/取消置顶”按钮,支持动态切换窗口置顶状态,按钮文本随状态变化自动更新。优化 sort.txt 文件读取,改用 cmd type 命令读取并按行分割,提升编码兼容性,避免因编码问题导致读取异常。
This commit is contained in:
@@ -42,6 +42,10 @@
|
|||||||
Click="ApplyOrderButton_Click"
|
Click="ApplyOrderButton_Click"
|
||||||
Content="应用并保存"
|
Content="应用并保存"
|
||||||
IsEnabled="{Binding HasOriginalFile}" />
|
IsEnabled="{Binding HasOriginalFile}" />
|
||||||
|
<Button
|
||||||
|
Name="ToggleTopmostButton"
|
||||||
|
Click="ToggleTopmostButton_Click"
|
||||||
|
Content="{Binding TopmostButtonText}" />
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
|
|
||||||
<!-- 主内容区域 -->
|
<!-- 主内容区域 -->
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ namespace DrillTools
|
|||||||
var viewModel = new MainWindowViewModel();
|
var viewModel = new MainWindowViewModel();
|
||||||
DataContext = viewModel;
|
DataContext = viewModel;
|
||||||
InitializeDragDrop();
|
InitializeDragDrop();
|
||||||
|
|
||||||
|
// 设置默认置顶状态
|
||||||
|
this.Topmost = viewModel.IsTopmost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -141,6 +144,15 @@ namespace DrillTools
|
|||||||
ViewModel.MoveSelectedToolDown();
|
ViewModel.MoveSelectedToolDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 置顶按钮点击事件
|
||||||
|
/// </summary>
|
||||||
|
private void ToggleTopmostButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
ViewModel.ToggleTopmost();
|
||||||
|
this.Topmost = ViewModel.IsTopmost;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 刀具列表双击事件
|
/// 刀具列表双击事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace DrillTools
|
|||||||
private bool _canMoveUp;
|
private bool _canMoveUp;
|
||||||
private bool _canMoveDown;
|
private bool _canMoveDown;
|
||||||
private string _originalFilePath = string.Empty;
|
private string _originalFilePath = string.Empty;
|
||||||
|
private bool _isTopmost = true; // 默认置顶
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 刀具列表
|
/// 刀具列表
|
||||||
@@ -107,6 +108,27 @@ namespace DrillTools
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasOriginalFile => !string.IsNullOrEmpty(OriginalFilePath);
|
public bool HasOriginalFile => !string.IsNullOrEmpty(OriginalFilePath);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 窗口是否置顶
|
||||||
|
/// </summary>
|
||||||
|
public bool IsTopmost
|
||||||
|
{
|
||||||
|
get => _isTopmost;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (SetProperty(ref _isTopmost, value))
|
||||||
|
{
|
||||||
|
// 当IsTopmost改变时,通知TopmostButtonText属性也已更改
|
||||||
|
OnPropertyChanged(nameof(TopmostButtonText));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 置顶按钮显示文本
|
||||||
|
/// </summary>
|
||||||
|
public string TopmostButtonText => IsTopmost ? "取消置顶" : "窗口置顶";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从钻带内容加载刀具信息
|
/// 从钻带内容加载刀具信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1223,7 +1245,7 @@ M30";
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 使用ANSI编码读取文件
|
// 使用ANSI编码
|
||||||
Encoding ansiEncoding;
|
Encoding ansiEncoding;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1234,7 +1256,26 @@ M30";
|
|||||||
ansiEncoding = Encoding.Default; // 如果获取失败,使用系统默认编码
|
ansiEncoding = Encoding.Default; // 如果获取失败,使用系统默认编码
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] lines = File.ReadAllLines(sortFilePath, ansiEncoding);
|
// 使用 cmd 命令读取-sort.txt文件,参考钻带文件读取方法
|
||||||
|
var process = new Process
|
||||||
|
{
|
||||||
|
StartInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = "cmd.exe",
|
||||||
|
Arguments = $"/c type \"{sortFilePath}\"",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
StandardOutputEncoding = ansiEncoding
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
process.Start();
|
||||||
|
string fileContent = process.StandardOutput.ReadToEnd();
|
||||||
|
process.WaitForExit();
|
||||||
|
|
||||||
|
// 按行分割内容
|
||||||
|
string[] lines = fileContent.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
@@ -1293,5 +1334,13 @@ M30";
|
|||||||
tools.Add(tool);
|
tools.Add(tool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 切换窗口置顶状态
|
||||||
|
/// </summary>
|
||||||
|
public void ToggleTopmost()
|
||||||
|
{
|
||||||
|
IsTopmost = !IsTopmost;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user