From 2042c6c94985c52af7518bfd10e2ea50012bdb05 Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 23 Apr 2026 17:50:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BACNC=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=EF=BC=8C=E5=8F=96=E6=B6=88=E8=8A=82=E7=82=B9=E7=9A=84?= =?UTF-8?q?=E4=B8=8A=E3=80=81=E4=B8=8B=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/Cnc/CncEditorViewModel.cs | 16 ++++++++++ XplorePlane/Views/Cnc/CncPageView.xaml | 31 ++----------------- XplorePlane/Views/Cnc/CncPageView.xaml.cs | 13 ++++++++ 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs b/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs index 61a3cdb..b870f77 100644 --- a/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs +++ b/XplorePlane/ViewModels/Cnc/CncEditorViewModel.cs @@ -33,6 +33,7 @@ namespace XplorePlane.ViewModels.Cnc private CncNodeViewModel _selectedNode; private bool _isModified; private string _programName; + private string _programDisplayName = "NewCncProgram"; private Guid? _preferredSelectedNodeId; public CncEditorViewModel( @@ -110,6 +111,12 @@ namespace XplorePlane.ViewModels.Cnc set => SetProperty(ref _programName, value); } + public string ProgramDisplayName + { + get => _programDisplayName; + private set => SetProperty(ref _programDisplayName, value); + } + public DelegateCommand InsertReferencePointCommand { get; } public DelegateCommand InsertSaveNodeWithImageCommand { get; } public DelegateCommand InsertSaveNodeCommand { get; } @@ -256,6 +263,7 @@ namespace XplorePlane.ViewModels.Cnc return; await _cncProgramService.SaveAsync(_currentProgram, dlg.FileName); + ProgramDisplayName = Path.GetFileName(dlg.FileName); IsModified = false; } catch (Exception ex) @@ -280,6 +288,7 @@ namespace XplorePlane.ViewModels.Cnc _currentProgram = await _cncProgramService.LoadAsync(dlg.FileName); ProgramName = _currentProgram.Name; + ProgramDisplayName = Path.GetFileName(dlg.FileName); IsModified = false; RefreshNodes(); } @@ -294,6 +303,7 @@ namespace XplorePlane.ViewModels.Cnc var name = string.IsNullOrWhiteSpace(ProgramName) ? "NewCncProgram" : ProgramName; _currentProgram = _cncProgramService.CreateProgram(name); ProgramName = _currentProgram.Name; + ProgramDisplayName = FormatProgramDisplayName(_currentProgram.Name); IsModified = false; RefreshNodes(); } @@ -622,5 +632,11 @@ namespace XplorePlane.ViewModels.Cnc .GetEvent() .Publish(new CncProgramChangedPayload(ProgramName ?? string.Empty, IsModified)); } + + private static string FormatProgramDisplayName(string programName) + { + var name = string.IsNullOrWhiteSpace(programName) ? "NewCncProgram" : programName; + return name.EndsWith(".xp", StringComparison.OrdinalIgnoreCase) ? name : $"{name}.xp"; + } } } diff --git a/XplorePlane/Views/Cnc/CncPageView.xaml b/XplorePlane/Views/Cnc/CncPageView.xaml index 975b87d..1b86e33 100644 --- a/XplorePlane/Views/Cnc/CncPageView.xaml +++ b/XplorePlane/Views/Cnc/CncPageView.xaml @@ -106,14 +106,14 @@ FontFamily="{StaticResource UiFont}" FontSize="13" FontWeight="SemiBold" - Text="{Binding ProgramName, TargetNullValue=CNC编辑}" + Text="{Binding ProgramDisplayName, TargetNullValue=CNC编辑}" TextWrapping="Wrap" /> @@ -125,6 +125,7 @@ Background="Transparent" BorderThickness="0" ItemsSource="{Binding TreeNodes}" + PreviewKeyDown="CncTreeView_PreviewKeyDown" SelectedItemChanged="CncTreeView_SelectedItemChanged"> @@ -204,32 +205,6 @@ VerticalAlignment="Center" Orientation="Horizontal" Visibility="Collapsed"> -