[Bf-blender-cvs] [af146e77454] property-search-ui: Use operator to toggle pin data-block
Hans Goudey
noreply at git.blender.org
Thu Jul 23 18:16:44 CEST 2020
Commit: af146e774546d9c2b5ba1e425d3f42b9b4d35b0b
Author: Hans Goudey
Date: Thu Jul 23 12:16:49 2020 -0400
Branches: property-search-ui
https://developer.blender.org/rBaf146e774546d9c2b5ba1e425d3f42b9b4d35b0b
Use operator to toggle pin data-block
===================================================================
M release/scripts/startup/bl_ui/space_properties.py
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/release/scripts/startup/bl_ui/space_properties.py b/release/scripts/startup/bl_ui/space_properties.py
index c5b019d58bb..a6cff0b2787 100644
--- a/release/scripts/startup/bl_ui/space_properties.py
+++ b/release/scripts/startup/bl_ui/space_properties.py
@@ -36,7 +36,7 @@ class PROPERTIES_HT_header(Header):
# Note: pin ID doesn't properly work with this simple button in python yet.
row = layout.row()
row.emboss = 'NONE'
- row.prop(view, "use_pin_id", icon=('PINNED' if view.use_pin_id else 'UNPINNED'), text="")
+ row.operator("buttons.toggle_pin", icon=('PINNED' if view.use_pin_id else 'UNPINNED'), text="")
class PROPERTIES_PT_navigation_bar(Panel):
diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h
index ce6490f6baa..459c0dc2448 100644
--- a/source/blender/editors/space_buttons/buttons_intern.h
+++ b/source/blender/editors/space_buttons/buttons_intern.h
@@ -92,6 +92,7 @@ void buttons_texture_context_compute(const struct bContext *C, struct SpacePrope
/* buttons_ops.c */
void BUTTONS_OT_start_filter(struct wmOperatorType *ot);
void BUTTONS_OT_clear_filter(struct wmOperatorType *ot);
+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 d0fc17aa6c2..9c2ef613ba4 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -108,6 +108,33 @@ void BUTTONS_OT_clear_filter(struct wmOperatorType *ot)
ot->poll = ED_operator_buttons_active;
}
+/********************** 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 56b693f9e2b..ac0baeb1a68 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -399,6 +399,7 @@ static void buttons_operatortypes(void)
{
WM_operatortype_append(BUTTONS_OT_start_filter);
WM_operatortype_append(BUTTONS_OT_clear_filter);
+ 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