新增窗口置顶功能并优化sort.txt读取方式
新增窗口“置顶/取消置顶”按钮,支持动态切换窗口置顶状态,按钮文本随状态变化自动更新。优化 sort.txt 文件读取,改用 cmd type 命令读取并按行分割,提升编码兼容性,避免因编码问题导致读取异常。
This commit is contained in:
@@ -25,6 +25,7 @@ namespace DrillTools
|
||||
private bool _canMoveUp;
|
||||
private bool _canMoveDown;
|
||||
private string _originalFilePath = string.Empty;
|
||||
private bool _isTopmost = true; // 默认置顶
|
||||
|
||||
/// <summary>
|
||||
/// 刀具列表
|
||||
@@ -107,6 +108,27 @@ namespace DrillTools
|
||||
/// </summary>
|
||||
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>
|
||||
@@ -1223,7 +1245,7 @@ M30";
|
||||
|
||||
try
|
||||
{
|
||||
// 使用ANSI编码读取文件
|
||||
// 使用ANSI编码
|
||||
Encoding ansiEncoding;
|
||||
try
|
||||
{
|
||||
@@ -1234,7 +1256,26 @@ M30";
|
||||
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)
|
||||
{
|
||||
@@ -1293,5 +1334,13 @@ M30";
|
||||
tools.Add(tool);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换窗口置顶状态
|
||||
/// </summary>
|
||||
public void ToggleTopmost()
|
||||
{
|
||||
IsTopmost = !IsTopmost;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user