-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add per-scene UndoRedo #59564
Merged
akien-mga
merged 1 commit into
godotengine:master
from
KoBeWi:FINALLY,_ULTIMATE_UNDO_REDO
Aug 22, 2022
Merged
Add per-scene UndoRedo #59564
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<class name="EditorUndoRedoManager" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> | ||
<brief_description> | ||
Manages undo history of scenes opened in the editor. | ||
</brief_description> | ||
<description> | ||
[EditorUndoRedoManager] is a manager for [UndoRedo] objects associated with edited scenes. Each scene has its own undo history and [EditorUndoRedoManager] ensures that each action performed in the editor gets associated with a proper scene. For actions not related to scenes ([ProjectSettings] edits, external resources, etc.), a separate global history is used. | ||
The usage is mostly the same as [UndoRedo]. You create and commit actions and the manager automatically decides under-the-hood what scenes it belongs to. The scene is deduced based on the first operation in an action, using the object from the operation. The rules are as follows: | ||
- If the object is a [Node], use the currently edited scene; | ||
- If the object is a built-in resource, use the scene from its path; | ||
- If the object is external resource or anything else, use global history. | ||
This guessing can sometimes yield false results, so you can provide a custom context object when creating an action. | ||
</description> | ||
<tutorials> | ||
</tutorials> | ||
<methods> | ||
<method name="add_do_method" qualifiers="vararg"> | ||
<return type="void" /> | ||
<param index="0" name="object" type="Object" /> | ||
<param index="1" name="method" type="StringName" /> | ||
<description> | ||
Register a method that will be called when the action is committed (i.e. the "do" action). | ||
If this is the first operation, the [param object] will be used to deduce target undo history. | ||
</description> | ||
</method> | ||
<method name="add_do_property"> | ||
<return type="void" /> | ||
<param index="0" name="object" type="Object" /> | ||
<param index="1" name="property" type="StringName" /> | ||
<param index="2" name="value" type="Variant" /> | ||
<description> | ||
Register a property value change for "do". | ||
If this is the first operation, the [param object] will be used to deduce target undo history. | ||
</description> | ||
</method> | ||
<method name="add_do_reference"> | ||
<return type="void" /> | ||
<param index="0" name="object" type="Object" /> | ||
<description> | ||
Register a reference for "do" that will be erased if the "do" history is lost. This is useful mostly for new nodes created for the "do" call. Do not use for resources. | ||
</description> | ||
</method> | ||
<method name="add_undo_method" qualifiers="vararg"> | ||
<return type="void" /> | ||
<param index="0" name="object" type="Object" /> | ||
<param index="1" name="method" type="StringName" /> | ||
<description> | ||
Register a method that will be called when the action is undone (i.e. the "undo" action). | ||
If this is the first operation, the [param object] will be used to deduce target undo history. | ||
</description> | ||
</method> | ||
<method name="add_undo_property"> | ||
<return type="void" /> | ||
<param index="0" name="object" type="Object" /> | ||
<param index="1" name="property" type="StringName" /> | ||
<param index="2" name="value" type="Variant" /> | ||
<description> | ||
Register a property value change for "undo". | ||
If this is the first operation, the [param object] will be used to deduce target undo history. | ||
</description> | ||
</method> | ||
<method name="add_undo_reference"> | ||
<return type="void" /> | ||
<param index="0" name="object" type="Object" /> | ||
<description> | ||
Register a reference for "undo" that will be erased if the "undo" history is lost. This is useful mostly for nodes removed with the "do" call (not the "undo" call!). | ||
</description> | ||
</method> | ||
<method name="commit_action"> | ||
<return type="void" /> | ||
<param index="0" name="execute" type="bool" default="true" /> | ||
<description> | ||
Commit the action. If [param execute] is true (default), all "do" methods/properties are called/set when this function is called. | ||
</description> | ||
</method> | ||
<method name="create_action"> | ||
<return type="void" /> | ||
<param index="0" name="name" type="String" /> | ||
<param index="1" name="merge_mode" type="int" enum="UndoRedo.MergeMode" default="0" /> | ||
<param index="2" name="custom_context" type="Object" default="null" /> | ||
<description> | ||
Create a new action. After this is called, do all your calls to [method add_do_method], [method add_undo_method], [method add_do_property], and [method add_undo_property], then commit the action with [method commit_action]. | ||
The way actions are merged is dictated by the [param merge_mode] argument. See [enum UndoRedo.MergeMode] for details. | ||
If [param custom_context] object is provided, it will be used for deducing target history (instead of using the first operation). | ||
</description> | ||
</method> | ||
<method name="get_history_undo_redo" qualifiers="const"> | ||
<return type="UndoRedo" /> | ||
<param index="0" name="id" type="int" /> | ||
<description> | ||
Returns the [UndoRedo] object associated with the given history [param id]. | ||
[param id] above [code]0[/code] are mapped to the opened scene tabs (but it doesn't match their order). [param id] of [code]0[/code] or lower have special meaning (see [enum SpecialHistory]). | ||
Best used with [method get_object_history_id]. This method is only provided in case you need some more advanced methods of [UndoRedo] (but keep in mind that directly operating on the [UndoRedo] object might affect editor's stability). | ||
</description> | ||
</method> | ||
<method name="get_object_history_id" qualifiers="const"> | ||
<return type="int" /> | ||
<param index="0" name="object" type="Object" /> | ||
<description> | ||
Returns the history ID deduced from the given [param object]. It can be used with [method get_history_undo_redo]. | ||
</description> | ||
</method> | ||
<method name="is_committing_action" qualifiers="const"> | ||
<return type="bool" /> | ||
<description> | ||
Returns [code]true[/code] if the [EditorUndoRedoManager] is currently committing the action, i.e. running its "do" method or property change (see [method commit_action]). | ||
</description> | ||
</method> | ||
</methods> | ||
<constants> | ||
<constant name="GLOBAL_HISTORY" value="0" enum="SpecialHistory"> | ||
Global history not associated with any scene, but with external resources etc. | ||
</constant> | ||
<constant name="INVALID_HISTORY" value="-99" enum="SpecialHistory"> | ||
Invalid "null" history. It's a special value, not associated with any object. | ||
</constant> | ||
</constants> | ||
</class> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe be
const Ref<T> &
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually planning to remove all the
set_undo_redo()
methods and just access it directly from the EditorNode singleton (similar to #57306), just not sure if it's better to do it after this PR or before. If done before it might make this PR even bigger, but if done after, this PR will add code that will need to be removed later.