WIP: Rewrite asset browser as separate editor #104978

Closed
Julian Eisel wants to merge 68 commits from asset-browser-grid-view into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
14 changed files with 221 additions and 15 deletions
Showing only changes of commit b8b7b0af70 - Show all commits

View File

@ -25,10 +25,12 @@ class ASSETBROWSER_HT_header(Header):
def draw(self, context):
layout = self.layout
# space = context.space_data
space = context.space_data
layout.template_header()
layout.prop(space, "asset_library_ref", text="")
classes = (
ASSETBROWSER_HT_header,

View File

@ -201,6 +201,7 @@ struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C);
struct SpaceClip *CTX_wm_space_clip(const bContext *C);
struct SpaceTopBar *CTX_wm_space_topbar(const bContext *C);
struct SpaceSpreadsheet *CTX_wm_space_spreadsheet(const bContext *C);
struct SpaceAssets *CTX_wm_space_assets(const bContext *C);
void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm);
void CTX_wm_window_set(bContext *C, struct wmWindow *win);

View File

@ -945,6 +945,15 @@ struct SpaceSpreadsheet *CTX_wm_space_spreadsheet(const bContext *C)
return NULL;
}
struct SpaceAssets *CTX_wm_space_assets(const bContext *C)
{
ScrArea *area = CTX_wm_area(C);
if (area && area->spacetype == SPACE_ASSETS) {
return area->spacedata.first;
}
return NULL;
}
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
{
C->wm.manager = wm;

View File

@ -38,7 +38,7 @@ struct wmNotifier;
void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_reference,
const struct bContext *C);
void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference,
struct bContext *C);
const 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);
/**

View File

@ -35,4 +35,9 @@ std::string ED_assetlist_asset_filepath_get(const bContext *C,
/* Can return false to stop iterating. */
using AssetListIterFn = blender::FunctionRef<bool(AssetHandle)>;
/**
* Iterate the currently loaded assets for the referenced asset library, calling \a fn for each
* asset. This may be executed while the asset list is loading asynchronously. Assets will then be
* included as they get done loading.
*/
void ED_assetlist_iterate(const AssetLibraryReference &library_reference, AssetListIterFn fn);

View File

