123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "EditorDefs.h"
- #include "AzAssetBrowserWindow.h"
- #include "AzAssetBrowserMultiWindow.h"
- #include <AssetBrowser/Views/AssetBrowserTreeView.h>
- // AzToolsFramework
- #include <AzCore/Console/IConsole.h>
- #include <AzToolsFramework/API/ToolsApplicationAPI.h>
- #include <AzToolsFramework/API/ViewPaneOptions.h>
- #include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
- #include <AzToolsFramework/AssetBrowser/AssetBrowserModel.h>
- #include <AzToolsFramework/AssetBrowser/AssetBrowserListModel.h>
- #include <AzToolsFramework/AssetBrowser/AssetBrowserFilterModel.h>
- #include <AzToolsFramework/AssetBrowser/AssetBrowserThumbnailViewProxyModel.h>
- #include <AzToolsFramework/AssetBrowser/Entries/AssetBrowserEntryUtils.h>
- #include <AzToolsFramework/AssetBrowser/AssetBrowserEntityInspectorWidget.h>
- // AzQtComponents
- #include <AzQtComponents/Utilities/QtWindowUtilities.h>
- #include <AzQtComponents/Components/Widgets/AssetFolderThumbnailView.h>
- #include <AzQtComponents/Components/Widgets/AssetFolderTableView.h>
- // Editor
- #include "AzAssetBrowser/AzAssetBrowserRequestHandler.h"
- #include "LyViewPaneNames.h"
- AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
- #include <AzAssetBrowser/ui_AzAssetBrowserWindow.h>
- AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
- AZ_CVAR_EXTERNED(bool, ed_useNewAssetBrowserListView);
- AZ_CVAR(bool, ed_useWIPAssetBrowserDesign, true, nullptr, AZ::ConsoleFunctorFlags::Null, "Use the in-progress new Asset Browser design");
- //! When the Asset Browser window is resized to be less than this many pixels in width
- //! the layout changes to accomodate its narrow state better. See AzAssetBrowserWindow::SetNarrowMode
- static constexpr int s_narrowModeThreshold = 700;
- static constexpr int MinimumWidth = 328;
- using namespace AzToolsFramework::AssetBrowser;
- namespace
- {
- inline QString FromStdString(AZStd::string_view string)
- {
- return QString::fromUtf8(string.data(), static_cast<int>(string.size()));
- }
- }
- namespace AzToolsFramework
- {
- namespace AssetBrowser
- {
- static constexpr const char* MenuIcon = ":/Menu/menu.svg";
- } // namespace AssetBrowser
- } // namespace AzToolsFramework
- class ListenerForShowAssetEditorEvent
- : public QObject
- , private AzToolsFramework::EditorEvents::Bus::Handler
- {
- public:
- ListenerForShowAssetEditorEvent(QObject* parent = nullptr)
- : QObject(parent)
- {
- AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
- }
- ~ListenerForShowAssetEditorEvent() override
- {
- AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
- }
- void SelectAsset(const QString& assetPath) override
- {
- AzToolsFramework::OpenViewPane(LyViewPane::AssetBrowser);
- AzAssetBrowserWindow* assetBrowser = AzToolsFramework::GetViewPaneWidget<AzAssetBrowserWindow>(LyViewPane::AssetBrowser);
- if (assetBrowser)
- {
- AzQtComponents::bringWindowToTop(assetBrowser);
- assetBrowser->SelectAsset(assetPath);
- }
- }
- };
- AzAssetBrowserWindow::AzAssetBrowserWindow(QWidget* parent)
- : QWidget(parent)
- , m_ui(new Ui::AzAssetBrowserWindowClass())
- , m_filterModel(new AzToolsFramework::AssetBrowser::AssetBrowserFilterModel(parent))
- , m_listModel(new AzToolsFramework::AssetBrowser::AssetBrowserListModel(parent))
- {
- m_ui->setupUi(this);
- m_ui->m_searchWidget->Setup(true, true);
- CreateToolsMenu();
- namespace AzAssetBrowser = AzToolsFramework::AssetBrowser;
- AzAssetBrowser::AssetBrowserComponentRequestBus::BroadcastResult(
- m_assetBrowserModel, &AzAssetBrowser::AssetBrowserComponentRequests::GetAssetBrowserModel);
- AZ_Assert(m_assetBrowserModel, "Failed to get filebrowser model");
- m_filterModel->setSourceModel(m_assetBrowserModel);
- m_filterModel->SetFilter(m_ui->m_searchWidget->GetFilter());
- // Turn off DynamicSort as sorting is now manual.
- m_filterModel->setDynamicSortFilter(false);
- m_ui->m_assetBrowserListViewWidget->setVisible(false);
- m_ui->m_toolsMenuButton->setVisible(false);
- m_ui->m_searchWidget->SetFilterInputInterval(AZStd::chrono::milliseconds(250));
- m_assetBrowserModel->SetFilterModel(m_filterModel.data());
- m_assetBrowserModel->EnableTickBus();
- this->setMinimumWidth(MinimumWidth);
- if (ed_useNewAssetBrowserListView)
- {
- m_ui->m_toolsMenuButton->setVisible(true);
- m_ui->m_toolsMenuButton->setEnabled(true);
- m_ui->m_toolsMenuButton->setAutoRaise(true);
- m_ui->m_toolsMenuButton->setIcon(QIcon(AzAssetBrowser::MenuIcon));
- m_listModel->setFilterRole(Qt::DisplayRole);
- m_listModel->setSourceModel(m_filterModel.data());
- m_listModel->setDynamicSortFilter(true);
- m_ui->m_assetBrowserListViewWidget->setModel(m_listModel.data());
- m_createMenu = new QMenu("Create New Asset Menu", this);
- m_ui->m_createButton->setMenu(m_createMenu);
- m_ui->m_createButton->setEnabled(true);
- m_ui->m_createButton->setAutoRaise(true);
- m_ui->m_createButton->setPopupMode(QToolButton::InstantPopup);
- connect(m_createMenu, &QMenu::aboutToShow, this, &AzAssetBrowserWindow::AddCreateMenu);
- connect(m_filterModel.data(), &AzAssetBrowser::AssetBrowserFilterModel::filterChanged,
- this, &AzAssetBrowserWindow::UpdateWidgetAfterFilter);
- connect(m_ui->m_assetBrowserListViewWidget->selectionModel(), &QItemSelectionModel::currentChanged,
- this, &AzAssetBrowserWindow::CurrentIndexChangedSlot);
- connect(
- m_ui->m_assetBrowserListViewWidget->selectionModel(),
- &QItemSelectionModel::selectionChanged,
- this,
- [this](const QItemSelection& selected, const QItemSelection& deselected)
- {
- Q_UNUSED(deselected);
- if (selected.indexes().size() > 0)
- {
- CurrentIndexChangedSlot(selected.indexes()[0]);
- }
- });
- connect(m_ui->m_assetBrowserListViewWidget, &QAbstractItemView::doubleClicked,
- this, &AzAssetBrowserWindow::DoubleClickedItem);
- connect(m_ui->m_assetBrowserListViewWidget, &AzAssetBrowser::AssetBrowserListView::ClearStringFilter,
- m_ui->m_searchWidget, &AzAssetBrowser::SearchWidget::ClearStringFilter);
- connect(m_ui->m_assetBrowserListViewWidget, &AzAssetBrowser::AssetBrowserListView::ClearTypeFilter,
- m_ui->m_searchWidget, &AzAssetBrowser::SearchWidget::ClearTypeFilter);
- m_ui->m_assetBrowserListViewWidget->SetIsAssetBrowserMainView();
- connect(
- m_ui->m_thumbnailView,
- &AssetBrowserThumbnailView::entryDoubleClicked,
- this,
- [this](const AssetBrowserEntry* entry)
- {
- OnDoubleClick(entry);
- });
- connect(
- m_ui->m_thumbnailView,
- &AssetBrowserThumbnailView::showInFolderTriggered,
- this,
- [this](const AssetBrowserEntry* entry)
- {
- if (entry && entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product)
- {
- entry = entry->GetParent();
- }
- if (!entry || !entry->GetParent())
- {
- return;
- }
- m_ui->m_searchWidget->ClearStringFilter();
- QModelIndex indexForEntry;
- m_assetBrowserModel->GetEntryIndex(const_cast<AssetBrowserEntry*>(entry->GetParent()), indexForEntry);
- if (!indexForEntry.isValid())
- {
- return;
- }
- auto targetIndex = m_filterModel.data()->mapFromSource(indexForEntry);
- m_ui->m_assetBrowserTreeViewWidget->SetShowIndexAfterUpdate(targetIndex);
- });
- }
- connect(m_ui->m_tableView, &AssetBrowserTableView::entryDoubleClicked,
- this,
- [this](const AssetBrowserEntry* entry)
- {
- OnDoubleClick(entry);
- });
- if (!ed_useWIPAssetBrowserDesign)
- {
- m_ui->m_breadcrumbsWrapper->hide();
- m_ui->m_middleStackWidget->hide();
- m_ui->m_treeViewButton->hide();
- m_ui->m_thumbnailViewButton->hide();
- m_ui->m_tableViewButton->hide();
- m_ui->m_createButton->hide();
- m_ui->m_searchWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
- }
- m_ui->horizontalLayout->setAlignment(m_ui->m_toolsMenuButton, Qt::AlignTop);
- m_ui->horizontalLayout->setAlignment(m_ui->m_treeViewButton, Qt::AlignTop);
- m_ui->horizontalLayout->setAlignment(m_ui->m_tableViewButton, Qt::AlignTop);
- m_ui->horizontalLayout->setAlignment(m_ui->m_thumbnailViewButton, Qt::AlignTop);
- m_ui->horizontalLayout->setAlignment(m_ui->m_breadcrumbsWrapper, Qt::AlignTop);
- m_ui->horizontalLayout->setAlignment(m_ui->m_createButton, Qt::AlignTop);
- m_ui->m_breadcrumbsLayout->insertWidget(0, m_ui->m_pathBreadCrumbs->createSeparator());
- m_ui->m_breadcrumbsLayout->insertWidget(0, m_ui->m_pathBreadCrumbs->createBackForwardToolBar());
- connect(m_ui->m_pathBreadCrumbs, &AzQtComponents::BreadCrumbs::linkClicked, this, [this](const QString& path) {
- m_ui->m_assetBrowserTreeViewWidget->SelectFolder(path.toUtf8().constData());
- });
- connect(m_ui->m_pathBreadCrumbs, &AzQtComponents::BreadCrumbs::pathChanged, this, &AzAssetBrowserWindow::BreadcrumbsPathChangedSlot);
- connect(m_ui->m_pathBreadCrumbs, &AzQtComponents::BreadCrumbs::pathEdited, this, [this](const QString& path) {
- const auto* entry = m_ui->m_assetBrowserTreeViewWidget->GetEntryByPath(path);
- const auto* folderEntry = AzToolsFramework::AssetBrowser::Utils::FolderForEntry(entry);
- if (folderEntry)
- {
- // No need to select the folder ourselves, callback from Breadcrumbs will take care of that
- m_ui->m_pathBreadCrumbs->pushFullPath(FromStdString(folderEntry->GetFullPath()), FromStdString(folderEntry->GetVisiblePath()));
- }
- });
- connect(m_ui->m_thumbnailViewButton, &QAbstractButton::clicked, this, [this] { SetCurrentMode(AssetBrowserMode::ThumbnailView); });
- connect(m_ui->m_tableViewButton, &QAbstractButton::clicked, this, [this] { SetCurrentMode(AssetBrowserMode::TableView); });
- connect(m_ui->m_treeViewButton, &QAbstractButton::clicked, this, [this] { SetCurrentMode(AssetBrowserMode::ListView); });
- m_ui->m_assetBrowserTreeViewWidget->setModel(m_filterModel.data());
- m_ui->m_thumbnailView->SetAssetTreeView(m_ui->m_assetBrowserTreeViewWidget);
- m_ui->m_tableView->SetAssetTreeView(m_ui->m_assetBrowserTreeViewWidget);
- connect(m_ui->m_searchWidget->GetFilter().data(), &AzAssetBrowser::AssetBrowserEntryFilter::updatedSignal,
- m_filterModel.data(), &AzAssetBrowser::AssetBrowserFilterModel::filterUpdatedSlot);
- connect(m_filterModel.data(), &AzAssetBrowser::AssetBrowserFilterModel::filterChanged, this,
- [this]()
- {
- const bool hasFilter = !m_ui->m_searchWidget->GetFilterString().isEmpty();
- const bool selectFirstFilteredIndex = false;
- m_ui->m_assetBrowserTreeViewWidget->UpdateAfterFilter(hasFilter, selectFirstFilteredIndex);
- });
- connect(m_ui->m_assetBrowserTreeViewWidget->selectionModel(), &QItemSelectionModel::currentChanged,
- this, &AzAssetBrowserWindow::CurrentIndexChangedSlot);
- connect(
- m_ui->m_assetBrowserTreeViewWidget->selectionModel(),
- &QItemSelectionModel::selectionChanged,
- this,
- [this](const QItemSelection& selected, const QItemSelection& deselected)
- {
- Q_UNUSED(deselected);
- if (selected.indexes().size() > 0)
- {
- CurrentIndexChangedSlot(selected.indexes()[0]);
- m_ui->m_createButton->setEnabled(true);
- }
- else
- {
- m_ui->m_createButton->setDisabled(true);
- }
- });
- connect(
- m_ui->m_assetBrowserTreeViewWidget,
- &QAbstractItemView::clicked,
- this,
- [this](const QModelIndex& idx)
- {
- using namespace AzToolsFramework::AssetBrowser;
- auto* entry = idx.data(AssetBrowserModel::Roles::EntryRole).value<const AssetBrowserEntry*>();
- if (entry->GetEntryType() != AssetBrowserEntry::AssetEntryType::Folder)
- {
- AssetBrowserPreviewRequestBus::Broadcast(&AssetBrowserPreviewRequest::PreviewAsset, entry);
- }
- m_ui->m_searchWidget->ClearStringFilter();
- });
- connect(m_ui->m_assetBrowserTreeViewWidget, &QAbstractItemView::doubleClicked, this, &AzAssetBrowserWindow::DoubleClickedItem);
- connect(m_ui->m_assetBrowserTreeViewWidget, &AzAssetBrowser::AssetBrowserTreeView::ClearStringFilter,
- m_ui->m_searchWidget, &AzAssetBrowser::SearchWidget::ClearStringFilter);
- connect(m_ui->m_assetBrowserTreeViewWidget, &AzAssetBrowser::AssetBrowserTreeView::ClearTypeFilter,
- m_ui->m_searchWidget, &AzAssetBrowser::SearchWidget::ClearTypeFilter);
- connect(
- m_assetBrowserModel,
- &AzAssetBrowser::AssetBrowserModel::RequestOpenItemForEditing,
- this,
- [this](const QModelIndex& index)
- {
- // If multiple AssetBrowsers are open, only the focused browser should perform the rename.
- QWidget* focusWidget = QApplication::focusWidget();
- if (!isAncestorOf(focusWidget))
- {
- return;
- }
- if (m_ui->m_thumbnailView->GetThumbnailActiveView())
- {
- m_ui->m_thumbnailView->OpenItemForEditing(index);
- }
- else if (m_ui->m_tableView->GetTableViewActive())
- {
- m_ui->m_tableView->OpenItemForEditing(index);
- }
- m_ui->m_assetBrowserTreeViewWidget->OpenItemForEditing(index);
- });
- connect(this, &AzAssetBrowserWindow::SizeChangedSignal,
- m_ui->m_assetBrowserListViewWidget, &AzAssetBrowser::AssetBrowserListView::UpdateSizeSlot);
- m_ui->m_assetBrowserTreeViewWidget->SetIsAssetBrowserMainView();
- m_ui->m_thumbnailView->SetIsAssetBrowserMainView();
- m_ui->m_tableView->SetIsAssetBrowserMainView();
- }
- AzAssetBrowserWindow::~AzAssetBrowserWindow()
- {
- m_assetBrowserModel->DisableTickBus();
- m_ui->m_assetBrowserTreeViewWidget->SaveState();
- }
- void AzAssetBrowserWindow::AddCreateMenu()
- {
- using namespace AzToolsFramework::AssetBrowser;
- m_createMenu->clear();
- const auto& selectedAssets = m_ui->m_assetBrowserTreeViewWidget->isVisible() ? m_ui->m_assetBrowserTreeViewWidget->GetSelectedAssets()
- : m_ui->m_assetBrowserListViewWidget->GetSelectedAssets();
- const AssetBrowserEntry* entry = selectedAssets.empty() ? nullptr : selectedAssets.front();
- if (!entry || selectedAssets.size() != 1)
- {
- return;
- }
- if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Product)
- {
- entry = entry->GetParent();
- if (!entry)
- {
- return;
- }
- }
- AZStd::string fullFilePath = entry->GetFullPath();
- AZStd::string folderPath;
- if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Folder)
- {
- folderPath = fullFilePath;
- }
- else
- {
- AzFramework::StringFunc::Path::GetFolderPath(fullFilePath.c_str(), folderPath);
- }
- AZ::Uuid sourceID = AZ::Uuid::CreateNull();
- SourceFileCreatorList creators;
- AssetBrowserInteractionNotificationBus::Broadcast(
- &AssetBrowserInteractionNotificationBus::Events::AddSourceFileCreators, folderPath.c_str(), sourceID, creators);
- if (!creators.empty())
- {
- for (const SourceFileCreatorDetails& creatorDetails : creators)
- {
- if (creatorDetails.m_creator)
- {
- m_createMenu->addAction(
- creatorDetails.m_iconToUse,
- tr("New ") + tr(creatorDetails.m_displayText.c_str()),
- [sourceID, fullFilePath, creatorDetails]()
- {
- creatorDetails.m_creator(fullFilePath.c_str(), sourceID);
- });
- }
- }
- }
- }
- void AzAssetBrowserWindow::RegisterViewClass()
- {
- AzToolsFramework::ViewPaneOptions options;
- options.preferedDockingArea = Qt::BottomDockWidgetArea;
- AzToolsFramework::RegisterViewPane<AzAssetBrowserWindow>(LyViewPane::AssetBrowser, LyViewPane::CategoryTools, options);
- options.showInMenu = false;
- const QString name = QString("%1 (2)").arg(LyViewPane::AssetBrowser);
- AzToolsFramework::RegisterViewPane<AzAssetBrowserWindow>(qPrintable(name), LyViewPane::CategoryTools, options);
- }
- QObject* AzAssetBrowserWindow::createListenerForShowAssetEditorEvent(QObject* parent)
- {
- auto* listener = new ListenerForShowAssetEditorEvent(parent);
- // the listener is attached to the parent and will get cleaned up then
- return listener;
- }
- bool AzAssetBrowserWindow::ViewWidgetBelongsTo(QWidget* viewWidget)
- {
- return m_ui->m_assetBrowserTreeViewWidget == viewWidget ||
- m_ui->m_assetBrowserListViewWidget == viewWidget ||
- m_ui->m_thumbnailView == viewWidget ||
- m_ui->m_tableView == viewWidget;
- }
- void AzAssetBrowserWindow::resizeEvent(QResizeEvent* resizeEvent)
- {
- // leftLayout is the parent of the listView
- // rightLayout is the parent of the preview window.
- // Workaround: When docking windows this event keeps holding the old size of the widgets instead of the new one
- // but the resizeEvent holds the new size of the whole widget
- // So we have to save the proportions somehow
- const QWidget* leftLayout = m_ui->m_leftLayout;
- const float oldLeftLayoutWidth = aznumeric_cast<float>(leftLayout->geometry().width());
- const float oldWidth = aznumeric_cast<float>(leftLayout->geometry().width());
- const float newWidth = oldLeftLayoutWidth * aznumeric_cast<float>(resizeEvent->size().width()) / oldWidth;
- const bool isNarrow = resizeEvent->size().width() < s_narrowModeThreshold;
- SetNarrowMode(isNarrow);
- emit SizeChangedSignal(aznumeric_cast<int>(newWidth));
- QWidget::resizeEvent(resizeEvent);
- }
- void AzAssetBrowserWindow::CreateToolsMenu()
- {
- if (m_toolsMenu != nullptr)
- {
- return;
- }
- m_toolsMenu = new QMenu("Asset Browser Mode Selection", this);
- m_ui->m_toolsMenuButton->setMenu(m_toolsMenu);
- m_ui->m_toolsMenuButton->setPopupMode(QToolButton::InstantPopup);
- if (ed_useWIPAssetBrowserDesign)
- {
- auto* openNewAction = new QAction(tr("Open Another Asset Browser"), this);
- connect(openNewAction, &QAction::triggered, this, [] { AzAssetBrowserMultiWindow::OpenNewAssetBrowserWindow(); });
- m_toolsMenu->addAction(openNewAction);
- m_toolsMenu->addSeparator();
- auto* collapseAllAction = new QAction(tr("Collapse All"), this);
- connect(collapseAllAction, &QAction::triggered, this, [this] { m_ui->m_assetBrowserTreeViewWidget->collapseAll(); });
- m_toolsMenu->addAction(collapseAllAction);
- m_toolsMenu->addSeparator();
- auto* projectSourceAssets = new QAction(tr("Hide Engine Folders"), this);
- projectSourceAssets->setCheckable(true);
- projectSourceAssets->setChecked(true);
- connect(projectSourceAssets, &QAction::triggered, this,
- [this, projectSourceAssets]
- {
- m_ui->m_searchWidget->ToggleEngineFilter(projectSourceAssets->isChecked());
- });
- m_toolsMenu->addAction(projectSourceAssets);
- m_ui->m_searchWidget->ToggleEngineFilter(projectSourceAssets->isChecked());
- auto* unusableProductAssets = new QAction(tr("Hide Unusable Product Assets"), this);
- unusableProductAssets->setCheckable(true);
- unusableProductAssets->setChecked(true);
- connect(
- unusableProductAssets,
- &QAction::triggered,
- this,
- [this, unusableProductAssets]
- {
- m_ui->m_searchWidget->ToggleUnusableProductsFilter(unusableProductAssets->isChecked());
- });
- m_toolsMenu->addAction(unusableProductAssets);
- m_ui->m_searchWidget->ToggleUnusableProductsFilter(unusableProductAssets->isChecked());
- m_ui->m_searchWidget->AddFolderFilter();
- m_assetBrowserDisplayState = AzToolsFramework::AssetBrowser::AssetBrowserDisplayState::TreeViewMode;
- m_ui->m_assetBrowserListViewWidget->setVisible(false);
- m_ui->m_assetBrowserTreeViewWidget->setVisible(true);
- m_ui->m_thumbnailView->SetThumbnailActiveView(true);
- m_ui->m_tableView->SetTableViewActive(false);
- }
- else
- {
- m_listViewMode = new QAction(tr("List View"), this);
- m_listViewMode->setCheckable(true);
- connect(m_listViewMode, &QAction::triggered, this, &AzAssetBrowserWindow::SetListViewMode);
- m_toolsMenu->addAction(m_listViewMode);
- m_treeViewMode = new QAction(tr("Tree View"), this);
- m_treeViewMode->setCheckable(true);
- connect(m_treeViewMode, &QAction::triggered, this, &AzAssetBrowserWindow::SetTreeViewMode);
- m_toolsMenu->addAction(m_treeViewMode);
- connect(m_toolsMenu, &QMenu::aboutToShow, this, &AzAssetBrowserWindow::UpdateDisplayInfo);
- UpdateDisplayInfo();
- }
- }
- void AzAssetBrowserWindow::UpdateDisplayInfo()
- {
- namespace AzAssetBrowser = AzToolsFramework::AssetBrowser;
- if (m_toolsMenu == nullptr)
- {
- return;
- }
- m_treeViewMode->setChecked(false);
- m_listViewMode->setChecked(false);
- switch (m_assetBrowserDisplayState)
- {
- case AzAssetBrowser::AssetBrowserDisplayState::TreeViewMode:
- {
- m_treeViewMode->setChecked(true);
- break;
- }
- case AzAssetBrowser::AssetBrowserDisplayState::ListViewMode:
- {
- m_listViewMode->setChecked(true);
- break;
- }
- }
- }
- void AzAssetBrowserWindow::SetNarrowMode(bool narrow)
- {
- if (m_inNarrowMode == narrow)
- {
- return;
- }
- // In narrow mode, breadcrumbs are below the search bar and view switching buttons
- m_inNarrowMode = narrow;
- if (narrow)
- {
- m_ui->scrollAreaVerticalLayout->insertWidget(1, m_ui->m_breadcrumbsWrapper);
- m_ui->m_searchWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
- m_ui->m_breadcrumbsWrapper->setContentsMargins(0, 0, 0, 5);
- }
- else
- {
- m_ui->horizontalLayout->insertWidget(4, m_ui->m_breadcrumbsWrapper);
- m_ui->m_breadcrumbsWrapper->setContentsMargins(0, 0, 0, 0);
- m_ui->horizontalLayout->setAlignment(m_ui->m_breadcrumbsWrapper, Qt::AlignTop);
- // Once we fully move to new design this cvar will be gone and the condition can be deleted
- if (ed_useWIPAssetBrowserDesign)
- {
- m_ui->m_searchWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
- }
- }
- }
- void AzAssetBrowserWindow::SetTreeViewMode()
- {
- namespace AzAssetBrowser = AzToolsFramework::AssetBrowser;
- m_assetBrowserDisplayState = AzAssetBrowser::AssetBrowserDisplayState::TreeViewMode;
- if (m_ui->m_assetBrowserListViewWidget->isVisible())
- {
- m_ui->m_assetBrowserListViewWidget->setVisible(false);
- m_ui->m_assetBrowserTreeViewWidget->setVisible(true);
- }
- }
- void AzAssetBrowserWindow::SetListViewMode()
- {
- namespace AzAssetBrowser = AzToolsFramework::AssetBrowser;
- m_assetBrowserDisplayState = AzAssetBrowser::AssetBrowserDisplayState::ListViewMode;
- UpdateWidgetAfterFilter();
- }
- void AzAssetBrowserWindow::UpdateWidgetAfterFilter()
- {
- namespace AzAssetBrowser = AzToolsFramework::AssetBrowser;
- const bool hasFilter = !m_ui->m_searchWidget->GetFilterString().isEmpty();
- if (m_assetBrowserDisplayState == AzAssetBrowser::AssetBrowserDisplayState::ListViewMode)
- {
- m_ui->m_assetBrowserListViewWidget->setVisible(hasFilter);
- m_ui->m_assetBrowserTreeViewWidget->setVisible(!hasFilter);
- }
- if (hasFilter)
- {
- m_ui->m_assetBrowserTreeViewWidget->selectionModel()->select(
- m_ui->m_assetBrowserTreeViewWidget->model()->index(0, 0, {}), QItemSelectionModel::ClearAndSelect);
- }
- if (ed_useNewAssetBrowserListView)
- {
- auto thumbnailWidget = m_ui->m_thumbnailView->GetThumbnailViewWidget();
- auto tableWidget = m_ui->m_tableView->GetTableViewWidget();
- if (hasFilter)
- {
- if (thumbnailWidget)
- {
- thumbnailWidget->setRootIndex(thumbnailWidget->model()->index(0, 0, {}));
- m_ui->m_thumbnailView->SetSearchString(m_ui->m_searchWidget->GetFilterString());
- }
- if (tableWidget)
- {
- tableWidget->setRootIndex(tableWidget->model()->index(0, 0, {}));
- m_ui->m_tableView->SetSearchString(m_ui->m_searchWidget->GetFilterString());
- }
- m_ui->m_assetBrowserTreeViewWidget->SetSearchString(m_ui->m_searchWidget->GetFilterString());
- }
- else
- {
- if (thumbnailWidget)
- {
- m_ui->m_thumbnailView->SetSearchString("");
- }
- if (tableWidget)
- {
- m_ui->m_tableView->SetSearchString("");
- }
- m_ui->m_assetBrowserTreeViewWidget->SetSearchString("");
- }
- }
- }
- void AzAssetBrowserWindow::UpdateBreadcrumbs(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* selectedEntry) const
- {
- using namespace AzToolsFramework::AssetBrowser;
- QString entryPath;
- QString fullPath;
- if (selectedEntry)
- {
- const AssetBrowserEntry* folderEntry = Utils::FolderForEntry(selectedEntry);
- if (folderEntry)
- {
- entryPath = FromStdString(folderEntry->GetVisiblePath());
- fullPath = FromStdString(folderEntry->GetFullPath());
- }
- }
- m_ui->m_pathBreadCrumbs->pushFullPath(fullPath, entryPath);
- }
- void AzAssetBrowserWindow::SetTwoColumnMode(QWidget* viewToShow)
- {
- auto* thumbnailView = qobject_cast<AssetBrowserThumbnailView*>(viewToShow);
- if (thumbnailView && m_ui->m_thumbnailView->GetThumbnailActiveView())
- {
- return;
- }
- auto* tableView = qobject_cast<AssetBrowserTableView*>(viewToShow);
- if (tableView && m_ui->m_tableView->GetTableViewActive())
- {
- return;
- }
- m_ui->m_middleStackWidget->show();
- m_ui->m_middleStackWidget->setCurrentWidget(viewToShow);
- m_ui->m_assetBrowserTreeViewWidget->SetApplySnapshot(false);
- m_ui->m_searchWidget->AddFolderFilter();
- if (thumbnailView)
- {
- m_ui->m_thumbnailView->SetThumbnailActiveView(true);
- m_ui->m_tableView->SetTableViewActive(false);
- }
- else if (tableView)
- {
- m_ui->m_thumbnailView->SetThumbnailActiveView(false);
- m_ui->m_tableView->SetTableViewActive(true);
- }
- }
- void AzAssetBrowserWindow::SetOneColumnMode()
- {
- if (m_ui->m_thumbnailView->GetThumbnailActiveView() || m_ui->m_tableView->GetTableViewActive())
- {
- m_ui->m_middleStackWidget->hide();
- m_ui->m_assetBrowserTreeViewWidget->SetApplySnapshot(false);
- m_ui->m_searchWidget->RemoveFolderFilter();
- if (!m_ui->m_assetBrowserTreeViewWidget->selectionModel()->selectedRows().isEmpty())
- {
- m_ui->m_assetBrowserTreeViewWidget->expand(m_ui->m_assetBrowserTreeViewWidget->selectionModel()->selectedRows()[0]);
- }
- m_ui->m_thumbnailView->SetThumbnailActiveView(false);
- m_ui->m_tableView->SetTableViewActive(false);
- }
- }
- void AzAssetBrowserWindow::OnDoubleClick(const AssetBrowserEntry* entry)
- {
- if (!m_ui->m_assetBrowserTreeViewWidget || !entry || !m_assetBrowserModel || !m_filterModel.data())
- {
- return;
- }
- QModelIndex indexForEntry;
- m_assetBrowserModel->GetEntryIndex(const_cast<AssetBrowserEntry*>(entry), indexForEntry);
- if (!indexForEntry.isValid())
- {
- return;
- }
- auto entryType = entry->GetEntryType();
- if (entryType == AssetBrowserEntry::AssetEntryType::Folder)
- {
- m_ui->m_searchWidget->ClearStringFilter();
- auto selectionModel = m_ui->m_assetBrowserTreeViewWidget->selectionModel();
- auto targetIndex = m_filterModel.data()->mapFromSource(indexForEntry);
- selectionModel->select(targetIndex, QItemSelectionModel::ClearAndSelect);
- auto targetIndexAncestor = targetIndex.parent();
- while (targetIndexAncestor.isValid())
- {
- m_ui->m_assetBrowserTreeViewWidget->expand(targetIndexAncestor);
- targetIndexAncestor = targetIndexAncestor.parent();
- }
- if (m_ui->m_thumbnailView->GetThumbnailActiveView())
- {
- m_ui->m_thumbnailView->GetThumbnailViewWidget()->selectionModel()->clearSelection();
- }
- else if (m_ui->m_tableView->GetTableViewActive())
- {
- m_ui->m_tableView->GetTableViewWidget()->selectionModel()->clearSelection();
- }
- m_ui->m_assetBrowserTreeViewWidget->scrollTo(targetIndex, QAbstractItemView::ScrollHint::PositionAtCenter);
- }
- else if (entryType == AssetBrowserEntry::AssetEntryType::Product || entryType == AssetBrowserEntry::AssetEntryType::Source)
- {
- AZ::Data::AssetId assetIdToOpen;
- AZStd::string fullFilePath;
- if (const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry* productEntry =
- azrtti_cast<const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry*>(entry))
- {
- assetIdToOpen = productEntry->GetAssetId();
- fullFilePath = entry->GetFullPath();
- }
- else if (const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* sourceEntry =
- azrtti_cast<const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry*>(entry))
- {
- // manufacture an empty AssetID with the source's UUID
- assetIdToOpen = AZ::Data::AssetId(sourceEntry->GetSourceUuid(), 0);
- fullFilePath = entry->GetFullPath();
- }
- bool handledBySomeone = false;
- if (assetIdToOpen.IsValid())
- {
- AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Broadcast(
- &AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotifications::OpenAssetInAssociatedEditor,
- assetIdToOpen,
- handledBySomeone);
- }
- if (!handledBySomeone && !fullFilePath.empty())
- {
- AzAssetBrowserRequestHandler::OpenWithOS(fullFilePath);
- }
- }
- }
- static void ExpandTreeToIndex(QTreeView* treeView, const QModelIndex& index)
- {
- treeView->collapseAll();
- // Note that we deliberately don't expand the index passed in
- // collapseAll above will close all but the top level nodes.
- // treeView->expand(index) marks a node as expanded, but if it's parent isn't expanded,
- // there won't be any paint updates because it doesn't expand parent nodes.
- // So, to minimize paint updates, we expand everything in reverse order (leaf up to root), so that
- // painting will only actually occur once the top level parent is expanded.
- QModelIndex parentIndex = index.parent();
- while (parentIndex.isValid())
- {
- treeView->expand(parentIndex);
- parentIndex = parentIndex.parent();
- }
- }
- void AzAssetBrowserWindow::SelectAsset(const QString& assetPath)
- {
- if (ed_useWIPAssetBrowserDesign)
- {
- QTimer::singleShot(
- 0,
- this,
- [this, assetPath]
- {
- m_ui->m_searchWidget->ClearTextFilter();
- m_ui->m_searchWidget->ClearTypeFilter();
- m_ui->m_assetBrowserTreeViewWidget->SelectFileAtPathAfterUpdate(assetPath.toUtf8().data());
- });
- }
- else
- {
- QModelIndex index = m_assetBrowserModel->findIndex(assetPath);
- if (index.isValid())
- {
- m_ui->m_searchWidget->ClearTextFilter();
- m_ui->m_searchWidget->ClearTypeFilter();
- // Queue the expand and select stuff, so that it doesn't get processed the same
- // update as the search widget clearing - something with the search widget clearing
- // interferes with the update from the select and expand, and if you don't
- // queue it, the tree doesn't expand reliably.
- QTimer::singleShot(
- 0,
- this,
- [this, filteredIndex = index]
- {
- // the treeview has a filter model so we have to backwards go from that
- QModelIndex modelIndex = m_filterModel->mapFromSource(filteredIndex);
- QTreeView* treeView = m_ui->m_assetBrowserTreeViewWidget;
- ExpandTreeToIndex(treeView, modelIndex);
- treeView->scrollTo(modelIndex);
- treeView->setCurrentIndex(modelIndex);
- treeView->selectionModel()->select(modelIndex, QItemSelectionModel::ClearAndSelect);
- });
- }
- }
- }
- void AzAssetBrowserWindow::CurrentIndexChangedSlot(const QModelIndex& idx) const
- {
- using namespace AzToolsFramework::AssetBrowser;
- auto* entry = idx.data(AssetBrowserModel::Roles::EntryRole).value<const AssetBrowserEntry*>();
- UpdateBreadcrumbs(entry);
- }
- // while its tempting to use Activated here, we don't actually want it to count as activation
- // just because on some OS clicking once is activation.
- void AzAssetBrowserWindow::DoubleClickedItem([[maybe_unused]] const QModelIndex& element)
- {
- namespace AzAssetBrowser = AzToolsFramework::AssetBrowser;
- const auto& selectedAssets = m_ui->m_assetBrowserTreeViewWidget->isVisible() ? m_ui->m_assetBrowserTreeViewWidget->GetSelectedAssets()
- : m_ui->m_assetBrowserListViewWidget->GetSelectedAssets();
- for (const AzAssetBrowser::AssetBrowserEntry* entry : selectedAssets)
- {
- AZ::Data::AssetId assetIdToOpen;
- AZStd::string fullFilePath;
- if (const AzAssetBrowser::ProductAssetBrowserEntry* productEntry =
- azrtti_cast<const AzAssetBrowser::ProductAssetBrowserEntry*>(entry))
- {
- assetIdToOpen = productEntry->GetAssetId();
- fullFilePath = entry->GetFullPath();
- }
- else if (
- const AzAssetBrowser::SourceAssetBrowserEntry* sourceEntry = azrtti_cast<const AzAssetBrowser::SourceAssetBrowserEntry*>(entry))
- {
- // manufacture an empty AssetID with the source's UUID
- assetIdToOpen = AZ::Data::AssetId(sourceEntry->GetSourceUuid(), 0);
- fullFilePath = entry->GetFullPath();
- }
- bool handledBySomeone = false;
- if (assetIdToOpen.IsValid())
- {
- AzAssetBrowser::AssetBrowserInteractionNotificationBus::Broadcast(
- &AzAssetBrowser::AssetBrowserInteractionNotifications::OpenAssetInAssociatedEditor, assetIdToOpen, handledBySomeone);
- }
- if (!handledBySomeone && !fullFilePath.empty())
- {
- AzAssetBrowserRequestHandler::OpenWithOS(fullFilePath);
- }
- }
- }
- //! This slot ignores path change coming from breadcrumbs if we already have a file selected directly in this folder. This may happen
- //! in the one column mode where tree view shows files too.
- void AzAssetBrowserWindow::BreadcrumbsPathChangedSlot(const QString& path) const
- {
- using namespace AzToolsFramework::AssetBrowser;
- const auto* currentEntry =
- m_ui->m_assetBrowserTreeViewWidget->currentIndex().data(AssetBrowserModel::Roles::EntryRole).value<const AssetBrowserEntry*>();
- const AssetBrowserEntry* folderForCurrent = Utils::FolderForEntry(currentEntry);
- const QString currentFolderPath =
- folderForCurrent ? QString::fromUtf8(folderForCurrent->GetVisiblePath().c_str()).replace('\\', '/') : QString();
- if (path != currentFolderPath)
- {
- m_ui->m_assetBrowserTreeViewWidget->SelectFolder(path.toUtf8().constData());
- }
- }
- AssetBrowserMode AzAssetBrowserWindow::GetCurrentMode() const
- {
- return m_currentMode;
- }
- void AzAssetBrowserWindow::SetCurrentMode(const AssetBrowserMode mode)
- {
- if (ed_useWIPAssetBrowserDesign)
- {
- switch (mode)
- {
- case AssetBrowserMode::TableView:
- SetTwoColumnMode(m_ui->m_tableView);
- break;
- case AssetBrowserMode::ListView:
- SetOneColumnMode();
- break;
- default:
- SetTwoColumnMode(m_ui->m_thumbnailView);
- break;
- }
- }
- m_currentMode = mode;
- }
- #include <AzAssetBrowser/moc_AzAssetBrowserWindow.cpp>
|