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"> -