@ -123,7 +123,7 @@ class AssetList : NonCopyable {
void setup();
void fetch(const bContext &C);
void ensurePreviewsJob(bContext *C);
void ensurePreviewsJob(const bContext *C);
void clear(bContext *C);
bool needsRefetch() const;
@ -224,7 +224,7 @@ void AssetList::iterate(AssetListIterFn fn) const
}
}
void AssetList::ensurePreviewsJob(bContext *C)
void AssetList::ensurePreviewsJob(const bContext *C)
{
FileList *files = filelist_;
int numfiles = filelist_files_ensure(files);
@ -434,7 +434,8 @@ void ED_assetlist_storage_fetch(const AssetLibraryReference *library_reference,
AssetListStorage::fetch_library(*library_reference, *C);
}
void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_reference, bContext *C)
void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_reference,
const bContext *C)
{
AssetList *list = AssetListStorage::lookup_list(*library_reference);

View File

@ -30,8 +30,13 @@ set(INC
)
set(SRC
asset_browser_draw.cc
asset_browser_ops.cc
asset_view.cc
space_assets.cc
asset_browser_intern.hh
asset_view.hh
)
set(LIB

View File

@ -0,0 +1,60 @@
/*
* 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 spassets
*/
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BKE_context.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "asset_browser_intern.hh"
#include "asset_view.hh"
namespace blender::ed::asset_browser {
} // namespace blender::ed::asset_browser
using namespace blender::ed::asset_browser;
void asset_browser_main_region_draw(const bContext *C, ARegion *region)
{
const SpaceAssets *asset_space = CTX_wm_space_assets(C);
UI_ThemeClearColor(TH_BACK);
const uiStyle *style = UI_style_get_dpi();
uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
uiLayout *layout = UI_block_layout(block,
UI_LAYOUT_VERTICAL,
UI_LAYOUT_PANEL,
style->panelspace,
0,
region->sizex,
1,
0,
style);
asset_view_create_in_layout(*C, asset_space->asset_library_ref, *layout);
UI_block_end(C, block);
UI_block_draw(C, block);
}

View File

@ -22,6 +22,7 @@
void asset_browser_operatortypes();
namespace blender::ed::asset_browser {
struct ARegion;
struct bContext;
}
void asset_browser_main_region_draw(const bContext *C, ARegion *region);

View File

@ -0,0 +1,62 @@
/*
* 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 spassets
*/
#include <iostream>
#include "DNA_asset_types.h"
#include "ED_asset.h"
#include "UI_interface.h"
#include "asset_view.hh"
namespace blender::ed::asset_browser {
AssetGridView::AssetGridView(const AssetLibraryReference &asset_library_ref)
: asset_library_ref_(asset_library_ref)
{
}
void AssetGridView::build()
{
ED_assetlist_iterate(asset_library_ref_, [](AssetHandle asset) {
std::cout << ED_asset_handle_get_name(&asset) << std::endl;
return true;
});
std::cout << std::endl;
}
void asset_view_create_in_layout(const bContext &C,
const AssetLibraryReference &asset_library_ref,
uiLayout &layout)
{
uiBlock *block = uiLayoutGetBlock(&layout);
ED_assetlist_storage_fetch(&asset_library_ref, &C);
ED_assetlist_ensure_previews_job(&asset_library_ref, &C);
UI_block_layout_set_current(block, &layout);
AssetGridView grid_view{asset_library_ref};
grid_view.build();
}
} // namespace blender::ed::asset_browser

View File

@ -0,0 +1,42 @@
/*
* 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 spassets
*/
#pragma once
struct bContext;
struct AssetLibraryReference;
struct uiLayout;
namespace blender::ed::asset_browser {
class AssetGridView {
AssetLibraryReference asset_library_ref_;
public:
AssetGridView(const AssetLibraryReference &);
void build();
};
void asset_view_create_in_layout(const bContext &C,
const AssetLibraryReference &asset_library_ref,
uiLayout &layout);
} // namespace blender::ed::asset_browser

View File

@ -23,6 +23,7 @@
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BKE_asset.h"
#include "BKE_screen.h"
#include "BLI_listbase.h"
@ -35,6 +36,7 @@
#include "UI_resources.h"
#include "asset_browser_intern.hh"
#include "asset_view.hh"
/* ---------------------------------------------------------------------- */
/* Asset Browser Space */
@ -44,6 +46,8 @@ static SpaceLink *asset_browser_create(const ScrArea *UNUSED(area), const Scene
SpaceAssets *assets_space = MEM_cnew<SpaceAssets>("asset browser space");
assets_space->spacetype = SPACE_ASSETS;
BKE_asset_library_reference_init_default(&assets_space->asset_library_ref);
{
/* Header. */
ARegion *region = MEM_cnew<ARegion>("asset browser header");
@ -90,11 +94,6 @@ static void asset_browser_main_region_init(wmWindowManager *UNUSED(wm), ARegion
{
}
static void asset_browser_main_region_draw(const bContext *UNUSED(C), ARegion *UNUSED(region))
{
UI_ThemeClearColor(TH_BACK);
}
static void asset_browser_main_region_listener(const wmRegionListenerParams *UNUSED(params))
{
}
@ -129,7 +128,7 @@ void ED_spacetype_assets(void)
st->operatortypes = asset_browser_operatortypes;
st->keymap = asset_browser_keymap;
/* regions: main window */
/* Main region. */
art = MEM_cnew<ARegionType>("spacetype asset browser main region");
art->regionid = RGN_TYPE_WINDOW;
art->init = asset_browser_main_region_init;
@ -138,7 +137,7 @@ void ED_spacetype_assets(void)
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
BLI_addhead(&st->regiontypes, art);
/* regions: header */
/* Header region. */
art = MEM_cnew<ARegionType>("spacetype asset browser header region");
art->regionid = RGN_TYPE_HEADER;
art->prefsizey = HEADERY;

View File

@ -2047,6 +2047,8 @@ typedef struct SpaceAssets {
char link_flag;
char _pad0[6];
/* End 'SpaceLink' header. */
AssetLibraryReference asset_library_ref;
} SpaceAssets;
/** \} */

View File

@ -3265,6 +3265,18 @@ static int rna_FileAssetSelectParams_catalog_id_length(PointerRNA *UNUSED(ptr))
return UUID_STRING_LEN - 1;
}
static int rna_SpaceAssets_asset_library_get(PointerRNA *ptr)
{
SpaceAssets *asset_space = ptr->data;
return ED_asset_library_reference_to_enum_value(&asset_space->asset_library_ref);
}
static void rna_SpaceAssets_asset_library_set(PointerRNA *ptr, int value)
{
SpaceAssets *asset_space = ptr->data;
asset_space->asset_library_ref = ED_asset_library_reference_from_enum_value(value);
}
#else
static const EnumPropertyItem dt_uv_items[] = {
@ -7977,7 +7989,7 @@ static void rna_def_space_spreadsheet(BlenderRNA *brna)
static void rna_def_space_assets(BlenderRNA *brna)
{
// PropertyRNA *prop;
PropertyRNA *prop;
StructRNA *srna;
srna = RNA_def_struct(brna, "SpaceAssets", "Space");
@ -7985,6 +7997,11 @@ static void rna_def_space_assets(BlenderRNA *brna)
// rna_def_space_generic_show_region_toggles(
// srna, (1 << RGN_TYPE_UI) | (1 << RGN_TYPE_CHANNELS) | (1 << RGN_TYPE_FOOTER));
prop = rna_def_asset_library_reference_common(
srna, "rna_SpaceAssets_asset_library_get", "rna_SpaceAssets_asset_library_set");
RNA_def_property_ui_text(prop, "Asset Library", "");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
}
void RNA_def_space(BlenderRNA *brna)