[Bf-blender-cvs] [a5509371164] master: UI: Use operator to set property editor's pinned data-block

Hans Goudey noreply at git.blender.org
Fri Sep 11 21:08:57 CEST 2020


Commit: a55093711644f1a87eb058d2bed20d530a4de155
Author: Hans Goudey
Date:   Fri Sep 11 14:08:38 2020 -0500
Branches: master
https://developer.blender.org/rBa55093711644f1a87eb058d2bed20d530a4de155

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

===================================================================

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 e0a5158e510..9228853ed19 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -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
diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h
index 911cf4526bb..a1e2b9e9aaf 100644
--- a/source/blender/editors/space_buttons/buttons_intern.h
+++ b/source/blender/editors/space_buttons/buttons_intern.h
@@ -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);
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c
index a062b178fc8..2e6ad82ef08 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -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
  * \{ */
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index fd713e7094a..3b7fe45f9c8 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -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);



More information about the Bf-blender-cvs mailing list