mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -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));
|
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() {
|
protected override DependencyObject GetContainerForItemOverride() {
|
||||||
return new TreeItem(0, Indent);
|
return new TreeItem(0, Indent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ namespace SourceGit.Views.Controls {
|
||||||
this.indent = indent;
|
this.indent = indent;
|
||||||
|
|
||||||
Padding = new Thickness(indent * depth, 0, 0, 0);
|
Padding = new Thickness(indent * depth, 0, 0, 0);
|
||||||
RequestBringIntoView += (o, e) => e.Handled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DependencyObject GetContainerForItemOverride() {
|
protected override DependencyObject GetContainerForItemOverride() {
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
private List<Models.Commit> range = null;
|
private List<Models.Commit> range = null;
|
||||||
private List<Models.Change> cachedChanges = new List<Models.Change>();
|
private List<Models.Change> cachedChanges = new List<Models.Change>();
|
||||||
private string filter = null;
|
private string filter = null;
|
||||||
|
private bool isSelecting = false;
|
||||||
|
|
||||||
public class ChangeNode {
|
public class ChangeNode {
|
||||||
public string Path { get; set; } = "";
|
public string Path { get; set; } = "";
|
||||||
|
@ -37,7 +38,28 @@ namespace SourceGit.Views.Widgets {
|
||||||
UpdateVisible();
|
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(() => {
|
Task.Run(() => {
|
||||||
// 筛选出可见的列表
|
// 筛选出可见的列表
|
||||||
List<Models.Change> visible;
|
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) {
|
private void SortFileNodes(List<ChangeNode> nodes) {
|
||||||
nodes.Sort((l, r) => {
|
nodes.Sort((l, r) => {
|
||||||
if (l.IsFolder == r.IsFolder) {
|
if (l.IsFolder == r.IsFolder) {
|
||||||
|
@ -237,7 +274,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) {
|
private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) {
|
||||||
e.Handled = true;
|
if (!isSelecting) e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTreeSelectionChanged(object sender, RoutedEventArgs e) {
|
private void OnTreeSelectionChanged(object sender, RoutedEventArgs e) {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
|
xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
<TabControl>
|
<TabControl x:Name="body">
|
||||||
<TabItem Header="{StaticResource Text.CommitViewer.Info}">
|
<TabItem Header="{StaticResource Text.CommitViewer.Info}">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
@ -203,6 +203,7 @@
|
||||||
<DataGrid.RowStyle>
|
<DataGrid.RowStyle>
|
||||||
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource Style.DataGridRow}">
|
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource Style.DataGridRow}">
|
||||||
<EventSetter Event="ContextMenuOpening" Handler="OnChangeListContextMenuOpening"/>
|
<EventSetter Event="ContextMenuOpening" Handler="OnChangeListContextMenuOpening"/>
|
||||||
|
<EventSetter Event="MouseDoubleClick" Handler="OnChangeListMouseDoubleClick"/>
|
||||||
</Style>
|
</Style>
|
||||||
</DataGrid.RowStyle>
|
</DataGrid.RowStyle>
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
|
|
||||||
namespace SourceGit.Views.Widgets {
|
namespace SourceGit.Views.Widgets {
|
||||||
|
@ -88,11 +89,23 @@ namespace SourceGit.Views.Widgets {
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region INFORMATION
|
#region EVENTS
|
||||||
private void OnNavigateParent(object sender, RequestNavigateEventArgs e) {
|
private void OnNavigateParent(object sender, RequestNavigateEventArgs e) {
|
||||||
Models.Watcher.Get(repo)?.NavigateTo(e.Uri.OriginalString);
|
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) {
|
private void OnChangeListContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||||
var row = sender as DataGridRow;
|
var row = sender as DataGridRow;
|
||||||
if (row == null) return;
|
if (row == null) return;
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
|
|
||||||
foreach (var item in commitList.ItemsSource) {
|
foreach (var item in commitList.ItemsSource) {
|
||||||
var c = item as Models.Commit;
|
var c = item as Models.Commit;
|
||||||
if (c.SHA.Contains(commit)) {
|
if (c.SHA.StartsWith(commit, StringComparison.Ordinal)) {
|
||||||
commitList.SelectedItem = c;
|
commitList.SelectedItem = c;
|
||||||
commitList.ScrollIntoView(c);
|
commitList.ScrollIntoView(c);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue