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()`.
This commit is contained in:
Julian Eisel 2021-07-21 20:17:34 +02:00
parent 178086d581
commit 64bb49fa4e
15 changed files with 302 additions and 84 deletions

View File

@ -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
)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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)
{

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -16,70 +16,19 @@
/** \file
* \ingroup editors
*
* The public API for assets is defined in dedicated headers. This is a utility file that just
* includes all of these.
*/
#pragma once
#include "DNA_ID_enums.h"
#ifdef __cplusplus
extern "C" {
#endif
struct AssetFilterSettings;
struct AssetLibraryReference;
struct Main;
struct ReportList;
struct bContext;
struct wmNotifier;
typedef struct AssetTempIDConsumer AssetTempIDConsumer;
bool ED_asset_mark_id(const struct bContext *C, struct ID *id);
bool ED_asset_clear_id(struct ID *id);
bool ED_asset_can_make_single_from_context(const struct bContext *C);
int ED_asset_library_reference_to_enum_value(const struct AssetLibraryReference *library);
struct AssetLibraryReference ED_asset_library_reference_from_enum_value(int value);
const struct EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(void);
const char *ED_asset_handle_get_name(const AssetHandle *asset);
AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset);
struct ID *ED_asset_handle_get_local_id(const AssetHandle *asset);
ID_Type ED_asset_handle_get_id_type(const AssetHandle *asset);
int ED_asset_handle_get_preview_icon_id(const AssetHandle *asset);
void ED_asset_handle_get_full_library_path(const struct bContext *C,
const AssetLibraryReference *asset_library,
const AssetHandle *asset,
char r_full_lib_path[]);
AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const 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 AssetLibraryReference *asset_library,
ID_Type id_type,
struct Main *bmain,
struct ReportList *reports);
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);
/* Barely anything here. Just general editor level functions. Actual asset level code is in
* dedicated headers. */
void ED_operatortypes_asset(void);
@ -87,17 +36,13 @@ void ED_operatortypes_asset(void);
}
#endif
/* TODO move to C++ asset-list header? */
#include "../asset/ED_asset_handle.h"
#include "../asset/ED_asset_library.h"
#include "../asset/ED_asset_list.h"
#include "../asset/ED_asset_mark_clear.h"
#include "../asset/ED_asset_temp_id_consumer.h"
/* C++ only headers. */
#ifdef __cplusplus
# include <string>
std::string ED_assetlist_asset_filepath_get(const bContext *C,
const AssetLibraryReference &library_reference,
const AssetHandle &asset_handle);
# include "BLI_function_ref.hh"
/* Can return false to stop iterating. */
using AssetListIterFn = blender::FunctionRef<bool(FileDirEntry &)>;
void ED_assetlist_iterate(const AssetLibraryReference *library_reference, AssetListIterFn fn);
# include "../asset/ED_asset_list.hh"
#endif

View File

@ -952,7 +952,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
}
/* If the button represents an id, it can set the "id" context pointer. */
if (U.experimental.use_asset_browser && ED_asset_can_make_single_from_context(C)) {
if (U.experimental.use_asset_browser && ED_asset_can_mark_single_from_context(C)) {
ID *id = CTX_data_pointer_get_type(C, "id", &RNA_ID).data;
/* Gray out items depending on if data-block is an asset. Preferably this could be done via