aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SharedUI/Components
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-07 14:44:45 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-07 14:44:45 +0300
commit070db71577b05f72e7531d0e530a4ef5bd1d128a (patch)
treec51be10d80fd45f73cee513f38ca5be738c8aca1 /Software/Visual_Studio/Tango.SharedUI/Components
parent822707058d3fe957e03887a3969d553a65537031 (diff)
downloadTango-070db71577b05f72e7531d0e530a4ef5bd1d128a.tar.gz
Tango-070db71577b05f72e7531d0e530a4ef5bd1d128a.zip
Users & Roles !
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI/Components')
-rw-r--r--Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs44
1 files changed, 38 insertions, 6 deletions
diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
index e09bb832e..8aa087ed3 100644
--- a/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
+++ b/Software/Visual_Studio/Tango.SharedUI/Components/SelectedObjectCollection.cs
@@ -10,37 +10,69 @@ namespace Tango.SharedUI.Components
{
public class SelectedObjectCollection<T> : ObservableCollection<SelectedObject<T>>
{
+ private Func<T, T, bool> _compareFunc;
+
public event EventHandler SelectionChanged;
public ObservableCollection<T> Source { get; set; }
public ObservableCollection<T> SynchedSource { get; set; }
- public SelectedObjectCollection(ObservableCollection<T> source, ObservableCollection<T> synchedSource)
+ public SelectedObjectCollection(ObservableCollection<T> source, ObservableCollection<T> synchedSource, Func<T, T, bool> compareFunc)
{
+ _compareFunc = compareFunc;
+
SynchedSource = synchedSource;
Source = source;
foreach (var item in source)
{
- var selectedItem = new SelectedObject<T>(item, synchedSource.Contains(item));
+ var selectedItem = new SelectedObject<T>(item, _compareFunc == null ? synchedSource.Contains(item) : synchedSource.ToList().Exists(x => _compareFunc(x, item)));
this.Add(selectedItem);
selectedItem.IsSelectedChanged += SelectedItem_IsSelectedChanged;
}
}
+ public SelectedObjectCollection(ObservableCollection<T> source, ObservableCollection<T> synchedSource) : this(source, synchedSource, null)
+ {
+
+ }
+
private void SelectedItem_IsSelectedChanged(object sender, EventArgs e)
{
SelectedObject<T> item = sender as SelectedObject<T>;
-
+
if (item.IsSelected)
{
- if (!SynchedSource.Contains(item.Data))
+ if (_compareFunc == null)
{
- SynchedSource.Add(item.Data);
+ if (!SynchedSource.Contains(item.Data))
+ {
+ SynchedSource.Add(item.Data);
+ }
+ }
+ else
+ {
+ if (!SynchedSource.ToList().Exists(x => _compareFunc(x, item.Data)))
+ {
+ SynchedSource.Add(item.Data);
+ }
}
}
else
{
- SynchedSource.Remove(item.Data);
+ if (_compareFunc == null)
+ {
+ SynchedSource.Remove(item.Data);
+ }
+ else
+ {
+ foreach (var s in SynchedSource.ToList())
+ {
+ if (_compareFunc(s, item.Data))
+ {
+ SynchedSource.Remove(s);
+ }
+ }
+ }
}
SelectionChanged?.Invoke(this, new EventArgs());