diff options
author | Julian Eisel <julian@blender.org> | 2021-10-23 19:07:48 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-10-23 19:07:48 +0300 |
commit | 9ad642c59ade21d8664ba968d317b062e9654c07 (patch) | |
tree | 6228d5fb6583f59275f1558e1d540e18148dc6ef | |
parent | 50e7645211fb023280c6c55147fe15edcadddc17 (diff) |
Assets/UI: Improve asset library Preferences UI
* Open File Browser when pressing "Add Asset Library". This just makes sense,
since users have to select a directory for the asset library anyway.
* Move '+' icon back to the right side of the box. Then it is right under the
'x' icons for each indivdual library, which seems like the more natural
place.
* Correct tooltip for the "Add Asset Library" operator.
* Mark empty asset library name or paths field in red, to make clear that these
need to be set.
-rw-r--r-- | release/scripts/startup/bl_ui/space_userpref.py | 12 | ||||
-rw-r--r-- | source/blender/editors/space_userpref/userpref_ops.c | 37 |
2 files changed, 42 insertions, 7 deletions
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index bb3b3fbc23b..abd235f1c44 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -1410,12 +1410,18 @@ class USERPREF_PT_file_paths_asset_libraries(FilePathsPanel, Panel): row.label(text="Path") for i, library in enumerate(paths.asset_libraries): - name_col.prop(library, "name", text="") + row = name_col.row() + row.alert = not library.name + row.prop(library, "name", text="") + row = path_col.row() - row.prop(library, "path", text="") + subrow = row.row() + subrow.alert = not library.path + subrow.prop(library, "path", text="") row.operator("preferences.asset_library_remove", text="", icon='X', emboss=False).index = i + row = box.row() - row.alignment = 'LEFT' + row.alignment = 'RIGHT' row.operator("preferences.asset_library_add", text="", icon='ADD', emboss=False) diff --git a/source/blender/editors/space_userpref/userpref_ops.c b/source/blender/editors/space_userpref/userpref_ops.c index 63506678b70..d40229332fd 100644 --- a/source/blender/editors/space_userpref/userpref_ops.c +++ b/source/blender/editors/space_userpref/userpref_ops.c @@ -24,6 +24,7 @@ #include <string.h> #include "DNA_screen_types.h" +#include "DNA_space_types.h" #include "BLI_listbase.h" #ifdef WIN32 @@ -139,23 +140,51 @@ static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot) /** \name Add Asset Library Operator * \{ */ -static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) +static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *op) { - BKE_preferences_asset_library_add(&U, NULL, NULL); + char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL); + + /* NULL is a valid directory path here. A library without path will be created then. */ + BKE_preferences_asset_library_add(&U, NULL, directory); U.runtime.is_dirty = true; + + /* There's no dedicated notifier for the Preferences. */ + WM_main_add_notifier(NC_WINDOW, NULL); + + MEM_freeN(directory); return OPERATOR_FINISHED; } +static int preferences_asset_library_add_invoke(bContext *C, + wmOperator *op, + const wmEvent *UNUSED(event)) +{ + if (!RNA_struct_property_is_set(op->ptr, "directory")) { + WM_event_add_fileselect(C, op); + return OPERATOR_RUNNING_MODAL; + } + + return preferences_asset_library_add_exec(C, op); +} + static void PREFERENCES_OT_asset_library_add(wmOperatorType *ot) { ot->name = "Add Asset Library"; ot->idname = "PREFERENCES_OT_asset_library_add"; - ot->description = - "Add a path to a .blend file to be used by the Asset Browser as source of assets"; + ot->description = "Add a directory to be used by the Asset Browser as source of assets"; ot->exec = preferences_asset_library_add_exec; + ot->invoke = preferences_asset_library_add_invoke; ot->flag = OPTYPE_INTERNAL; + + WM_operator_properties_filesel(ot, + FILE_TYPE_FOLDER, + FILE_SPECIAL, + FILE_OPENFILE, + WM_FILESEL_DIRECTORY, + FILE_DEFAULTDISPLAY, + FILE_SORT_DEFAULT); } /** \} */ |