From ce3f88312310a420d530495cf21f6c5f565eafd5 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 13 Aug 2021 19:24:46 +0800 Subject: [PATCH] optimize: dereference Launcher from its child widget Welcome --- src/Views/Launcher.xaml.cs | 1 + src/Views/Widgets/Welcome.xaml.cs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Views/Launcher.xaml.cs b/src/Views/Launcher.xaml.cs index a5617934..acaba972 100644 --- a/src/Views/Launcher.xaml.cs +++ b/src/Views/Launcher.xaml.cs @@ -96,6 +96,7 @@ namespace SourceGit.Views { #region TAB_OPERATION private void OnTabAdding(object sender, Widgets.PageTabBar.TabEventArgs e) { var page = new Widgets.Welcome(); + page.OnNodeEdited += node => tabs.Update(node.Id, node.Bookmark, node.Name); container.Add(e.TabId, page); Controls.PopupWidget.RegisterContainer(e.TabId, page); } diff --git a/src/Views/Widgets/Welcome.xaml.cs b/src/Views/Widgets/Welcome.xaml.cs index bd5977aa..7426d52f 100644 --- a/src/Views/Widgets/Welcome.xaml.cs +++ b/src/Views/Widgets/Welcome.xaml.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -12,6 +13,7 @@ namespace SourceGit.Views.Widgets { /// 新标签页 /// public partial class Welcome : UserControl, Controls.IPopupContainer { + /// /// 树节点数据 /// @@ -44,6 +46,11 @@ namespace SourceGit.Views.Widgets { public List Children { get; set; } } + /// + /// 仓库节点编辑事件参数 + /// + public event Action OnNodeEdited; + public Welcome() { InitializeComponent(); UpdateTree(); @@ -144,7 +151,7 @@ namespace SourceGit.Views.Widgets { if (repo != null) { repo.Bookmark = refIdx; node.Bookmark = refIdx; - (Application.Current.MainWindow as Launcher)?.tabs.Update(node.Id, refIdx, node.Name); + OnNodeEdited?.Invoke(node); } ev.Handled = true; }; @@ -400,7 +407,7 @@ namespace SourceGit.Views.Widgets { Models.Preference.Instance.RenameGroup(node.Id, edit.Text); } else { Models.Preference.Instance.RenameRepository(node.Id, node.Name); - (Application.Current.MainWindow as Launcher)?.tabs.Update(node.Id, node.Bookmark, edit.Text); + OnNodeEdited?.Invoke(node); } e.Handled = false; }