Merge pull request #65012 from KoBeWi/Godot_museum

Add history dock
This commit is contained in:
Rémi Verschelde
2022-11-02 18:52:42 +01:00
6 changed files with 387 additions and 17 deletions

View File

@@ -241,6 +241,7 @@ void EditorUndoRedoManager::commit_action(bool p_execute) {
history.undo_stack.push_back(pending_action);
pending_action = Action();
is_committing = false;
emit_signal(SNAME("history_changed"));
}
bool EditorUndoRedoManager::is_committing_action() const {
@@ -252,14 +253,14 @@ bool EditorUndoRedoManager::undo() {
return false;
}
History *selected_history = nullptr;
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;
selected_history = history.id;
global_timestamp = history.undo_stack.back()->get().timestamp;
}
}
@@ -267,32 +268,44 @@ bool EditorUndoRedoManager::undo() {
{
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;
selected_history = history.id;
}
}
if (selected_history) {
Action action = selected_history->undo_stack.back()->get();
selected_history->undo_stack.pop_back();
selected_history->redo_stack.push_back(action);
return selected_history->undo_redo->undo();
if (selected_history != INVALID_HISTORY) {
return undo_history(selected_history);
}
return false;
}
bool EditorUndoRedoManager::undo_history(int p_id) {
ERR_FAIL_COND_V(p_id == INVALID_HISTORY, false);
History &history = get_or_create_history(p_id);
Action action = history.undo_stack.back()->get();
history.undo_stack.pop_back();
history.redo_stack.push_back(action);
bool success = history.undo_redo->undo();
if (success) {
emit_signal(SNAME("version_changed"));
}
return success;
}
bool EditorUndoRedoManager::redo() {
if (!has_redo()) {
return false;
}
History *selected_history = nullptr;
int selected_history = INVALID_HISTORY;
double global_timestamp = INFINITY;
// Pick the history with lowest last action timestamp (either global or current scene).
{
History &history = get_or_create_history(GLOBAL_HISTORY);
if (!history.redo_stack.is_empty()) {
selected_history = &history;
selected_history = history.id;
global_timestamp = history.redo_stack.back()->get().timestamp;
}
}
@@ -300,19 +313,31 @@ bool EditorUndoRedoManager::redo() {
{
History &history = get_or_create_history(EditorNode::get_editor_data().get_current_edited_scene_history_id());
if (!history.redo_stack.is_empty() && history.redo_stack.back()->get().timestamp < global_timestamp) {
selected_history = &history;
selected_history = history.id;
}
}
if (selected_history) {
Action action = selected_history->redo_stack.back()->get();
selected_history->redo_stack.pop_back();
selected_history->undo_stack.push_back(action);
return selected_history->undo_redo->redo();
if (selected_history != INVALID_HISTORY) {
return redo_history(selected_history);
}
return false;
}
bool EditorUndoRedoManager::redo_history(int p_id) {
ERR_FAIL_COND_V(p_id == INVALID_HISTORY, false);
History &history = get_or_create_history(p_id);
Action action = history.redo_stack.back()->get();
history.redo_stack.pop_back();
history.undo_stack.push_back(action);
bool success = history.undo_redo->redo();
if (success) {
emit_signal(SNAME("version_changed"));
}
return success;
}
void EditorUndoRedoManager::set_history_as_saved(int p_id) {
History &history = get_or_create_history(p_id);
history.saved_version = history.undo_redo->get_version();
@@ -352,6 +377,7 @@ void EditorUndoRedoManager::clear_history(bool p_increase_version, int p_idx) {
if (!p_increase_version) {
set_history_as_saved(p_idx);
}
emit_signal(SNAME("history_changed"));
return;
}
@@ -359,6 +385,7 @@ void EditorUndoRedoManager::clear_history(bool p_increase_version, int p_idx) {
E.value.undo_redo->clear_history(p_increase_version);
set_history_as_saved(E.key);
}
emit_signal(SNAME("history_changed"));
}
String EditorUndoRedoManager::get_current_action_name() {
@@ -434,6 +461,9 @@ void EditorUndoRedoManager::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_object_history_id", "object"), &EditorUndoRedoManager::get_history_id_for_object);
ClassDB::bind_method(D_METHOD("get_history_undo_redo", "id"), &EditorUndoRedoManager::get_history_undo_redo);
ADD_SIGNAL(MethodInfo("history_changed"));
ADD_SIGNAL(MethodInfo("version_changed"));
BIND_ENUM_CONSTANT(GLOBAL_HISTORY);
BIND_ENUM_CONSTANT(INVALID_HISTORY);
}