2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-30 19:01:12 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-30 19:01:12 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2004 Blender Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edundo
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-30 19:01:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2018-04-05 13:41:52 +02:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
2018-04-16 16:27:55 +02:00
|
|
|
#include "DNA_object_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_scene_types.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
|
2018-07-12 14:43:35 +02:00
|
|
|
#include "BLI_listbase.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-04-13 19:59:29 +00:00
|
|
|
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_blender_undo.h"
|
2019-09-05 15:52:38 +02:00
|
|
|
#include "BKE_callbacks.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_global.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_layer.h"
|
2018-04-03 08:35:42 +02:00
|
|
|
#include "BKE_main.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_paint.h"
|
2018-10-17 16:43:02 +02:00
|
|
|
#include "BKE_report.h"
|
2018-08-03 10:15:34 +02:00
|
|
|
#include "BKE_scene.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BKE_screen.h"
|
2018-03-19 14:17:59 +01:00
|
|
|
#include "BKE_undo_system.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "BKE_workspace.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
|
2019-01-25 17:31:32 +01:00
|
|
|
#include "BLO_blend_validate.h"
|
2018-10-17 16:43:02 +02:00
|
|
|
|
2011-09-06 07:59:18 +00:00
|
|
|
#include "ED_gpencil.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "ED_object.h"
|
2019-08-19 08:58:13 -06:00
|
|
|
#include "ED_outliner.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_render.h"
|
2008-12-31 18:52:15 +00:00
|
|
|
#include "ED_screen.h"
|
2018-04-02 15:02:08 +02:00
|
|
|
#include "ED_undo.h"
|
2008-12-31 18:52:15 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
2018-06-04 16:41:03 +02:00
|
|
|
#include "WM_toolsystem.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "WM_types.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
|
2011-02-22 02:42:19 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2008-12-30 19:01:12 +00:00
|
|
|
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
#include "UI_interface.h"
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
2018-04-05 13:41:52 +02:00
|
|
|
/** We only need this locally. */
|
|
|
|
static CLG_LogRef LOG = {"ed.undo"};
|
|
|
|
|
2021-01-14 09:49:22 +11:00
|
|
|
/**
|
|
|
|
* \warning Values are used in #ED_undo_gpencil_step,
|
|
|
|
* which should eventually be replaced with the undo-system.
|
|
|
|
*/
|
|
|
|
enum eUndoStepDir {
|
|
|
|
STEP_REDO = 1,
|
|
|
|
STEP_UNDO = -1,
|
2021-01-14 11:34:00 +01:00
|
|
|
/** Only used when the undo step name or index is passed to #ed_undo_step_impl. */
|
2021-01-14 09:49:22 +11:00
|
|
|
STEP_NONE = 0,
|
|
|
|
};
|
|
|
|
|
2018-04-02 15:02:08 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Generic Undo System Access
|
|
|
|
*
|
|
|
|
* Non-operator undo editor functions.
|
|
|
|
* \{ */
|
2008-12-30 19:01:12 +00:00
|
|
|
|
2020-10-30 20:24:13 +11:00
|
|
|
/**
|
|
|
|
* Run from the main event loop, basic checks that undo is left in a correct state.
|
|
|
|
*/
|
|
|
|
bool ED_undo_is_state_valid(bContext *C)
|
|
|
|
{
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
|
|
|
|
/* Currently only checks matching begin/end calls. */
|
|
|
|
if (wm->undo_stack == NULL) {
|
|
|
|
/* No undo stack is valid, nothing to do. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (wm->undo_stack->group_level != 0) {
|
|
|
|
/* If this fails #ED_undo_grouped_begin, #ED_undo_grouped_end calls don't match. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (wm->undo_stack->step_active != NULL) {
|
|
|
|
if (wm->undo_stack->step_active->skip == true) {
|
|
|
|
/* Skip is only allowed between begin/end calls,
|
|
|
|
* a state that should never happen in main event loop. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_undo_group_begin(bContext *C)
|
|
|
|
{
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
BKE_undosys_stack_group_begin(wm->undo_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_undo_group_end(bContext *C)
|
|
|
|
{
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
BKE_undosys_stack_group_end(wm->undo_stack);
|
|
|
|
}
|
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
void ED_undo_push(bContext *C, const char *str)
|
2008-12-30 19:01:12 +00:00
|
|
|
{
|
2018-04-05 13:41:52 +02:00
|
|
|
CLOG_INFO(&LOG, 1, "name='%s'", str);
|
2020-05-14 14:58:54 +10:00
|
|
|
WM_file_tag_modified();
|
2018-04-05 13:41:52 +02:00
|
|
|
|
2020-05-14 14:58:54 +10:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
int steps = U.undosteps;
|
|
|
|
|
|
|
|
/* Ensure steps that have been initialized are always pushed,
|
|
|
|
* even when undo steps are zero.
|
|
|
|
*
|
|
|
|
* Note that some modes (paint, sculpt) initialize an undo step before an action runs,
|
|
|
|
* then accumulate changes there, or restore data from it in the case of 2D painting.
|
|
|
|
*
|
|
|
|
* For this reason we need to handle the undo step even when undo steps is set to zero.
|
|
|
|
*/
|
|
|
|
if ((steps <= 0) && wm->undo_stack->step_init != NULL) {
|
|
|
|
steps = 1;
|
|
|
|
}
|
2018-03-19 14:17:59 +01:00
|
|
|
if (steps <= 0) {
|
|
|
|
return;
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
2020-07-19 18:59:14 +10:00
|
|
|
if (G.background) {
|
|
|
|
/* Python developers may have explicitly created the undo stack in background mode,
|
|
|
|
* otherwise allow it to be NULL, see: T60934.
|
|
|
|
* Otherwise it must never be NULL, even when undo is disabled. */
|
|
|
|
if (wm->undo_stack == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 14:17:59 +01:00
|
|
|
|
2020-12-27 22:15:20 +01:00
|
|
|
UndoPushReturn push_retval;
|
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/* Only apply limit if this is the last undo step. */
|
|
|
|
if (wm->undo_stack->step_active && (wm->undo_stack->step_active->next == NULL)) {
|
|
|
|
BKE_undosys_stack_limit_steps_and_memory(wm->undo_stack, steps - 1, 0);
|
2014-05-14 01:09:09 +03:00
|
|
|
}
|
2018-03-19 14:17:59 +01:00
|
|
|
|
2020-12-27 22:15:20 +01:00
|
|
|
push_retval = BKE_undosys_step_push(wm->undo_stack, C, str);
|
2018-03-19 14:17:59 +01:00
|
|
|
|
|
|
|
if (U.undomemory != 0) {
|
|
|
|
const size_t memory_limit = (size_t)U.undomemory * 1024 * 1024;
|
2020-05-14 14:52:07 +10:00
|
|
|
BKE_undosys_stack_limit_steps_and_memory(wm->undo_stack, -1, memory_limit);
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
2014-03-13 22:35:26 +02:00
|
|
|
|
2019-07-10 19:37:33 +10:00
|
|
|
if (CLOG_CHECK(&LOG, 1)) {
|
|
|
|
BKE_undosys_print(wm->undo_stack);
|
|
|
|
}
|
2020-12-27 22:15:20 +01:00
|
|
|
|
|
|
|
if (push_retval & UNDO_PUSH_RET_OVERRIDE_CHANGED) {
|
|
|
|
WM_main_add_notifier(NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL);
|
|
|
|
}
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 10:09:56 +11:00
|
|
|
/**
|
|
|
|
* \note Also check #undo_history_exec in bottom if you change notifiers.
|
|
|
|
*/
|
2021-01-14 11:44:16 +01:00
|
|
|
static int ed_undo_step_impl(bContext *C,
|
|
|
|
enum eUndoStepDir step,
|
|
|
|
const char *undo_name,
|
|
|
|
const int undo_index,
|
|
|
|
ReportList *reports)
|
2014-02-15 13:28:26 +11:00
|
|
|
{
|
2019-02-07 10:09:56 +11:00
|
|
|
/* Mutually exclusives, ensure correct input. */
|
2021-01-14 11:44:16 +01:00
|
|
|
BLI_assert(((undo_name || undo_index != -1) && (step == STEP_NONE)) ||
|
|
|
|
(!(undo_name || undo_index != -1) && (step != STEP_NONE)));
|
|
|
|
CLOG_INFO(&LOG, 1, "name='%s', index=%d, step=%d", undo_name, undo_index, step);
|
2014-02-15 13:28:26 +11:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-29 15:26:46 +00:00
|
|
|
/* undo during jobs are running can easily lead to freeing data using by jobs,
|
2011-12-11 19:23:02 +00:00
|
|
|
* or they can just lead to freezing job in some other cases */
|
2018-08-24 12:36:19 +10:00
|
|
|
WM_jobs_kill_all(wm);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-17 16:43:02 +02:00
|
|
|
if (G.debug & G_DEBUG_IO) {
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
if (bmain->lock != NULL) {
|
2018-12-24 15:02:20 +01:00
|
|
|
BKE_report(reports, RPT_INFO, "Checking sanity of current .blend file *BEFORE* undo step");
|
2018-10-17 16:43:02 +02:00
|
|
|
BLO_main_validate_libraries(bmain, reports);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-10-17 16:43:02 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/* TODO(campbell): undo_system: use undo system */
|
2011-09-06 07:59:18 +00:00
|
|
|
/* grease pencil can be can be used in plenty of spaces, so check it first */
|
2021-01-14 11:34:00 +01:00
|
|
|
/* FIXME: This gpencil undo effectively only supports the one step undo/redo, undo based on name
|
|
|
|
* or index is fully not implemented.
|
|
|
|
* FIXME: However, it seems to never be used in current code (`ED_gpencil_session_active` seems
|
|
|
|
* to always return false). */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ED_gpencil_session_active()) {
|
2021-01-14 11:34:00 +01:00
|
|
|
return ED_undo_gpencil_step(C, (int)step);
|
2011-09-06 07:59:18 +00:00
|
|
|
}
|
2020-04-03 13:25:03 +02:00
|
|
|
if (area && (area->spacetype == SPACE_VIEW3D)) {
|
2018-07-31 10:22:19 +02:00
|
|
|
Object *obact = CTX_data_active_object(C);
|
|
|
|
if (obact && (obact->type == OB_GPENCIL)) {
|
|
|
|
ED_gpencil_toggle_brush_cursor(C, false, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-12 14:43:35 +02:00
|
|
|
UndoStep *step_data_from_name = NULL;
|
2021-01-14 09:49:22 +11:00
|
|
|
enum eUndoStepDir step_for_callback = step;
|
2021-01-14 11:44:16 +01:00
|
|
|
if (undo_name != NULL) {
|
|
|
|
step_data_from_name = BKE_undosys_step_find_by_name(wm->undo_stack, undo_name);
|
2018-07-12 14:43:35 +02:00
|
|
|
if (step_data_from_name == NULL) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-12 14:43:35 +02:00
|
|
|
/* TODO(campbell), could use simple optimization. */
|
2018-07-13 17:59:26 +02:00
|
|
|
/* Pointers match on redo. */
|
2018-07-12 14:43:35 +02:00
|
|
|
step_for_callback = (BLI_findindex(&wm->undo_stack->steps, step_data_from_name) <
|
|
|
|
BLI_findindex(&wm->undo_stack->steps, wm->undo_stack->step_active)) ?
|
2021-01-14 09:49:22 +11:00
|
|
|
STEP_UNDO :
|
|
|
|
STEP_REDO;
|
2018-07-12 14:43:35 +02:00
|
|
|
}
|
2019-06-07 15:30:49 +10:00
|
|
|
else if (undo_index != -1) {
|
|
|
|
step_for_callback = (undo_index <
|
|
|
|
BLI_findindex(&wm->undo_stack->steps, wm->undo_stack->step_active)) ?
|
2021-01-14 09:49:22 +11:00
|
|
|
STEP_UNDO :
|
|
|
|
STEP_REDO;
|
2019-06-07 15:30:49 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-12 14:43:35 +02:00
|
|
|
/* App-Handlers (pre). */
|
|
|
|
{
|
|
|
|
/* Note: ignore grease pencil for now. */
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
wm->op_undo_depth++;
|
2019-09-09 10:25:04 +02:00
|
|
|
BKE_callback_exec_id(
|
2019-09-05 15:52:38 +02:00
|
|
|
bmain, &scene->id, (step_for_callback > 0) ? BKE_CB_EVT_UNDO_PRE : BKE_CB_EVT_REDO_PRE);
|
2018-07-12 14:43:35 +02:00
|
|
|
wm->op_undo_depth--;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
/* Undo System */
|
|
|
|
{
|
2021-01-14 11:44:16 +01:00
|
|
|
if (undo_name) {
|
2018-07-12 14:43:35 +02:00
|
|
|
BKE_undosys_step_undo_with_data(wm->undo_stack, C, step_data_from_name);
|
2009-07-08 15:34:41 +00:00
|
|
|
}
|
2019-06-07 15:30:49 +10:00
|
|
|
else if (undo_index != -1) {
|
|
|
|
BKE_undosys_step_undo_from_index(wm->undo_stack, C, undo_index);
|
|
|
|
}
|
2018-03-19 14:17:59 +01:00
|
|
|
else {
|
2021-01-14 09:49:22 +11:00
|
|
|
if (step == STEP_UNDO) {
|
2019-02-07 10:09:56 +11:00
|
|
|
BKE_undosys_step_undo(wm->undo_stack, C);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_undosys_step_redo(wm->undo_stack, C);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-02-07 10:09:56 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
/* Set special modes for grease pencil */
|
2020-04-03 13:25:03 +02:00
|
|
|
if (area && (area->spacetype == SPACE_VIEW3D)) {
|
2018-07-31 10:22:19 +02:00
|
|
|
Object *obact = CTX_data_active_object(C);
|
|
|
|
if (obact && (obact->type == OB_GPENCIL)) {
|
|
|
|
/* set cursor */
|
2018-12-14 16:45:57 +01:00
|
|
|
if (ELEM(obact->mode,
|
|
|
|
OB_MODE_PAINT_GPENCIL,
|
|
|
|
OB_MODE_SCULPT_GPENCIL,
|
2020-03-09 16:27:24 +01:00
|
|
|
OB_MODE_WEIGHT_GPENCIL,
|
|
|
|
OB_MODE_VERTEX_GPENCIL)) {
|
2018-07-31 10:22:19 +02:00
|
|
|
ED_gpencil_toggle_brush_cursor(C, true, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ED_gpencil_toggle_brush_cursor(C, false, NULL);
|
|
|
|
}
|
|
|
|
/* set workspace mode */
|
|
|
|
Base *basact = CTX_data_active_base(C);
|
|
|
|
ED_object_base_activate(C, basact);
|
|
|
|
}
|
|
|
|
}
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-12 14:43:35 +02:00
|
|
|
/* App-Handlers (post). */
|
|
|
|
{
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
scene = CTX_data_scene(C);
|
|
|
|
wm->op_undo_depth++;
|
2019-09-09 10:25:04 +02:00
|
|
|
BKE_callback_exec_id(
|
2019-09-05 15:52:38 +02:00
|
|
|
bmain, &scene->id, step_for_callback > 0 ? BKE_CB_EVT_UNDO_POST : BKE_CB_EVT_REDO_POST);
|
2018-07-12 14:43:35 +02:00
|
|
|
wm->op_undo_depth--;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-17 16:43:02 +02:00
|
|
|
if (G.debug & G_DEBUG_IO) {
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
if (bmain->lock != NULL) {
|
2018-12-24 12:31:39 +01:00
|
|
|
BKE_report(reports, RPT_INFO, "Checking sanity of current .blend file *AFTER* undo step");
|
2018-10-17 16:43:02 +02:00
|
|
|
BLO_main_validate_libraries(bmain, reports);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-31 18:52:15 +00:00
|
|
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
2014-09-16 14:28:58 +06:00
|
|
|
WM_event_add_notifier(C, NC_WM | ND_UNDO, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-29 20:20:16 +11:00
|
|
|
WM_toolsystem_refresh_active(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-04 16:41:03 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
WM_toolsystem_refresh_screen_all(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-07-10 19:37:33 +10:00
|
|
|
if (CLOG_CHECK(&LOG, 1)) {
|
|
|
|
BKE_undosys_print(wm->undo_stack);
|
|
|
|
}
|
|
|
|
|
2008-12-31 18:52:15 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 09:49:22 +11:00
|
|
|
static int ed_undo_step_direction(bContext *C, enum eUndoStepDir step, ReportList *reports)
|
2019-06-07 15:30:49 +10:00
|
|
|
{
|
|
|
|
return ed_undo_step_impl(C, step, NULL, -1, reports);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports)
|
|
|
|
{
|
2021-01-14 09:49:22 +11:00
|
|
|
return ed_undo_step_impl(C, STEP_NONE, undo_name, -1, reports);
|
2019-06-07 15:30:49 +10:00
|
|
|
}
|
|
|
|
|
2021-01-14 11:44:16 +01:00
|
|
|
static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *reports)
|
2019-06-07 15:30:49 +10:00
|
|
|
{
|
2021-01-14 11:44:16 +01:00
|
|
|
return ed_undo_step_impl(C, STEP_NONE, NULL, undo_index, reports);
|
2019-06-07 15:30:49 +10:00
|
|
|
}
|
|
|
|
|
Implement grouped undo option for operators
This option makes an operator to not push a task to the undo stack if the previous stored elemen is the same operator or part of the same undo group.
The main usage is for animation, so you can change frames to inspect the
poses, and revert the previous pose without having to roll back tons of
"change frame" operator, or even see the undo stack full.
This complements rB13ee9b8e
Design with help by Sergey Sharybin.
Reviewers: sergey, mont29
Reviewed By: mont29, sergey
Subscribers: pyc0d3r, hjalti, Severin, lowercase, brecht, monio, aligorith, hadrien, jbakker
Differential Revision: https://developer.blender.org/D2330
2016-11-15 11:50:11 +01:00
|
|
|
void ED_undo_grouped_push(bContext *C, const char *str)
|
|
|
|
{
|
|
|
|
/* do nothing if previous undo task is the same as this one (or from the same undo group) */
|
2018-06-13 18:22:17 +02:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
const UndoStep *us = wm->undo_stack->step_active;
|
|
|
|
if (us && STREQ(str, us->name)) {
|
|
|
|
BKE_undosys_stack_clear_active(wm->undo_stack);
|
Implement grouped undo option for operators
This option makes an operator to not push a task to the undo stack if the previous stored elemen is the same operator or part of the same undo group.
The main usage is for animation, so you can change frames to inspect the
poses, and revert the previous pose without having to roll back tons of
"change frame" operator, or even see the undo stack full.
This complements rB13ee9b8e
Design with help by Sergey Sharybin.
Reviewers: sergey, mont29
Reviewed By: mont29, sergey
Subscribers: pyc0d3r, hjalti, Severin, lowercase, brecht, monio, aligorith, hadrien, jbakker
Differential Revision: https://developer.blender.org/D2330
2016-11-15 11:50:11 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Implement grouped undo option for operators
This option makes an operator to not push a task to the undo stack if the previous stored elemen is the same operator or part of the same undo group.
The main usage is for animation, so you can change frames to inspect the
poses, and revert the previous pose without having to roll back tons of
"change frame" operator, or even see the undo stack full.
This complements rB13ee9b8e
Design with help by Sergey Sharybin.
Reviewers: sergey, mont29
Reviewed By: mont29, sergey
Subscribers: pyc0d3r, hjalti, Severin, lowercase, brecht, monio, aligorith, hadrien, jbakker
Differential Revision: https://developer.blender.org/D2330
2016-11-15 11:50:11 +01:00
|
|
|
/* push as usual */
|
|
|
|
ED_undo_push(C, str);
|
|
|
|
}
|
|
|
|
|
2009-02-04 11:52:16 +00:00
|
|
|
void ED_undo_pop(bContext *C)
|
|
|
|
{
|
2021-01-14 09:49:22 +11:00
|
|
|
ed_undo_step_direction(C, STEP_UNDO, NULL);
|
2009-02-04 11:52:16 +00:00
|
|
|
}
|
2009-04-15 17:53:12 +00:00
|
|
|
void ED_undo_redo(bContext *C)
|
|
|
|
{
|
2021-01-14 09:49:22 +11:00
|
|
|
ed_undo_step_direction(C, STEP_REDO, NULL);
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ED_undo_push_op(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
/* in future, get undo string info? */
|
|
|
|
ED_undo_push(C, op->type->name);
|
|
|
|
}
|
|
|
|
|
Implement grouped undo option for operators
This option makes an operator to not push a task to the undo stack if the previous stored elemen is the same operator or part of the same undo group.
The main usage is for animation, so you can change frames to inspect the
poses, and revert the previous pose without having to roll back tons of
"change frame" operator, or even see the undo stack full.
This complements rB13ee9b8e
Design with help by Sergey Sharybin.
Reviewers: sergey, mont29
Reviewed By: mont29, sergey
Subscribers: pyc0d3r, hjalti, Severin, lowercase, brecht, monio, aligorith, hadrien, jbakker
Differential Revision: https://developer.blender.org/D2330
2016-11-15 11:50:11 +01:00
|
|
|
void ED_undo_grouped_push_op(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if (op->type->undo_group[0] != '\0') {
|
|
|
|
ED_undo_grouped_push(C, op->type->undo_group);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ED_undo_grouped_push(C, op->type->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
void ED_undo_pop_op(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
/* search back a couple of undo's, in case something else added pushes */
|
2019-06-07 15:30:49 +10:00
|
|
|
ed_undo_step_by_name(C, op->type->name, op->reports);
|
2009-04-15 17:53:12 +00:00
|
|
|
}
|
2009-02-04 11:52:16 +00:00
|
|
|
|
2011-01-12 18:00:23 +00:00
|
|
|
/* name optionally, function used to check for operator redo panel */
|
2015-04-18 15:41:12 +02:00
|
|
|
bool ED_undo_is_valid(const bContext *C, const char *undoname)
|
2011-01-12 18:00:23 +00:00
|
|
|
{
|
2018-03-19 14:17:59 +01:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
return BKE_undosys_stack_has_undo(wm->undo_stack, undoname);
|
2011-01-12 18:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-01-19 00:48:00 +11:00
|
|
|
bool ED_undo_is_memfile_compatible(const bContext *C)
|
|
|
|
{
|
|
|
|
/* Some modes don't co-exist with memfile undo, disable their use: T60593
|
|
|
|
* (this matches 2.7x behavior). */
|
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
if (view_layer != NULL) {
|
|
|
|
Object *obact = OBACT(view_layer);
|
|
|
|
if (obact != NULL) {
|
2019-11-07 16:52:03 +11:00
|
|
|
if (obact->mode & OB_MODE_EDIT) {
|
2019-01-19 00:48:00 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-05 13:46:48 +10:00
|
|
|
/**
|
|
|
|
* 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: T61948.
|
|
|
|
*/
|
|
|
|
bool ED_undo_is_legacy_compatible_for_property(struct bContext *C, ID *id)
|
|
|
|
{
|
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
if (view_layer != NULL) {
|
|
|
|
Object *obact = OBACT(view_layer);
|
|
|
|
if (obact != NULL) {
|
|
|
|
if (obact->mode & OB_MODE_ALL_PAINT) {
|
|
|
|
/* Don't store property changes when painting
|
|
|
|
* (only do undo pushes on brush strokes which each paint operator handles on its own). */
|
|
|
|
CLOG_INFO(&LOG, 1, "skipping undo for paint-mode");
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-03 17:30:31 +02:00
|
|
|
if (obact->mode & OB_MODE_EDIT) {
|
2019-07-05 13:46:48 +10:00
|
|
|
if ((id == NULL) || (obact->data == NULL) ||
|
|
|
|
(GS(id->name) != GS(((ID *)obact->data)->name))) {
|
|
|
|
/* No undo push on id type mismatch in edit-mode. */
|
|
|
|
CLOG_INFO(&LOG, 1, "skipping undo for edit-mode");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-03 08:35:42 +02:00
|
|
|
/**
|
|
|
|
* Ideally we wont access the stack directly,
|
|
|
|
* this is needed for modes which handle undo themselves (bypassing #ED_undo_push).
|
|
|
|
*
|
|
|
|
* Using global isn't great, this just avoids doing inline,
|
|
|
|
* causing 'BKE_global.h' & 'BKE_main.h' includes.
|
|
|
|
*/
|
|
|
|
UndoStack *ED_undo_stack_get(void)
|
|
|
|
{
|
2018-06-15 17:21:07 +02:00
|
|
|
wmWindowManager *wm = G_MAIN->wm.first;
|
2018-04-03 08:35:42 +02:00
|
|
|
return wm->undo_stack;
|
|
|
|
}
|
|
|
|
|
2018-04-02 15:02:08 +02:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Undo, Undo Push & Redo Operators
|
|
|
|
* \{ */
|
|
|
|
|
2018-10-17 16:43:02 +02:00
|
|
|
static int ed_undo_exec(bContext *C, wmOperator *op)
|
2009-01-01 13:15:35 +00:00
|
|
|
{
|
2012-06-01 11:46:25 +00:00
|
|
|
/* "last operator" should disappear, later we can tie this with undo stack nicer */
|
2011-05-18 10:56:26 +00:00
|
|
|
WM_operator_stack_clear(CTX_wm_manager(C));
|
2021-01-14 09:49:22 +11:00
|
|
|
int ret = ed_undo_step_direction(C, STEP_UNDO, op->reports);
|
2018-09-13 23:20:04 +10:00
|
|
|
if (ret & OPERATOR_FINISHED) {
|
|
|
|
/* Keep button under the cursor active. */
|
2020-03-06 16:22:28 +01:00
|
|
|
WM_event_add_mousemove(CTX_wm_window(C));
|
2018-09-13 23:20:04 +10:00
|
|
|
}
|
2019-08-19 08:58:13 -06:00
|
|
|
|
|
|
|
ED_outliner_select_sync_from_all_tag(C);
|
2018-09-13 23:20:04 +10:00
|
|
|
return ret;
|
2009-01-01 13:15:35 +00:00
|
|
|
}
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
|
2011-02-22 02:42:19 +00:00
|
|
|
static int ed_undo_push_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-02-08 10:15:11 +11:00
|
|
|
if (G.background) {
|
|
|
|
/* Exception for background mode, see: T60934.
|
|
|
|
* Note: since the undo stack isn't initialized on startup, background mode behavior
|
|
|
|
* won't match regular usage, this is just for scripts to do explicit undo pushes. */
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
if (wm->undo_stack == NULL) {
|
|
|
|
wm->undo_stack = BKE_undosys_stack_create();
|
|
|
|
}
|
|
|
|
}
|
2012-09-10 01:55:58 +00:00
|
|
|
char str[BKE_UNDO_STR_MAX];
|
2011-02-22 02:42:19 +00:00
|
|
|
RNA_string_get(op->ptr, "message", str);
|
|
|
|
ED_undo_push(C, str);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:43:02 +02:00
|
|
|
static int ed_redo_exec(bContext *C, wmOperator *op)
|
2008-12-30 19:01:12 +00:00
|
|
|
{
|
2021-01-14 09:49:22 +11:00
|
|
|
int ret = ed_undo_step_direction(C, STEP_REDO, op->reports);
|
2018-09-13 23:20:04 +10:00
|
|
|
if (ret & OPERATOR_FINISHED) {
|
|
|
|
/* Keep button under the cursor active. */
|
2020-03-06 16:22:28 +01:00
|
|
|
WM_event_add_mousemove(CTX_wm_window(C));
|
2018-09-13 23:20:04 +10:00
|
|
|
}
|
2019-08-19 08:58:13 -06:00
|
|
|
|
|
|
|
ED_outliner_select_sync_from_all_tag(C);
|
2018-09-13 23:20:04 +10:00
|
|
|
return ret;
|
2008-12-30 19:01:12 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 12:38:20 +01:00
|
|
|
static int ed_undo_redo_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
wmOperator *last_op = WM_operator_last_redo(C);
|
2018-09-13 23:20:04 +10:00
|
|
|
int ret = ED_undo_operator_repeat(C, last_op);
|
|
|
|
ret = ret ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
|
|
|
if (ret & OPERATOR_FINISHED) {
|
|
|
|
/* Keep button under the cursor active. */
|
2020-03-06 16:22:28 +01:00
|
|
|
WM_event_add_mousemove(CTX_wm_window(C));
|
2018-09-13 23:20:04 +10:00
|
|
|
}
|
|
|
|
return ret;
|
2016-12-29 12:38:20 +01:00
|
|
|
}
|
|
|
|
|
2019-02-01 14:05:33 +11:00
|
|
|
/* Disable in background mode, we could support if it's useful, T60934. */
|
|
|
|
|
|
|
|
static bool ed_undo_is_init_poll(bContext *C)
|
|
|
|
{
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
if (wm->undo_stack == NULL) {
|
2019-02-08 10:15:11 +11:00
|
|
|
CTX_wm_operator_poll_msg_set(C, "Undo disabled at startup");
|
2019-02-01 14:05:33 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ed_undo_is_init_and_screenactive_poll(bContext *C)
|
|
|
|
{
|
|
|
|
if (ed_undo_is_init_poll(C) == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return ED_operator_screenactive(C);
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool ed_undo_redo_poll(bContext *C)
|
2017-07-01 10:50:29 +03:00
|
|
|
{
|
|
|
|
wmOperator *last_op = WM_operator_last_redo(C);
|
2019-02-01 14:05:33 +11:00
|
|
|
return (last_op && ed_undo_is_init_and_screenactive_poll(C) &&
|
|
|
|
WM_operator_check_ui_enabled(C, last_op->type->name));
|
2017-07-01 10:50:29 +03:00
|
|
|
}
|
2008-12-30 19:01:12 +00:00
|
|
|
|
2020-01-28 09:33:41 -08:00
|
|
|
static bool ed_undo_poll(bContext *C)
|
|
|
|
{
|
|
|
|
if (!ed_undo_is_init_and_screenactive_poll(C)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UndoStack *undo_stack = CTX_wm_manager(C)->undo_stack;
|
|
|
|
return (undo_stack->step_active != NULL) && (undo_stack->step_active->prev != NULL);
|
|
|
|
}
|
|
|
|
|
2008-12-31 18:52:15 +00:00
|
|
|
void ED_OT_undo(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Undo";
|
|
|
|
ot->description = "Undo previous action";
|
|
|
|
ot->idname = "ED_OT_undo";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-31 18:52:15 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = ed_undo_exec;
|
2020-01-28 09:33:41 -08:00
|
|
|
ot->poll = ed_undo_poll;
|
2008-12-31 18:52:15 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 02:42:19 +00:00
|
|
|
void ED_OT_undo_push(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Undo Push";
|
|
|
|
ot->description = "Add an undo state (internal use only)";
|
|
|
|
ot->idname = "ED_OT_undo_push";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-02-22 02:42:19 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = ed_undo_push_exec;
|
2019-02-08 10:15:11 +11:00
|
|
|
/* Unlike others undo operators this initializes undo stack. */
|
|
|
|
ot->poll = ED_operator_screenactive;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = OPTYPE_INTERNAL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-10 01:55:58 +00:00
|
|
|
RNA_def_string(ot->srna,
|
|
|
|
"message",
|
|
|
|
"Add an undo step *function may be moved*",
|
|
|
|
BKE_UNDO_STR_MAX,
|
|
|
|
"Undo Message",
|
|
|
|
"");
|
2011-02-22 02:42:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 09:33:41 -08:00
|
|
|
static bool ed_redo_poll(bContext *C)
|
|
|
|
{
|
|
|
|
if (!ed_undo_is_init_and_screenactive_poll(C)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UndoStack *undo_stack = CTX_wm_manager(C)->undo_stack;
|
|
|
|
return (undo_stack->step_active != NULL) && (undo_stack->step_active->next != NULL);
|
|
|
|
}
|
|
|
|
|
2008-12-31 18:52:15 +00:00
|
|
|
void ED_OT_redo(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Redo";
|
|
|
|
ot->description = "Redo previous action";
|
|
|
|
ot->idname = "ED_OT_redo";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-31 18:52:15 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = ed_redo_exec;
|
2020-01-28 09:33:41 -08:00
|
|
|
ot->poll = ed_redo_poll;
|
2008-12-31 18:52:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 12:38:20 +01:00
|
|
|
void ED_OT_undo_redo(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Undo and Redo";
|
|
|
|
ot->description = "Undo and redo previous action";
|
|
|
|
ot->idname = "ED_OT_undo_redo";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-29 12:38:20 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ed_undo_redo_exec;
|
2017-07-01 10:50:29 +03:00
|
|
|
ot->poll = ed_undo_redo_poll;
|
2016-12-29 12:38:20 +01:00
|
|
|
}
|
2008-12-31 18:52:15 +00:00
|
|
|
|
2018-04-02 15:02:08 +02:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Operator Repeat
|
|
|
|
* \{ */
|
|
|
|
|
2011-05-28 13:11:24 +00:00
|
|
|
/* ui callbacks should call this rather than calling WM_operator_repeat() themselves */
|
UI: New Global Top-Bar (WIP)
== Main Features/Changes for Users
* Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars.
* Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector.
* Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here.
* Individual sections of the topbar are individually scrollable.
* Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting.
* Top-bar should scale nicely with DPI.
* The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes).
* Info editors at the top of the window and using the full window width with be replaced by the top-bar.
* In fullscreen modes, no more info editor is added on top, the top-bar replaces it.
== Technical Features/Changes
* Adds initial support for global areas
A global area is part of the window, not part of the regular screen-layout.
I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas.
* Adds a TOPBAR editor type
The editor type is hidden in the UI editor type menu.
* Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY)
* Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar.
* Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds.
The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved.
* Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code.
Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being.
NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility.
== ToDo's
It's a bit hard to predict all the ToDo's here are the known main ones:
* Add options for the new active-tool system and for operator redo to the topbar.
* Automatically hide the top-bar in fullscreen modes.
* General visual polish.
* Top-bar drag & drop support (WIP in temp-tab_drag_drop).
* Improve dynamic regions (should also fix some layout glitches).
* Make internal terminology consistent.
* Enable topbar file writing once design is more advanced.
* Address TODO's and XXX's in code :)
Thanks @brecht for the review! And @sergey for the complaining ;)
Differential Revision: D2758
2018-04-20 17:14:03 +02:00
|
|
|
int ED_undo_operator_repeat(bContext *C, wmOperator *op)
|
2010-12-15 04:06:19 +00:00
|
|
|
{
|
2012-03-30 10:00:20 +00:00
|
|
|
int ret = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (op) {
|
2018-04-05 13:41:52 +02:00
|
|
|
CLOG_INFO(&LOG, 1, "idname='%s'", op->type->idname);
|
2012-03-30 10:00:20 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
struct Scene *scene = CTX_data_scene(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-14 21:55:40 +02:00
|
|
|
/* keep in sync with logic in view3d_panel_operator_redo() */
|
2020-04-03 12:51:03 +02:00
|
|
|
ARegion *region_orig = CTX_wm_region(C);
|
|
|
|
ARegion *region_win = BKE_area_find_region_active_win(CTX_wm_area(C));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 12:51:03 +02:00
|
|
|
if (region_win) {
|
|
|
|
CTX_wm_region_set(C, region_win);
|
2018-06-14 21:55:40 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-12 22:05:24 +11:00
|
|
|
if ((WM_operator_repeat_check(C, op)) && (WM_operator_poll(C, op->type)) &&
|
2011-12-11 19:23:02 +00:00
|
|
|
/* note, undo/redo cant run if there are jobs active,
|
2019-04-18 07:21:26 +02:00
|
|
|
* check for screen jobs only so jobs like material/texture/world preview
|
2020-09-30 20:09:02 +10:00
|
|
|
* (which copy their data), wont stop redo, see T29579],
|
2019-04-18 07:21:26 +02:00
|
|
|
*
|
|
|
|
* note, - WM_operator_check_ui_enabled() jobs test _must_ stay in sync with this */
|
2014-01-12 22:05:24 +11:00
|
|
|
(WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY) == 0)) {
|
2010-12-15 04:06:19 +00:00
|
|
|
int retval;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.debug & G_DEBUG) {
|
2010-12-15 04:06:19 +00:00
|
|
|
printf("redo_cb: operator redo %s\n", op->type->name);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-03-15 05:16:07 +11:00
|
|
|
WM_operator_free_all_after(wm, op);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-12-15 04:06:19 +00:00
|
|
|
ED_undo_pop_op(C, op);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (op->type->check) {
|
2014-06-15 01:40:15 +10:00
|
|
|
if (op->type->check(C, op)) {
|
|
|
|
/* check for popup and re-layout buttons */
|
2020-04-03 12:51:03 +02:00
|
|
|
ARegion *region_menu = CTX_wm_menu(C);
|
|
|
|
if (region_menu) {
|
|
|
|
ED_region_tag_refresh_ui(region_menu);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-06-15 01:40:15 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-30 10:00:20 +00:00
|
|
|
retval = WM_operator_repeat(C, op);
|
|
|
|
if ((retval & OPERATOR_FINISHED) == 0) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (G.debug & G_DEBUG) {
|
2010-12-15 04:06:19 +00:00
|
|
|
printf("redo_cb: operator redo failed: %s, return %d\n", op->type->name, retval);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2010-12-15 04:06:19 +00:00
|
|
|
ED_undo_redo(C);
|
|
|
|
}
|
|
|
|
else {
|
2012-03-30 10:00:20 +00:00
|
|
|
ret = 1;
|
2010-12-15 04:06:19 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-26 13:05:22 +00:00
|
|
|
else {
|
2012-03-31 00:59:17 +00:00
|
|
|
if (G.debug & G_DEBUG) {
|
2011-07-26 13:05:22 +00:00
|
|
|
printf("redo_cb: WM_operator_repeat_check returned false %s\n", op->type->name);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-14 21:55:40 +02:00
|
|
|
/* set region back */
|
2020-04-03 12:51:03 +02:00
|
|
|
CTX_wm_region_set(C, region_orig);
|
2010-12-15 04:06:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-04-05 13:41:52 +02:00
|
|
|
CLOG_WARN(&LOG, "called with NULL 'op'");
|
2010-12-15 04:06:19 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-12-15 04:06:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void *UNUSED(arg_unused))
|
|
|
|
{
|
|
|
|
ED_undo_operator_repeat(C, (wmOperator *)arg_op);
|
|
|
|
}
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int UNUSED(arg_unused))
|
2010-12-15 04:06:19 +00:00
|
|
|
{
|
|
|
|
ED_undo_operator_repeat(C, (wmOperator *)arg_op);
|
|
|
|
}
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
|
2018-04-02 15:02:08 +02:00
|
|
|
/** \} */
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
|
2018-04-02 15:02:08 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Undo History Operator
|
|
|
|
* \{ */
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
|
|
|
|
/* create enum based on undo items */
|
2018-03-19 14:17:59 +01:00
|
|
|
static const EnumPropertyItem *rna_undo_itemf(bContext *C, int *totitem)
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
{
|
2012-03-30 10:00:20 +00:00
|
|
|
EnumPropertyItem item_tmp = {0}, *item = NULL;
|
2015-04-18 15:41:12 +02:00
|
|
|
int i = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
if (wm->undo_stack == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
for (UndoStep *us = wm->undo_stack->steps.first; us; us = us->next, i++) {
|
|
|
|
if (us->skip == false) {
|
|
|
|
item_tmp.identifier = us->name;
|
|
|
|
item_tmp.name = IFACE_(us->name);
|
|
|
|
if (us == wm->undo_stack->step_active) {
|
2019-05-19 13:12:15 -07:00
|
|
|
item_tmp.icon = ICON_LAYER_ACTIVE;
|
2018-03-19 14:17:59 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-03-30 10:00:20 +00:00
|
|
|
item_tmp.icon = ICON_NONE;
|
2018-03-19 14:17:59 +01:00
|
|
|
}
|
|
|
|
item_tmp.value = i;
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
RNA_enum_item_add(&item, totitem, &item_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RNA_enum_item_end(&item, totitem);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
{
|
2018-03-19 14:17:59 +01:00
|
|
|
int totitem = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-19 14:17:59 +01:00
|
|
|
{
|
|
|
|
const EnumPropertyItem *item = rna_undo_itemf(C, &totitem);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (totitem > 0) {
|
2019-06-05 14:30:44 +02:00
|
|
|
uiPopupMenu *pup = UI_popup_menu_begin(
|
|
|
|
C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
|
2014-11-09 21:20:40 +01:00
|
|
|
uiLayout *layout = UI_popup_menu_layout(pup);
|
2014-04-01 11:34:00 +11:00
|
|
|
uiLayout *split = uiLayoutSplit(layout, 0.0f, false);
|
2012-06-19 23:08:16 +00:00
|
|
|
uiLayout *column = NULL;
|
2014-04-15 16:49:49 +02:00
|
|
|
const int col_size = 20 + totitem / 12;
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
int i, c;
|
2014-04-15 16:49:49 +02:00
|
|
|
bool add_col = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-15 16:49:49 +02:00
|
|
|
for (c = 0, i = totitem; i--;) {
|
|
|
|
if (add_col && !(c % col_size)) {
|
2014-04-01 11:34:00 +11:00
|
|
|
column = uiLayoutColumn(split, false);
|
2014-04-15 16:49:49 +02:00
|
|
|
add_col = false;
|
|
|
|
}
|
|
|
|
if (item[i].identifier) {
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
uiItemIntO(column, item[i].name, item[i].icon, op->type->idname, "item", item[i].value);
|
2019-09-08 00:12:26 +10:00
|
|
|
c++;
|
2014-04-15 16:49:49 +02:00
|
|
|
add_col = true;
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
MEM_freeN((void *)item);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_popup_menu_end(C, pup);
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
}
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note: also check ed_undo_step() in top if you change notifiers */
|
|
|
|
static int undo_history_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-03-19 14:17:59 +01:00
|
|
|
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item");
|
|
|
|
if (RNA_property_is_set(op->ptr, prop)) {
|
|
|
|
int item = RNA_property_int_get(op->ptr, prop);
|
2019-06-07 15:30:49 +10:00
|
|
|
WM_operator_stack_clear(CTX_wm_manager(C));
|
|
|
|
ed_undo_step_by_index(C, item, op->reports);
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2020-01-28 09:33:41 -08:00
|
|
|
static bool undo_history_poll(bContext *C)
|
|
|
|
{
|
|
|
|
if (!ed_undo_is_init_and_screenactive_poll(C)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UndoStack *undo_stack = CTX_wm_manager(C)->undo_stack;
|
|
|
|
/* More than just original state entry. */
|
|
|
|
return BLI_listbase_count_at_most(&undo_stack->steps, 2) > 1;
|
|
|
|
}
|
|
|
|
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
void ED_OT_undo_history(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Undo History";
|
|
|
|
ot->description = "Redo specific action in history";
|
|
|
|
ot->idname = "ED_OT_undo_history";
|
2018-04-02 15:02:08 +02:00
|
|
|
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = undo_history_invoke;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = undo_history_exec;
|
2020-01-28 09:33:41 -08:00
|
|
|
ot->poll = undo_history_poll;
|
Code holiday commit:
- fix: user pref, window title was reset to 'Blender' on tab usage
- Undo history menu back:
- name "Undo History"
- hotkey alt+ctrl+z (alt+apple+z for mac)
- works like 2.4x, only for global undo, editmode and particle edit.
- Menu scroll
- for small windows or screens, popup menus now allow to display
all items, using internal scrolling
- works with a timer, scrolling 10 items per second when mouse
is over the top or bottom arrow
- if menu is too big to display, it now draws to top or bottom,
based on largest available space.
- also works for hotkey driven pop up menus.
- User pref "DPI" follows widget/layout size
- widgets & headers now become bigger and smaller, to match
'dpi' font sizes. Works well to match UI to monitor size.
- note that icons can get fuzzy, we need better mipmaps for it
2011-06-04 17:03:46 +00:00
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX);
|
|
|
|
}
|
|
|
|
|
2018-04-02 15:02:08 +02:00
|
|
|
/** \} */
|
2018-04-16 16:27:55 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Undo Helper Functions
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
void ED_undo_object_set_active_or_warn(ViewLayer *view_layer,
|
|
|
|
Object *ob,
|
|
|
|
const char *info,
|
|
|
|
CLG_LogRef *log)
|
|
|
|
{
|
|
|
|
Object *ob_prev = OBACT(view_layer);
|
|
|
|
if (ob_prev != ob) {
|
|
|
|
Base *base = BKE_view_layer_base_find(view_layer, ob);
|
|
|
|
if (base != NULL) {
|
|
|
|
view_layer->basact = base;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Should never fail, may not crash but can give odd behavior. */
|
|
|
|
CLOG_WARN(log, "'%s' failed to restore active object: '%s'", info, ob->id.name + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:27:11 +11:00
|
|
|
void ED_undo_object_editmode_restore_helper(struct bContext *C,
|
|
|
|
Object **object_array,
|
|
|
|
uint object_array_len,
|
|
|
|
uint object_array_stride)
|
|
|
|
{
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
uint bases_len = 0;
|
2019-08-01 13:53:25 +10:00
|
|
|
/* Don't request unique data because we want to de-select objects when exiting edit-mode
|
2019-02-07 20:27:11 +11:00
|
|
|
* for that to be done on all objects we can't skip ones that share data. */
|
2020-02-04 18:26:57 +11:00
|
|
|
Base **bases = ED_undo_editmode_bases_from_view_layer(view_layer, &bases_len);
|
2019-02-07 20:27:11 +11:00
|
|
|
for (uint i = 0; i < bases_len; i++) {
|
|
|
|
((ID *)bases[i]->object->data)->tag |= LIB_TAG_DOIT;
|
|
|
|
}
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object **ob_p = object_array;
|
|
|
|
for (uint i = 0; i < object_array_len; i++, ob_p = POINTER_OFFSET(ob_p, object_array_stride)) {
|
|
|
|
Object *obedit = *ob_p;
|
|
|
|
ED_object_editmode_enter_ex(bmain, scene, obedit, EM_NO_CONTEXT);
|
|
|
|
((ID *)obedit->data)->tag &= ~LIB_TAG_DOIT;
|
|
|
|
}
|
|
|
|
for (uint i = 0; i < bases_len; i++) {
|
|
|
|
ID *id = bases[i]->object->data;
|
|
|
|
if (id->tag & LIB_TAG_DOIT) {
|
|
|
|
ED_object_editmode_exit_ex(bmain, scene, bases[i]->object, EM_FREEDATA);
|
|
|
|
/* Ideally we would know the selection state it was before entering edit-mode,
|
|
|
|
* for now follow the convention of having them unselected when exiting the mode. */
|
|
|
|
ED_object_base_select(bases[i], BA_DESELECT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MEM_freeN(bases);
|
|
|
|
}
|
|
|
|
|
2018-04-16 16:27:55 +02:00
|
|
|
/** \} */
|
2020-02-04 18:26:57 +11:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name 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.
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
static int undo_editmode_objects_from_view_layer_prepare(ViewLayer *view_layer,
|
|
|
|
Object *obact,
|
|
|
|
int *r_active_index)
|
|
|
|
{
|
|
|
|
const short object_type = obact->type;
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
2020-02-04 18:26:57 +11:00
|
|
|
Object *ob = base->object;
|
|
|
|
if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
|
|
|
|
ID *id = ob->data;
|
|
|
|
id->tag &= ~LIB_TAG_DOIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int len = 0;
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
2020-02-04 18:26:57 +11:00
|
|
|
Object *ob = base->object;
|
|
|
|
if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
|
|
|
|
if (ob == obact) {
|
|
|
|
*r_active_index = len;
|
|
|
|
}
|
|
|
|
ID *id = ob->data;
|
|
|
|
if ((id->tag & LIB_TAG_DOIT) == 0) {
|
|
|
|
len += 1;
|
|
|
|
id->tag |= LIB_TAG_DOIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object **ED_undo_editmode_objects_from_view_layer(ViewLayer *view_layer, uint *r_len)
|
|
|
|
{
|
|
|
|
Object *obact = OBACT(view_layer);
|
|
|
|
if ((obact == NULL) || (obact->mode & OB_MODE_EDIT) == 0) {
|
|
|
|
return MEM_mallocN(0, __func__);
|
|
|
|
}
|
|
|
|
int active_index = 0;
|
|
|
|
const int len = undo_editmode_objects_from_view_layer_prepare(view_layer, obact, &active_index);
|
|
|
|
const short object_type = obact->type;
|
|
|
|
int i = 0;
|
|
|
|
Object **objects = MEM_malloc_arrayN(len, sizeof(*objects), __func__);
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
2020-02-04 18:26:57 +11:00
|
|
|
Object *ob = base->object;
|
|
|
|
if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
|
|
|
|
ID *id = ob->data;
|
|
|
|
if (id->tag & LIB_TAG_DOIT) {
|
|
|
|
objects[i++] = ob;
|
|
|
|
id->tag &= ~LIB_TAG_DOIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_assert(i == len);
|
|
|
|
if (active_index > 0) {
|
|
|
|
SWAP(Object *, objects[0], objects[active_index]);
|
|
|
|
}
|
|
|
|
*r_len = len;
|
|
|
|
return objects;
|
|
|
|
}
|
|
|
|
|
|
|
|
Base **ED_undo_editmode_bases_from_view_layer(ViewLayer *view_layer, uint *r_len)
|
|
|
|
{
|
|
|
|
Object *obact = OBACT(view_layer);
|
|
|
|
if ((obact == NULL) || (obact->mode & OB_MODE_EDIT) == 0) {
|
|
|
|
return MEM_mallocN(0, __func__);
|
|
|
|
}
|
|
|
|
int active_index = 0;
|
|
|
|
const int len = undo_editmode_objects_from_view_layer_prepare(view_layer, obact, &active_index);
|
|
|
|
const short object_type = obact->type;
|
|
|
|
int i = 0;
|
|
|
|
Base **base_array = MEM_malloc_arrayN(len, sizeof(*base_array), __func__);
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
2020-02-04 18:26:57 +11:00
|
|
|
Object *ob = base->object;
|
|
|
|
if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
|
|
|
|
ID *id = ob->data;
|
|
|
|
if (id->tag & LIB_TAG_DOIT) {
|
|
|
|
base_array[i++] = base;
|
|
|
|
id->tag &= ~LIB_TAG_DOIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BLI_assert(i == len);
|
|
|
|
if (active_index > 0) {
|
|
|
|
SWAP(Base *, base_array[0], base_array[active_index]);
|
|
|
|
}
|
|
|
|
*r_len = len;
|
|
|
|
return base_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|