[Bf-blender-cvs] [67766079133] property-search-ui-v2: UI: Use an operator to set the property editor's pinned data-block
Hans Goudey
noreply at git.blender.org
Wed Sep 9 18:11:50 CEST 2020
Commit: 67766079133d484f791ee1188e21c70f857c3cea
Author: Hans Goudey
Date: Thu Jul 23 12:42:28 2020 -0400
Branches: property-search-ui-v2
https://developer.blender.org/rB67766079133d484f791ee1188e21c70f857c3cea
UI: Use an operator to set the property editor's pinned data-block
This is another change pulled from the `property-search-ui` branch. This is useful
because it means the pin button doesn't have to be a custom button defined in C.
Replacing the use of button callbacks with operators is always nice too.
Differential Revision: https://developer.blender.org/D8376
===================================================================
M source/blender/editors/space_buttons/buttons_context.c
M source/blender/editors/space_buttons/buttons_intern.h
M source/blender/editors/space_buttons/buttons_ops.c
M source/blender/editors/space_buttons/space_buttons.c
===================================================================
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index f2f377c142f..7233347e481 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -1120,7 +1120,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;
@@ -1186,25 +1186,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
diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h
index 64166f15ea3..e64de167619 100644
--- a/source/blender/editors/space_buttons/buttons_intern.h
+++ b/source/blender/editors/space_buttons/buttons_intern.h
@@ -94,6 +94,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);
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c
index 733f344fbc6..7f04bad3700 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -52,6 +52,33 @@
#include "buttons_intern.h" /* own include */
+/********************** pin id operator *********************/
+
+static int toggle_pin_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ SpaceProperties *sbuts = CTX_wm_space_properties(C);
+
+ sbuts->pinid = (sbuts->flag & SB_PIN_CONTEXT) ? NULL : buttons_context_id_path(C);
+
+ sbuts->flag ^= SB_PIN_CONTEXT;
+
+ 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";
+
+ /* api callbacks */
+ ot->exec = toggle_pin_exec;
+ ot->poll = ED_operator_buttons_active;
+}
+
/********************** context_menu operator *********************/
static int context_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index 8337c9b792a..d0f82386c28 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -332,6 +332,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);
More information about the Bf-blender-cvs
mailing list