public IObservable <Unit> Clear()
 {
     UpdateSubjects(true);
     StackRedo.Clear();
     StackUndo.Clear();
     UpdateSubjects();
     return(Observables.Unit);
 }
        public void Dispose()
        {
            StackRedo.Clear();
            StackUndo.Clear();

            _canUndo.Dispose();
            _canRedo.Dispose();
            _canClear.Dispose();
            _canRecord.Dispose();
        }
 public IObservable <HistoryEntry> Record(HistoryEntry entry, Func <HistoryEntry, IObservable <HistoryEntry> > execute)
 {
     StackRedo.Clear();
     UpdateSubjects(true);
     return(execute(entry).Do(updatedEntry =>
     {
         StackUndo.Push(updatedEntry);
         UpdateSubjects();
     }));
 }
        public IObservable <HistoryEntry> Redo(Func <HistoryEntry, IObservable <HistoryEntry> > execute)
        {
            if (StackRedo.Count == 0)
            {
                throw new Exception();
            }

            UpdateSubjects(true);
            return(execute(StackRedo.Pop()).Do(entry =>
            {
                StackUndo.Push(entry);
                UpdateSubjects();
            }));
        }
        private void UpdateSubjects(bool disableAll = false)
        {
            if (disableAll)
            {
                _canUndo.OnNext(false);
                _canRedo.OnNext(false);
                _canClear.OnNext(false);
                _canRecord.OnNext(false);
            }
            else
            {
                var hasUndoEntries = StackUndo.Any();
                var hasRedoEntries = StackRedo.Any();

                _canUndo.OnNext(hasUndoEntries);
                _canRedo.OnNext(hasRedoEntries);
                _canClear.OnNext(hasUndoEntries || hasRedoEntries);
                _canRecord.OnNext(true);
            }
        }