Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-03-15 04:45:41 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-15 06:53:08 +0300
commit3400fe3ecee99cb6a74455943f2755e6f22ef047 (patch)
treed38e6d65b73f32d4b7685f2010e3f70df45994a0 /source/blender
parent388ff003e28bb8077d3dbd300e7e1f6beccea263 (diff)
Tool System: split UI label from tool identifiers
Prepare for exposing tool registration to the Python API. - Generated tools can use their own prefix so naming collisions won't happen between hard coded & generated tools. - Add-on authors can use the add-on name as a prefix. Currently the names match, renaming will happen next.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/interface/interface_query.c2
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c68
-rw-r--r--source/blender/makesrna/intern/rna_workspace.c5
-rw-r--r--source/blender/makesrna/intern/rna_workspace_api.c2
-rw-r--r--source/blender/windowmanager/WM_toolsystem.h2
-rw-r--r--source/blender/windowmanager/intern/wm_keymap_utils.c4
-rw-r--r--source/blender/windowmanager/intern/wm_toolsystem.c6
7 files changed, 59 insertions, 30 deletions
diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c
index d4d5e3d3df6..ad83bce97a6 100644
--- a/source/blender/editors/interface/interface_query.c
+++ b/source/blender/editors/interface/interface_query.c
@@ -83,7 +83,7 @@ bool UI_but_is_tool(const uiBut *but)
if (but->optype != NULL) {
static wmOperatorType *ot = NULL;
if (ot == NULL) {
- ot = WM_operatortype_find("WM_OT_tool_set_by_name", false);
+ ot = WM_operatortype_find("WM_OT_tool_set_by_id", false);
}
if (but->optype == ot) {
return true;
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 0da96cc09c6..629de557a2d 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -364,7 +364,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
return NULL;
}
- if (!STREQ(but->optype->idname, "WM_OT_tool_set_by_name")) {
+ if (!STREQ(but->optype->idname, "WM_OT_tool_set_by_id")) {
return NULL;
}
@@ -373,9 +373,9 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
return NULL;
}
- char tool_name[MAX_NAME];
- RNA_string_get(but->opptr, "name", tool_name);
- BLI_assert(tool_name[0] != '\0');
+ char tool_id[MAX_NAME];
+ RNA_string_get(but->opptr, "name", tool_id);
+ BLI_assert(tool_id[0] != '\0');
/* We have a tool, now extract the info. */
uiTooltipData *data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
@@ -387,13 +387,43 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
/* Title (when icon-only). */
if (but->drawstr[0] == '\0') {
- uiTooltipField *field = text_field_add(
- data, &(uiTooltipFormat){
- .style = UI_TIP_STYLE_NORMAL,
- .color_id = UI_TIP_LC_MAIN,
- .is_pad = true,
- });
- field->text = BLI_strdup(tool_name);
+ const char *expr_imports[] = {"bpy", "bl_ui", NULL};
+ char expr[256];
+ SNPRINTF(
+ expr,
+ "bl_ui.space_toolsystem_common.item_from_id("
+ "bpy.context, "
+ "bpy.context.space_data.type, "
+ "'%s').label",
+ tool_id);
+ char *expr_result = NULL;
+ bool is_error = false;
+ if (BPY_execute_string_as_string(C, expr_imports, expr, true, &expr_result)) {
+ if (STREQ(expr_result, "")) {
+ MEM_freeN(expr_result);
+ expr_result = NULL;
+ }
+ }
+ else {
+ /* Note, this is an exceptional case, we could even remove it
+ * however there have been reports of tooltips failing, so keep it for now. */
+ expr_result = BLI_strdup("Internal error!");
+ is_error = true;
+ }
+
+ if (expr_result != NULL) {
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_NORMAL,
+ .color_id = UI_TIP_LC_MAIN,
+ .is_pad = true,
+ });
+ field->text = expr_result;
+
+ if (UNLIKELY(is_error)) {
+ field->format.color_id = UI_TIP_LC_ALERT;
+ }
+ }
}
/* Tip. */
@@ -402,11 +432,11 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
char expr[256];
SNPRINTF(
expr,
- "bl_ui.space_toolsystem_common.description_from_name("
+ "bl_ui.space_toolsystem_common.description_from_id("
"bpy.context, "
"bpy.context.space_data.type, "
"'%s') + '.'",
- tool_name);
+ tool_id);
char *expr_result = NULL;
bool is_error = false;
@@ -461,7 +491,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
const char *tool_attr = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
if (tool_attr != NULL) {
const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
- const int i = RNA_enum_from_name(items, tool_name);
+ const int i = RNA_enum_from_name(items, tool_id);
if (i != -1) {
wmOperatorType *ot = WM_operatortype_find("paint.brush_select", true);
PointerRNA op_props;
@@ -504,9 +534,9 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
wmKeyMap *keymap = (wmKeyMap *)expr_result;
for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
if (STREQ(kmi->idname, but->optype->idname)) {
- char tool_name_test[MAX_NAME];
- RNA_string_get(kmi->ptr, "name", tool_name_test);
- if (STREQ(tool_name, tool_name_test)) {
+ char tool_id_test[MAX_NAME];
+ RNA_string_get(kmi->ptr, "name", tool_id_test);
+ if (STREQ(tool_id, tool_id_test)) {
char buf[128];
WM_keymap_item_to_string(kmi, false, buf, sizeof(buf));
shortcut = BLI_sprintfN("%s, %s", shortcut_toolbar, buf);
@@ -543,12 +573,12 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
SNPRINTF(
expr,
"getattr("
- "bl_ui.space_toolsystem_common.keymap_from_name("
+ "bl_ui.space_toolsystem_common.keymap_from_id("
"bpy.context, "
"bpy.context.space_data.type, "
"'%s'), "
"'as_pointer', lambda: 0)()",
- tool_name);
+ tool_id);
intptr_t expr_result = 0;
if (BPY_execute_string_as_intptr(C, expr_imports, expr, true, &expr_result)) {
diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c
index 3ae3f435ffb..ab0af6c0a91 100644
--- a/source/blender/makesrna/intern/rna_workspace.c
+++ b/source/blender/makesrna/intern/rna_workspace.c
@@ -234,9 +234,8 @@ static void rna_def_workspace_tool(BlenderRNA *brna)
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
RNA_def_struct_ui_text(srna, "Work Space Tool", "");
- prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "idname");
- RNA_def_property_ui_text(prop, "Name", "");
+ prop = RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Identifier", "");
RNA_def_struct_name_property(srna, prop);
prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c
index 3f1a30a5075..f82b1ecda60 100644
--- a/source/blender/makesrna/intern/rna_workspace_api.c
+++ b/source/blender/makesrna/intern/rna_workspace_api.c
@@ -133,7 +133,7 @@ void RNA_api_workspace_tool(StructRNA *srna)
RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Set the tool settings");
- parm = RNA_def_string(func, "name", NULL, KMAP_MAX_NAME, "Name", "");
+ parm = RNA_def_string(func, "idname", NULL, MAX_NAME, "Identifier", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
/* 'bToolRef_Runtime' */
diff --git a/source/blender/windowmanager/WM_toolsystem.h b/source/blender/windowmanager/WM_toolsystem.h
index 7f9b17dbe17..762c25b3f18 100644
--- a/source/blender/windowmanager/WM_toolsystem.h
+++ b/source/blender/windowmanager/WM_toolsystem.h
@@ -54,7 +54,7 @@ struct bToolRef *WM_toolsystem_ref_find(struct WorkSpace *workspace, const bTool
bool WM_toolsystem_ref_ensure(
struct WorkSpace *workspace, const bToolKey *tkey,
struct bToolRef **r_tref);
-struct bToolRef *WM_toolsystem_ref_set_by_name(
+struct bToolRef *WM_toolsystem_ref_set_by_id(
struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey,
const char *name, bool cycle);
diff --git a/source/blender/windowmanager/intern/wm_keymap_utils.c b/source/blender/windowmanager/intern/wm_keymap_utils.c
index b387cd0cfa8..6e70511ce63 100644
--- a/source/blender/windowmanager/intern/wm_keymap_utils.c
+++ b/source/blender/windowmanager/intern/wm_keymap_utils.c
@@ -69,7 +69,7 @@ wmKeyMapItem *WM_keymap_add_panel(wmKeyMap *keymap, const char *idname, int type
/* tool wrapper for WM_keymap_add_item */
wmKeyMapItem *WM_keymap_add_tool(wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier)
{
- wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_tool_set_by_name", type, val, modifier, keymodifier);
+ wmKeyMapItem *kmi = WM_keymap_add_item(keymap, "WM_OT_tool_set_by_id", type, val, modifier, keymodifier);
RNA_string_set(kmi->ptr, "name", idname);
return kmi;
}
@@ -169,7 +169,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
if (STRPREFIX(opname, "WM_OT") ||
STRPREFIX(opname, "ED_OT_undo"))
{
- if (STREQ(opname, "WM_OT_tool_set_by_name")) {
+ if (STREQ(opname, "WM_OT_tool_set_by_id")) {
km = WM_keymap_guess_from_context(C);
}
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c
index 1c8bea19952..75bcee562a0 100644
--- a/source/blender/windowmanager/intern/wm_toolsystem.c
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -728,11 +728,11 @@ static void toolsystem_refresh_screen_from_active_tool(
}
}
-bToolRef *WM_toolsystem_ref_set_by_name(
+bToolRef *WM_toolsystem_ref_set_by_id(
bContext *C, WorkSpace *workspace, const bToolKey *tkey,
const char *name, bool cycle)
{
- wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_name", false);
+ wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_id", false);
/* On startup, Python operatores are not yet loaded. */
if (ot == NULL) {
return NULL;
@@ -775,7 +775,7 @@ static void toolsystem_reinit_with_toolref(
.space_type = tref->space_type,
.mode = tref->mode,
};
- WM_toolsystem_ref_set_by_name(C, workspace, &tkey, tref->idname, false);
+ WM_toolsystem_ref_set_by_id(C, workspace, &tkey, tref->idname, false);
}
static const char *toolsystem_default_tool(const bToolKey *tkey)