[Bf-blender-cvs] [5baff62] gooseberry: Reorganized RMB menu and new entry "Copy Full Data Path"
Julian Eisel
noreply at git.blender.org
Wed Apr 1 13:42:47 CEST 2015
Commit: 5baff6246f7f50bdb637f988adb8fbbfe4adaf46
Author: Julian Eisel
Date: Wed Apr 1 13:41:38 2015 +0200
Branches: gooseberry
https://developer.blender.org/rB5baff6246f7f50bdb637f988adb8fbbfe4adaf46
Reorganized RMB menu and new entry "Copy Full Data Path"
D763 ready for testing from the sheepy people.
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/interface_intern.h
M source/blender/editors/interface/interface_ops.c
M source/blender/editors/interface/interface_utils.c
===================================================================
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index d9f09b0..0681cac 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -182,6 +182,7 @@ enum {
UI_BUT_TIP_FORCE = (1 << 28), /* force show tooltips when holding option/alt if U's USER_TOOLTIPS is off */
UI_BUT_TEXTEDIT_UPDATE = (1 << 29), /* when widget is in textedit mode, update value on each char stroke */
UI_BUT_SEARCH_UNLINK = (1 << 30), /* show unlink for search button */
+ UI_BUT_MENU_ROOT = (1 << 31), /* but is root of a menu */
};
#define UI_PANEL_WIDTH 340
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index b4f2699..754967d 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3102,6 +3102,8 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat
data->menu->popup = but->block->handle->popup;
}
+ but->flag |= UI_BUT_MENU_ROOT;
+
/* this makes adjacent blocks auto open from now on */
//if (but->block->auto_open == 0) but->block->auto_open = 1;
}
@@ -5996,6 +5998,33 @@ void ui_panel_menu(bContext *C, ARegion *ar, Panel *pa)
UI_popup_menu_end(C, pup);
}
+static void ui_menu_scripting(bContext *UNUSED(C), uiLayout *layout, void *arg)
+{
+ uiBut *but = arg;
+
+ if (!ui_block_is_menu(but->block)) {
+ uiItemFullO(layout, "UI_OT_editsource", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0);
+ }
+
+ uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Data Path"),
+ ICON_NONE, "UI_OT_copy_data_path_button", "full", 0);
+ uiItemBooleanO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Full Data Path"),
+ ICON_NONE, "UI_OT_copy_data_path_button", "full", 1);
+
+ if (but->rnapoin.data && but->rnaprop) {
+ PointerRNA ptr_props;
+ char buf[512];
+
+ BLI_snprintf(buf, sizeof(buf), "%s.%s",
+ RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
+
+ WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
+ RNA_string_set(&ptr_props, "doc_id", buf);
+ uiItemFullO(layout, "WM_OT_doc_view", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
+ ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
+ }
+}
+
static bool ui_but_menu(bContext *C, uiBut *but)
{
uiPopupMenu *pup;
@@ -6010,7 +6039,9 @@ static bool ui_but_menu(bContext *C, uiBut *but)
if (but->type == UI_BTYPE_IMAGE) {
return false;
}
-
+
+ but->flag |= UI_BUT_MENU_ROOT;
+
button_timers_tooltip_remove(C, but);
/* highly unlikely getting the label ever fails */
@@ -6180,15 +6211,16 @@ static bool ui_but_menu(bContext *C, uiBut *but)
uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Unset"),
ICON_NONE, "UI_OT_unset_property_button");
}
-
- uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy Data Path"),
- ICON_NONE, "UI_OT_copy_data_path_button");
uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy To Selected"),
ICON_NONE, "UI_OT_copy_to_selected_button");
uiItemS(layout);
}
+ /* Scripting submenu */
+ uiItemMenuF(layout, IFACE_("Scripting"), ICON_NONE, ui_menu_scripting, but);
+ uiItemS(layout);
+
/* Operator buttons */
if (but->optype) {
uiBlock *block = uiLayoutGetBlock(layout);
@@ -6248,11 +6280,6 @@ static bool ui_but_menu(bContext *C, uiBut *but)
uiItemFullO(layout, "WM_OT_doc_view_manual", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
- WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
- RNA_string_set(&ptr_props, "doc_id", buf);
- uiItemFullO(layout, "WM_OT_doc_view", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
- ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
-
/* XXX inactive option, not for public! */
#if 0
WM_operator_properties_create(&ptr_props, "WM_OT_doc_edit");
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 65e94c5..999b762 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -619,6 +619,7 @@ extern int ui_but_menu_direction(uiBut *but);
extern void ui_but_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut *but, const bool restore);
extern uiBut *ui_but_find_select_in_enum(uiBut *but, int direction);
extern uiBut *ui_but_find_active_in_region(struct ARegion *ar);
+extern uiBut *ui_but_find_menu_root(struct bContext *C);
bool ui_but_is_editable(const uiBut *but);
bool ui_but_is_editable_as_text(const uiBut *but);
void ui_but_pie_dir_visual(RadialDirection dir, float vec[2]);
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 41d2a90..4baaade 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -92,15 +92,15 @@ static void UI_OT_reset_default_theme(wmOperatorType *ot)
static int copy_data_path_button_poll(bContext *C)
{
- PointerRNA ptr;
- PropertyRNA *prop;
- char *path;
- int index;
+ uiBut *but = ui_but_find_menu_root(C);
- UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+ /* fallback to find but->active */
+ if (but == NULL) {
+ but = UI_context_active_but_get(C);
+ }
- if (ptr.id.data && ptr.data && prop) {
- path = RNA_path_from_ID_to_property(&ptr, prop);
+ if (but && but->rnapoin.data) {
+ char *path = RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
if (path) {
MEM_freeN(path);
@@ -111,19 +111,20 @@ static int copy_data_path_button_poll(bContext *C)
return 0;
}
-static int copy_data_path_button_exec(bContext *C, wmOperator *UNUSED(op))
+static int copy_data_path_button_exec(bContext *C, wmOperator *op)
{
- PointerRNA ptr;
- PropertyRNA *prop;
- char *path;
- int index;
+ uiBut *but = ui_but_find_menu_root(C);
- /* try to create driver using property retrieved from UI */
- UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+ /* fallback to find but->active */
+ if (but == NULL) {
+ but = UI_context_active_but_get(C);
+ }
+
+ if (but && but->rnapoin.data) {
+ const bool full = RNA_boolean_get(op->ptr, "full");
+ char *path = full ? RNA_path_full_property_py(&but->rnapoin, but->rnaprop, -1) :
+ RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
- if (ptr.id.data && ptr.data && prop) {
- path = RNA_path_from_ID_to_property(&ptr, prop);
-
if (path) {
WM_clipboard_text_set(path, false);
MEM_freeN(path);
@@ -147,6 +148,9 @@ static void UI_OT_copy_data_path_button(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "full", 0, "Full", "Copy the full RNA data path for this property to the clipboard");
}
/* Reset to Default Values Button Operator ------------------------ */
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 28bd637..6f8ef04 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -43,6 +43,7 @@
#include "BLF_translation.h"
+#include "BKE_context.h"
#include "BKE_report.h"
#include "MEM_guardedalloc.h"
@@ -309,6 +310,25 @@ int UI_calc_float_precision(int prec, double value)
return prec;
}
+uiBut *ui_but_find_menu_root(struct bContext *C) {
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar;
+ uiBlock *block;
+ uiBut *but;
+
+ for (ar = sa->regionbase.first; ar; ar = ar->next) {
+ for (block = ar->uiblocks.first; block; block = block->next) {
+ for (but = block->buttons.first; but; but = but->next) {
+ if (but->flag & UI_BUT_MENU_ROOT) {
+ return but;
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+
/* -------------------------------------------------------------------- */
/* Modal Button Store API */
More information about the Bf-blender-cvs
mailing list