Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/undo/ed_undo.c
| Show First 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | static int ed_undo_step_direction(bContext *C, enum eUndoStepDir step, ReportList *reports) | ||||
| ed_undo_step_post(C, wm, step, reports); | ed_undo_step_post(C, wm, step, reports); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /** Undo the step matching given name. | /** Undo the step matching given name. | ||||
| * May undo several steps at once. | * May undo several steps at once. | ||||
| * The target step will be the one immediately before given named one. | * The target step will be the one immediately before given named one. */ | ||||
| * Only supposed to undo (will assert in case given named step is after current active one). */ | |||||
| static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports) | static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports) | ||||
| { | { | ||||
| BLI_assert(undo_name != NULL); | BLI_assert(undo_name != NULL); | ||||
| /* FIXME: See comments in `ed_undo_step_direction`. */ | /* FIXME: See comments in `ed_undo_step_direction`. */ | ||||
| if (ED_gpencil_session_active()) { | if (ED_gpencil_session_active()) { | ||||
| BLI_assert(!"Not implemented currently."); | BLI_assert(!"Not implemented currently."); | ||||
| } | } | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| UndoStep *undo_step_from_name = BKE_undosys_step_find_by_name(wm->undo_stack, undo_name); | UndoStep *undo_step_from_name = BKE_undosys_step_find_by_name(wm->undo_stack, undo_name); | ||||
| if (undo_step_from_name == NULL) { | if (undo_step_from_name == NULL) { | ||||
| CLOG_ERROR(&LOG, "Step name='%s' not found in current undo stack", undo_name); | CLOG_ERROR(&LOG, "Step name='%s' not found in current undo stack", undo_name); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| /* TODO(campbell), could use simple optimization. */ | UndoStep *undo_step_target = undo_step_from_name->prev; | ||||
| /* Pointers match on redo. */ | if (undo_step_target == NULL) { | ||||
| const int target_step_index = BLI_findindex(&wm->undo_stack->steps, undo_step_from_name); | CLOG_ERROR(&LOG, "Step name='%s' cannot be undone", undo_name); | ||||
| const int active_step_index = BLI_findindex(&wm->undo_stack->steps, wm->undo_stack->step_active); | |||||
| const enum eUndoStepDir undo_dir = (target_step_index < active_step_index) ? STEP_UNDO : | return OPERATOR_CANCELLED; | ||||
| STEP_REDO; | } | ||||
| const int undo_dir_i = BKE_undosys_step_find_direction(wm->undo_stack, undo_step_target, NULL); | |||||
campbellbarton: Missing bracket. | |||||
| BLI_assert(undo_dir_i != 0); | |||||
| const enum eUndoStepDir undo_dir = (undo_dir_i == -1) ? STEP_UNDO : STEP_REDO; | |||||
| CLOG_INFO(&LOG, | CLOG_INFO(&LOG, | ||||
| 1, | 1, | ||||
| "name='%s', found direction=%s, index=%d", | "name='%s', found direction=%s", | ||||
| undo_name, | undo_name, | ||||
| (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO", | (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO"); | ||||
| target_step_index); | |||||
| /* This function is currently not supposed to redo ever. | |||||
| * TODO: Will be fixed in future in continuing undo code refactor effort. */ | |||||
| BLI_assert(undo_dir == STEP_UNDO); | |||||
| ed_undo_step_pre(C, wm, undo_dir, reports); | ed_undo_step_pre(C, wm, undo_dir, reports); | ||||
| BKE_undosys_step_undo_with_data(wm->undo_stack, C, undo_step_from_name); | BKE_undosys_step_load_data_ex(wm->undo_stack, C, undo_step_target, NULL, true); | ||||
| ed_undo_step_post(C, wm, undo_dir, reports); | ed_undo_step_post(C, wm, undo_dir, reports); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /** Load the step matching given index in the stack. | /** Load the step matching given index in the stack. | ||||
| * May undo or redo several steps at once. | * May undo or redo several steps at once. | ||||
| Show All 14 Lines | static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *reports) | ||||
| CLOG_INFO(&LOG, | CLOG_INFO(&LOG, | ||||
| 1, | 1, | ||||
| "index='%d', found direction=%s", | "index='%d', found direction=%s", | ||||
| undo_index, | undo_index, | ||||
| (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO"); | (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO"); | ||||
| ed_undo_step_pre(C, wm, undo_dir, reports); | ed_undo_step_pre(C, wm, undo_dir, reports); | ||||
| BKE_undosys_step_undo_from_index(wm->undo_stack, C, undo_index); | BKE_undosys_step_load_from_index(wm->undo_stack, C, undo_index); | ||||
| ed_undo_step_post(C, wm, undo_dir, reports); | ed_undo_step_post(C, wm, undo_dir, reports); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void ED_undo_grouped_push(bContext *C, const char *str) | void ED_undo_grouped_push(bContext *C, const char *str) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 634 Lines • Show Last 20 Lines | |||||
Missing bracket.