|
@@ -270,35 +270,9 @@ bool EditorUndoRedoManager::undo() {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- int selected_history = INVALID_HISTORY;
|
|
|
- double global_timestamp = 0;
|
|
|
-
|
|
|
- // Pick the history with greatest last action timestamp (either global or current scene).
|
|
|
- {
|
|
|
- History &history = get_or_create_history(GLOBAL_HISTORY);
|
|
|
- if (!history.undo_stack.is_empty()) {
|
|
|
- selected_history = history.id;
|
|
|
- global_timestamp = history.undo_stack.back()->get().timestamp;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- History &history = get_or_create_history(REMOTE_HISTORY);
|
|
|
- if (!history.undo_stack.is_empty() && history.undo_stack.back()->get().timestamp > global_timestamp) {
|
|
|
- selected_history = history.id;
|
|
|
- global_timestamp = history.undo_stack.back()->get().timestamp;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- History &history = get_or_create_history(EditorNode::get_editor_data().get_current_edited_scene_history_id());
|
|
|
- if (!history.undo_stack.is_empty() && history.undo_stack.back()->get().timestamp > global_timestamp) {
|
|
|
- selected_history = history.id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (selected_history != INVALID_HISTORY) {
|
|
|
- return undo_history(selected_history);
|
|
|
+ History *selected_history = _get_newest_undo();
|
|
|
+ if (selected_history) {
|
|
|
+ return undo_history(selected_history->id);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -427,33 +401,7 @@ void EditorUndoRedoManager::clear_history(bool p_increase_version, int p_idx) {
|
|
|
|
|
|
String EditorUndoRedoManager::get_current_action_name() {
|
|
|
if (has_undo()) {
|
|
|
- History *selected_history = nullptr;
|
|
|
- double global_timestamp = 0;
|
|
|
-
|
|
|
- // Pick the history with greatest last action timestamp (either global or current scene).
|
|
|
- {
|
|
|
- History &history = get_or_create_history(GLOBAL_HISTORY);
|
|
|
- if (!history.undo_stack.is_empty()) {
|
|
|
- selected_history = &history;
|
|
|
- global_timestamp = history.undo_stack.back()->get().timestamp;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- History &history = get_or_create_history(REMOTE_HISTORY);
|
|
|
- if (!history.undo_stack.is_empty() && history.undo_stack.back()->get().timestamp > global_timestamp) {
|
|
|
- selected_history = &history;
|
|
|
- global_timestamp = history.undo_stack.back()->get().timestamp;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- {
|
|
|
- History &history = get_or_create_history(EditorNode::get_editor_data().get_current_edited_scene_history_id());
|
|
|
- if (!history.undo_stack.is_empty() && history.undo_stack.back()->get().timestamp > global_timestamp) {
|
|
|
- selected_history = &history;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ History *selected_history = _get_newest_undo();
|
|
|
if (selected_history) {
|
|
|
return selected_history->undo_redo->get_current_action_name();
|
|
|
}
|
|
@@ -461,6 +409,16 @@ String EditorUndoRedoManager::get_current_action_name() {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
+int EditorUndoRedoManager::get_current_action_history_id() {
|
|
|
+ if (has_undo()) {
|
|
|
+ History *selected_history = _get_newest_undo();
|
|
|
+ if (selected_history) {
|
|
|
+ return selected_history->id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return INVALID_HISTORY;
|
|
|
+}
|
|
|
+
|
|
|
void EditorUndoRedoManager::discard_history(int p_idx, bool p_erase_from_map) {
|
|
|
ERR_FAIL_COND(!history_map.has(p_idx));
|
|
|
History &history = history_map[p_idx];
|
|
@@ -475,6 +433,37 @@ void EditorUndoRedoManager::discard_history(int p_idx, bool p_erase_from_map) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+EditorUndoRedoManager::History *EditorUndoRedoManager::_get_newest_undo() {
|
|
|
+ History *selected_history = nullptr;
|
|
|
+ double global_timestamp = 0;
|
|
|
+
|
|
|
+ // Pick the history with greatest last action timestamp (either global or current scene).
|
|
|
+ {
|
|
|
+ History &history = get_or_create_history(GLOBAL_HISTORY);
|
|
|
+ if (!history.undo_stack.is_empty()) {
|
|
|
+ selected_history = &history;
|
|
|
+ global_timestamp = history.undo_stack.back()->get().timestamp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ History &history = get_or_create_history(REMOTE_HISTORY);
|
|
|
+ if (!history.undo_stack.is_empty() && history.undo_stack.back()->get().timestamp > global_timestamp) {
|
|
|
+ selected_history = &history;
|
|
|
+ global_timestamp = history.undo_stack.back()->get().timestamp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ History &history = get_or_create_history(EditorNode::get_editor_data().get_current_edited_scene_history_id());
|
|
|
+ if (!history.undo_stack.is_empty() && history.undo_stack.back()->get().timestamp > global_timestamp) {
|
|
|
+ selected_history = &history;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return selected_history;
|
|
|
+}
|
|
|
+
|
|
|
void EditorUndoRedoManager::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("create_action", "name", "merge_mode", "custom_context"), &EditorUndoRedoManager::create_action, DEFVAL(UndoRedo::MERGE_DISABLE), DEFVAL((Object *)nullptr));
|
|
|
ClassDB::bind_method(D_METHOD("commit_action", "execute"), &EditorUndoRedoManager::commit_action, DEFVAL(true));
|