diff options
author | Julian Eisel <julian@blender.org> | 2021-07-21 21:17:34 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-07-21 21:41:29 +0300 |
commit | 64bb49fa4e3c8bd7e02fd6e5252e40f089d787de (patch) | |
tree | 67c1855bd624ae605ec08ba1295ed2a3b4c2d487 /source/blender/editors/asset | |
parent | 178086d5810a0de9e1d95c7fbd6c443cd53af40d (diff) |
Cleanup: Move reorganize asset files
I'm trying to move away from general files with lots of things in them,
and instead have many small & focused files. I find that easier to
work with since everything has clear responsibilities, even if there is
some minor overhead in managing all these files.
I also try to differentiate more clearly between public and internal
files. So source files and internal headers are in a `intern/`
sub-directory, public functions are in a number of headers one level
higher.
For convenience and to make this compatible with our existing general
headers in `editors/include`, I made the `ED_asset.h` there include all
these public headers.
This is of course a bit of an experiment, let's see how it works in
practice.
Also corrected the name of `ED_asset_can_make_single_from_context()`.
Diffstat (limited to 'source/blender/editors/asset')
13 files changed, 288 insertions, 15 deletions
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt index 64024eea986..d56edd43d7d 100644 --- a/source/blender/editors/asset/CMakeLists.txt +++ b/source/blender/editors/asset/CMakeLists.txt @@ -16,6 +16,7 @@ # ***** END GPL LICENSE BLOCK ***** set(INC + . ../include ../../blenkernel ../../blenlib @@ -30,14 +31,20 @@ set(INC_SYS ) set(SRC - asset_edit.cc - asset_list.cc - asset_ops.cc - asset_temp_id_consumer.cc intern/asset_handle.cc intern/asset_library_reference.cc intern/asset_library_reference_enum.cc + intern/asset_list.cc + intern/asset_mark_clear.cc + intern/asset_ops.cc + intern/asset_temp_id_consumer.cc + ED_asset_handle.h + ED_asset_library.h + ED_asset_list.h + ED_asset_list.hh + ED_asset_mark_clear.h + ED_asset_temp_id_consumer.h intern/asset_library_reference.hh ) diff --git a/source/blender/editors/asset/ED_asset_handle.h b/source/blender/editors/asset/ED_asset_handle.h new file mode 100644 index 00000000000..c51ce422c25 --- /dev/null +++ b/source/blender/editors/asset/ED_asset_handle.h @@ -0,0 +1,45 @@ +/* + * 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_ID_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct AssetHandle; +struct AssetLibraryReference; +struct bContext; + +const char *ED_asset_handle_get_name(const struct AssetHandle *asset); +struct AssetMetaData *ED_asset_handle_get_metadata(const struct AssetHandle *asset); +struct ID *ED_asset_handle_get_local_id(const struct AssetHandle *asset); +ID_Type ED_asset_handle_get_id_type(const struct AssetHandle *asset); +int ED_asset_handle_get_preview_icon_id(const struct AssetHandle *asset); +void ED_asset_handle_get_full_library_path(const struct bContext *C, + const struct AssetLibraryReference *asset_library, + const struct AssetHandle *asset, + char r_full_lib_path[]); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/editors/asset/ED_asset_library.h b/source/blender/editors/asset/ED_asset_library.h new file mode 100644 index 00000000000..905d097d223 --- /dev/null +++ b/source/blender/editors/asset/ED_asset_library.h @@ -0,0 +1,35 @@ +/* + * 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_asset_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int ED_asset_library_reference_to_enum_value(const AssetLibraryReference *library); +AssetLibraryReference ED_asset_library_reference_from_enum_value(int value); +const struct EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(void); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h new file mode 100644 index 00000000000..1e7f0f0de55 --- /dev/null +++ b/source/blender/editors/asset/ED_asset_list.h @@ -0,0 +1,54 @@ +/* + * 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 AssetFilterSettings; +struct AssetHandle; +struct AssetLibraryReference; +struct bContext; +struct ID; +struct wmNotifier; + +void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_reference, + const struct AssetFilterSettings *filter_settings, + const struct bContext *C); +void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference, + struct bContext *C); +void ED_assetlist_clear(const struct AssetLibraryReference *library_reference, struct bContext *C); +bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference); +void ED_assetlist_storage_tag_main_data_dirty(void); +void ED_assetlist_storage_id_remap(struct ID *id_old, struct ID *id_new); +void ED_assetlist_storage_exit(void); + +struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle); +const char *ED_assetlist_library_path(const struct AssetLibraryReference *library_reference); + +bool ED_assetlist_listen(const struct AssetLibraryReference *library_reference, + const struct wmNotifier *notifier); +int ED_assetlist_size(const struct AssetLibraryReference *library_reference); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/editors/asset/ED_asset_list.hh b/source/blender/editors/asset/ED_asset_list.hh new file mode 100644 index 00000000000..7f41fba3457 --- /dev/null +++ b/source/blender/editors/asset/ED_asset_list.hh @@ -0,0 +1,38 @@ +/* + * 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 <string> + +#include "BLI_function_ref.hh" + +struct AssetLibraryReference; +struct AssetHandle; +struct bContext; +struct FileDirEntry; + +std::string ED_assetlist_asset_filepath_get(const bContext *C, + const AssetLibraryReference &library_reference, + const AssetHandle &asset_handle); + +/* Can return false to stop iterating. */ +using AssetListIterFn = blender::FunctionRef<bool(FileDirEntry &)>; +void ED_assetlist_iterate(const AssetLibraryReference *library_reference, AssetListIterFn fn); diff --git a/source/blender/editors/asset/ED_asset_mark_clear.h b/source/blender/editors/asset/ED_asset_mark_clear.h new file mode 100644 index 00000000000..cdd1f0d080b --- /dev/null +++ b/source/blender/editors/asset/ED_asset_mark_clear.h @@ -0,0 +1,37 @@ +/* + * 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 bContext; +struct ID; + +bool ED_asset_mark_id(const struct bContext *C, struct ID *id); +bool ED_asset_clear_id(struct ID *id); + +bool ED_asset_can_mark_single_from_context(const struct bContext *C); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/editors/asset/ED_asset_temp_id_consumer.h b/source/blender/editors/asset/ED_asset_temp_id_consumer.h new file mode 100644 index 00000000000..8aa53f9ea3b --- /dev/null +++ b/source/blender/editors/asset/ED_asset_temp_id_consumer.h @@ -0,0 +1,48 @@ +/* + * 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_ID_enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct AssetTempIDConsumer AssetTempIDConsumer; + +struct AssetHandle; +struct AssetLibraryReference; +struct bContext; +struct Main; +struct ReportList; + +AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const struct AssetHandle *handle); +void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer); +struct ID *ED_asset_temp_id_consumer_ensure_local_id(AssetTempIDConsumer *consumer, + const struct bContext *C, + const struct AssetLibraryReference *asset_library, + ID_Type id_type, + struct Main *bmain, + struct ReportList *reports); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/editors/asset/intern/asset_handle.cc b/source/blender/editors/asset/intern/asset_handle.cc index 428fa62d130..aae85e61372 100644 --- a/source/blender/editors/asset/intern/asset_handle.cc +++ b/source/blender/editors/asset/intern/asset_handle.cc @@ -24,12 +24,15 @@ * although that doesn't always work (see #rna_def_asset_handle()). */ +#include <string> + #include "DNA_asset_types.h" #include "DNA_space_types.h" #include "BLO_readfile.h" -#include "ED_asset.h" +#include "ED_asset_handle.h" +#include "ED_asset_list.hh" const char *ED_asset_handle_get_name(const AssetHandle *asset) { diff --git a/source/blender/editors/asset/intern/asset_library_reference_enum.cc b/source/blender/editors/asset/intern/asset_library_reference_enum.cc index f3c6ec1952c..13595ffa6ba 100644 --- a/source/blender/editors/asset/intern/asset_library_reference_enum.cc +++ b/source/blender/editors/asset/intern/asset_library_reference_enum.cc @@ -30,12 +30,12 @@ #include "DNA_asset_types.h" #include "DNA_userdef_types.h" -#include "ED_asset.h" - #include "UI_resources.h" #include "RNA_define.h" +#include "ED_asset_library.h" + /** * Return an index that can be used to uniquely identify \a library, assuming * that all relevant indices were created with this function. @@ -153,4 +153,4 @@ const EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf() RNA_enum_item_end(&item, &totitem); return item; -}
\ No newline at end of file +} diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc index 9e611edd715..445269d563e 100644 --- a/source/blender/editors/asset/asset_list.cc +++ b/source/blender/editors/asset/intern/asset_list.cc @@ -37,7 +37,6 @@ #include "BKE_preferences.h" -#include "ED_asset.h" #include "ED_fileselect.h" #include "WM_api.h" @@ -46,7 +45,10 @@ /* XXX uses private header of file-space. */ #include "../space_file/filelist.h" -#include "intern/asset_library_reference.hh" +#include "ED_asset_handle.h" +#include "ED_asset_list.h" +#include "ED_asset_list.hh" +#include "asset_library_reference.hh" namespace blender::ed::asset { diff --git a/source/blender/editors/asset/asset_edit.cc b/source/blender/editors/asset/intern/asset_mark_clear.cc index c55e7a95120..ba348e38823 100644 --- a/source/blender/editors/asset/asset_edit.cc +++ b/source/blender/editors/asset/intern/asset_mark_clear.cc @@ -16,6 +16,8 @@ /** \file * \ingroup edasset + * + * Functions for marking and clearing assets. */ #include <memory> @@ -35,9 +37,8 @@ #include "RNA_access.h" -#include "ED_asset.h" - -using namespace blender; +#include "ED_asset_list.h" +#include "ED_asset_mark_clear.h" bool ED_asset_mark_id(const bContext *C, ID *id) { @@ -75,7 +76,7 @@ bool ED_asset_clear_id(ID *id) return true; } -bool ED_asset_can_make_single_from_context(const bContext *C) +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 --git a/source/blender/editors/asset/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc index 79edd1f8a6a..79edd1f8a6a 100644 --- a/source/blender/editors/asset/asset_ops.cc +++ b/source/blender/editors/asset/intern/asset_ops.cc diff --git a/source/blender/editors/asset/asset_temp_id_consumer.cc b/source/blender/editors/asset/intern/asset_temp_id_consumer.cc index 464320fdce9..bed35fdeeb5 100644 --- a/source/blender/editors/asset/asset_temp_id_consumer.cc +++ b/source/blender/editors/asset/intern/asset_temp_id_consumer.cc @@ -21,6 +21,8 @@ * Uses the `BLO_library_temp_xxx()` API internally. */ +#include <new> + #include "DNA_asset_types.h" #include "DNA_space_types.h" @@ -32,7 +34,8 @@ #include "MEM_guardedalloc.h" -#include "ED_asset.h" +#include "ED_asset_handle.h" +#include "ED_asset_temp_id_consumer.h" using namespace blender; |