feat: display alias with [original name] suffix, fix false alias detection
- Two stacked TextBlocks: alias (red, bold) + [原文] (black, bold) - [原文] suffix only visible when HasAlias=true - CommitEdit/toolbar: treat unchanged text as no alias (set to null) - Fixes: nodes edited without actual changes no longer show false [原文] suffix
This commit is contained in:
parent
d358c31a7d
commit
903ed856e3
@ -47,8 +47,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
_alias = value;
|
||||
HasAlias = !string.IsNullOrEmpty(value);
|
||||
// 更新显示文本
|
||||
DisplayName = HasAlias ? value : (OriginalName ?? "?");
|
||||
// 更新显示文本:别名 [原名]
|
||||
DisplayName = HasAlias ? value : (_originalName ?? "?");
|
||||
OnPropertyChanged(nameof(Alias));
|
||||
}
|
||||
}
|
||||
@ -62,9 +62,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
if (_isEditing == value) return;
|
||||
_isEditing = value;
|
||||
OnPropertyChanged(nameof(IsEditing));
|
||||
// 进入编辑时初始化 EditValue 为当前显示名
|
||||
// 进入编辑时初始化 EditValue 为当前别名(无别名用原名)
|
||||
if (value)
|
||||
EditValue = DisplayName;
|
||||
EditValue = HasAlias ? Alias : (OriginalName ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,33 +18,62 @@
|
||||
<HierarchicalDataTemplate DataType="{x:Type vm:AliasNodeViewModel}"
|
||||
ItemsSource="{Binding Children}">
|
||||
<Grid VerticalAlignment="Center">
|
||||
<!-- 显示模式 -->
|
||||
<TextBlock Text="{Binding DisplayName}"
|
||||
FontSize="12" TextTrimming="CharacterEllipsis" MaxWidth="200"
|
||||
FontWeight="SemiBold">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="#FF1A1A1A"/>
|
||||
<Setter Property="FontStyle" Value="Normal"/>
|
||||
<!-- 显示模式:StackPanel 包含别名(红色)+ [原文](黑色) -->
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasAlias}" Value="True">
|
||||
<Setter Property="Foreground" Value="#FFC62828"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=TreeViewItem}}" Value="True">
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsOrphan}" Value="True">
|
||||
<Setter Property="TextDecorations" Value="Strikethrough"/>
|
||||
<Setter Property="Foreground" Value="#FFAAAAAA"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsEditing}" Value="True">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</StackPanel.Style>
|
||||
<!-- 别名/原名 -->
|
||||
<TextBlock Text="{Binding DisplayName}"
|
||||
FontSize="12" FontWeight="SemiBold"
|
||||
TextTrimming="CharacterEllipsis" MaxWidth="140">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="#FF1A1A1A"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasAlias}" Value="True">
|
||||
<Setter Property="Foreground" Value="#FFC62828"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=TreeViewItem}}" Value="True">
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsOrphan}" Value="True">
|
||||
<Setter Property="TextDecorations" Value="Strikethrough"/>
|
||||
<Setter Property="Foreground" Value="#FFAAAAAA"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
<!-- [原文] 后缀,黑色加粗 -->
|
||||
<TextBlock FontSize="12" FontWeight="SemiBold"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="#FF1A1A1A"/>
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding HasAlias}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=TreeViewItem}}" Value="True">
|
||||
<Setter Property="Foreground" Value="White"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
<Run Text=" ["/>
|
||||
<Run Text="{Binding OriginalName}"/>
|
||||
<Run Text="]"/>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 编辑模式 -->
|
||||
<TextBox Text="{Binding EditValue, UpdateSourceTrigger=PropertyChanged}"
|
||||
|
||||
@ -127,7 +127,7 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
/// </summary>
|
||||
private void OnTreeViewSelected(AliasNodeViewModel node)
|
||||
{
|
||||
LogManager.Info($"[别名树] 树点击: NodeKey={node.NodeKey}, OriginalName={node.OriginalName}, ModelItem={node.ModelItem?.DisplayName ?? "null"}");
|
||||
LogManager.Info($"[别名树] OnTreeViewSelected 进入: {node.OriginalName}");
|
||||
|
||||
_isInternalSelection = true;
|
||||
try
|
||||
@ -135,9 +135,11 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
var doc = NavisApplication.ActiveDocument;
|
||||
if (doc != null && node.ModelItem != null)
|
||||
{
|
||||
LogManager.Info("[别名树] OnTreeViewSelected 设置NW选择");
|
||||
var coll = new Autodesk.Navisworks.Api.ModelItemCollection { node.ModelItem };
|
||||
doc.CurrentSelection.Clear();
|
||||
doc.CurrentSelection.CopyFrom(coll);
|
||||
LogManager.Info("[别名树] OnTreeViewSelected 设置完成");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -148,6 +150,7 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
{
|
||||
_isInternalSelection = false;
|
||||
}
|
||||
LogManager.Info("[别名树] OnTreeViewSelected 退出");
|
||||
}
|
||||
|
||||
private void StartInlineEdit(AliasNodeViewModel node, TreeViewItem tvi)
|
||||
@ -630,6 +633,8 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
if (_currentSelectionItem == null || _dataStore == null) return;
|
||||
string input = TxtAliasInput.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(input)) return;
|
||||
if (input == _currentSelectionItem?.DisplayName)
|
||||
input = null;
|
||||
|
||||
var identity = AliasNodeIdentity.FromModelItem(_currentSelectionItem);
|
||||
LogManager.Info($"[别名树] 保存别名: {input}, NodeKey={identity.ToKey()}");
|
||||
@ -742,6 +747,8 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
if (textBox?.DataContext is AliasNodeViewModel node)
|
||||
{
|
||||
string newAlias = textBox.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(newAlias) || newAlias == node.OriginalName)
|
||||
newAlias = null;
|
||||
LogManager.Info($"[别名树] 内联编辑: {newAlias}, NodeKey={node.NodeKey}");
|
||||
if (_dataStore != null)
|
||||
{
|
||||
@ -751,7 +758,6 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
node.Alias = newAlias;
|
||||
node.IsEditing = false;
|
||||
|
||||
// 清除别名高亮 / 应用别名高亮
|
||||
ApplyAliasHighlight(node.NodeKey, node.HasAlias);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user