Merge pull request #69732 from KoBeWi/rc_undo
Add remote history to EditorUndoRedoManager
This commit is contained in:
commit
f3080459d9
4 changed files with 43 additions and 3 deletions
|
@ -123,6 +123,9 @@
|
|||
<constant name="GLOBAL_HISTORY" value="0" enum="SpecialHistory">
|
||||
Global history not associated with any scene, but with external resources etc.
|
||||
</constant>
|
||||
<constant name="REMOTE_HISTORY" value="-9" enum="SpecialHistory">
|
||||
History associated with remote inspector. Used when live editing a running project.
|
||||
</constant>
|
||||
<constant name="INVALID_HISTORY" value="-99" enum="SpecialHistory">
|
||||
Invalid "null" history. It's a special value, not associated with any object.
|
||||
</constant>
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "editor/editor_log.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "editor/editor_undo_redo_manager.h"
|
||||
#include "editor/inspector_dock.h"
|
||||
#include "editor/plugins/editor_debugger_plugin.h"
|
||||
#include "editor/plugins/script_editor_plugin.h"
|
||||
|
@ -274,6 +275,7 @@ void EditorDebuggerNode::stop(bool p_force) {
|
|||
});
|
||||
_break_state_changed();
|
||||
breakpoints.clear();
|
||||
EditorNode::get_undo_redo()->clear_history(false, EditorUndoRedoManager::REMOTE_HISTORY);
|
||||
set_process(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "core/io/resource.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "editor/debugger/editor_debugger_inspector.h"
|
||||
#include "editor/debugger/editor_debugger_node.h"
|
||||
#include "editor/editor_log.h"
|
||||
#include "editor/editor_node.h"
|
||||
|
@ -59,6 +60,10 @@ UndoRedo *EditorUndoRedoManager::get_history_undo_redo(int p_idx) const {
|
|||
int EditorUndoRedoManager::get_history_id_for_object(Object *p_object) const {
|
||||
int history_id = INVALID_HISTORY;
|
||||
|
||||
if (Object::cast_to<EditorDebuggerRemoteObject>(p_object)) {
|
||||
return REMOTE_HISTORY;
|
||||
}
|
||||
|
||||
if (Node *node = Object::cast_to<Node>(p_object)) {
|
||||
Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
|
||||
|
||||
|
@ -277,6 +282,14 @@ bool EditorUndoRedoManager::undo() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
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) {
|
||||
|
@ -322,6 +335,14 @@ bool EditorUndoRedoManager::redo() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
History &history = get_or_create_history(REMOTE_HISTORY);
|
||||
if (!history.redo_stack.is_empty() && history.redo_stack.back()->get().timestamp < global_timestamp) {
|
||||
selected_history = history.id;
|
||||
global_timestamp = history.redo_stack.back()->get().timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
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) {
|
||||
|
@ -367,7 +388,7 @@ bool EditorUndoRedoManager::is_history_unsaved(int p_id) {
|
|||
|
||||
bool EditorUndoRedoManager::has_undo() {
|
||||
for (const KeyValue<int, History> &E : history_map) {
|
||||
if ((E.key == GLOBAL_HISTORY || E.key == EditorNode::get_editor_data().get_current_edited_scene_history_id()) && !E.value.undo_stack.is_empty()) {
|
||||
if ((E.key == GLOBAL_HISTORY || E.key == REMOTE_HISTORY || E.key == EditorNode::get_editor_data().get_current_edited_scene_history_id()) && !E.value.undo_stack.is_empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +397,7 @@ bool EditorUndoRedoManager::has_undo() {
|
|||
|
||||
bool EditorUndoRedoManager::has_redo() {
|
||||
for (const KeyValue<int, History> &E : history_map) {
|
||||
if ((E.key == GLOBAL_HISTORY || E.key == EditorNode::get_editor_data().get_current_edited_scene_history_id()) && !E.value.redo_stack.is_empty()) {
|
||||
if ((E.key == GLOBAL_HISTORY || E.key == REMOTE_HISTORY || E.key == EditorNode::get_editor_data().get_current_edited_scene_history_id()) && !E.value.redo_stack.is_empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +406,11 @@ bool EditorUndoRedoManager::has_redo() {
|
|||
|
||||
void EditorUndoRedoManager::clear_history(bool p_increase_version, int p_idx) {
|
||||
if (p_idx != INVALID_HISTORY) {
|
||||
get_or_create_history(p_idx).undo_redo->clear_history(p_increase_version);
|
||||
History &history = get_or_create_history(p_idx);
|
||||
history.undo_redo->clear_history(p_increase_version);
|
||||
history.undo_stack.clear();
|
||||
history.redo_stack.clear();
|
||||
|
||||
if (!p_increase_version) {
|
||||
set_history_as_saved(p_idx);
|
||||
}
|
||||
|
@ -414,6 +439,14 @@ String EditorUndoRedoManager::get_current_action_name() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
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) {
|
||||
|
@ -477,6 +510,7 @@ void EditorUndoRedoManager::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo("version_changed"));
|
||||
|
||||
BIND_ENUM_CONSTANT(GLOBAL_HISTORY);
|
||||
BIND_ENUM_CONSTANT(REMOTE_HISTORY);
|
||||
BIND_ENUM_CONSTANT(INVALID_HISTORY);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ class EditorUndoRedoManager : public RefCounted {
|
|||
public:
|
||||
enum SpecialHistory {
|
||||
GLOBAL_HISTORY = 0,
|
||||
REMOTE_HISTORY = -9,
|
||||
INVALID_HISTORY = -99,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue