Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions LemonUI/Menus/ItemModifiedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace LemonUI.Menus
{
/// <summary>
/// Represents the addition or removal of an item in a list.
/// </summary>
/// <typeparam name="T">The type of object that was modified.</typeparam>
public class ItemModifiedEventArgs<T>
{
#region Properties

/// <summary>
/// The item that was added or removed.
/// </summary>
public T Item { get; }

Check warning on line 15 in LemonUI/Menus/ItemModifiedEventArgs.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 15 in LemonUI/Menus/ItemModifiedEventArgs.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

/// <summary>
/// The position where the item was added or removed.
/// </summary>
public int Position { get; }

#endregion

#region Constructors

/// <summary>
/// Creates a new instance of <see cref="ItemModifiedEventArgs{T}"/>.
/// </summary>
/// <param name="item">The item that was added or removed.</param>
/// <param name="position">The position where the item was added or removed.</param>
public ItemModifiedEventArgs(T item, int position)
{
Item = item;
Position = position;
}

#endregion
}
}
10 changes: 10 additions & 0 deletions LemonUI/Menus/ItemModifiedEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace LemonUI.Menus
{
/// <summary>
/// Represents the method that is called when an item is added to or removed from a List Item.
/// </summary>
/// <typeparam name="T">The type of item that was modified.</typeparam>
/// <param name="sender">The source of the event.</param>
/// <param name="e">A <see cref="ItemModifiedEventArgs{T}"/> with the information of the modified item.</param>
public delegate void ItemModifiedEventHandler<T>(object sender, ItemModifiedEventArgs<T> e);
}
33 changes: 30 additions & 3 deletions LemonUI/Menus/NativeListItem{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
/// Event triggered when the selected item is changed.
/// </summary>
public event ItemChangedEventHandler<T> ItemChanged;

Check warning on line 106 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 106 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

/// <summary>
/// Event triggered when an item is added to the list.
/// </summary>
public event ItemModifiedEventHandler<T> ItemAdded;

Check warning on line 111 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 111 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

/// <summary>
/// Event triggered when an item is removed from the list.
/// </summary>
public event ItemModifiedEventHandler<T> ItemRemoved;

#endregion

Expand Down Expand Up @@ -202,18 +212,30 @@
{
UpdateIndex();
}

Check warning on line 215 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 215 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

// Trigger the ItemAdded event
ItemAdded?.Invoke(this, new ItemModifiedEventArgs<T>(item, position));
}

Check warning on line 219 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 219 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

/// <summary>
/// Removes a specific <typeparamref name="T" />.
/// </summary>
/// <param name="item">The <typeparamref name="T" /> to remove.</param>
public void Remove(T item)
{
if (items.Remove(item))
int position = items.IndexOf(item);
if (position >= 0)
{
FixIndexIfRequired();
T removedItem = items[position];
if (items.Remove(item))
{
FixIndexIfRequired();
// Trigger the ItemRemoved event
ItemRemoved?.Invoke(this, new ItemModifiedEventArgs<T>(removedItem, position));
}
}
}

Check warning on line 238 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 238 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

/// <summary>
/// Removes a <typeparamref name="T" /> at a specific location.
/// </summary>
Expand All @@ -224,11 +246,16 @@
{
return;
}


Check warning on line 249 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 249 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

T removedItem = items[position];
items.RemoveAt(position);
FixIndexIfRequired();
UpdateIndex();

Check warning on line 254 in LemonUI/Menus/NativeListItem{T}.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

// Trigger the ItemRemoved event
ItemRemoved?.Invoke(this, new ItemModifiedEventArgs<T>(removedItem, position));
}

/// <summary>
/// Removes all of the items that match the <paramref name="pred"/>.
/// </summary>
Expand Down
Loading