Merge pull request #69761 from KoBeWi/where_undo
Add scope prefix to undo actions
This commit is contained in:
commit
1c5cfc4675
|
@ -2754,11 +2754,20 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
|
||||||
log->add_message(TTR("Can't undo while mouse buttons are pressed."), EditorLog::MSG_TYPE_EDITOR);
|
log->add_message(TTR("Can't undo while mouse buttons are pressed."), EditorLog::MSG_TYPE_EDITOR);
|
||||||
} else {
|
} else {
|
||||||
String action = editor_data.get_undo_redo()->get_current_action_name();
|
String action = editor_data.get_undo_redo()->get_current_action_name();
|
||||||
|
int id = editor_data.get_undo_redo()->get_current_action_history_id();
|
||||||
if (!editor_data.get_undo_redo()->undo()) {
|
if (!editor_data.get_undo_redo()->undo()) {
|
||||||
log->add_message(TTR("Nothing to undo."), EditorLog::MSG_TYPE_EDITOR);
|
log->add_message(TTR("Nothing to undo."), EditorLog::MSG_TYPE_EDITOR);
|
||||||
} else if (!action.is_empty()) {
|
} else if (!action.is_empty()) {
|
||||||
log->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
switch (id) {
|
||||||
|
case EditorUndoRedoManager::GLOBAL_HISTORY:
|
||||||
|
log->add_message(vformat(TTR("Global Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
||||||
|
break;
|
||||||
|
case EditorUndoRedoManager::REMOTE_HISTORY:
|
||||||
|
log->add_message(vformat(TTR("Remote Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log->add_message(vformat(TTR("Scene Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
@ -2770,7 +2779,20 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
|
||||||
log->add_message(TTR("Nothing to redo."), EditorLog::MSG_TYPE_EDITOR);
|
log->add_message(TTR("Nothing to redo."), EditorLog::MSG_TYPE_EDITOR);
|
||||||
} else {
|
} else {
|
||||||
String action = editor_data.get_undo_redo()->get_current_action_name();
|
String action = editor_data.get_undo_redo()->get_current_action_name();
|
||||||
log->add_message(vformat(TTR("Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
if (action.is_empty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (editor_data.get_undo_redo()->get_current_action_history_id()) {
|
||||||
|
case EditorUndoRedoManager::GLOBAL_HISTORY:
|
||||||
|
log->add_message(vformat(TTR("Global Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
||||||
|
break;
|
||||||
|
case EditorUndoRedoManager::REMOTE_HISTORY:
|
||||||
|
log->add_message(vformat(TTR("Remote Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log->add_message(vformat(TTR("Scene Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
|
@ -270,35 +270,9 @@ bool EditorUndoRedoManager::undo() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int selected_history = INVALID_HISTORY;
|
History *selected_history = _get_newest_undo();
|
||||||
double global_timestamp = 0;
|
if (selected_history) {
|
||||||
|
return undo_history(selected_history->id);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -427,33 +401,7 @@ void EditorUndoRedoManager::clear_history(bool p_increase_version, int p_idx) {
|
||||||
|
|
||||||
String EditorUndoRedoManager::get_current_action_name() {
|
String EditorUndoRedoManager::get_current_action_name() {
|
||||||
if (has_undo()) {
|
if (has_undo()) {
|
||||||
History *selected_history = nullptr;
|
History *selected_history = _get_newest_undo();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected_history) {
|
if (selected_history) {
|
||||||
return selected_history->undo_redo->get_current_action_name();
|
return selected_history->undo_redo->get_current_action_name();
|
||||||
}
|
}
|
||||||
|
@ -461,6 +409,16 @@ String EditorUndoRedoManager::get_current_action_name() {
|
||||||
return "";
|
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) {
|
void EditorUndoRedoManager::discard_history(int p_idx, bool p_erase_from_map) {
|
||||||
ERR_FAIL_COND(!history_map.has(p_idx));
|
ERR_FAIL_COND(!history_map.has(p_idx));
|
||||||
History &history = history_map[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() {
|
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("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));
|
ClassDB::bind_method(D_METHOD("commit_action", "execute"), &EditorUndoRedoManager::commit_action, DEFVAL(true));
|
||||||
|
|
|
@ -66,6 +66,8 @@ private:
|
||||||
|
|
||||||
bool is_committing = false;
|
bool is_committing = false;
|
||||||
|
|
||||||
|
History *_get_newest_undo();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
@ -127,6 +129,7 @@ public:
|
||||||
bool has_redo();
|
bool has_redo();
|
||||||
|
|
||||||
String get_current_action_name();
|
String get_current_action_name();
|
||||||
|
int get_current_action_history_id();
|
||||||
|
|
||||||
void discard_history(int p_idx, bool p_erase_from_map = true);
|
void discard_history(int p_idx, bool p_erase_from_map = true);
|
||||||
~EditorUndoRedoManager();
|
~EditorUndoRedoManager();
|
||||||
|
|
Loading…
Reference in New Issue