mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08: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,7 +137,8 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectedStaged = [];
|
if (_selectedStaged != null && _selectedStaged.Count > 0)
|
||||||
|
SelectedStaged = [];
|
||||||
|
|
||||||
if (value.Count == 1)
|
if (value.Count == 1)
|
||||||
SetDetail(value[0]);
|
SetDetail(value[0]);
|
||||||
|
@ -162,7 +163,8 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectedUnstaged = [];
|
if (_selectedUnstaged != null && _selectedUnstaged.Count > 0)
|
||||||
|
SelectedUnstaged = [];
|
||||||
|
|
||||||
if (value.Count == 1)
|
if (value.Count == 1)
|
||||||
SetDetail(value[0]);
|
SetDetail(value[0]);
|
||||||
|
|
|
@ -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