[Bf-blender-cvs] [ca2ae350ecb] master: Asset Browser: Improve hint for asset library that isn't found

Julian Eisel noreply at git.blender.org
Tue Oct 26 21:58:08 CEST 2021


Commit: ca2ae350ecb5eb154609fd673e3049b77d426774
Author: Julian Eisel
Date:   Tue Oct 26 21:55:46 2021 +0200
Branches: master
https://developer.blender.org/rBca2ae350ecb5eb154609fd673e3049b77d426774

Asset Browser: Improve hint for asset library that isn't found

We already show a message when showing an asset library whose path can't be
found on disk. The red text was making it look like some fatal error happened.
And the message could be a bit more useful generally.

So this removes the red color of the text, (arguably) improves the text and
adds a button as shortcut to open the Preferences with the asset library
settings.

Differential Revision: https://developer.blender.org/D12894

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

M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/space_file.c

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

diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index e516c3ba2c3..66140cba9c6 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -5072,6 +5072,18 @@ static int userpref_show_exec(bContext *C, wmOperator *op)
   int sizex = (500 + UI_NAVIGATION_REGION_WIDTH) * UI_DPI_FAC;
   int sizey = 520 * UI_DPI_FAC;
 
+  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "section");
+  if (prop && RNA_property_is_set(op->ptr, prop)) {
+    /* Set active section via RNA, so it can fail properly. */
+
+    PointerRNA pref_ptr;
+    RNA_pointer_create(NULL, &RNA_Preferences, &U, &pref_ptr);
+    PropertyRNA *active_section_prop = RNA_struct_find_property(&pref_ptr, "active_section");
+
+    RNA_property_enum_set(&pref_ptr, active_section_prop, RNA_property_enum_get(op->ptr, prop));
+    RNA_property_update(C, &pref_ptr, active_section_prop);
+  }
+
   /* changes context! */
   if (WM_window_open(C,
                      IFACE_("Blender Preferences"),
@@ -5105,6 +5117,8 @@ static int userpref_show_exec(bContext *C, wmOperator *op)
 
 static void SCREEN_OT_userpref_show(struct wmOperatorType *ot)
 {
+  PropertyRNA *prop;
+
   /* identifiers */
   ot->name = "Open Preferences...";
   ot->description = "Edit user preferences and system settings";
@@ -5113,6 +5127,14 @@ static void SCREEN_OT_userpref_show(struct wmOperatorType *ot)
   /* api callbacks */
   ot->exec = userpref_show_exec;
   ot->poll = ED_operator_screenactive_nobackground; /* Not in background as this opens a window. */
+
+  prop = RNA_def_enum(ot->srna,
+                      "section",
+                      rna_enum_preference_section_items,
+                      0,
+                      "",
+                      "Section to activate in the Preferences");
+  RNA_def_property_flag(prop, PROP_HIDDEN);
 }
 
 /** \} */
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 5c6b753d4a5..2e2f0c146d6 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -243,8 +243,9 @@ static void file_draw_string(int sx,
 }
 
 /**
- * \param r_sx, r_sy: The lower right corner of the last line drawn. AKA the cursor position on
- *                    completion.
+ * \param r_sx, r_sy: The lower right corner of the last line drawn, plus the height of the last
+ *                    line. This is the cursor position on completion to allow drawing more text
+ *                    behind that.
  */
 static void file_draw_string_multiline(int sx,
                                        int sy,
@@ -1066,7 +1067,9 @@ void file_draw_list(const bContext *C, ARegion *region)
   layout->curr_size = params->thumbnail_size;
 }
 
-static void file_draw_invalid_library_hint(const SpaceFile *sfile, const ARegion *region)
+static void file_draw_invalid_library_hint(const bContext *C,
+                                           const SpaceFile *sfile,
+                                           ARegion *region)
 {
   const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
 
@@ -1074,9 +1077,7 @@ static void file_draw_invalid_library_hint(const SpaceFile *sfile, const ARegion
   file_path_to_ui_path(asset_params->base_params.dir, library_ui_path, sizeof(library_ui_path));
 
   uchar text_col[4];
-  uchar text_alert_col[4];
   UI_GetThemeColor4ubv(TH_TEXT, text_col);
-  UI_GetThemeColor4ubv(TH_REDALERT, text_alert_col);
 
   const View2D *v2d = &region->v2d;
   const int pad = sfile->layout->tile_border_x;
@@ -1087,23 +1088,42 @@ static void file_draw_invalid_library_hint(const SpaceFile *sfile, const ARegion
   int sy = v2d->tot.ymax;
 
   {
-    const char *message = TIP_("Library not found");
-    const int draw_string_str_len = strlen(message) + 2 + sizeof(library_ui_path);
-    char *draw_string = alloca(draw_string_str_len);
-    BLI_snprintf(draw_string, draw_string_str_len, "%s: %s", message, library_ui_path);
-    file_draw_string_multiline(sx, sy, draw_string, width, line_height, text_alert_col, NULL, &sy);
+    const char *message = TIP_("Path to asset library does not exist:");
+    file_draw_string_multiline(sx, sy, message, width, line_height, text_col, NULL, &sy);
+
+    sy -= line_height;
+    file_draw_string(sx, sy, library_ui_path, width, line_height, UI_STYLE_TEXT_LEFT, text_col);
   }
 
-  /* Next line, but separate it a bit further. */
-  sy -= line_height;
+  /* Separate a bit further. */
+  sy -= line_height * 2.2f;
 
   {
     UI_icon_draw(sx, sy - UI_UNIT_Y, ICON_INFO);
 
     const char *suggestion = TIP_(
-        "Set up the library or edit libraries in the Preferences, File Paths section");
+        "Asset Libraries are local directories that can contain .blend files with assets inside.\n"
+        "Manage Asset Libraries from the File Paths section in Preferences.");
     file_draw_string_multiline(
-        sx + UI_UNIT_X, sy, suggestion, width - UI_UNIT_X, line_height, text_col, NULL, NULL);
+        sx + UI_UNIT_X, sy, suggestion, width - UI_UNIT_X, line_height, text_col, NULL, &sy);
+
+    uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
+    uiBut *but = uiDefIconTextButO(block,
+                                   UI_BTYPE_BUT,
+                                   "SCREEN_OT_userpref_show",
+                                   WM_OP_INVOKE_DEFAULT,
+                                   ICON_PREFERENCES,
+                                   NULL,
+                                   sx + UI_UNIT_X,
+                                   sy - line_height - UI_UNIT_Y * 1.2f,
+                                   UI_UNIT_X * 8,
+                                   UI_UNIT_Y,
+                                   NULL);
+    PointerRNA *but_opptr = UI_but_operator_ptr_get(but);
+    RNA_enum_set(but_opptr, "section", USER_SECTION_FILE_PATHS);
+
+    UI_block_end(C, block);
+    UI_block_draw(C, block);
   }
 }
 
@@ -1111,7 +1131,7 @@ static void file_draw_invalid_library_hint(const SpaceFile *sfile, const ARegion
  * Draw a string hint if the file list is invalid.
  * \return true if the list is invalid and a hint was drawn.
  */
-bool file_draw_hint_if_invalid(const SpaceFile *sfile, const ARegion *region)
+bool file_draw_hint_if_invalid(const bContext *C, const SpaceFile *sfile, ARegion *region)
 {
   FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile);
   /* Only for asset browser. */
@@ -1124,7 +1144,7 @@ bool file_draw_hint_if_invalid(const SpaceFile *sfile, const ARegion *region)
     return false;
   }
 
-  file_draw_invalid_library_hint(sfile, region);
+  file_draw_invalid_library_hint(C, sfile, region);
 
   return true;
 }
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index ba08777e4e2..f6b5f0f47cd 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -47,7 +47,7 @@ struct View2D;
 
 void file_calc_previews(const bContext *C, ARegion *region);
 void file_draw_list(const bContext *C, ARegion *region);
-bool file_draw_hint_if_invalid(const SpaceFile *sfile, const ARegion *region);
+bool file_draw_hint_if_invalid(const bContext *C, const SpaceFile *sfile, ARegion *region);
 
 void file_draw_check_ex(bContext *C, struct ScrArea *area);
 void file_draw_check(bContext *C);
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index a875b7a2c12..ef503708335 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -659,7 +659,7 @@ static void file_main_region_draw(const bContext *C, ARegion *region)
     file_highlight_set(sfile, region, event->xy[0], event->xy[1]);
   }
 
-  if (!file_draw_hint_if_invalid(sfile, region)) {
+  if (!file_draw_hint_if_invalid(C, sfile, region)) {
     file_draw_list(C, region);
   }



More information about the Bf-blender-cvs mailing list