Struct redo::RedoGroup
[−]
[src]
pub struct RedoGroup<'a, T> { /* fields omitted */ }
A collection of RedoStack
s.
A RedoGroup
is useful when working with multiple stacks and only one of them should
be active at a given time, eg. a text editor with multiple documents opened. However, if only
a single stack is needed, it is easier to just use the stack directly.
Methods
impl<'a, T> RedoGroup<'a, T>
[src]
fn new() -> RedoGroup<'a, T>
fn with_capacity(capacity: usize) -> RedoGroup<'a, T>
Creates a new RedoGroup
with the specified capacity.
Examples
let group = RedoGroup::<PopCmd>::with_capacity(10); assert!(group.capacity() >= 10);
fn capacity(&self) -> usize
Returns the capacity of the RedoGroup
.
Examples
let group = RedoGroup::<PopCmd>::with_capacity(10); assert!(group.capacity() >= 10);
fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more stacks to be inserted in the given group.
The group may reserve more space to avoid frequent reallocations.
Panics
Panics if the new capacity overflows usize.
Examples
let mut group = RedoGroup::<PopCmd>::new(); group.add_default(); group.reserve(10); assert!(group.capacity() >= 11);
fn shrink_to_fit(&mut self)
Shrinks the capacity of the RedoGroup
as much as possible.
Examples
let mut group = RedoGroup::<PopCmd>::with_capacity(10); group.add_default(); group.add_default(); group.add_default(); assert!(group.capacity() >= 10); group.shrink_to_fit(); assert!(group.capacity() >= 3);
fn add(&mut self, stack: RedoStack<'a, T>) -> Key
Adds an RedoStack
to the group and returns an unique id for this stack.
Examples
let mut group = RedoGroup::<PopCmd>::new(); let a = group.add_default(); let b = group.add_default(); let c = group.add_default();
fn remove(&mut self, key: Key) -> Option<RedoStack<'a, T>>
Removes the RedoStack
with the specified id and returns the stack.
Returns None
if the stack was not found.
Examples
let mut group = RedoGroup::<PopCmd>::new(); let a = group.add_default(); let stack = group.remove(a); assert!(stack.is_some());
fn set_active(&mut self, key: Key)
Sets the RedoStack
with the specified id as the current active one.
Examples
let mut group = RedoGroup::<PopCmd>::new(); let a = group.add_default(); group.set_active(a);
fn clear_active(&mut self)
Clears the current active RedoStack
.
Examples
let mut group = RedoGroup::<PopCmd>::new(); let a = group.add_default(); group.set_active(a); group.clear_active();
fn is_clean(&self) -> Option<bool>
Calls is_clean
on the active RedoStack
, if there is one.
Returns None
if there is no active stack.
Examples
let mut vec = vec![1, 2, 3]; let mut group = RedoGroup::new(); let cmd = PopCmd { vec: &mut vec, e: None }; let a = group.add(RedoStack::new()); assert_eq!(group.is_clean(), None); group.set_active(a); assert_eq!(group.is_clean(), Some(true)); // An empty stack is always clean. group.push(cmd); assert_eq!(group.is_clean(), Some(true)); group.undo(); assert_eq!(group.is_clean(), Some(false));
fn is_dirty(&self) -> Option<bool>
Calls is_dirty
on the active RedoStack
, if there is one.
Returns None
if there is no active stack.
Examples
let mut vec = vec![1, 2, 3]; let mut group = RedoGroup::new(); let cmd = PopCmd { vec: &mut vec, e: None }; let a = group.add(RedoStack::new()); assert_eq!(group.is_dirty(), None); group.set_active(a); assert_eq!(group.is_dirty(), Some(false)); // An empty stack is always clean. group.push(cmd); assert_eq!(group.is_dirty(), Some(false)); group.undo(); assert_eq!(group.is_dirty(), Some(true));
impl<'a, T: RedoCmd> RedoGroup<'a, T>
[src]
fn push(&mut self, cmd: T) -> Option<Result<T::Err>>
Calls push
on the active RedoStack
, if there is one.
Returns Some(Ok)
if everything went fine, Some(Err)
if something went wrong, and None
if there is no active stack.
Examples
let mut vec = vec![1, 2, 3]; let mut group = RedoGroup::new(); let cmd = PopCmd { vec: &mut vec, e: None }; let a = group.add(RedoStack::new()); group.set_active(a); group.push(cmd); group.push(cmd); group.push(cmd); assert!(vec.is_empty());
fn redo(&mut self) -> Option<Result<T::Err>>
Calls redo
on the active RedoStack
, if there is one.
Returns Some(Ok)
if everything went fine, Some(Err)
if something went wrong, and None
if there is no active stack.
Examples
let mut vec = vec![1, 2, 3]; let mut group = RedoGroup::new(); let cmd = PopCmd { vec: &mut vec, e: None }; let a = group.add(RedoStack::new()); group.set_active(a); group.push(cmd); group.push(cmd); group.push(cmd); assert!(vec.is_empty()); group.undo(); group.undo(); group.undo(); assert_eq!(vec, vec![1, 2, 3]); group.redo(); group.redo(); group.redo(); assert!(vec.is_empty());
fn undo(&mut self) -> Option<Result<T::Err>>
Calls undo
on the active RedoStack
, if there is one.
Returns Some(Ok)
if everything went fine, Some(Err)
if something went wrong, and None
if there is no active stack.
Examples
let mut vec = vec![1, 2, 3]; let mut group = RedoGroup::new(); let cmd = PopCmd { vec: &mut vec, e: None }; let a = group.add(RedoStack::new()); group.set_active(a); group.push(cmd); group.push(cmd); group.push(cmd); assert!(vec.is_empty()); group.undo(); group.undo(); group.undo(); assert_eq!(vec, vec![1, 2, 3]);
impl<'a, T: Default> RedoGroup<'a, T>
[src]
fn add_default(&mut self) -> Key
Adds a default RedoStack
to the group and returns an unique id for this stack.
Examples
let mut group = RedoGroup::<PopCmd>::new(); let a = group.add_default(); let b = group.add_default(); let c = group.add_default();