@ -10,36 +10,32 @@
*
*/
# include <Atom/Document/MaterialDocumentRequestBus.h>
# include <Atom/Document/MaterialDocumentSystemRequestBus.h>
# include <Atom/RPI.Reflect/Image/StreamingImageAsset.h>
# include <Atom/RPI.Reflect/Material/MaterialAsset.h>
# include <AzQtComponents/Utilities/DesktopUtilities.h>
# include <AzToolsFramework/AssetBrowser/AssetBrowserModel.h>
# include <AzToolsFramework/AssetBrowser/AssetBrowserFilterModel.h>
# include <AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.h>
# include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
# include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
# include <AzToolsFramework/AssetBrowser/Search/Filter.h>
# include <AzToolsFramework/AssetBrowser/AssetBrowserFilterModel.h>
# include <AzToolsFramework/AssetBrowser/AssetBrowserModel.h>
# include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
# include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
# include <Atom/RPI.Reflect/Material/MaterialAsset.h>
# include <Atom/RPI.Reflect/Image/StreamingImageAsset.h>
# include <Atom/Document/MaterialDocumentSystemRequestBus.h>
# include <Atom/Document/MaterialDocumentRequestBus.h>
# include <AzToolsFramework/AssetBrowser/Search/Filter.h>
# include <AzToolsFramework/AssetBrowser/Views/AssetBrowserTreeView.h>
# include <Source/Window/MaterialBrowserWidget.h>
# include <Source/Window/ui_MaterialBrowserWidget.h>
AZ_PUSH_DISABLE_WARNING ( 4251 4800 , " -Wunknown-warning-option " ) // disable warnings spawned by QT
# include <QDesktopServices>
# include <QUrl>
# include <QMessageBox>
# include <QMenu>
# include <QAction>
# include <QByteArray>
# include <QCursor>
# include <Q PushButton >
# include <QDesktopServices>
# include <QList>
# include <QByteArray>
# include <QMenu>
# include <QMessageBox>
# include <QPushButton>
# include <QUrl>
AZ_POP_DISABLE_WARNING
namespace MaterialEditor
@ -99,7 +95,6 @@ namespace MaterialEditor
}
} ) ;
AssetBrowserModelNotificationBus : : Handler : : BusConnect ( ) ;
MaterialDocumentNotificationBus : : Handler : : BusConnect ( ) ;
}
@ -108,7 +103,7 @@ namespace MaterialEditor
// Maintains the tree expansion state between runs
m_ui - > m_assetBrowserTreeViewWidget - > SaveState ( ) ;
MaterialDocumentNotificationBus : : Handler : : BusDisconnect ( ) ;
A ssetBrowserModelNotification Bus: : Handler : : BusDisconnect ( ) ;
A Z: : Tick Bus: : Handler : : BusDisconnect ( ) ;
}
AzToolsFramework : : AssetBrowser : : FilterConstType MaterialBrowserWidget : : CreateFilter ( ) const
@ -151,72 +146,65 @@ namespace MaterialEditor
for ( const AssetBrowserEntry * entry : entries )
{
const SourceAssetBrowserEntry * sourceEntry = azrtti_cast < const SourceAssetBrowserEntry * > ( entry ) ;
if ( ! sourceEntry )
{
const ProductAssetBrowserEntry * productEntry = azrtti_cast < const ProductAssetBrowserEntry * > ( entry ) ;
if ( productEntry )
{
sourceEntry = azrtti_cast < const SourceAssetBrowserEntry * > ( productEntry - > GetParent ( ) ) ;
}
}
if ( sourceEntry )
if ( entry )
{
if ( AzFramework : : StringFunc : : Path : : IsExtension ( sourc eE ntry- > GetFullPath ( ) . c_str ( ) , MaterialExtension ) )
if ( AzFramework : : StringFunc : : Path : : IsExtension ( entry - > GetFullPath ( ) . c_str ( ) , MaterialExtension ) )
{
MaterialDocumentSystemRequestBus : : Broadcast ( & MaterialDocumentSystemRequestBus : : Events : : OpenDocument , sourc eE ntry- > GetFullPath ( ) ) ;
MaterialDocumentSystemRequestBus : : Broadcast ( & MaterialDocumentSystemRequestBus : : Events : : OpenDocument , entry - > GetFullPath ( ) ) ;
}
else if ( AzFramework : : StringFunc : : Path : : IsExtension ( sourc eE ntry- > GetFullPath ( ) . c_str ( ) , MaterialTypeExtension ) )
else if ( AzFramework : : StringFunc : : Path : : IsExtension ( entry - > GetFullPath ( ) . c_str ( ) , MaterialTypeExtension ) )
{
//ignore MaterialTypeExtension
}
else
{
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( sourc eE ntry- > GetFullPath ( ) . c_str ( ) ) ) ;
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( entry- > GetFullPath ( ) . c_str ( ) ) ) ;
}
}
}
}
void MaterialBrowserWidget : : EntryAdded ( const AssetBrowserEntry * entry )
{
if ( m_pathToSelect . empty ( ) )
{
return ;
}
const SourceAssetBrowserEntry * sourceEntry = azrtti_cast < const SourceAssetBrowserEntry * > ( entry ) ;
if ( ! sourceEntry )
{
const ProductAssetBrowserEntry * productEntry = azrtti_cast < const ProductAssetBrowserEntry * > ( entry ) ;
if ( productEntry )
{
sourceEntry = azrtti_cast < const SourceAssetBrowserEntry * > ( productEntry - > GetParent ( ) ) ;
}
}
if ( sourceEntry )
{
AZStd : : string sourcePath = sourceEntry - > GetFullPath ( ) ;
AzFramework : : StringFunc : : Path : : Normalize ( sourcePath ) ;
if ( m_pathToSelect = = sourcePath )
{
m_ui - > m_assetBrowserTreeViewWidget - > SelectFileAtPath ( m_pathToSelect ) ;
m_pathToSelect . clear ( ) ;
}
}
}
void MaterialBrowserWidget : : OnDocumentOpened ( const AZ : : Uuid & documentId )
{
AZStd : : string absolutePath ;
MaterialDocumentRequestBus : : EventResult ( absolutePath , documentId , & MaterialDocumentRequestBus : : Events : : GetAbsolutePath ) ;
if ( ! absolutePath . empty ( ) )
{
// Selecting a new asset in the browser is not guaranteed to happen immediately.
// The asset browser model notifications are sent before the model is updated.
// Instead of relying on the notifications, queue the selection and process it on tick until this change occurs.
m_pathToSelect = absolutePath ;
AzFramework : : StringFunc : : Path : : Normalize ( m_pathToSelect ) ;
m_ui - > m_assetBrowserTreeViewWidget - > SelectFileAtPath ( m_pathToSelect ) ;
AZ : : TickBus : : Handler : : BusConnect ( ) ;
}
}
void MaterialBrowserWidget : : OnTick ( float deltaTime , AZ : : ScriptTimePoint time )
{
AZ_UNUSED ( time ) ;
AZ_UNUSED ( deltaTime ) ;
if ( ! m_pathToSelect . empty ( ) )
{
// Attempt to select the new path
AzToolsFramework : : AssetBrowser : : AssetBrowserViewRequestBus : : Broadcast (
& AzToolsFramework : : AssetBrowser : : AssetBrowserViewRequestBus : : Events : : SelectFileAtPath , m_pathToSelect ) ;
// Iterate over the selected entries to verify if the selection was made
for ( const AssetBrowserEntry * entry : m_ui - > m_assetBrowserTreeViewWidget - > GetSelectedAssets ( ) )
{
if ( entry )
{
AZStd : : string sourcePath = entry - > GetFullPath ( ) ;
AzFramework : : StringFunc : : Path : : Normalize ( sourcePath ) ;
if ( m_pathToSelect = = sourcePath )
{
// Once the selection is confirmed, cancel the operation and disconnect
AZ : : TickBus : : Handler : : BusDisconnect ( ) ;
m_pathToSelect . clear ( ) ;
}
}
}
}
}