Skip to content

SelectionHistoryBuffer

Namespace: SideXP.Selection

public class SelectionHistoryBuffer

Ordered list of selection snapshots, with a cursor on the current one. Works like a web browser history: adding a snapshot after going back discards the "forward" entries.

Fields

DefaultMaxCount

public const int DefaultMaxCount = 50

The default maximum number of entries in the history.

Properties

Entries

public IReadOnlyList<SelectionSnapshot> Entries

The entries of the history, from the oldest to the most recent.

Count

public int Count

The number of entries in the history.

CurrentIndex

public int CurrentIndex

The index of the current entry, or -1 if the history is empty.

Current

public SelectionSnapshot Current

The current entry, or null if the history is empty.

MaxCount

public int MaxCount

The maximum number of entries in the history. The oldest entries are discarded when this limit is exceeded.

Remarks

Can't be lower than 1. Setting a lower value than the current number of entries discards the oldest ones.

Methods

Push(SelectionSnapshot)

public bool Push(SelectionSnapshot snapshot)

Adds a snapshot after the current entry, and makes it the current one. The entries after the current one are discarded.

Parameters

  • snapshot: The snapshot to add.

Returns

Returns true if the snapshot has been added, or false if it matches the current entry.

Exceptions

  • ArgumentNullException: Thrown if the given snapshot is null.

FindTarget(int)

public int FindTarget(int steps)

Finds the entry to move to when going back or forward from the current entry. Entries that can't be resolved are skipped.

Parameters

  • steps: The number of entries to move by. Negative values go back, positive values go forward.

Returns

Returns the index of the found entry. If there are fewer valid entries than the given number of steps, returns the furthest valid entry in that direction. Returns -1 if there's no valid entry in that direction.

SetCurrentIndex(int)

public bool SetCurrentIndex(int index)

Makes the entry at the given index the current one.

Parameters

  • index: The index of the entry.

Returns

Returns true if the current entry has changed, or false if the index is out of range.

Clear()

public void Clear()

Removes all the entries.

Clean()

public bool Clean()

Removes the objects that don't exist anymore from the entries, and the entries that become empty. If the current entry is removed, the previous remaining entry becomes the current one.

Returns

Returns true if at least one object or entry has been removed.

Remarks

The objects that don't have a stable id but are still resolved are refreshed, so they get one if possible (for example, an object selected in play mode that also exists in edit mode).

Refresh()

public void Refresh()

Captures again the identifiers of the objects that are still alive in all the entries.

Returns

Returns true if the identifiers have been captured again.

Remarks

Does nothing in play mode, so the stable ids captured in edit mode are not lost.