-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RemoveComponent, support IntX and UintX
- Loading branch information
Showing
14 changed files
with
696 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Collections.Specialized; | ||
|
||
namespace RszTool.App.Common | ||
{ | ||
public static class ObjectModelUtils | ||
{ | ||
public static void SyncObservableCollection<T>( | ||
ObservableCollection<T> list, | ||
Func<object, T> converter, | ||
NotifyCollectionChangedEventArgs e) | ||
{ | ||
switch (e.Action) | ||
{ | ||
case NotifyCollectionChangedAction.Add: | ||
for (int i = 0; i < e.NewItems!.Count; i++) | ||
{ | ||
list.Insert(e.NewStartingIndex + i, converter(e.NewItems[i]!)); | ||
} | ||
break; | ||
|
||
case NotifyCollectionChangedAction.Move: | ||
if (e.OldItems!.Count == 1) | ||
{ | ||
list.Move(e.OldStartingIndex, e.NewStartingIndex); | ||
} | ||
else | ||
{ | ||
T[] items = list.Skip(e.OldStartingIndex).Take(e.OldItems.Count).ToArray(); | ||
for (int i = 0; i < e.OldItems.Count; i++) | ||
{ | ||
list.RemoveAt(e.OldStartingIndex); | ||
} | ||
|
||
for (int i = 0; i < items.Length; i++) | ||
{ | ||
list.Insert(e.NewStartingIndex + i, items[i]); | ||
} | ||
} | ||
break; | ||
|
||
case NotifyCollectionChangedAction.Remove: | ||
for (int i = 0; i < e.OldItems!.Count; i++) | ||
list.RemoveAt(e.OldStartingIndex); | ||
break; | ||
|
||
case NotifyCollectionChangedAction.Replace: | ||
// remove | ||
for (int i = 0; i < e.OldItems!.Count; i++) | ||
{ | ||
list.RemoveAt(e.OldStartingIndex); | ||
} | ||
// add | ||
goto case NotifyCollectionChangedAction.Add; | ||
|
||
case NotifyCollectionChangedAction.Reset: | ||
list.Clear(); | ||
for (int i = 0; i < e.NewItems!.Count; i++) | ||
list.Add(converter(e.NewItems[i]!)); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.