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:
authorSybren A. Stüvel <sybren@blender.org>2021-03-05 17:00:56 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-03-05 17:11:40 +0300
commitfe35551df2d874d51073b1dc4a582a1962255949 (patch)
tree7926ab181119dc64510e99695d4ab3ab634a6fde /source/blender/editors/space_file/space_file.c
parent0dd9a4a576452007da9d3f02a03499e50a8ddfae (diff)
Asset Browser Space API: add `activate_asset_by_id()` function
Add an RNA function `activate_asset_by_id(asset_id: ID, deferred: bool)` to the File Browser space type, which intended to be used to activate an asset's entry as identified by its `ID *`. Calling it changes the active asset, but only if the given ID can actually be found. The activation can be deferred (by passing `deferred=True`) until the next refresh operation has finished. This is necessary when an asset has just been added, as it will be loaded by the filebrowser in a background job. Reviewed By: Severin Differential Revision: https://developer.blender.org/D10549
Diffstat (limited to 'source/blender/editors/space_file/space_file.c')
-rw-r--r--source/blender/editors/space_file/space_file.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index b175844a710..2c9c2688e88 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -173,6 +173,7 @@ static void file_free(SpaceLink *sl)
MEM_SAFE_FREE(sfile->params);
MEM_SAFE_FREE(sfile->asset_params);
+ MEM_SAFE_FREE(sfile->runtime);
if (sfile->layout) {
MEM_freeN(sfile->layout);
@@ -188,6 +189,10 @@ static void file_init(wmWindowManager *UNUSED(wm), ScrArea *area)
if (sfile->layout) {
sfile->layout->dirty = true;
}
+
+ if (sfile->runtime == NULL) {
+ sfile->runtime = MEM_callocN(sizeof(*sfile->runtime), __func__);
+ }
}
static void file_exit(wmWindowManager *wm, ScrArea *area)
@@ -209,6 +214,7 @@ static SpaceLink *file_duplicate(SpaceLink *sl)
/* clear or remove stuff from old */
sfilen->op = NULL; /* file window doesn't own operators */
+ sfilen->runtime = NULL;
sfilen->previews_timer = NULL;
sfilen->smoothscroll_timer = NULL;
@@ -392,6 +398,26 @@ static void file_refresh(const bContext *C, ScrArea *area)
ED_area_tag_redraw(area);
}
+void file_on_reload_callback_register(SpaceFile *sfile,
+ onReloadFn callback,
+ onReloadFnData custom_data)
+{
+ sfile->runtime->on_reload = callback;
+ sfile->runtime->on_reload_custom_data = custom_data;
+}
+
+static void file_on_reload_callback_call(SpaceFile *sfile)
+{
+ if (sfile->runtime->on_reload == NULL) {
+ return;
+ }
+
+ sfile->runtime->on_reload(sfile, sfile->runtime->on_reload_custom_data);
+
+ sfile->runtime->on_reload = NULL;
+ sfile->runtime->on_reload_custom_data = NULL;
+}
+
static void file_listener(const wmSpaceTypeListenerParams *params)
{
ScrArea *area = params->area;
@@ -419,12 +445,26 @@ static void file_listener(const wmSpaceTypeListenerParams *params)
}
break;
}
+ switch (wmn->action) {
+ case NA_JOB_FINISHED:
+ file_on_reload_callback_call(sfile);
+ break;
+ }
break;
case NC_ASSET: {
- if (sfile->files && filelist_needs_reset_on_main_changes(sfile->files)) {
- /* Full refresh of the file list if local asset data was changed. Refreshing this view is
- * cheap and users expect this to be updated immediately. */
- file_tag_reset_list(area, sfile);
+ switch (wmn->action) {
+ case NA_SELECTED:
+ case NA_ACTIVATED:
+ ED_area_tag_refresh(area);
+ break;
+ case NA_ADDED:
+ case NA_REMOVED:
+ if (sfile->files && filelist_needs_reset_on_main_changes(sfile->files)) {
+ /* Full refresh of the file list if local asset data was changed. Refreshing this view
+ * is cheap and users expect this to be updated immediately. */
+ file_tag_reset_list(area, sfile);
+ }
+ break;
}
break;
}
@@ -464,8 +504,7 @@ static void file_main_region_listener(const wmRegionListenerParams *params)
}
break;
case NC_ID:
- if (ELEM(wmn->action, NA_RENAME)) {
- /* In case the filelist shows ID names. */
+ if (ELEM(wmn->action, NA_SELECTED, NA_ACTIVATED, NA_RENAME)) {
ED_region_tag_redraw(region);
}
break;