void UndoRedo::clear_history() { ERR_FAIL_COND(action_level > 0); _discard_redo(); while (actions.size()) _pop_history_tail(); //version++; }
void UndoRedo::clear_history(bool p_increase_version) { ERR_FAIL_COND(action_level > 0); _discard_redo(); while (actions.size()) _pop_history_tail(); if (p_increase_version) version++; }
void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { uint32_t ticks = OS::get_singleton()->get_ticks_msec(); if (action_level == 0) { _discard_redo(); // Check if the merge operation is valid if (p_mode != MERGE_DISABLE && actions.size() && actions[actions.size() - 1].name == p_name && actions[actions.size() - 1].last_tick + 800 > ticks) { current_action = actions.size() - 2; if (p_mode == MERGE_ENDS) { // Clear all do ops from last action, and delete all object references List<Operation>::Element *E = actions[current_action + 1].do_ops.front(); while (E) { if (E->get().type == Operation::TYPE_REFERENCE) { Object *obj = ObjectDB::get_instance(E->get().object); if (obj) memdelete(obj); } E = E->next(); actions[current_action + 1].do_ops.pop_front(); } } actions[actions.size() - 1].last_tick = ticks; merge_mode = p_mode; } else { Action new_action; new_action.name = p_name; new_action.last_tick = ticks; actions.push_back(new_action); merge_mode = MERGE_DISABLE; } } action_level++; }
void UndoRedo::_pop_history_tail() { _discard_redo(); if (!actions.size()) return; for (List<Operation>::Element *E = actions[0].undo_ops.front(); E; E = E->next()) { if (E->get().type == Operation::TYPE_REFERENCE) { Object *obj = ObjectDB::get_instance(E->get().object); if (obj) memdelete(obj); } } actions.remove(0); current_action--; }
void UndoRedo::create_action(const String& p_name,bool p_mergeable) { if (action_level==0) { _discard_redo(); if (p_mergeable && actions.size() && actions[actions.size()-1].name==p_name) { //old will replace new (it's mergeable after all) // should check references though! current_action=actions.size()-2; actions[current_action+1].do_ops.clear(); //actions[current_action+1].undo_ops.clear(); - no, this is kept merging=true; } else { Action new_action; new_action.name=p_name; actions.push_back(new_action); merging=false; } } action_level++; }