Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_undo.c
| Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BLI_assert(ELEM(direction, -1, 1)); | BLI_assert(ELEM(direction, -1, 1)); | ||||
| if (direction < 0) { | if (direction < 0) { | ||||
| return ui_textedit_undo_impl(stack, r_cursor_index); | return ui_textedit_undo_impl(stack, r_cursor_index); | ||||
| } | } | ||||
| return ui_textedit_redo_impl(stack, r_cursor_index); | return ui_textedit_redo_impl(stack, r_cursor_index); | ||||
| } | } | ||||
| /** | |||||
| * Push the information in the arguments to a new state in the undo stack. | |||||
| * | |||||
| * \note Currently the total length of the undo stack is not limited. | |||||
| */ | |||||
| void ui_textedit_undo_push(uiUndoStack_Text *stack, const char *text, int cursor_index) | void ui_textedit_undo_push(uiUndoStack_Text *stack, const char *text, int cursor_index) | ||||
| { | { | ||||
| /* Clear all redo actions from the current state. */ | /* Clear all redo actions from the current state. */ | ||||
| if (stack->current != NULL) { | if (stack->current != NULL) { | ||||
| while (stack->current->next) { | while (stack->current->next) { | ||||
| uiUndoStack_Text_State *state = stack->current->next; | uiUndoStack_Text_State *state = stack->current->next; | ||||
| BLI_remlink(&stack->states, state); | BLI_remlink(&stack->states, state); | ||||
| MEM_freeN(state); | MEM_freeN(state); | ||||
| } | } | ||||
| } | } | ||||
| /* Create the new state. */ | /* Create the new state. */ | ||||
| const int text_size = strlen(text) + 1; | const int text_size = strlen(text) + 1; | ||||
| stack->current = MEM_mallocN(sizeof(uiUndoStack_Text_State) + text_size, __func__); | stack->current = MEM_mallocN(sizeof(uiUndoStack_Text_State) + text_size, __func__); | ||||
| stack->current->cursor_index = cursor_index; | stack->current->cursor_index = cursor_index; | ||||
| memcpy(stack->current->text, text, text_size); | memcpy(stack->current->text, text, text_size); | ||||
| BLI_addtail(&stack->states, stack->current); | BLI_addtail(&stack->states, stack->current); | ||||
| } | } | ||||
| /** | |||||
| * Start the undo stack. | |||||
| * | |||||
| * \note The current state should be pushed immediately after calling this. | |||||
| */ | |||||
| uiUndoStack_Text *ui_textedit_undo_stack_create(void) | uiUndoStack_Text *ui_textedit_undo_stack_create(void) | ||||
| { | { | ||||
| uiUndoStack_Text *stack = MEM_mallocN(sizeof(uiUndoStack_Text), __func__); | uiUndoStack_Text *stack = MEM_mallocN(sizeof(uiUndoStack_Text), __func__); | ||||
| stack->current = NULL; | stack->current = NULL; | ||||
| BLI_listbase_clear(&stack->states); | BLI_listbase_clear(&stack->states); | ||||
| return stack; | return stack; | ||||
| } | } | ||||
| void ui_textedit_undo_stack_destroy(uiUndoStack_Text *stack) | void ui_textedit_undo_stack_destroy(uiUndoStack_Text *stack) | ||||
| { | { | ||||
| BLI_freelistN(&stack->states); | BLI_freelistN(&stack->states); | ||||
| MEM_freeN(stack); | MEM_freeN(stack); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||