UI: Use operator to set property editor's pinned data-block

This commit removes the custom callback that's currently used to set the
property editor's pinned data, replacing it with an operator. This means
"pin" button doesn't have to be defined in C.

Differential Revision: https://developer.blender.org/D8376
This commit is contained in:
Hans Goudey 2020-09-11 14:08:38 -05:00
parent e22e302837
commit a550937116
Notes: blender-bot 2023-02-14 11:34:30 +01:00
Referenced by issue #77824, Properties Search Implementation
4 changed files with 50 additions and 20 deletions

View File

@ -1133,7 +1133,7 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
{
SpaceProperties *sbuts = CTX_wm_space_properties(C);
ButsContextPath *path = sbuts->path;
uiLayout *row;
uiLayout *row, *sub;
uiBlock *block;
uiBut *but;
PointerRNA *ptr;
@ -1199,25 +1199,12 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
uiItemSpacer(row);
block = uiLayoutGetBlock(row);
UI_block_emboss_set(block, UI_EMBOSS_NONE);
but = uiDefIconButBitC(block,
UI_BTYPE_ICON_TOGGLE,
SB_PIN_CONTEXT,
0,
ICON_UNPINNED,
0,
0,
UI_UNIT_X,
UI_UNIT_Y,
&sbuts->flag,
0,
0,
0,
0,
TIP_("Follow context or keep fixed data-block displayed"));
UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
UI_but_func_set(but, pin_cb, NULL, NULL);
sub = uiLayoutRow(row, false);
uiLayoutSetEmboss(sub, UI_EMBOSS_NONE);
uiItemO(sub,
"",
(sbuts->flag & SB_PIN_CONTEXT) ? ICON_PINNED : ICON_UNPINNED,
"BUTTONS_OT_toggle_pin");
}
#ifdef USE_HEADER_CONTEXT_PATH

View File

@ -93,6 +93,7 @@ extern const char *buttons_context_dir[]; /* doc access */
void buttons_texture_context_compute(const struct bContext *C, struct SpaceProperties *sbuts);
/* buttons_ops.c */
void BUTTONS_OT_toggle_pin(struct wmOperatorType *ot);
void BUTTONS_OT_file_browse(struct wmOperatorType *ot);
void BUTTONS_OT_directory_browse(struct wmOperatorType *ot);
void BUTTONS_OT_context_menu(struct wmOperatorType *ot);

View File

@ -52,6 +52,47 @@
#include "buttons_intern.h" /* own include */
/* -------------------------------------------------------------------- */
/** \name Pin ID Operator
* \{ */
static int toggle_pin_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceProperties *sbuts = CTX_wm_space_properties(C);
sbuts->flag ^= SB_PIN_CONTEXT;
/* Create the properties space pointer. */
PointerRNA sbuts_ptr;
bScreen *screen = CTX_wm_screen(C);
RNA_pointer_create(&screen->id, &RNA_SpaceProperties, sbuts, &sbuts_ptr);
/* Create the new ID pointer and set the the pin ID with RNA
* so we can use the property's RNA update functionality. */
ID *new_id = (sbuts->flag & SB_PIN_CONTEXT) ? buttons_context_id_path(C) : NULL;
PointerRNA new_id_ptr;
RNA_id_pointer_create(new_id, &new_id_ptr);
RNA_pointer_set(&sbuts_ptr, "pin_id", new_id_ptr);
ED_area_tag_redraw(CTX_wm_area(C));
return OPERATOR_FINISHED;
}
void BUTTONS_OT_toggle_pin(wmOperatorType *ot)
{
/* Identifiers. */
ot->name = "Toggle Pin ID";
ot->description = "Keep the current data-block displayed";
ot->idname = "BUTTONS_OT_toggle_pin";
/* Callbacks. */
ot->exec = toggle_pin_exec;
ot->poll = ED_operator_buttons_active;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Context Menu Operator
* \{ */

View File

@ -328,6 +328,7 @@ static void buttons_main_region_listener(wmWindow *UNUSED(win),
static void buttons_operatortypes(void)
{
WM_operatortype_append(BUTTONS_OT_toggle_pin);
WM_operatortype_append(BUTTONS_OT_context_menu);
WM_operatortype_append(BUTTONS_OT_file_browse);
WM_operatortype_append(BUTTONS_OT_directory_browse);