WM: revert part of Top-Bar inclusion
This removes OperatorRepeatContextHandle, from 5f6c45498c
since we now only have redo in the area an operator is executed in.
These values could be invalid and crashed in some cases.
This commit is contained in:
@@ -52,14 +52,6 @@ int ED_undo_operator_repeat(struct bContext *C, struct wmOperator *op);
|
||||
void ED_undo_operator_repeat_cb(struct bContext *C, void *arg_op, void *arg_unused);
|
||||
void ED_undo_operator_repeat_cb_evt(struct bContext *C, void *arg_op, int arg_unused);
|
||||
|
||||
/* Context sanity helpers for operator repeat. */
|
||||
typedef struct OperatorRepeatContextHandle OperatorRepeatContextHandle;
|
||||
|
||||
const OperatorRepeatContextHandle *ED_operator_repeat_prepare_context(
|
||||
struct bContext *C, struct wmOperator *op) ATTR_WARN_UNUSED_RESULT;
|
||||
void ED_operator_repeat_reset_context(
|
||||
struct bContext *C, const OperatorRepeatContextHandle *context_info);
|
||||
|
||||
bool ED_undo_is_valid(const struct bContext *C, const char *undoname);
|
||||
|
||||
struct UndoStack *ED_undo_stack_get(void);
|
||||
|
||||
@@ -57,9 +57,6 @@
|
||||
#include "WM_types.h"
|
||||
#include "WM_message.h"
|
||||
|
||||
|
||||
void topbar_panels_register(ARegionType *art);
|
||||
|
||||
/* ******************** default callbacks for topbar space ***************** */
|
||||
|
||||
static SpaceLink *topbar_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
|
||||
@@ -277,64 +274,9 @@ void ED_spacetype_topbar(void)
|
||||
art->layout = ED_region_header_layout;
|
||||
art->draw = ED_region_header_draw;
|
||||
|
||||
/* For popovers. */
|
||||
topbar_panels_register(art);
|
||||
|
||||
BLI_addhead(&st->regiontypes, art);
|
||||
|
||||
recent_files_menu_register();
|
||||
|
||||
BKE_spacetype_register(st);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Redo Panel
|
||||
* \{ */
|
||||
|
||||
static int topbar_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt))
|
||||
{
|
||||
wmOperator *op = WM_operator_last_redo(C);
|
||||
if (op == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
if (!WM_operator_check_ui_empty(op->type)) {
|
||||
const OperatorRepeatContextHandle *context_info;
|
||||
context_info = ED_operator_repeat_prepare_context((bContext *)C, op);
|
||||
success = WM_operator_poll((bContext *)C, op->type);
|
||||
ED_operator_repeat_reset_context((bContext *)C, context_info);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
static void topbar_panel_operator_redo(const bContext *C, Panel *pa)
|
||||
{
|
||||
wmOperator *op = WM_operator_last_redo(C);
|
||||
if (op == NULL) {
|
||||
return;
|
||||
}
|
||||
if (!WM_operator_check_ui_enabled(C, op->type->name)) {
|
||||
uiLayoutSetEnabled(pa->layout, false);
|
||||
}
|
||||
uiLayout *col = uiLayoutColumn(pa->layout, false);
|
||||
uiTemplateOperatorRedoProperties(col, C);
|
||||
}
|
||||
|
||||
void topbar_panels_register(ARegionType *art)
|
||||
{
|
||||
PanelType *pt;
|
||||
|
||||
pt = MEM_callocN(sizeof(PanelType), __func__);
|
||||
strcpy(pt->idname, "TOPBAR_PT_redo");
|
||||
strcpy(pt->label, N_("Redo"));
|
||||
strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
|
||||
pt->draw = topbar_panel_operator_redo;
|
||||
pt->poll = topbar_panel_operator_redo_poll;
|
||||
pt->space_type = SPACE_TOPBAR;
|
||||
pt->region_type = RGN_TYPE_HEADER;
|
||||
BLI_addtail(&art->paneltypes, pt);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -302,36 +302,6 @@ void ED_OT_undo_redo(wmOperatorType *ot)
|
||||
|
||||
/** \} */
|
||||
|
||||
struct OperatorRepeatContextHandle {
|
||||
ScrArea *restore_area;
|
||||
ARegion *restore_region;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the context to the state \a op was executed in (or at least, was in when registering).
|
||||
* #ED_operator_repeat_reset_context should be called when done repeating!
|
||||
*/
|
||||
const OperatorRepeatContextHandle *ED_operator_repeat_prepare_context(bContext *C, wmOperator *op)
|
||||
{
|
||||
static OperatorRepeatContextHandle context_info;
|
||||
|
||||
context_info.restore_area = CTX_wm_area(C);
|
||||
context_info.restore_region = CTX_wm_region(C);
|
||||
|
||||
CTX_wm_area_set(C, op->execution_area);
|
||||
CTX_wm_region_set(C, op->execution_region);
|
||||
|
||||
return &context_info;
|
||||
}
|
||||
/**
|
||||
* Resets context to the old state from before #ED_operator_repeat_prepare_context was called.
|
||||
*/
|
||||
void ED_operator_repeat_reset_context(bContext *C, const OperatorRepeatContextHandle *context_info)
|
||||
{
|
||||
CTX_wm_area_set(C, context_info->restore_area);
|
||||
CTX_wm_region_set(C, context_info->restore_region);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Operator Repeat
|
||||
* \{ */
|
||||
@@ -346,8 +316,13 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op)
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
struct Scene *scene = CTX_data_scene(C);
|
||||
|
||||
const OperatorRepeatContextHandle *context_info;
|
||||
context_info = ED_operator_repeat_prepare_context(C, op);
|
||||
/* keep in sync with logic in view3d_panel_operator_redo() */
|
||||
ARegion *ar_orig = CTX_wm_region(C);
|
||||
ARegion *ar_win = BKE_area_find_region_active_win(CTX_wm_area(C));
|
||||
|
||||
if (ar_win) {
|
||||
CTX_wm_region_set(C, ar_win);
|
||||
}
|
||||
|
||||
if ((WM_operator_repeat_check(C, op)) &&
|
||||
(WM_operator_poll(C, op->type)) &&
|
||||
@@ -393,7 +368,8 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op)
|
||||
}
|
||||
}
|
||||
|
||||
ED_operator_repeat_reset_context(C, context_info);
|
||||
/* set region back */
|
||||
CTX_wm_region_set(C, ar_orig);
|
||||
}
|
||||
else {
|
||||
CLOG_WARN(&LOG, "called with NULL 'op'");
|
||||
|
||||
@@ -377,11 +377,6 @@ typedef struct wmOperator {
|
||||
struct wmOperator *opm; /* current running macro, not saved */
|
||||
struct uiLayout *layout; /* runtime for drawing */
|
||||
short flag, pad[3];
|
||||
|
||||
/* Screen context the operator was finished in. It gets temporarily
|
||||
* restored during operator repeat. Only set for registered operators. */
|
||||
struct ScrArea *execution_area;
|
||||
struct ARegion *execution_region;
|
||||
} wmOperator;
|
||||
|
||||
/* operator type return flags: exec(), invoke() modal(), return values */
|
||||
|
||||
@@ -165,9 +165,6 @@ void wm_operator_register(bContext *C, wmOperator *op)
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
int tot = 0;
|
||||
|
||||
op->execution_area = CTX_wm_area(C);
|
||||
op->execution_region = CTX_wm_region(C);
|
||||
|
||||
BLI_addtail(&wm->operators, op);
|
||||
|
||||
/* only count registered operators */
|
||||
|
||||
@@ -1007,14 +1007,7 @@ int WM_operator_call_notest(bContext *C, wmOperator *op)
|
||||
*/
|
||||
int WM_operator_repeat(bContext *C, wmOperator *op)
|
||||
{
|
||||
const OperatorRepeatContextHandle *context_info;
|
||||
int retval;
|
||||
|
||||
context_info = ED_operator_repeat_prepare_context(C, op);
|
||||
retval = wm_operator_exec(C, op, true, true);
|
||||
ED_operator_repeat_reset_context(C, context_info);
|
||||
|
||||
return retval;
|
||||
return wm_operator_exec(C, op, true, true);
|
||||
}
|
||||
/**
|
||||
* \return true if #WM_operator_repeat can run
|
||||
|
||||
Reference in New Issue
Block a user