弹窗优化
This commit is contained in:
@@ -27,7 +27,7 @@ namespace DeviceEditModule.ViewModels
|
||||
/// <summary>所有 Tab 项集合,绑定到标签条的 ItemsControl。</summary>
|
||||
public ObservableCollection<DialogTabItemVM> TagItems { get; } = new();
|
||||
|
||||
/// <summary>以 Tab 标题为 key 追踪已打开的 Tab,防止重复打开。</summary>
|
||||
/// <summary>以设备指纹为 key 追踪已打开的 Tab,防止同一物理设备重复打开。</summary>
|
||||
private readonly Dictionary<string, DialogTabItemVM> _tabDictionary = new();
|
||||
|
||||
private DialogTabItemVM? _selectedTag;
|
||||
@@ -87,11 +87,11 @@ namespace DeviceEditModule.ViewModels
|
||||
|
||||
#region Tab 管理
|
||||
|
||||
/// <summary>收到事件:若 Tab 已存在则激活,否则创建并追加到集合。</summary>
|
||||
/// <summary>收到事件:若指纹已存在则激活,否则创建并追加到集合。</summary>
|
||||
private void OnAddTab(DialogTabInfo info)
|
||||
{
|
||||
// 已有相同标题的 Tab → 直接激活,不重复创建
|
||||
if (_tabDictionary.TryGetValue(info.Title, out var existing))
|
||||
// 已有相同指纹的 Tab → 直接激活,不重复创建
|
||||
if (!string.IsNullOrEmpty(info.Fingerprint) && _tabDictionary.TryGetValue(info.Fingerprint, out var existing))
|
||||
{
|
||||
ActivateTab(existing);
|
||||
return;
|
||||
@@ -99,11 +99,14 @@ namespace DeviceEditModule.ViewModels
|
||||
|
||||
var tab = new DialogTabItemVM(OnSelectTab, OnCloseTab)
|
||||
{
|
||||
Title = info.Title,
|
||||
Content = info.Content
|
||||
Title = info.Title,
|
||||
Fingerprint = info.Fingerprint,
|
||||
Content = info.Content
|
||||
};
|
||||
|
||||
_tabDictionary[info.Title] = tab;
|
||||
if (!string.IsNullOrEmpty(info.Fingerprint))
|
||||
_tabDictionary[info.Fingerprint] = tab;
|
||||
|
||||
TagItems.Add(tab);
|
||||
RaisePropertyChanged(nameof(HasNoTabs));
|
||||
ActivateTab(tab);
|
||||
@@ -116,7 +119,8 @@ namespace DeviceEditModule.ViewModels
|
||||
private void OnCloseTab(DialogTabItemVM tab)
|
||||
{
|
||||
int idx = TagItems.IndexOf(tab);
|
||||
_tabDictionary.Remove(tab.Title);
|
||||
if (!string.IsNullOrEmpty(tab.Fingerprint))
|
||||
_tabDictionary.Remove(tab.Fingerprint);
|
||||
TagItems.Remove(tab);
|
||||
RaisePropertyChanged(nameof(HasNoTabs));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user