+void
+Editor::begin_selection_op_history ()
+{
+ selection_op_cmd_depth = 0;
+ selection_op_history_it = 0;
+
+ while(!selection_op_history.empty()) {
+ delete selection_op_history.front();
+ selection_op_history.pop_front();
+ }
+
+ selection_undo_action->set_sensitive (false);
+ selection_redo_action->set_sensitive (false);
+ selection_op_history.push_front (&_selection_memento->get_state ());
+}
+
+void
+Editor::begin_reversible_selection_op (string name)
+{
+ if (_session) {
+ //cerr << name << endl;
+ /* begin/commit pairs can be nested */
+ selection_op_cmd_depth++;
+ }
+}
+
+void
+Editor::commit_reversible_selection_op ()
+{
+ if (_session) {
+ if (selection_op_cmd_depth == 1) {
+
+ if (selection_op_history_it > 0 && selection_op_history_it < selection_op_history.size()) {
+ /**
+ The user has undone some selection ops and then made a new one,
+ making anything earlier in the list invalid.
+ */
+
+ list<XMLNode *>::iterator it = selection_op_history.begin();
+ list<XMLNode *>::iterator e_it = it;
+ advance (e_it, selection_op_history_it);
+
+ for ( ; it != e_it; ++it) {
+ delete *it;
+ }
+ selection_op_history.erase (selection_op_history.begin(), e_it);
+ }
+
+ selection_op_history.push_front (&_selection_memento->get_state ());
+ selection_op_history_it = 0;
+
+ selection_undo_action->set_sensitive (true);
+ selection_redo_action->set_sensitive (false);
+ }
+
+ if (selection_op_cmd_depth > 0) {
+ selection_op_cmd_depth--;
+ }
+ }
+}
+
+void
+Editor::undo_selection_op ()
+{
+ if (_session) {
+ selection_op_history_it++;
+ uint32_t n = 0;
+ for (std::list<XMLNode *>::iterator i = selection_op_history.begin(); i != selection_op_history.end(); ++i) {
+ if (n == selection_op_history_it) {
+ _selection_memento->set_state (*(*i), Stateful::current_state_version);
+ selection_redo_action->set_sensitive (true);
+ }
+ ++n;
+ }
+ /* is there an earlier entry? */
+ if ((selection_op_history_it + 1) >= selection_op_history.size()) {
+ selection_undo_action->set_sensitive (false);
+ }
+ }
+}
+
+void
+Editor::redo_selection_op ()
+{
+ if (_session) {
+ if (selection_op_history_it > 0) {
+ selection_op_history_it--;
+ }
+ uint32_t n = 0;
+ for (std::list<XMLNode *>::iterator i = selection_op_history.begin(); i != selection_op_history.end(); ++i) {
+ if (n == selection_op_history_it) {
+ _selection_memento->set_state (*(*i), Stateful::current_state_version);
+ selection_undo_action->set_sensitive (true);
+ }
+ ++n;
+ }
+
+ if (selection_op_history_it == 0) {
+ selection_redo_action->set_sensitive (false);
+ }
+ }
+}
+