[Bf-blender-cvs] [76a212f947a] asset-browser-snap-dragging: Merge branch 'master' into asset-browser-snap-dragging

Julian Eisel noreply at git.blender.org
Mon Sep 13 18:14:23 CEST 2021


Commit: 76a212f947a958a87dc7f7e54765cb00c0a83e22
Author: Julian Eisel
Date:   Mon Sep 13 18:14:14 2021 +0200
Branches: asset-browser-snap-dragging
https://developer.blender.org/rB76a212f947a958a87dc7f7e54765cb00c0a83e22

Merge branch 'master' into asset-browser-snap-dragging

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



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

diff --cc source/blender/blenkernel/BKE_asset.h
index 38c053607f5,50eb2859279..fdc7ed8c145
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@@ -27,7 -26,7 +27,8 @@@
  extern "C" {
  #endif
  
+ struct AssetLibraryReference;
 +struct AssetMetaData;
  struct BlendDataReader;
  struct BlendWriter;
  struct ID;
@@@ -58,10 -46,8 +59,12 @@@ struct AssetTagEnsureResult BKE_asset_m
                                                            const char *name);
  void BKE_asset_metadata_tag_remove(struct AssetMetaData *asset_data, struct AssetTag *tag);
  
+ void BKE_asset_library_reference_init_default(struct AssetLibraryReference *library_ref);
+ 
 +void BKE_asset_metadata_idprop_ensure(struct AssetMetaData *asset_data, struct IDProperty *prop);
 +struct IDProperty *BKE_asset_metadata_idprop_find(const struct AssetMetaData *asset_data,
 +                                                  const char *name) ATTR_WARN_UNUSED_RESULT;
 +
  struct PreviewImage *BKE_asset_metadata_preview_get_from_id(const struct AssetMetaData *asset_data,
                                                              const struct ID *owner_id);
  
diff --cc source/blender/blenkernel/intern/asset.cc
index 412fdcf6944,f74018b20c5..6974feb9e5d
--- a/source/blender/blenkernel/intern/asset.cc
+++ b/source/blender/blenkernel/intern/asset.cc
@@@ -110,25 -110,11 +110,30 @@@ void BKE_asset_metadata_tag_remove(Asse
    BLI_assert(BLI_listbase_count(&asset_data->tags) == asset_data->tot_tags);
  }
  
+ void BKE_asset_library_reference_init_default(AssetLibraryReference *library_ref)
+ {
+   memcpy(library_ref, DNA_struct_default_get(AssetLibraryReference), sizeof(*library_ref));
+ }
+ 
 +void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop)
 +{
 +  if (!asset_data->properties) {
 +    IDPropertyTemplate val = {0};
 +    asset_data->properties = IDP_New(IDP_GROUP, &val, "AssetMetaData.properties");
 +  }
 +  /* Important: The property may already exist. For now just allow always allow a newly allocated
 +   * property, and replace the existing one as a way of updating. */
 +  IDP_ReplaceInGroup(asset_data->properties, prop);
 +}
 +
 +IDProperty *BKE_asset_metadata_idprop_find(const AssetMetaData *asset_data, const char *name)
 +{
 +  if (!asset_data->properties) {
 +    return nullptr;
 +  }
 +  return IDP_GetPropertyFromGroup(asset_data->properties, name);
 +}
 +
  /* Queries -------------------------------------------- */
  
  PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *UNUSED(asset_data),
diff --cc source/blender/blenloader/intern/readfile.c
index 96ee8424a31,15653264211..a22f687d8a9
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -2468,12 -2204,9 +2204,12 @@@ static void direct_link_id_common
    if (id->asset_data) {
      BLO_read_data_address(reader, &id->asset_data);
      BKE_asset_metadata_read(reader, id->asset_data);
 +    /* Restore runtime asset type info. */
 +    const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
 +    id->asset_data->local_type_info = id_type->asset_type_info;
    }
  
-   /*link direct data of ID properties*/
+   /* Link direct data of ID properties. */
    if (id->properties) {
      BLO_read_data_address(reader, &id->properties);
      /* this case means the data was written incorrectly, it should not happen */
diff --cc source/blender/editors/asset/ED_asset_mark_clear.h
index 00000000000,7524ec6b02a..04dd2d3b759
mode 000000,100644..100644
--- a/source/blender/editors/asset/ED_asset_mark_clear.h
+++ b/source/blender/editors/asset/ED_asset_mark_clear.h
@@@ -1,0 -1,37 +1,40 @@@
+ /*
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software Foundation,
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  */
+ 
+ /** \file
+  * \ingroup edasset
+  */
+ 
+ #pragma once
+ 
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
+ struct ID;
+ struct bContext;
++struct Main;
+ 
+ bool ED_asset_mark_id(const struct bContext *C, struct ID *id);
+ bool ED_asset_clear_id(struct ID *id);
+ 
++void ED_assets_pre_save(struct Main *bmain);
++
+ bool ED_asset_can_mark_single_from_context(const struct bContext *C);
+ 
+ #ifdef __cplusplus
+ }
+ #endif
diff --cc source/blender/editors/asset/intern/asset_mark_clear.cc
index 00000000000,ba348e38823..86dd6e8a538
mode 000000,100644..100644
--- a/source/blender/editors/asset/intern/asset_mark_clear.cc
+++ b/source/blender/editors/asset/intern/asset_mark_clear.cc
@@@ -1,0 -1,83 +1,102 @@@
+ /*
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  *
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software Foundation,
+  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+  */
+ 
+ /** \file
+  * \ingroup edasset
+  *
+  * Functions for marking and clearing assets.
+  */
+ 
+ #include <memory>
+ #include <string>
+ 
+ #include "BKE_asset.h"
+ #include "BKE_context.h"
++#include "BKE_idtype.h"
+ #include "BKE_lib_id.h"
++#include "BKE_main.h"
+ 
+ #include "BLO_readfile.h"
+ 
+ #include "DNA_ID.h"
+ #include "DNA_asset_types.h"
+ #include "DNA_space_types.h"
+ 
+ #include "UI_interface_icons.h"
+ 
+ #include "RNA_access.h"
+ 
+ #include "ED_asset_list.h"
+ #include "ED_asset_mark_clear.h"
+ 
+ bool ED_asset_mark_id(const bContext *C, ID *id)
+ {
+   if (id->asset_data) {
+     return false;
+   }
+   if (!BKE_id_can_be_asset(id)) {
+     return false;
+   }
+ 
+   id_fake_user_set(id);
+ 
++  const IDTypeInfo *id_type_info = BKE_idtype_get_info_from_id(id);
+   id->asset_data = BKE_asset_metadata_create();
++  id->asset_data->local_type_info = id_type_info->asset_type_info;
+ 
+   UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true);
+ 
+   /* Important for asset storage to update properly! */
+   ED_assetlist_storage_tag_main_data_dirty();
+ 
+   return true;
+ }
+ 
+ bool ED_asset_clear_id(ID *id)
+ {
+   if (!id->asset_data) {
+     return false;
+   }
+   BKE_asset_metadata_free(&id->asset_data);
+   /* Don't clear fake user here, there's no guarantee that it was actually set by
+    * #ED_asset_mark_id(), it might have been something/someone else. */
+ 
+   /* Important for asset storage to update properly! */
+   ED_assetlist_storage_tag_main_data_dirty();
+ 
+   return true;
+ }
+ 
++void ED_assets_pre_save(struct Main *bmain)
++{
++  ID *id;
++  FOREACH_MAIN_ID_BEGIN (bmain, id) {
++    if (!id->asset_data || !id->asset_data->local_type_info) {
++      continue;
++    }
++
++    if (id->asset_data->local_type_info->pre_save_fn) {
++      id->asset_data->local_type_info->pre_save_fn(id, id->asset_data);
++    }
++  }
++  FOREACH_MAIN_ID_END;
++}
++
+ bool ED_asset_can_mark_single_from_context(const bContext *C)
+ {
+   /* Context needs a "id" pointer to be set for #ASSET_OT_mark()/#ASSET_OT_clear() to use. */
+   return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != nullptr;
+ }
diff --cc source/blender/editors/include/UI_interface.h
index c0466307288,7211cf9f893..e6e36a44e53
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@@ -34,9 -35,11 +35,12 @@@ extern "C" 
  /* Struct Declarations */
  
  struct ARegion;
+ struct AssetFilterSettings;
+ struct AssetHandle;
 +struct AssetMetaData;
  struct AutoComplete;
  struct EnumPropertyItem;
+ struct FileDirEntry;
  struct FileSelectParams;
  struct ID;
  struct IDProperty;
@@@ -721,10 -771,8 +772,9 @@@ int UI_but_return_value_get(uiBut *but)
  
  void UI_but_drag_set_id(uiBut *but, struct ID *id);
  void UI_but_drag_set_asset(uiBut *but,
-                            const char *name,
+                            const struct AssetHandle *asset,
                             const char *path,
-                            int id_type,
 +                           struct AssetMetaData *metadata,
                             int import_type, /* eFileAssetImportType */
                             int icon,
                             struct ImBuf *imb,
diff --cc source/blender/editors/interface/interface.c
index 6c6e90d5339,fd75be5b847..b7338076d62
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@@ -6140,11 -6180,12 +6180,13 @@@ void UI_but_drag_set_id(uiBut *but, ID 
    but->dragpoin = (void *)id;
  }
  
+ /**
+  * \param asset: May be passed from a temporary variable, drag data only stores a copy of this.
+  */
  void UI_but_drag_set_asset(uiBut *but,
-                            const char *name,
+                            const AssetHandle *asset,
                             const char *path,
-                            int id_type,
 +                           struct AssetMetaData *metadata,
                             int import_type,
                             int icon,
                             struct ImBuf *imb,
@@@ -6152,10 -6193,9 +6194,10 @@@
  {
    wmDragAsset *asset_drag = MEM_mallocN(sizeof(*asset_drag), "wmDragAsset");
  
-   BLI_strncpy(asset_drag->name, name, sizeof(asset_drag->name));
+   BLI_strncpy(asset

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list