optimize<WorkingCopy>: fix treeview item selection changed triggered when click same item; remove unused code

This commit is contained in:
leo 2021-01-04 22:11:03 +08:00
parent 065aeb67ca
commit d110b9e451
3 changed files with 21 additions and 29 deletions

View file

@ -239,6 +239,8 @@ namespace SourceGit.Helpers {
selected.Add(item);
item.SetValue(IsCheckedProperty, true);
} else {
if (selected.Count == 1 && selected[0] == item) return;
foreach (var old in selected) old.SetValue(IsCheckedProperty, false);
selected.Clear();
selected.Add(item);

View file

@ -17,11 +17,12 @@ namespace SourceGit.UI {
/// Viewer for git diff
/// </summary>
public partial class DiffViewer : UserControl {
public static readonly Brush BG_EMPTY = new SolidColorBrush(Color.FromArgb(40, 0, 0, 0));
public static readonly Brush BG_ADDED = new SolidColorBrush(Color.FromArgb(60, 0, 255, 0));
public static readonly Brush BG_DELETED = new SolidColorBrush(Color.FromArgb(60, 255, 0, 0));
public static readonly Brush BG_NORMAL = Brushes.Transparent;
private List<Git.Diff.LineChange> lineChanges = null;
private Brush bgEmpty = new SolidColorBrush(Color.FromArgb(40, 0, 0, 0));
private Brush bgAdded = new SolidColorBrush(Color.FromArgb(60, 0, 255, 0));
private Brush bgDeleted = new SolidColorBrush(Color.FromArgb(60, 255, 0, 0));
private Brush bgNormal = Brushes.Transparent;
private List<DataGrid> editors = new List<DataGrid>();
/// <summary>
@ -85,19 +86,16 @@ namespace SourceGit.UI {
public void Diff(Git.Repository repo, Option opts) {
SetTitle(opts.Path, opts.OrgPath);
lineChanges = null;
loading.Visibility = Visibility.Visible;
mask.Visibility = Visibility.Collapsed;
sizeChange.Visibility = Visibility.Collapsed;
noChange.Visibility = Visibility.Collapsed;
editorContainer.Children.Clear();
editorLines.Children.Clear();
editors.Clear();
editorLines.Children.Clear();
editorLines.ColumnDefinitions.Clear();
editors.Clear();
lineChanges = null;
Task.Run(() => {
var args = $"{opts.ExtraArgs} ";
@ -195,7 +193,6 @@ namespace SourceGit.UI {
editorContainer.Children.Add(editor);
editors.Add(editor);
editorLines.ColumnDefinitions.Clear();
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(lineNumberWidth) });
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(lineNumberWidth) });
@ -253,7 +250,6 @@ namespace SourceGit.UI {
var oldEditor = CreateTextEditor(new string[] { "OldLine" });
oldEditor.SetValue(Grid.ColumnProperty, 0);
oldEditor.ContextMenuOpening += OnTextChangeContextMenuOpening;
oldEditor.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnTwoSidesScroll));
oldEditor.Columns[0].Width = new DataGridLength(lineNumberWidth, DataGridLengthUnitType.Pixel);
oldEditor.Columns[1].MinWidth = minWidth;
@ -261,7 +257,6 @@ namespace SourceGit.UI {
var newEditor = CreateTextEditor(new string[] { "NewLine" });
newEditor.SetValue(Grid.ColumnProperty, 1);
newEditor.ContextMenuOpening += OnTextChangeContextMenuOpening;
newEditor.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnTwoSidesScroll));
newEditor.Columns[0].Width = new DataGridLength(lineNumberWidth, DataGridLengthUnitType.Pixel);
newEditor.Columns[1].MinWidth = minWidth;
@ -273,7 +268,6 @@ namespace SourceGit.UI {
editors.Add(oldEditor);
editors.Add(newEditor);
editorLines.ColumnDefinitions.Clear();
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(lineNumberWidth) });
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(lineNumberWidth) });
@ -343,11 +337,11 @@ namespace SourceGit.UI {
private Brush GetLineBackground(Git.Diff.LineChange line) {
switch (line.Mode) {
case Git.Diff.LineMode.Added:
return bgAdded;
return BG_ADDED;
case Git.Diff.LineMode.Deleted:
return bgDeleted;
return BG_DELETED;
default:
return bgNormal;
return BG_NORMAL;
}
}
@ -364,7 +358,7 @@ namespace SourceGit.UI {
var empty = new ChangeBlock();
empty.Content = "";
empty.Mode = Git.Diff.LineMode.None;
empty.BG = bgEmpty;
empty.BG = BG_EMPTY;
empty.FG = Brushes.Transparent;
empty.Style = FontStyles.Normal;
empty.OldLine = "";
@ -378,7 +372,7 @@ namespace SourceGit.UI {
var empty = new ChangeBlock();
empty.Content = "";
empty.Mode = Git.Diff.LineMode.None;
empty.BG = bgEmpty;
empty.BG = BG_EMPTY;
empty.FG = Brushes.Transparent;
empty.Style = FontStyles.Normal;
empty.OldLine = "";
@ -632,6 +626,7 @@ namespace SourceGit.UI {
editorContainer.Children.Clear();
editorLines.Children.Clear();
editorLines.ColumnDefinitions.Clear();
editors.Clear();
SetTextChange();

View file

@ -72,8 +72,6 @@ namespace SourceGit.UI {
}
}
Dispatcher.Invoke(() => mergePanel.Visibility = Visibility.Collapsed);
SetData(unstaged, true);
SetData(staged, false);
@ -85,6 +83,7 @@ namespace SourceGit.UI {
btnCommitAndPush.Visibility = Visibility.Collapsed;
}
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset();
});
@ -126,12 +125,11 @@ namespace SourceGit.UI {
#region UNSTAGED
private void UnstagedTreeMultiSelectionChanged(object sender, RoutedEventArgs e) {
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset();
var selected = Helpers.TreeViewHelper.GetSelectedItems(unstagedTree);
if (selected.Count == 0) return;
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset();
Helpers.TreeViewHelper.UnselectTree(stageTree);
stageList.SelectedItems.Clear();
@ -532,12 +530,11 @@ namespace SourceGit.UI {
#region STAGED
private void StageTreeMultiSelectionChanged(object sender, RoutedEventArgs e) {
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset();
var selected = Helpers.TreeViewHelper.GetSelectedItems(stageTree);
if (selected.Count == 0) return;
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Reset();
Helpers.TreeViewHelper.UnselectTree(unstagedTree);
unstagedList.SelectedItems.Clear();
@ -546,7 +543,6 @@ namespace SourceGit.UI {
var node = selected[0].DataContext as Node;
if (!node.IsFile) return;
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Diff(Repo, new DiffViewer.Option() {
ExtraArgs = "--cached",
Path = node.FilePath,
@ -567,7 +563,6 @@ namespace SourceGit.UI {
if (selected.Count != 1) return;
var change = selected[0] as Git.Change;
mergePanel.Visibility = Visibility.Collapsed;
diffViewer.Diff(Repo, new DiffViewer.Option() {
ExtraArgs = "--cached",
Path = change.Path,