mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
feature<CommitDetail>: goto diff view by double click changed file in commit information panel
This commit is contained in:
parent
0810e19f93
commit
b9b0899d48
6 changed files with 66 additions and 6 deletions
|
@ -75,6 +75,16 @@ namespace SourceGit.Views.Controls {
|
|||
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
|
||||
}
|
||||
|
||||
public void Select(object dataContext) {
|
||||
if (Selected.Count == 1 && Selected[0] == dataContext) return;
|
||||
|
||||
var item = FindItemByDataContext(this, dataContext);
|
||||
if (item != null) {
|
||||
AddSelected(item, true);
|
||||
item.BringIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride() {
|
||||
return new TreeItem(0, Indent);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ namespace SourceGit.Views.Controls {
|
|||
this.indent = indent;
|
||||
|
||||
Padding = new Thickness(indent * depth, 0, 0, 0);
|
||||
RequestBringIntoView += (o, e) => e.Handled = true;
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride() {
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace SourceGit.Views.Widgets {
|
|||
private List<Models.Commit> range = null;
|
||||
private List<Models.Change> cachedChanges = new List<Models.Change>();
|
||||
private string filter = null;
|
||||
private bool isSelecting = false;
|
||||
|
||||
public class ChangeNode {
|
||||
public string Path { get; set; } = "";
|
||||
|
@ -37,7 +38,28 @@ namespace SourceGit.Views.Widgets {
|
|||
UpdateVisible();
|
||||
}
|
||||
|
||||
public void UpdateVisible() {
|
||||
public void Select(Models.Change change) {
|
||||
isSelecting = true;
|
||||
|
||||
switch (modeSwitcher.Mode) {
|
||||
case Models.Change.DisplayMode.Tree:
|
||||
var node = FindNodeByChange(modeTree.ItemsSource as List<ChangeNode>, change);
|
||||
modeTree.Select(node);
|
||||
break;
|
||||
case Models.Change.DisplayMode.List:
|
||||
modeList.SelectedItem = change;
|
||||
modeList.ScrollIntoView(change);
|
||||
break;
|
||||
case Models.Change.DisplayMode.Grid:
|
||||
modeGrid.SelectedItem = change;
|
||||
modeGrid.ScrollIntoView(change);
|
||||
break;
|
||||
}
|
||||
|
||||
isSelecting = false;
|
||||
}
|
||||
|
||||
private void UpdateVisible() {
|
||||
Task.Run(() => {
|
||||
// 筛选出可见的列表
|
||||
List<Models.Change> visible;
|
||||
|
@ -115,6 +137,21 @@ namespace SourceGit.Views.Widgets {
|
|||
});
|
||||
}
|
||||
|
||||
private ChangeNode FindNodeByChange(List<ChangeNode> nodes, Models.Change change) {
|
||||
if (nodes == null || nodes.Count == 0) return null;
|
||||
|
||||
foreach (var node in nodes) {
|
||||
if (node.IsFolder) {
|
||||
var found = FindNodeByChange(node.Children, change);
|
||||
if (found != null) return found;
|
||||
} else if (node.Change == change) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SortFileNodes(List<ChangeNode> nodes) {
|
||||
nodes.Sort((l, r) => {
|
||||
if (l.IsFolder == r.IsFolder) {
|
||||
|
@ -237,7 +274,7 @@ namespace SourceGit.Views.Widgets {
|
|||
}
|
||||
|
||||
private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) {
|
||||
e.Handled = true;
|
||||
if (!isSelecting) e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnTreeSelectionChanged(object sender, RoutedEventArgs e) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<TabControl>
|
||||
<TabControl x:Name="body">
|
||||
<TabItem Header="{StaticResource Text.CommitViewer.Info}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
@ -203,6 +203,7 @@
|
|||
<DataGrid.RowStyle>
|
||||
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource Style.DataGridRow}">
|
||||
<EventSetter Event="ContextMenuOpening" Handler="OnChangeListContextMenuOpening"/>
|
||||
<EventSetter Event="MouseDoubleClick" Handler="OnChangeListMouseDoubleClick"/>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.Columns>
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace SourceGit.Views.Widgets {
|
||||
|
@ -88,11 +89,23 @@ namespace SourceGit.Views.Widgets {
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region INFORMATION
|
||||
#region EVENTS
|
||||
private void OnNavigateParent(object sender, RequestNavigateEventArgs e) {
|
||||
Models.Watcher.Get(repo)?.NavigateTo(e.Uri.OriginalString);
|
||||
}
|
||||
|
||||
private void OnChangeListMouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
||||
var row = sender as DataGridRow;
|
||||
if (row == null) return;
|
||||
|
||||
var change = row.DataContext as Models.Change;
|
||||
if (change == null) return;
|
||||
|
||||
body.SelectedIndex = 1;
|
||||
changeContainer.Select(change);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnChangeListContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||
var row = sender as DataGridRow;
|
||||
if (row == null) return;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace SourceGit.Views.Widgets {
|
|||
|
||||
foreach (var item in commitList.ItemsSource) {
|
||||
var c = item as Models.Commit;
|
||||
if (c.SHA.Contains(commit)) {
|
||||
if (c.SHA.StartsWith(commit, StringComparison.Ordinal)) {
|
||||
commitList.SelectedItem = c;
|
||||
commitList.ScrollIntoView(c);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue