mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
optimize<WorkingCopy>: fix treeview item selection changed triggered when click same item; remove unused code
This commit is contained in:
parent
065aeb67ca
commit
d110b9e451
3 changed files with 21 additions and 29 deletions
|
@ -239,6 +239,8 @@ namespace SourceGit.Helpers {
|
||||||
selected.Add(item);
|
selected.Add(item);
|
||||||
item.SetValue(IsCheckedProperty, true);
|
item.SetValue(IsCheckedProperty, true);
|
||||||
} else {
|
} else {
|
||||||
|
if (selected.Count == 1 && selected[0] == item) return;
|
||||||
|
|
||||||
foreach (var old in selected) old.SetValue(IsCheckedProperty, false);
|
foreach (var old in selected) old.SetValue(IsCheckedProperty, false);
|
||||||
selected.Clear();
|
selected.Clear();
|
||||||
selected.Add(item);
|
selected.Add(item);
|
||||||
|
|
|
@ -17,11 +17,12 @@ namespace SourceGit.UI {
|
||||||
/// Viewer for git diff
|
/// Viewer for git diff
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class DiffViewer : UserControl {
|
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 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>();
|
private List<DataGrid> editors = new List<DataGrid>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -85,19 +86,16 @@ namespace SourceGit.UI {
|
||||||
public void Diff(Git.Repository repo, Option opts) {
|
public void Diff(Git.Repository repo, Option opts) {
|
||||||
SetTitle(opts.Path, opts.OrgPath);
|
SetTitle(opts.Path, opts.OrgPath);
|
||||||
|
|
||||||
lineChanges = null;
|
|
||||||
|
|
||||||
loading.Visibility = Visibility.Visible;
|
loading.Visibility = Visibility.Visible;
|
||||||
mask.Visibility = Visibility.Collapsed;
|
mask.Visibility = Visibility.Collapsed;
|
||||||
sizeChange.Visibility = Visibility.Collapsed;
|
sizeChange.Visibility = Visibility.Collapsed;
|
||||||
noChange.Visibility = Visibility.Collapsed;
|
noChange.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
editorContainer.Children.Clear();
|
editorContainer.Children.Clear();
|
||||||
editorLines.Children.Clear();
|
|
||||||
editors.Clear();
|
|
||||||
|
|
||||||
editorLines.Children.Clear();
|
editorLines.Children.Clear();
|
||||||
editorLines.ColumnDefinitions.Clear();
|
editorLines.ColumnDefinitions.Clear();
|
||||||
|
editors.Clear();
|
||||||
|
lineChanges = null;
|
||||||
|
|
||||||
Task.Run(() => {
|
Task.Run(() => {
|
||||||
var args = $"{opts.ExtraArgs} ";
|
var args = $"{opts.ExtraArgs} ";
|
||||||
|
@ -195,7 +193,6 @@ namespace SourceGit.UI {
|
||||||
editorContainer.Children.Add(editor);
|
editorContainer.Children.Add(editor);
|
||||||
editors.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) });
|
||||||
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" });
|
var oldEditor = CreateTextEditor(new string[] { "OldLine" });
|
||||||
oldEditor.SetValue(Grid.ColumnProperty, 0);
|
oldEditor.SetValue(Grid.ColumnProperty, 0);
|
||||||
oldEditor.ContextMenuOpening += OnTextChangeContextMenuOpening;
|
|
||||||
oldEditor.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnTwoSidesScroll));
|
oldEditor.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnTwoSidesScroll));
|
||||||
oldEditor.Columns[0].Width = new DataGridLength(lineNumberWidth, DataGridLengthUnitType.Pixel);
|
oldEditor.Columns[0].Width = new DataGridLength(lineNumberWidth, DataGridLengthUnitType.Pixel);
|
||||||
oldEditor.Columns[1].MinWidth = minWidth;
|
oldEditor.Columns[1].MinWidth = minWidth;
|
||||||
|
@ -261,7 +257,6 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
var newEditor = CreateTextEditor(new string[] { "NewLine" });
|
var newEditor = CreateTextEditor(new string[] { "NewLine" });
|
||||||
newEditor.SetValue(Grid.ColumnProperty, 1);
|
newEditor.SetValue(Grid.ColumnProperty, 1);
|
||||||
newEditor.ContextMenuOpening += OnTextChangeContextMenuOpening;
|
|
||||||
newEditor.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnTwoSidesScroll));
|
newEditor.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(OnTwoSidesScroll));
|
||||||
newEditor.Columns[0].Width = new DataGridLength(lineNumberWidth, DataGridLengthUnitType.Pixel);
|
newEditor.Columns[0].Width = new DataGridLength(lineNumberWidth, DataGridLengthUnitType.Pixel);
|
||||||
newEditor.Columns[1].MinWidth = minWidth;
|
newEditor.Columns[1].MinWidth = minWidth;
|
||||||
|
@ -273,7 +268,6 @@ namespace SourceGit.UI {
|
||||||
editors.Add(oldEditor);
|
editors.Add(oldEditor);
|
||||||
editors.Add(newEditor);
|
editors.Add(newEditor);
|
||||||
|
|
||||||
editorLines.ColumnDefinitions.Clear();
|
|
||||||
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(lineNumberWidth) });
|
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(1, GridUnitType.Star) });
|
||||||
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(lineNumberWidth) });
|
editorLines.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(lineNumberWidth) });
|
||||||
|
@ -343,11 +337,11 @@ namespace SourceGit.UI {
|
||||||
private Brush GetLineBackground(Git.Diff.LineChange line) {
|
private Brush GetLineBackground(Git.Diff.LineChange line) {
|
||||||
switch (line.Mode) {
|
switch (line.Mode) {
|
||||||
case Git.Diff.LineMode.Added:
|
case Git.Diff.LineMode.Added:
|
||||||
return bgAdded;
|
return BG_ADDED;
|
||||||
case Git.Diff.LineMode.Deleted:
|
case Git.Diff.LineMode.Deleted:
|
||||||
return bgDeleted;
|
return BG_DELETED;
|
||||||
default:
|
default:
|
||||||
return bgNormal;
|
return BG_NORMAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +358,7 @@ namespace SourceGit.UI {
|
||||||
var empty = new ChangeBlock();
|
var empty = new ChangeBlock();
|
||||||
empty.Content = "";
|
empty.Content = "";
|
||||||
empty.Mode = Git.Diff.LineMode.None;
|
empty.Mode = Git.Diff.LineMode.None;
|
||||||
empty.BG = bgEmpty;
|
empty.BG = BG_EMPTY;
|
||||||
empty.FG = Brushes.Transparent;
|
empty.FG = Brushes.Transparent;
|
||||||
empty.Style = FontStyles.Normal;
|
empty.Style = FontStyles.Normal;
|
||||||
empty.OldLine = "";
|
empty.OldLine = "";
|
||||||
|
@ -378,7 +372,7 @@ namespace SourceGit.UI {
|
||||||
var empty = new ChangeBlock();
|
var empty = new ChangeBlock();
|
||||||
empty.Content = "";
|
empty.Content = "";
|
||||||
empty.Mode = Git.Diff.LineMode.None;
|
empty.Mode = Git.Diff.LineMode.None;
|
||||||
empty.BG = bgEmpty;
|
empty.BG = BG_EMPTY;
|
||||||
empty.FG = Brushes.Transparent;
|
empty.FG = Brushes.Transparent;
|
||||||
empty.Style = FontStyles.Normal;
|
empty.Style = FontStyles.Normal;
|
||||||
empty.OldLine = "";
|
empty.OldLine = "";
|
||||||
|
@ -632,6 +626,7 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
editorContainer.Children.Clear();
|
editorContainer.Children.Clear();
|
||||||
editorLines.Children.Clear();
|
editorLines.Children.Clear();
|
||||||
|
editorLines.ColumnDefinitions.Clear();
|
||||||
editors.Clear();
|
editors.Clear();
|
||||||
|
|
||||||
SetTextChange();
|
SetTextChange();
|
||||||
|
|
|
@ -72,8 +72,6 @@ namespace SourceGit.UI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dispatcher.Invoke(() => mergePanel.Visibility = Visibility.Collapsed);
|
|
||||||
|
|
||||||
SetData(unstaged, true);
|
SetData(unstaged, true);
|
||||||
SetData(staged, false);
|
SetData(staged, false);
|
||||||
|
|
||||||
|
@ -85,6 +83,7 @@ namespace SourceGit.UI {
|
||||||
btnCommitAndPush.Visibility = Visibility.Collapsed;
|
btnCommitAndPush.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mergePanel.Visibility = Visibility.Collapsed;
|
||||||
diffViewer.Reset();
|
diffViewer.Reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -126,12 +125,11 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
#region UNSTAGED
|
#region UNSTAGED
|
||||||
private void UnstagedTreeMultiSelectionChanged(object sender, RoutedEventArgs e) {
|
private void UnstagedTreeMultiSelectionChanged(object sender, RoutedEventArgs e) {
|
||||||
mergePanel.Visibility = Visibility.Collapsed;
|
|
||||||
diffViewer.Reset();
|
|
||||||
|
|
||||||
var selected = Helpers.TreeViewHelper.GetSelectedItems(unstagedTree);
|
var selected = Helpers.TreeViewHelper.GetSelectedItems(unstagedTree);
|
||||||
if (selected.Count == 0) return;
|
if (selected.Count == 0) return;
|
||||||
|
|
||||||
|
mergePanel.Visibility = Visibility.Collapsed;
|
||||||
|
diffViewer.Reset();
|
||||||
Helpers.TreeViewHelper.UnselectTree(stageTree);
|
Helpers.TreeViewHelper.UnselectTree(stageTree);
|
||||||
stageList.SelectedItems.Clear();
|
stageList.SelectedItems.Clear();
|
||||||
|
|
||||||
|
@ -532,12 +530,11 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
#region STAGED
|
#region STAGED
|
||||||
private void StageTreeMultiSelectionChanged(object sender, RoutedEventArgs e) {
|
private void StageTreeMultiSelectionChanged(object sender, RoutedEventArgs e) {
|
||||||
mergePanel.Visibility = Visibility.Collapsed;
|
|
||||||
diffViewer.Reset();
|
|
||||||
|
|
||||||
var selected = Helpers.TreeViewHelper.GetSelectedItems(stageTree);
|
var selected = Helpers.TreeViewHelper.GetSelectedItems(stageTree);
|
||||||
if (selected.Count == 0) return;
|
if (selected.Count == 0) return;
|
||||||
|
|
||||||
|
mergePanel.Visibility = Visibility.Collapsed;
|
||||||
|
diffViewer.Reset();
|
||||||
Helpers.TreeViewHelper.UnselectTree(unstagedTree);
|
Helpers.TreeViewHelper.UnselectTree(unstagedTree);
|
||||||
unstagedList.SelectedItems.Clear();
|
unstagedList.SelectedItems.Clear();
|
||||||
|
|
||||||
|
@ -546,7 +543,6 @@ namespace SourceGit.UI {
|
||||||
var node = selected[0].DataContext as Node;
|
var node = selected[0].DataContext as Node;
|
||||||
if (!node.IsFile) return;
|
if (!node.IsFile) return;
|
||||||
|
|
||||||
mergePanel.Visibility = Visibility.Collapsed;
|
|
||||||
diffViewer.Diff(Repo, new DiffViewer.Option() {
|
diffViewer.Diff(Repo, new DiffViewer.Option() {
|
||||||
ExtraArgs = "--cached",
|
ExtraArgs = "--cached",
|
||||||
Path = node.FilePath,
|
Path = node.FilePath,
|
||||||
|
@ -567,7 +563,6 @@ namespace SourceGit.UI {
|
||||||
if (selected.Count != 1) return;
|
if (selected.Count != 1) return;
|
||||||
|
|
||||||
var change = selected[0] as Git.Change;
|
var change = selected[0] as Git.Change;
|
||||||
mergePanel.Visibility = Visibility.Collapsed;
|
|
||||||
diffViewer.Diff(Repo, new DiffViewer.Option() {
|
diffViewer.Diff(Repo, new DiffViewer.Option() {
|
||||||
ExtraArgs = "--cached",
|
ExtraArgs = "--cached",
|
||||||
Path = change.Path,
|
Path = change.Path,
|
||||||
|
|
Loading…
Reference in a new issue