[Bf-blender-cvs] [cf0884632a1] asset-browser: Asset Browser: Internal File Browser changes & Python API additions
Julian Eisel
noreply at git.blender.org
Thu Dec 3 01:58:54 CET 2020
Commit: cf0884632a1863cb8f00af5b75e02364903765cd
Author: Julian Eisel
Date: Wed Dec 2 21:33:17 2020 +0100
Branches: asset-browser
https://developer.blender.org/rBcf0884632a1863cb8f00af5b75e02364903765cd
Asset Browser: Internal File Browser changes & Python API additions
The Asset Browser will be a sub-editor of the File Browser. This prepares the File Browser code for that.
**File-Lists**
* Support loading assets with metadata read from external files into the file-list.
* New main based file-list type, for the "Current File" asset repository.
* Refresh file-list when switching between browse modes or asset repositories.
* Support empty file-lists (repository with no assets).
* Store file previews as icons, so scripts can reference them via icon-id. See D9719.
**Space Data**
* Introduce "browse mode" to differeniate between file and asset browsing.
* Add `FileAssetSelectParams` to `SpaceFile`, with `FileSelectParams` as base. Makes sure data is separated between asset and file browsing when switching between them. The active params can be obtained through `ED_fileselect_get_active_params()`.
* `FileAssetSelectParams` stores the currently visible repository ID.
* Introduce file history abstraction so file and asset browsing can keep a separate history (previous and next directories).
**General**
* Option to only show asset data-blocks while file browsing (not exposed here).
* Add "active_file" context member, so scripts can get and display info about the active file.
* Add "active_id" context member, so `ED_OT_lib_id_load_custom_preview` can set a custom ID preview. (Only for "Current File" repository)
* Expose some of `FileDirEntry` in RNA as (non-editable). That way scripts can obtain name, preview icon and asset-data.
Differential Revision: https://developer.blender.org/D9724
===================================================================
M source/blender/blenkernel/intern/screen.c
M source/blender/blenlib/intern/path_util.c
M source/blender/blenloader/intern/readblenentry.c
M source/blender/editors/include/ED_fileselect.h
M source/blender/editors/space_file/file_draw.c
M source/blender/editors/space_file/file_intern.h
M source/blender/editors/space_file/file_ops.c
M source/blender/editors/space_file/file_panels.c
M source/blender/editors/space_file/filelist.c
M source/blender/editors/space_file/filelist.h
M source/blender/editors/space_file/filesel.c
M source/blender/editors/space_file/space_file.c
M source/blender/makesdna/DNA_space_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/RNA_enum_types.h
M source/blender/makesrna/intern/rna_space.c
M source/blender/windowmanager/intern/wm_operator_props.c
M source/blender/windowmanager/intern/wm_operators.c
===================================================================
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 97bef99944a..ed74a8d89da 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -1265,6 +1265,9 @@ static void write_area_regions(BlendWriter *writer, ScrArea *area)
if (sfile->params) {
BLO_write_struct(writer, FileSelectParams, sfile->params);
}
+ if (sfile->asset_params) {
+ BLO_write_struct(writer, FileAssetSelectParams, sfile->asset_params);
+ }
}
else if (sl->spacetype == SPACE_SEQ) {
BLO_write_struct(writer, SpaceSeq, sl);
@@ -1663,11 +1666,13 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area)
* plus, it isn't saved to files yet!
*/
sfile->folders_prev = sfile->folders_next = NULL;
+ BLI_listbase_clear(&sfile->folder_histories);
sfile->files = NULL;
sfile->layout = NULL;
sfile->op = NULL;
sfile->previews_timer = NULL;
BLO_read_data_address(reader, &sfile->params);
+ BLO_read_data_address(reader, &sfile->asset_params);
}
else if (sl->spacetype == SPACE_CLIP) {
SpaceClip *sclip = (SpaceClip *)sl;
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 758feef6093..20344cf6bd8 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -264,6 +264,10 @@ void BLI_path_normalize(const char *relabase, char *path)
*/
void BLI_path_normalize_dir(const char *relabase, char *dir)
{
+ /* Would just create an unexpected "/" path, just early exit entirely. */
+ if (dir[0] == '\0') {
+ return;
+ }
BLI_path_normalize(relabase, dir);
BLI_path_slash_ensure(dir);
}
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index cf51129556c..21e76d679a4 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -301,7 +301,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *to
* (e.g. "Scene", "Mesh", "Light", etc.).
*
* \param bh: The blendhandle to access.
- * \return A BLI_linklist of strings. The string links should be freed with malloc.
+ * \return A BLI_linklist of strings. The string links should be freed with #MEM_freeN().
*/
LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
{
@@ -319,7 +319,7 @@ LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
const char *str = BKE_idtype_idcode_to_name(bhead->code);
if (BLI_gset_add(gathered, (void *)str)) {
- BLI_linklist_prepend(&names, strdup(str));
+ BLI_linklist_prepend(&names, BLI_strdup(str));
}
}
}
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index 84808416074..3288cf11cb0 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -29,6 +29,7 @@ extern "C" {
struct ARegion;
struct FileSelectParams;
+struct FileAssetSelectParams;
struct Scene;
struct ScrArea;
struct SpaceFile;
@@ -101,16 +102,16 @@ typedef struct FileSelection {
struct View2D;
struct rcti;
-struct FileSelectParams *ED_fileselect_get_params(struct SpaceFile *sfile);
+struct FileSelectParams *ED_fileselect_ensure_active_params(struct SpaceFile *sfile);
+struct FileSelectParams *ED_fileselect_get_active_params(const struct SpaceFile *sfile);
+struct FileSelectParams *ED_fileselect_get_file_params(const struct SpaceFile *sfile);
+struct FileAssetSelectParams *ED_fileselect_get_asset_params(const struct SpaceFile *sfile);
-short ED_fileselect_set_params(struct SpaceFile *sfile);
void ED_fileselect_set_params_from_userdef(struct SpaceFile *sfile);
void ED_fileselect_params_to_userdef(struct SpaceFile *sfile,
const int temp_win_size[],
const bool is_maximized);
-void ED_fileselect_reset_params(struct SpaceFile *sfile);
-
void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *region);
FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *region);
@@ -142,6 +143,8 @@ void ED_fileselect_exit(struct wmWindowManager *wm,
struct Scene *owner_scene,
struct SpaceFile *sfile);
+bool ED_fileselect_is_asset_browser(const struct SpaceFile *sfile);
+
void ED_fileselect_window_params_get(const struct wmWindow *win,
int win_size[2],
bool *is_maximized);
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 4b277435f63..7142126ebee 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -38,6 +38,7 @@
#include "BKE_context.h"
#include "BKE_main.h"
+#include "BKE_main_idmap.h"
#include "BLO_readfile.h"
@@ -400,11 +401,12 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
wmWindowManager *wm = CTX_wm_manager(C);
SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
ARegion *region = CTX_wm_region(C);
+ FileSelectParams *params = ED_fileselect_get_active_params(sfile);
- BLI_join_dirfile(orgname, sizeof(orgname), sfile->params->dir, oldname);
- BLI_strncpy(filename, sfile->params->renamefile, sizeof(filename));
+ BLI_join_dirfile(orgname, sizeof(orgname), params->dir, oldname);
+ BLI_strncpy(filename, params->renamefile, sizeof(filename));
BLI_filename_make_safe(filename);
- BLI_join_dirfile(newname, sizeof(newname), sfile->params->dir, filename);
+ BLI_join_dirfile(newname, sizeof(newname), params->dir, filename);
if (!STREQ(orgname, newname)) {
if (!BLI_exists(newname)) {
@@ -415,8 +417,8 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
}
else {
/* If rename is successful, scroll to newly renamed entry. */
- BLI_strncpy(sfile->params->renamefile, filename, sizeof(sfile->params->renamefile));
- sfile->params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_PENDING;
+ BLI_strncpy(params->renamefile, filename, sizeof(params->renamefile));
+ params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_PENDING;
if (sfile->smoothscroll_timer != NULL) {
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
@@ -688,7 +690,7 @@ static void draw_details_columns(const FileSelectParams *params,
void file_draw_list(const bContext *C, ARegion *region)
{
SpaceFile *sfile = CTX_wm_space_file(C);
- FileSelectParams *params = ED_fileselect_get_params(sfile);
+ FileSelectParams *params = ED_fileselect_get_active_params(sfile);
FileLayout *layout = ED_fileselect_get_layout(sfile, region);
View2D *v2d = ®ion->v2d;
struct FileList *files = sfile->files;
@@ -847,26 +849,26 @@ void file_draw_list(const bContext *C, ARegion *region)
}
if (file_selflag & FILE_SEL_EDITING) {
- uiBut *but;
+ FileSelectParams *params = ED_fileselect_get_active_params(sfile);
const short width = (params->display == FILE_IMGDISPLAY) ?
textwidth :
layout->attribute_columns[COLUMN_NAME].width -
ATTRIBUTE_COLUMN_PADDING;
- but = uiDefBut(block,
- UI_BTYPE_TEXT,
- 1,
- "",
- sx + icon_ofs,
- sy - layout->tile_h - 0.15f * UI_UNIT_X,
- width - icon_ofs,
- textheight,
- sfile->params->renamefile,
- 1.0f,
- (float)sizeof(sfile->params->renamefile),
- 0,
- 0,
- "");
+ uiBut *but = uiDefBut(block,
+ UI_BTYPE_TEXT,
+ 1,
+ "",
+ sx + icon_ofs,
+ sy - layout->tile_h - 0.15f * UI_UNIT_X,
+ width - icon_ofs,
+ textheight,
+ params->renamefile,
+ 1.0f,
+ (float)sizeof(params->renamefile),
+ 0,
+ 0,
+ "");
UI_but_func_rename_set(but, renamebutton_cb, file);
UI_but_flag_enable(but, UI_BUT_NO_UTF8); /* allow non utf8 names */
UI_but_flag_disable(but, UI_BUT_UNDO);
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index b459c02d9e5..a0e02681e0e 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -90,6 +90,7 @@ void file_sfile_to_operator(struct Main *bmain, struct wmOperator *op, struct Sp
void file_operator_to_sfile(struct Main *bmain, struct SpaceFile *sfile, struct wmOperator *op);
/* filesel.c */
+void fileselect_refresh_params(struct SpaceFile *sfile);
void fileselect_file_set(SpaceFile *sfile, const int index);
bool file_attribute_column_type_enabled(const FileSelectParams *params,
FileAttributeColumnType column);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 93367ad3d3c..8af84f65ced 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -188,7 +188,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
Main *bmain = CTX_data_main(C);
FileSelect retval = FILE_SELECT_NOTHING;
SpaceFile *sfile = CTX_wm_space_file(C);
- FileSelectParams *params = ED_fileselect_get_params(sfile);
+ FileSelectParams *params = ED_fileselect_get_active_params(sfile);
int numfiles = filelist_files
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list