Merge pull request #120 from gadfly3173/fix/handle-select-changed

fix: update search filter selected commit after Histories selected commit changed
This commit is contained in:
leo 2024-05-10 16:24:25 +08:00 committed by GitHub
commit efd8e72c4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 0 deletions

View file

@ -369,6 +369,18 @@ namespace SourceGit.ViewModels
return menu; 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) private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current)
{ {
var submenu = new MenuItem(); var submenu = new MenuItem();

View file

@ -221,6 +221,12 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _hasUnsolvedConflicts, value); private set => SetProperty(ref _hasUnsolvedConflicts, value);
} }
public Models.Commit SearchResultSelectedCommit
{
get => _searchResultSelectedCommit;
set => SetProperty(ref _searchResultSelectedCommit, value);
}
public void Open() public void Open()
{ {
_watcher = new Models.Watcher(this); _watcher = new Models.Watcher(this);
@ -1348,6 +1354,14 @@ namespace SourceGit.ViewModels
return menu; return menu;
} }
public void HandleSelectedCommitChanged(Models.Commit commit)
{
if (SearchedCommits.Count > 0)
{
SearchResultSelectedCommit = commit;
}
}
private string _fullpath = string.Empty; private string _fullpath = string.Empty;
private string _gitDir = string.Empty; private string _gitDir = string.Empty;
private Models.GitFlow _gitflow = new Models.GitFlow(); private Models.GitFlow _gitflow = new Models.GitFlow();
@ -1377,5 +1391,6 @@ namespace SourceGit.ViewModels
private InProgressContext _inProgressContext = null; private InProgressContext _inProgressContext = null;
private bool _hasUnsolvedConflicts = false; private bool _hasUnsolvedConflicts = false;
private Models.Commit _searchResultSelectedCommit = null;
} }
} }

View file

@ -291,6 +291,7 @@ namespace SourceGit.Views
if (DataContext is ViewModels.Histories histories) if (DataContext is ViewModels.Histories histories)
{ {
histories.Select(commitDataGrid.SelectedItems); histories.Select(commitDataGrid.SelectedItems);
histories.NotifyAutoSelectedCommitChanged();
} }
e.Handled = true; e.Handled = true;
} }

View file

@ -403,6 +403,7 @@
<DataGrid Grid.Row="1" <DataGrid Grid.Row="1"
ItemsSource="{Binding SearchedCommits}" ItemsSource="{Binding SearchedCommits}"
SelectionMode="Single" SelectionMode="Single"
SelectedItem="{Binding SearchResultSelectedCommit, Mode=OneWay}"
CanUserReorderColumns="False" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserResizeColumns="False"
CanUserSortColumns="False" CanUserSortColumns="False"