From 764cf24284992f6ecfadc0c72754703e6108ae70 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 10 May 2024 16:30:34 +0800 Subject: [PATCH] code_review: PR #120 * remove unnecessary code. The `SetProperty` function takes care of set same property in a loop --- src/ViewModels/Histories.cs | 18 ++++++------------ src/ViewModels/Repository.cs | 8 -------- src/Views/Histories.axaml.cs | 1 - 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 47ca8e10..8cab66c1 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -134,11 +134,14 @@ namespace SourceGit.ViewModels { if (commits.Count == 0) { + _repo.SearchResultSelectedCommit = null; DetailContext = null; } else if (commits.Count == 1) { var commit = commits[0] as Models.Commit; + _repo.SearchResultSelectedCommit = commit; + AutoSelectedCommit = commit; NavigationId = _navigationId + 1; @@ -155,12 +158,15 @@ namespace SourceGit.ViewModels } else if (commits.Count == 2) { + _repo.SearchResultSelectedCommit = null; + var end = commits[0] as Models.Commit; var start = commits[1] as Models.Commit; DetailContext = new RevisionCompare(_repo.FullPath, start, end); } else { + _repo.SearchResultSelectedCommit = null; DetailContext = new CountSelectedCommits() { Count = commits.Count }; } } @@ -369,18 +375,6 @@ namespace SourceGit.ViewModels return menu; } - public void NotifyAutoSelectedCommitChanged() - { - if (DetailContext is CommitDetail detail) - { - _repo.HandleSelectedCommitChanged(detail.Commit); - } - else - { - _repo.HandleSelectedCommitChanged(null); - } - } - private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current) { var submenu = new MenuItem(); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 89807206..0e67f11b 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1354,14 +1354,6 @@ namespace SourceGit.ViewModels return menu; } - public void HandleSelectedCommitChanged(Models.Commit commit) - { - if (SearchedCommits.Count > 0) - { - SearchResultSelectedCommit = commit; - } - } - private string _fullpath = string.Empty; private string _gitDir = string.Empty; private Models.GitFlow _gitflow = new Models.GitFlow(); diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index cbed193b..13f05aff 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -291,7 +291,6 @@ namespace SourceGit.Views if (DataContext is ViewModels.Histories histories) { histories.Select(commitDataGrid.SelectedItems); - histories.NotifyAutoSelectedCommitChanged(); } e.Handled = true; }