From 79084c9a9a1d0346729d5343680768aa91294f1a Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 22 Feb 2024 11:05:20 +0800 Subject: [PATCH] fix: fix crash after clone a new repository --- src/ViewModels/Clone.cs | 10 ++++++---- src/ViewModels/Repository.cs | 4 ++-- src/ViewModels/Welcome.cs | 5 +++-- src/Views/Welcome.axaml | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index 3a7de344..ba5c4610 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -41,9 +41,11 @@ namespace SourceGit.ViewModels { set => SetProperty(ref _extraArgs, value); } - public Clone(LauncherPage page) { - View = new Views.Clone() { DataContext = this }; + public Clone(Launcher launcher, LauncherPage page) { + _launcher = launcher; _page = page; + + View = new Views.Clone() { DataContext = this }; } public static ValidationResult ValidateRemote(string remote, ValidationContext _) { @@ -92,14 +94,14 @@ namespace SourceGit.ViewModels { }; Preference.AddNode(node); - _page.View = new Views.Repository() { DataContext = repo }; - _page.Node = node; + _launcher.OpenRepositoryInTab(node, _page); }); return true; }); } + private Launcher _launcher = null; private LauncherPage _page = null; private string _remote = string.Empty; private bool _useSSH = false; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index ede3624e..54919af0 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -106,12 +106,12 @@ namespace SourceGit.ViewModels { [JsonIgnore] public int WorkingCopyChangesCount { - get => _workingCopy.Count; + get => _workingCopy == null ? 0 : _workingCopy.Count; } [JsonIgnore] public int StashesCount { - get => _stashesPage.Count; + get => _stashesPage == null ? 0 : _stashesPage.Count; } [JsonIgnore] diff --git a/src/ViewModels/Welcome.cs b/src/ViewModels/Welcome.cs index b75ed664..e9e43434 100644 --- a/src/ViewModels/Welcome.cs +++ b/src/ViewModels/Welcome.cs @@ -34,7 +34,8 @@ namespace SourceGit.ViewModels { } public void Clone(object param) { - var page = param as LauncherPage; + var launcher = param as Launcher; + var page = launcher.ActivePage; if (!Preference.Instance.IsGitConfigured) { App.RaiseException(page.GetId(), App.Text("NotConfigured")); @@ -42,7 +43,7 @@ namespace SourceGit.ViewModels { } if (PopupHost.CanCreatePopup()) { - PopupHost.ShowPopup(new Clone(page)); + PopupHost.ShowPopup(new Clone(launcher, page)); } } diff --git a/src/Views/Welcome.axaml b/src/Views/Welcome.axaml index a4ea7774..f066d211 100644 --- a/src/Views/Welcome.axaml +++ b/src/Views/Welcome.axaml @@ -15,7 +15,7 @@ -