Blender V4.3
ed_undo.cc File Reference
#include <cstring>
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BKE_blender_undo.hh"
#include "BKE_callbacks.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_layer.hh"
#include "BKE_main.hh"
#include "BKE_paint.hh"
#include "BKE_report.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "BKE_undo_system.hh"
#include "BKE_workspace.hh"
#include "BLO_blend_validate.hh"
#include "ED_asset.hh"
#include "ED_gpencil_legacy.hh"
#include "ED_object.hh"
#include "ED_outliner.hh"
#include "ED_render.hh"
#include "ED_screen.hh"
#include "ED_undo.hh"
#include "WM_api.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "RNA_enum_types.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"

Go to the source code of this file.

Functions

Generic Undo System Access

Non-operator undo editor functions.

bool ED_undo_is_state_valid (bContext *C)
 
void ED_undo_group_begin (bContext *C)
 
void ED_undo_group_end (bContext *C)
 
void ED_undo_push (bContext *C, const char *str)
 
static void ed_undo_step_pre (bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
 
static void ed_undo_step_post (bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
 
static int ed_undo_step_direction (bContext *C, enum eUndoStepDir step, ReportList *reports)
 
static int ed_undo_step_by_name (bContext *C, const char *undo_name, ReportList *reports)
 
static int ed_undo_step_by_index (bContext *C, const int undo_index, ReportList *reports)
 
void ED_undo_grouped_push (bContext *C, const char *str)
 
void ED_undo_pop (bContext *C)
 
void ED_undo_redo (bContext *C)
 
void ED_undo_push_op (bContext *C, wmOperator *op)
 
void ED_undo_grouped_push_op (bContext *C, wmOperator *op)
 
void ED_undo_pop_op (bContext *C, wmOperator *op)
 
bool ED_undo_is_valid (const bContext *C, const char *undoname)
 
bool ED_undo_is_memfile_compatible (const bContext *C)
 
bool ED_undo_is_legacy_compatible_for_property (bContext *C, ID *id)
 
UndoStackED_undo_stack_get ()
 
Undo, Undo Push & Redo Operators
static void ed_undo_refresh_for_op (bContext *C)
 
static int ed_undo_exec (bContext *C, wmOperator *op)
 
static int ed_undo_push_exec (bContext *C, wmOperator *op)
 
static int ed_redo_exec (bContext *C, wmOperator *op)
 
static int ed_undo_redo_exec (bContext *C, wmOperator *)
 
static bool ed_undo_is_init_poll (bContext *C)
 
static bool ed_undo_is_init_and_screenactive_poll (bContext *C)
 
static bool ed_undo_redo_poll (bContext *C)
 
static bool ed_undo_poll (bContext *C)
 
void ED_OT_undo (wmOperatorType *ot)
 
void ED_OT_undo_push (wmOperatorType *ot)
 
static bool ed_redo_poll (bContext *C)
 
void ED_OT_redo (wmOperatorType *ot)
 
void ED_OT_undo_redo (wmOperatorType *ot)
 
Operator Repeat
int ED_undo_operator_repeat (bContext *C, wmOperator *op)
 
void ED_undo_operator_repeat_cb (bContext *C, void *arg_op, void *)
 
void ED_undo_operator_repeat_cb_evt (bContext *C, void *arg_op, int)
 
Undo History Operator

See TOPBAR_MT_undo_history which is used to access this operator.

static int undo_history_exec (bContext *C, wmOperator *op)
 
static int undo_history_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
void ED_OT_undo_history (wmOperatorType *ot)
 
Undo Helper Functions
void ED_undo_object_set_active_or_warn (Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
 
void ED_undo_object_editmode_validate_scene_from_windows (wmWindowManager *wm, const Scene *scene_ref, Scene **scene_p, ViewLayer **view_layer_p)
 
void ED_undo_object_editmode_restore_helper (Scene *scene, ViewLayer *view_layer, Object **object_array, uint object_array_len, uint object_array_stride)
 
Undo View Layer Helper Functions

Needed because view layer functions such as BKE_view_layer_array_from_objects_in_edit_mode_unique_data also check visibility, which is not reliable when it comes to object undo operations, since hidden objects can be operated on in the properties editor, and local collections may be used.

Vector< Object * > ED_undo_editmode_objects_from_view_layer (const Scene *scene, ViewLayer *view_layer)
 
Vector< Base * > ED_undo_editmode_bases_from_view_layer (const Scene *scene, ViewLayer *view_layer)
 

Variables

static CLG_LogRef LOG = {"ed.undo"}
 

Function Documentation

◆ ED_OT_redo()

◆ ED_OT_undo()

◆ ED_OT_undo_history()

◆ ED_OT_undo_push()

◆ ED_OT_undo_redo()

◆ ed_redo_exec()

static int ed_redo_exec ( bContext * C,
wmOperator * op )
static

◆ ed_redo_poll()

static bool ed_redo_poll ( bContext * C)
static

◆ ED_undo_editmode_bases_from_view_layer()

◆ ED_undo_editmode_objects_from_view_layer()

◆ ed_undo_exec()

static int ed_undo_exec ( bContext * C,
wmOperator * op )
static

◆ ED_undo_group_begin()

◆ ED_undo_group_end()

◆ ED_undo_grouped_push()

void ED_undo_grouped_push ( bContext * C,
const char * str )

◆ ED_undo_grouped_push_op()

void ED_undo_grouped_push_op ( bContext * C,
wmOperator * op )

◆ ed_undo_is_init_and_screenactive_poll()

static bool ed_undo_is_init_and_screenactive_poll ( bContext * C)
static

◆ ed_undo_is_init_poll()

static bool ed_undo_is_init_poll ( bContext * C)
static

◆ ED_undo_is_legacy_compatible_for_property()

bool ED_undo_is_legacy_compatible_for_property ( bContext * C,
ID * id )

When a property of ID changes, return false.

This is to avoid changes to a property making undo pushes which are ignored by the undo-system. For example, changing a brush property isn't stored by sculpt-mode undo steps. This workaround is needed until the limitation is removed, see: #61948.

Definition at line 427 of file ed_undo.cc.

References BKE_view_layer_active_object_get(), BKE_view_layer_synced_ensure(), CLOG_INFO, CTX_data_scene(), CTX_data_view_layer(), Object::data, GS, LOG, Object::mode, OB_MODE_ALL_PAINT, and OB_MODE_EDIT.

Referenced by radial_control_modal(), and ui_apply_but_undo().

◆ ED_undo_is_memfile_compatible()

◆ ED_undo_is_state_valid()

bool ED_undo_is_state_valid ( bContext * C)

Run from the main event loop, basic checks that undo is left in a correct state.

Definition at line 69 of file ed_undo.cc.

References CTX_wm_manager(), UndoStack::group_level, UndoStep::skip, UndoStack::step_active, and wmWindowManager::undo_stack.

Referenced by wm_event_do_handlers().

◆ ED_undo_is_valid()

bool ED_undo_is_valid ( const bContext * C,
const char * undoname )

Name optionally, function used to check for operator redo panel.

Definition at line 403 of file ed_undo.cc.

References BKE_undosys_stack_has_undo(), CTX_wm_manager(), and wmWindowManager::undo_stack.

Referenced by WM_operator_check_ui_enabled().

◆ ED_undo_object_editmode_restore_helper()

void ED_undo_object_editmode_restore_helper ( Scene * scene,
ViewLayer * view_layer,
Object ** object_array,
uint object_array_len,
uint object_array_stride )

◆ ED_undo_object_editmode_validate_scene_from_windows()

void ED_undo_object_editmode_validate_scene_from_windows ( wmWindowManager * wm,
const Scene * scene_ref,
Scene ** scene_p,
ViewLayer ** view_layer_p )

This function addresses the problem of restoring undo steps when multiple windows are used. Since undo steps don't track the full context that created them it's possible an edit-mode undo step will attempt to restore edit-mode into a different window, scene or view-layer.

Values scene_p & view_layer_p (typically initialized from the context) are updated from the visible windows using scene_ref as a reference. If the no window can be found, the values are left as-is.

Since users may close windows before undoing, it's expected the window may be unavailable. When this happens the edit-mode objects wont be restored into edit-mode by ED_undo_object_editmode_restore_helper which is acceptable since objects which aren't visible in any window don't need to enter edit-mode.

Definition at line 809 of file ed_undo.cc.

References LISTBASE_FOREACH, wmWindowManager::windows, and WM_window_get_active_view_layer().

Referenced by armature_undosys_step_decode(), curve_undosys_step_decode(), font_undosys_step_decode(), lattice_undosys_step_decode(), mball_undosys_step_decode(), mesh_undosys_step_decode(), particle_undosys_step_decode(), blender::ed::curves::undo::step_decode(), and blender::ed::greasepencil::undo::step_decode().

◆ ED_undo_object_set_active_or_warn()

◆ ED_undo_operator_repeat()

◆ ED_undo_operator_repeat_cb()

void ED_undo_operator_repeat_cb ( bContext * C,
void * arg_op,
void * arg_unused )

Convenience since UI callbacks use this mostly.

Definition at line 723 of file ed_undo.cc.

References ED_undo_operator_repeat().

◆ ED_undo_operator_repeat_cb_evt()

void ED_undo_operator_repeat_cb_evt ( bContext * C,
void * arg_op,
int arg_unused )

Definition at line 728 of file ed_undo.cc.

References ED_undo_operator_repeat().

Referenced by uiTemplateOperatorRedoProperties().

◆ ed_undo_poll()

static bool ed_undo_poll ( bContext * C)
static

◆ ED_undo_pop()

void ED_undo_pop ( bContext * C)

Definition at line 372 of file ed_undo.cc.

References ed_undo_step_direction(), and STEP_UNDO.

Referenced by redraw_timer_step().

◆ ED_undo_pop_op()

void ED_undo_pop_op ( bContext * C,
wmOperator * op )

◆ ED_undo_push()

void ED_undo_push ( bContext * C,
const char * str )

Definition at line 104 of file ed_undo.cc.

References BKE_undosys_print(), BKE_undosys_stack_limit_steps_and_memory(), BKE_undosys_step_push(), CLOG_CHECK, CLOG_INFO, CTX_wm_manager(), G, LOG, memory_limit, NC_WM, ND_LIB_OVERRIDE_CHANGED, UndoStep::next, UndoStack::step_active, UndoStack::step_init, steps, str, UNDO_PUSH_RET_OVERRIDE_CHANGED, wmWindowManager::undo_stack, WM_file_tag_modified(), and WM_main_add_notifier().

Referenced by blender::attribute_search_exec_fn(), blender::ed::space_node::attribute_search_exec_fn(), clear_render_border_exec(), colorband_add(), colorband_distribute(), colorband_flip(), colorband_tools_fn(), curve_profile_presets_fn(), curve_profile_tools_fn(), curvemap_tools_func(), delete_fmodifier_cb(), blender::ed::outliner::do_outliner_item_editmode_toggle(), blender::ed::outliner::do_outliner_item_mode_toggle_generic(), blender::ed::outliner::do_outliner_item_posemode_toggle(), driver_add_var_cb(), driver_delete_var_cb(), blender::ed::asset_browser::AssetCatalogDropTarget::drop_assets_into_catalog(), drop_color_invoke(), ED_undo_grouped_push(), ed_undo_push_exec(), ED_undo_push_op(), blender::ui::greasepencil::eyedropper_add_material(), file_browse_exec(), fly_modal(), fmodifier_reorder(), gizmo_tweak_finish(), blender::io::usd::import_endjob(), import_endjob(), blender::ed::outliner::namebutton_fn(), blender::ui::bonecollections::BoneCollectionItem::on_activate(), blender::ui::greasepencil::LayerGroupViewItem::on_activate(), blender::ui::greasepencil::LayerViewItem::on_activate(), blender::ui::bonecollections::BoneCollectionDropTarget::on_drop(), blender::ed::outliner::outliner_action_set_exec(), blender::ed::outliner::outliner_animdata_operation_exec(), blender::ed::outliner::outliner_constraint_operation_exec(), blender::ed::outliner::outliner_data_operation_exec(), blender::ed::outliner::outliner_id_operation_exec(), blender::ed::outliner::outliner_lib_operation_exec(), blender::ed::outliner::outliner_liboverride_operation_exec(), blender::ed::outliner::outliner_modifier_operation_exec(), blender::ed::outliner::outliner_object_operation_exec(), blender::ed::outliner::outliner_scene_operation_exec(), pack_islands_endjob(), blender::ed::sculpt_paint::undo::push_multires_mesh_end(), radial_control_modal(), blender::ui::bonecollections::BoneCollectionItem::rename(), blender::ui::greasepencil::LayerGroupViewItem::rename(), blender::ui::greasepencil::LayerViewItem::rename(), render_border_exec(), template_id_cb(), text_autocomplete_invoke(), text_autocomplete_modal(), ui_apply_but_funcs_after(), blender::ed::space_node::ui_node_link(), view3d_camera_lock_undo_ex(), view3d_collection_drop_copy_external_asset(), and walk_modal().

◆ ed_undo_push_exec()

◆ ED_undo_push_op()

◆ ED_undo_redo()

void ED_undo_redo ( bContext * C)

Definition at line 376 of file ed_undo.cc.

References ed_undo_step_direction(), and STEP_REDO.

Referenced by ED_undo_operator_repeat(), and redraw_timer_step().

◆ ed_undo_redo_exec()

static int ed_undo_redo_exec ( bContext * C,
wmOperator *  )
static

◆ ed_undo_redo_poll()

static bool ed_undo_redo_poll ( bContext * C)
static

◆ ed_undo_refresh_for_op()

static void ed_undo_refresh_for_op ( bContext * C)
static

Refresh to run after user activated undo/redo actions.

Definition at line 470 of file ed_undo.cc.

References CTX_wm_manager(), CTX_wm_window(), ED_outliner_select_sync_from_all_tag(), WM_event_add_mousemove(), and WM_operator_stack_clear().

Referenced by ed_redo_exec(), ed_undo_exec(), and undo_history_exec().

◆ ED_undo_stack_get()

◆ ed_undo_step_by_index()

static int ed_undo_step_by_index ( bContext * C,
const int undo_index,
ReportList * reports )
static

Load the step matching given index in the stack. May undo or redo several steps at once. The target step will be the one indicated by the given index.

Definition at line 328 of file ed_undo.cc.

References BKE_undosys_step_load_from_index(), BLI_assert, BLI_assert_msg, BLI_findindex(), CLOG_INFO, CTX_wm_manager(), ED_gpencil_session_active(), ed_undo_step_post(), ed_undo_step_pre(), LOG, OPERATOR_CANCELLED, OPERATOR_FINISHED, UndoStack::step_active, STEP_REDO, STEP_UNDO, UndoStack::steps, and wmWindowManager::undo_stack.

Referenced by undo_history_exec().

◆ ed_undo_step_by_name()

static int ed_undo_step_by_name ( bContext * C,
const char * undo_name,
ReportList * reports )
static

Undo the step matching given name. May undo several steps at once. The target step will be the one immediately before given named one.

Definition at line 279 of file ed_undo.cc.

References BKE_undosys_step_calc_direction(), BKE_undosys_step_find_by_name(), BKE_undosys_step_load_data_ex(), BLI_assert, BLI_assert_msg, CLOG_ERROR, CLOG_INFO, CTX_wm_manager(), ED_gpencil_session_active(), ed_undo_step_post(), ed_undo_step_pre(), ELEM, LOG, OPERATOR_CANCELLED, OPERATOR_FINISHED, UndoStep::prev, STEP_REDO, STEP_UNDO, and wmWindowManager::undo_stack.

Referenced by ED_undo_pop_op().

◆ ed_undo_step_direction()

static int ed_undo_step_direction ( bContext * C,
enum eUndoStepDir step,
ReportList * reports )
static

Undo or redo one step from current active one. May undo or redo several steps at once only if the target step is a 'skipped' one. The target step will be the one immediately before or after the active one.

Definition at line 242 of file ed_undo.cc.

References BKE_undosys_step_redo(), BKE_undosys_step_undo(), BLI_assert, CLOG_INFO, CTX_wm_manager(), ED_gpencil_session_active(), ED_undo_gpencil_step(), ed_undo_step_post(), ed_undo_step_pre(), ELEM, LOG, OPERATOR_FINISHED, STEP_REDO, STEP_UNDO, and wmWindowManager::undo_stack.

Referenced by ed_redo_exec(), ed_undo_exec(), ED_undo_pop(), and ED_undo_redo().

◆ ed_undo_step_post()

◆ ed_undo_step_pre()

static void ed_undo_step_pre ( bContext * C,
wmWindowManager * wm,
const enum eUndoStepDir undo_dir,
ReportList * reports )
static

◆ undo_history_exec()

◆ undo_history_invoke()

static int undo_history_invoke ( bContext * C,
wmOperator * op,
const wmEvent *  )
static

Variable Documentation

◆ LOG