mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
enhance: prevent property changed event if it is unchanged
This commit is contained in:
parent
aae1c41dcd
commit
85ce2f9cab
2 changed files with 27 additions and 31 deletions
|
@ -137,6 +137,7 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (_selectedStaged != null && _selectedStaged.Count > 0)
|
||||||
SelectedStaged = [];
|
SelectedStaged = [];
|
||||||
|
|
||||||
if (value.Count == 1)
|
if (value.Count == 1)
|
||||||
|
@ -162,6 +163,7 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (_selectedUnstaged != null && _selectedUnstaged.Count > 0)
|
||||||
SelectedUnstaged = [];
|
SelectedUnstaged = [];
|
||||||
|
|
||||||
if (value.Count == 1)
|
if (value.Count == 1)
|
||||||
|
|
|
@ -174,8 +174,9 @@ namespace SourceGit.Views
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_disableSelectionChangingEvent = true;
|
_disableSelectionChangingEvent = true;
|
||||||
|
|
||||||
var selected = new List<Models.Change>();
|
var selected = new List<Models.Change>();
|
||||||
if (sender is ListBox { SelectedItems: not null } list)
|
if (sender is ListBox list)
|
||||||
{
|
{
|
||||||
foreach (var item in list.SelectedItems)
|
foreach (var item in list.SelectedItems)
|
||||||
{
|
{
|
||||||
|
@ -186,7 +187,27 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TrySetSelected(selected);
|
var old = SelectedChanges ?? [];
|
||||||
|
if (old.Count != selected.Count)
|
||||||
|
{
|
||||||
|
SetCurrentValue(SelectedChangesProperty, selected);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool allEquals = true;
|
||||||
|
foreach (var c in old)
|
||||||
|
{
|
||||||
|
if (!selected.Contains(c))
|
||||||
|
{
|
||||||
|
allEquals = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allEquals)
|
||||||
|
SetCurrentValue(SelectedChangesProperty, selected);
|
||||||
|
}
|
||||||
|
|
||||||
_disableSelectionChangingEvent = false;
|
_disableSelectionChangingEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,33 +351,6 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TrySetSelected(List<Models.Change> changes)
|
|
||||||
{
|
|
||||||
var old = SelectedChanges;
|
|
||||||
if (old == null && changes.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (old != null && old.Count == changes.Count)
|
|
||||||
{
|
|
||||||
bool allEquals = true;
|
|
||||||
foreach (var c in old)
|
|
||||||
{
|
|
||||||
if (!changes.Contains(c))
|
|
||||||
{
|
|
||||||
allEquals = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (allEquals)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_disableSelectionChangingEvent = true;
|
|
||||||
SetCurrentValue(SelectedChangesProperty, changes);
|
|
||||||
_disableSelectionChangingEvent = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _disableSelectionChangingEvent = false;
|
private bool _disableSelectionChangingEvent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue