[Bf-blender-cvs] [eab2a8479ab] asset-browser-grid-view: Move asset catalog filtering to editors/assets

Julian Eisel noreply at git.blender.org
Mon Feb 7 18:58:46 CET 2022


Commit: eab2a8479ab27c7a670c44e3a0b63bca4bddd3d4
Author: Julian Eisel
Date:   Mon Feb 7 18:57:39 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rBeab2a8479ab27c7a670c44e3a0b63bca4bddd3d4

Move asset catalog filtering to editors/assets

Such general asset-view functionality can go to the general editors
level, I think that makes the most sense.

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

M	source/blender/editors/asset/CMakeLists.txt
M	source/blender/editors/asset/ED_asset_list.h
A	source/blender/editors/asset/ED_asset_view_catalog_filter.h
M	source/blender/editors/asset/intern/asset_list.cc
A	source/blender/editors/asset/intern/asset_view_catalog_filter.cc
M	source/blender/editors/space_assets/asset_browser_draw.cc
M	source/blender/editors/space_assets/asset_catalog_tree_view.cc
M	source/blender/editors/space_assets/asset_view.cc
M	source/blender/editors/space_assets/asset_view.hh
M	source/blender/editors/space_assets/space_assets.cc
M	source/blender/editors/space_file/asset_catalog_tree_view.cc
M	source/blender/editors/space_file/file_intern.h
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/makesdna/DNA_space_types.h

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

diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index d91102528e5..0bbaafc29b7 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -44,6 +44,7 @@ set(SRC
   intern/asset_ops.cc
   intern/asset_temp_id_consumer.cc
   intern/asset_type.cc
+  intern/asset_view_catalog_filter.cc
 
   ED_asset_catalog.h
   ED_asset_catalog.hh
@@ -56,6 +57,7 @@ set(SRC
   ED_asset_mark_clear.h
   ED_asset_temp_id_consumer.h
   ED_asset_type.h
+  ED_asset_view_catalog_filter.h
   intern/asset_library_reference.hh
 )
 
diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h
index 454323bd31e..f1704ec1cfe 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -24,6 +24,7 @@
 extern "C" {
 #endif
 
+struct AssetCatalogFilterSettings;
 struct AssetFilterSettings;
 struct AssetHandle;
 struct AssetLibrary;
@@ -40,8 +41,11 @@ void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_refe
                                 const struct bContext *C);
 void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference,
                                       const struct bContext *C);
+void ED_assetlist_catalog_filter_set(const struct AssetLibraryReference *,
+                                     const struct AssetCatalogFilterSettings *catalog_filter);
 void ED_assetlist_clear(const struct AssetLibraryReference *library_reference, struct bContext *C);
 bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference);
+
 /**
  * Tag all asset lists in the storage that show main data as needing an update (re-fetch).
  *
diff --git a/source/blender/editors/asset/ED_asset_view_catalog_filter.h b/source/blender/editors/asset/ED_asset_view_catalog_filter.h
new file mode 100644
index 00000000000..c55c108f0e5
--- /dev/null
+++ b/source/blender/editors/asset/ED_asset_view_catalog_filter.h
@@ -0,0 +1,51 @@
+/*
+ * 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
+
+#include "DNA_space_types.h"
+
+struct AssetLibrary;
+struct AssetMetaData;
+struct bUUID;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct AssetViewCatalogFilterSettingsHandle AssetViewCatalogFilterSettingsHandle;
+
+AssetViewCatalogFilterSettingsHandle *asset_view_create_catalog_filter_settings(void);
+void asset_view_delete_catalog_filter_settings(
+    AssetViewCatalogFilterSettingsHandle **filter_settings_handle);
+bool asset_view_set_catalog_filter_settings(
+    AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
+    AssetCatalogFilterMode catalog_visibility,
+    bUUID catalog_id);
+void asset_view_ensure_updated_catalog_filter_data(
+    AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
+    const AssetLibrary *asset_library);
+bool asset_view_is_asset_visible_in_catalog_filter_settings(
+    const AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
+    const AssetMetaData *asset_data);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index 7456d507817..90448b882ed 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -124,6 +124,7 @@ class AssetList : NonCopyable {
 
   void setup();
   void fetch(const bContext &C);
+  void setCatalogFilterSettings(const AssetCatalogFilterSettings &settings);
   void ensurePreviewsJob(const bContext *C);
   void clear(bContext *C);
 
@@ -163,7 +164,7 @@ void AssetList::setup()
   filelist_setlibrary(files, &library_ref_);
   filelist_setfilter_options(
       files,
-      false,
+      true,
       true,
       true, /* Just always hide parent, prefer to not add an extra user option for this. */
       FILE_TYPE_BLENDERLIB,
@@ -203,6 +204,14 @@ void AssetList::fetch(const bContext &C)
   filelist_filter(files);
 }
 
+void AssetList::setCatalogFilterSettings(const AssetCatalogFilterSettings &settings)
+{
+  filelist_set_asset_catalog_filter_options(
+      filelist_,
+      (AssetCatalogFilterMode)settings.filter_mode,
+      &settings.active_catalog_id);
+}
+
 bool AssetList::needsRefetch() const
 {
   return filelist_needs_force_reset(filelist_) || filelist_needs_reading(filelist_);
@@ -452,6 +461,15 @@ void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_refer
   }
 }
 
+void ED_assetlist_catalog_filter_set(const struct AssetLibraryReference *library_reference,
+                                     const struct AssetCatalogFilterSettings *settings)
+{
+  AssetList *list = AssetListStorage::lookup_list(*library_reference);
+  if (list) {
+    list->setCatalogFilterSettings(*settings);
+  }
+}
+
 void ED_assetlist_clear(const AssetLibraryReference *library_reference, bContext *C)
 {
   AssetList *list = AssetListStorage::lookup_list(*library_reference);
diff --git a/source/blender/editors/asset/intern/asset_view_catalog_filter.cc b/source/blender/editors/asset/intern/asset_view_catalog_filter.cc
new file mode 100644
index 00000000000..a8d68e38de4
--- /dev/null
+++ b/source/blender/editors/asset/intern/asset_view_catalog_filter.cc
@@ -0,0 +1,110 @@
+/*
+ * 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
+ */
+
+#include <memory>
+
+#include "DNA_space_types.h"
+
+#include "BKE_asset_catalog.hh"
+#include "BKE_asset_library.hh"
+
+#include "ED_asset_view_catalog_filter.h"
+
+namespace bke = blender::bke;
+
+struct AssetViewCatalogFilter {
+  AssetCatalogFilterSettings filter_settings;
+  std::unique_ptr<bke::AssetCatalogFilter> catalog_filter;
+};
+
+AssetViewCatalogFilterSettingsHandle *asset_view_create_catalog_filter_settings()
+{
+  AssetViewCatalogFilter *filter_settings = MEM_new<AssetViewCatalogFilter>(__func__);
+  return reinterpret_cast<AssetViewCatalogFilterSettingsHandle *>(filter_settings);
+}
+
+void asset_view_delete_catalog_filter_settings(
+    AssetViewCatalogFilterSettingsHandle **filter_settings_handle)
+{
+  AssetViewCatalogFilter **filter_settings = reinterpret_cast<AssetViewCatalogFilter **>(
+      filter_settings_handle);
+  MEM_delete(*filter_settings);
+  *filter_settings = nullptr;
+}
+
+bool asset_view_set_catalog_filter_settings(
+    AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
+    AssetCatalogFilterMode catalog_visibility,
+    ::bUUID catalog_id)
+{
+  AssetViewCatalogFilter *filter_settings = reinterpret_cast<AssetViewCatalogFilter *>(
+      filter_settings_handle);
+  bool needs_update = false;
+
+  if (filter_settings->filter_settings.filter_mode != catalog_visibility) {
+    filter_settings->filter_settings.filter_mode = catalog_visibility;
+    needs_update = true;
+  }
+
+  if (filter_settings->filter_settings.filter_mode == ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG &&
+      !BLI_uuid_equal(filter_settings->filter_settings.active_catalog_id, catalog_id)) {
+    filter_settings->filter_settings.active_catalog_id = catalog_id;
+    needs_update = true;
+  }
+
+  return needs_update;
+}
+
+void asset_view_ensure_updated_catalog_filter_data(
+    AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
+    const ::AssetLibrary *asset_library)
+{
+  AssetViewCatalogFilter *filter_settings = reinterpret_cast<AssetViewCatalogFilter *>(
+      filter_settings_handle);
+  const bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(
+      asset_library);
+
+  if (filter_settings->filter_settings.filter_mode != ASSET_CATALOG_SHOW_ALL_ASSETS) {
+    filter_settings->catalog_filter = std::make_unique<bke::AssetCatalogFilter>(
+        catalog_service->create_catalog_filter(
+            filter_settings->filter_settings.active_catalog_id));
+  }
+}
+
+bool asset_view_is_asset_visible_in_catalog_filter_settings(
+    const AssetViewCatalogFilterSettingsHandle *filter_settings_handle,
+    const AssetMetaData *asset_data)
+{
+  const AssetViewCatalogFilter *filter_settings = reinterpret_cast<const AssetViewCatalogFilter *>(
+      filter_settings_handle);
+
+  switch (filter_settings->filter_settings.filter_mode) {
+    case ASSET_CATALOG_SHOW_ASSETS_WITHOUT_CATALOG:
+      return !filter_settings->catalog_filter->is_known(asset_data->catalog_id);
+    case ASSET_CATALOG_SHOW_ASSETS_FROM_CATALOG:
+      return filter_settings->catalog_filter->contains(asset_data->catalog_id);
+    case ASSET_CATALOG_SHOW_ALL_ASSETS:
+      /* All asset files should be visible. */
+      return true;
+  }
+
+  BLI_assert_unreachable();
+  return false;
+}
diff --git a/source/blender/editors/space_assets/asset_browser_draw.cc b/source/blender/editors/space_assets/asset_browser_draw.cc

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list