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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-12-06 21:42:18 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-12-06 21:57:47 +0300
commit7465078e637b729e8b36a4f4b73a50a347052df4 (patch)
treee174b48c1831f2354f0a80a31e3ec74279f6df1c /source
parent8a8b549e56c6d2b7fd02e7e58205e0559dfca389 (diff)
Tool System: don't assert when showing tooltips in a different space
Needed to show fallback tool for the 3D view in the properties editor.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 8cea80bac7f..26ac8953e44 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -371,6 +371,28 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
RNA_string_get(but->opptr, "name", tool_id);
BLI_assert(tool_id[0] != '\0');
+ /* When false, we're in a diffrent space type to the tool being set.
+ * Needed for setting the fallback tool from the properties space.
+ *
+ * If we drop the hard coded 3D-view in properties hack, we can remove this check. */
+ bool has_valid_context = true;
+ const char *has_valid_context_error = IFACE_("Unsupported context");
+ {
+ ScrArea *sa = CTX_wm_area(C);
+ if (sa == NULL) {
+ has_valid_context = false;
+ }
+ else {
+ PropertyRNA *prop = RNA_struct_find_property(but->opptr, "space_type");
+ if (RNA_property_is_set(but->opptr, prop)) {
+ const int space_type_prop = RNA_property_enum_get(but->opptr, prop);
+ if (space_type_prop != sa->spacetype) {
+ has_valid_context = false;
+ }
+ }
+ }
+ }
+
/* We have a tool, now extract the info. */
uiTooltipData *data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
@@ -391,7 +413,11 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
tool_id);
char *expr_result = NULL;
bool is_error = false;
- if (BPY_execute_string_as_string(C, expr_imports, expr, true, &expr_result)) {
+
+ if (has_valid_context == false) {
+ expr_result = BLI_strdup(has_valid_context_error);
+ }
+ else if (BPY_execute_string_as_string(C, expr_imports, expr, true, &expr_result)) {
if (STREQ(expr_result, "")) {
MEM_freeN(expr_result);
expr_result = NULL;
@@ -444,7 +470,11 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
char *expr_result = NULL;
bool is_error = false;
- if (BPY_execute_string_as_string(C, expr_imports, expr, true, &expr_result)) {
+
+ if (has_valid_context == false) {
+ expr_result = BLI_strdup(has_valid_context_error);
+ }
+ else if (BPY_execute_string_as_string(C, expr_imports, expr, true, &expr_result)) {
if (STREQ(expr_result, ".")) {
MEM_freeN(expr_result);
expr_result = NULL;
@@ -541,7 +571,11 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
"'as_pointer', lambda: 0)()");
intptr_t expr_result = 0;
- if (BPY_execute_string_as_intptr(C, expr_imports, expr, true, &expr_result)) {
+
+ if (has_valid_context == false) {
+ shortcut = BLI_strdup(has_valid_context_error);
+ }
+ else if (BPY_execute_string_as_intptr(C, expr_imports, expr, true, &expr_result)) {
if (expr_result != 0) {
wmKeyMap *keymap = (wmKeyMap *)expr_result;
for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
@@ -592,7 +626,11 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
tool_id);
intptr_t expr_result = 0;
- if (BPY_execute_string_as_intptr(C, expr_imports, expr, true, &expr_result)) {
+
+ if (has_valid_context == false) {
+ /* pass */
+ }
+ else if (BPY_execute_string_as_intptr(C, expr_imports, expr, true, &expr_result)) {
if (expr_result != 0) {
{
uiTooltipField *field = text_field_add(data,