diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowserInteractions.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowserInteractions.h new file mode 100644 index 0000000000..1892b1ca0c --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowserInteractions.h @@ -0,0 +1,65 @@ +/* + * 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 + * + */ + +#pragma once + +#include +#include + +class QWidget; +class QMenu; +class QAction; + +namespace AzToolsFramework +{ + namespace AssetBrowser + { + class AssetBrowserEntry; + } // namespace AssetBrowser +} // namespace AzToolsFramework + +namespace AtomToolsFramework +{ + //! Provides common asset browser interactions, source control integration, and functionality to add custom menu actions + class AtomToolsAssetBrowserInteractions : public AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler + { + public: + AZ_CLASS_ALLOCATOR(AtomToolsAssetBrowserInteractions, AZ::SystemAllocator, 0); + + AtomToolsAssetBrowserInteractions(); + ~AtomToolsAssetBrowserInteractions(); + + using AssetBrowserEntryVector = AZStd::vector; + using FilterCallback = AZStd::function; + using ActionCallback = AZStd::function; + + //! Add a filter and handler for custom context menu entries that will be added to the top of the context menu + void RegisterContextMenuActions(const FilterCallback& filterCallback, const ActionCallback& actionCallback); + + private: + //! AssetBrowserInteractionNotificationBus::Handler overrides... + void AddContextMenuActions(QWidget* caller, QMenu* menu, const AssetBrowserEntryVector& entries) override; + + void AddContextMenuActionsForSourceEntries( + QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); + void AddContextMenuActionsForFolderEntries( + QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); + void AddContextMenuActionsForAllEntries( + QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); + void AddContextMenuActionsForSourceControl( + QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); + void UpdateContextMenuActionsForSourceControl(bool success, AzToolsFramework::SourceControlFileInfo info); + + QWidget* m_caller = {}; + QAction* m_addAction = {}; + QAction* m_checkOutAction = {}; + QAction* m_undoCheckOutAction = {}; + QAction* m_getLatestAction = {}; + AZStd::vector> m_contextMenuCallbacks; + }; +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorBrowserInteractions.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowserInteractions.cpp similarity index 52% rename from Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorBrowserInteractions.cpp rename to Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowserInteractions.cpp index 435d1f6f12..5b65356aab 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorBrowserInteractions.cpp +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/AssetBrowser/AtomToolsAssetBrowserInteractions.cpp @@ -7,44 +7,47 @@ */ #include -#include -#include -#include -#include +#include #include #include #include #include +#include #include #include #include #include -#include -#include #include #include #include +#include #include +#include #include #include #include -namespace MaterialEditor +namespace AtomToolsFramework { - MaterialEditorBrowserInteractions::MaterialEditorBrowserInteractions() + AtomToolsAssetBrowserInteractions::AtomToolsAssetBrowserInteractions() { - using namespace AzToolsFramework::AssetBrowser; - AssetBrowserInteractionNotificationBus::Handler::BusConnect(); } - MaterialEditorBrowserInteractions::~MaterialEditorBrowserInteractions() + AtomToolsAssetBrowserInteractions::~AtomToolsAssetBrowserInteractions() { AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); } - void MaterialEditorBrowserInteractions::AddContextMenuActions(QWidget* caller, QMenu* menu, const AZStd::vector& entries) + void AtomToolsAssetBrowserInteractions::RegisterContextMenuActions( + const FilterCallback& filterCallback, const ActionCallback& actionCallback) + { + m_contextMenuCallbacks.emplace_back(filterCallback, actionCallback); + } + + void AtomToolsAssetBrowserInteractions::AddContextMenuActions( + QWidget* caller, QMenu* menu, const AssetBrowserEntryVector& entries) { AssetBrowserEntry* entry = entries.empty() ? nullptr : entries.front(); if (!entry) @@ -53,79 +56,33 @@ namespace MaterialEditor } m_caller = caller; - QObject::connect(m_caller, &QObject::destroyed, [this]() - { - m_caller = nullptr; - }); - - AddGenericContextMenuActions(caller, menu, entry); + QObject::connect(m_caller, &QObject::destroyed, [this]() { m_caller = nullptr; }); - if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Source) + // Add all of the custom context menu entries first + for (const auto& contextMenuCallbackPair : m_contextMenuCallbacks) { - const auto source = azalias_cast(entry); - if (AzFramework::StringFunc::Path::IsExtension(entry->GetFullPath().c_str(), AZ::RPI::MaterialSourceData::Extension)) - { - AddContextMenuActionsForMaterialSource(caller, menu, source); - } - else if (AzFramework::StringFunc::Path::IsExtension(entry->GetFullPath().c_str(), AZ::RPI::MaterialTypeSourceData::Extension)) + if (contextMenuCallbackPair.first(entries)) { - AddContextMenuActionsForMaterialTypeSource(caller, menu, source); - } - else - { - AddContextMenuActionsForOtherSource(caller, menu, source); + contextMenuCallbackPair.second(caller, menu, entries); } } + + if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Source) + { + AddContextMenuActionsForSourceEntries(caller, menu, entry); + } else if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Folder) { - const auto folder = azalias_cast(entry); - AddContextMenuActionsForFolder(caller, menu, folder); + AddContextMenuActionsForFolderEntries(caller, menu, entry); } - } - - void MaterialEditorBrowserInteractions::AddGenericContextMenuActions([[maybe_unused]] QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) - { - menu->addAction(QObject::tr("Copy Name To Clipboard"), [=]() - { - QApplication::clipboard()->setText(entry->GetName().c_str()); - }); - menu->addAction(QObject::tr("Copy Path To Clipboard"), [=]() - { - QApplication::clipboard()->setText(entry->GetFullPath().c_str()); - }); - } - void MaterialEditorBrowserInteractions::AddContextMenuActionsForMaterialTypeSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry) - { - menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]() - { - AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str()); - }); - - menu->addSeparator(); - - menu->addAction("Create Material...", [entry]() - { - const QString defaultPath = AtomToolsFramework::GetUniqueFileInfo( - QString(AZ::Utils::GetProjectPath().c_str()) + - AZ_CORRECT_FILESYSTEM_SEPARATOR + "Assets" + - AZ_CORRECT_FILESYSTEM_SEPARATOR + "untitled." + - AZ::RPI::MaterialSourceData::Extension).absoluteFilePath(); - - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::CreateDocumentFromFile, - entry->GetFullPath(), AtomToolsFramework::GetSaveFileInfo(defaultPath).absoluteFilePath().toUtf8().constData()); - }); - - AddPerforceMenuActions(caller, menu, entry); + AddContextMenuActionsForAllEntries(caller, menu, entry); + AddContextMenuActionsForSourceControl(caller, menu, entry); } - void MaterialEditorBrowserInteractions::AddContextMenuActionsForOtherSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry) + void AtomToolsAssetBrowserInteractions::AddContextMenuActionsForSourceEntries( + [[maybe_unused]] QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) { - menu->addAction("Open", [entry]() - { - QDesktopServices::openUrl(QUrl::fromLocalFile(entry->GetFullPath().c_str())); - }); - menu->addAction("Duplicate...", [entry]() { const QFileInfo duplicateFileInfo(AtomToolsFramework::GetDuplicationFileInfo(entry->GetFullPath().c_str())); @@ -142,79 +99,26 @@ namespace MaterialEditor } }); - menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]() - { - AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str()); - }); - - AddPerforceMenuActions(caller, menu, entry); - } - - void MaterialEditorBrowserInteractions::AddContextMenuActionsForMaterialSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry) - { - menu->addAction("Open", [entry]() - { - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, entry->GetFullPath()); - }); - - menu->addAction("Duplicate...", [entry]() - { - const QFileInfo duplicateFileInfo(AtomToolsFramework::GetDuplicationFileInfo(entry->GetFullPath().c_str())); - if (!duplicateFileInfo.absoluteFilePath().isEmpty()) + menu->addAction("Run Python on File...", [caller, entry]() + { + const QString script = QFileDialog::getOpenFileName( + caller, QObject::tr("Run Script"), QString(AZ::Utils::GetProjectPath().c_str()), QString("*.py")); + if (!script.isEmpty()) { - if (QFile::copy(entry->GetFullPath().c_str(), duplicateFileInfo.absoluteFilePath())) - { - QFile::setPermissions(duplicateFileInfo.absoluteFilePath(), QFile::ReadOther | QFile::WriteOther); - - // Auto add file to source control - AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEdit, - duplicateFileInfo.absoluteFilePath().toUtf8().constData(), true, [](bool, const AzToolsFramework::SourceControlFileInfo&) {}); - } + AZStd::vector pythonArgs{ entry->GetFullPath() }; + AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast( + &AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, script.toUtf8().constData(), + pythonArgs); } }); - - menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]() - { - AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str()); - }); - - menu->addSeparator(); - - menu->addAction("Create Child Material...", [entry]() - { - const QString defaultPath = AtomToolsFramework::GetUniqueFileInfo( - QString(AZ::Utils::GetProjectPath().c_str()) + - AZ_CORRECT_FILESYSTEM_SEPARATOR + "Assets" + - AZ_CORRECT_FILESYSTEM_SEPARATOR + "untitled." + - AZ::RPI::MaterialSourceData::Extension).absoluteFilePath(); - - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::CreateDocumentFromFile, - entry->GetFullPath(), AtomToolsFramework::GetSaveFileInfo(defaultPath).absoluteFilePath().toUtf8().constData()); - }); - - menu->addSeparator(); - - QAction* openParentAction = menu->addAction("Open Parent Material", [entry]() - { - AZ_UNUSED(entry); - // ToDo - }); - openParentAction->setEnabled(false); - - AddPerforceMenuActions(caller, menu, entry); } - void MaterialEditorBrowserInteractions::AddContextMenuActionsForFolder(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::FolderAssetBrowserEntry* entry) + void AtomToolsAssetBrowserInteractions::AddContextMenuActionsForFolderEntries( + QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) { - menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]() + menu->addAction(QObject::tr("Create new sub folder..."), [caller, entry]() { - AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str()); - }); - - QAction* createFolderAction = menu->addAction(QObject::tr("Create new sub folder...")); - QObject::connect(createFolderAction, &QAction::triggered, caller, [caller, entry]() - { - bool ok; + bool ok = false; QString newFolderName = QInputDialog::getText(caller, "Enter new folder name", "name:", QLineEdit::Normal, "NewFolder", &ok); if (ok) { @@ -242,27 +146,29 @@ namespace MaterialEditor } } }); + } - menu->addSeparator(); - - QAction* createMaterialAction = menu->addAction(QObject::tr("Create Material...")); - QObject::connect(createMaterialAction, &QAction::triggered, caller, [caller, entry]() + void AtomToolsAssetBrowserInteractions::AddContextMenuActionsForAllEntries( + [[maybe_unused]] QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) + { + menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]() { - CreateMaterialDialog createDialog(entry->GetFullPath().c_str(), caller); - createDialog.adjustSize(); + AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str()); + }); - if (createDialog.exec() == QDialog::Accepted && - !createDialog.m_materialFileInfo.absoluteFilePath().isEmpty() && - !createDialog.m_materialTypeFileInfo.absoluteFilePath().isEmpty()) - { - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::CreateDocumentFromFile, - createDialog.m_materialTypeFileInfo.absoluteFilePath().toUtf8().constData(), - createDialog.m_materialFileInfo.absoluteFilePath().toUtf8().constData()); - } + menu->addSeparator(); + menu->addAction(QObject::tr("Copy Name To Clipboard"), [=]() + { + QApplication::clipboard()->setText(entry->GetName().c_str()); + }); + menu->addAction(QObject::tr("Copy Path To Clipboard"), [=]() + { + QApplication::clipboard()->setText(entry->GetFullPath().c_str()); }); } - void MaterialEditorBrowserInteractions::AddPerforceMenuActions([[maybe_unused]] QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) + void AtomToolsAssetBrowserInteractions::AddContextMenuActionsForSourceControl( + [[maybe_unused]] QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) { using namespace AzToolsFramework; @@ -282,7 +188,7 @@ namespace MaterialEditor QMenu::connect(sourceControlMenu, &QMenu::aboutToShow, [this, path]() { SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::GetFileInfo, path.c_str(), - [this](bool success, const SourceControlFileInfo& info) { UpdateSourceControlActions(success, info); }); + [this](bool success, const SourceControlFileInfo& info) { UpdateContextMenuActionsForSourceControl(success, info); }); }); // add get latest action @@ -344,7 +250,7 @@ namespace MaterialEditor } } - void MaterialEditorBrowserInteractions::UpdateSourceControlActions(bool success, AzToolsFramework::SourceControlFileInfo info) + void AtomToolsAssetBrowserInteractions::UpdateContextMenuActionsForSourceControl(bool success, AzToolsFramework::SourceControlFileInfo info) { if (!success && m_caller) { @@ -367,4 +273,4 @@ namespace MaterialEditor m_undoCheckOutAction->setEnabled(info.IsManaged() && !info.IsReadOnly()); } } -} // namespace MaterialEditor +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake index 1dbfb7b686..b7f9882e92 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake @@ -9,6 +9,7 @@ set(FILES Include/AtomToolsFramework/Application/AtomToolsApplication.h Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowser.h + Include/AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowserInteractions.h Include/AtomToolsFramework/AssetGridDialog/AssetGridDialog.h Include/AtomToolsFramework/Communication/LocalServer.h Include/AtomToolsFramework/Communication/LocalSocket.h @@ -44,6 +45,7 @@ set(FILES Source/AssetBrowser/AtomToolsAssetBrowser.cpp Source/AssetBrowser/AtomToolsAssetBrowser.qrc Source/AssetBrowser/AtomToolsAssetBrowser.ui + Source/AssetBrowser/AtomToolsAssetBrowserInteractions.cpp Source/AssetGridDialog/AssetGridDialog.cpp Source/AssetGridDialog/AssetGridDialog.ui Source/Communication/LocalServer.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp deleted file mode 100644 index 256497de54..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 -#include -#include - -namespace MaterialEditor -{ - void MaterialDocumentSettings::Reflect(AZ::ReflectContext* context) - { - if (auto serializeContext = azrtti_cast(context)) - { - serializeContext->Class() - ->Version(1) - ->Field("defaultMaterialTypeName", &MaterialDocumentSettings::m_defaultMaterialTypeName) - ; - - if (auto editContext = serializeContext->GetEditContext()) - { - editContext->Class( - "MaterialDocumentSettings", "") - ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->DataElement(AZ::Edit::UIHandlers::Default, &MaterialDocumentSettings::m_defaultMaterialTypeName, "Default Material Type Name", "") - ; - } - } - - if (auto behaviorContext = azrtti_cast(context)) - { - behaviorContext->Class("MaterialDocumentSettings") - ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) - ->Attribute(AZ::Script::Attributes::Category, "Editor") - ->Attribute(AZ::Script::Attributes::Module, "materialeditor") - ->Constructor() - ->Constructor() - ->Property("defaultMaterialTypeName", BehaviorValueProperty(&MaterialDocumentSettings::m_defaultMaterialTypeName)) - ; - } - } -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.h deleted file mode 100644 index 5f39c50717..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSettings.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 - * - */ - -#pragma once - -#if !defined(Q_MOC_RUN) -#include -#include -#include -#include -#endif - -namespace MaterialEditor -{ - struct MaterialDocumentSettings - : public AZ::UserSettings - { - AZ_RTTI(MaterialDocumentSettings, "{12E8461F-65AD-4AD2-8A1D-82C3B1183522}", AZ::UserSettings); - AZ_CLASS_ALLOCATOR(MaterialDocumentSettings, AZ::SystemAllocator, 0); - - static void Reflect(AZ::ReflectContext* context); - - AZStd::string m_defaultMaterialTypeName = "StandardPBR"; - }; -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 686715017c..17453bf7af 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -6,21 +6,32 @@ * */ +#include +#include +#include #include +#include #include #include #include #include +#include #include +#include #include #include -#include #include #include #include +#include #include #include +#include +#include +#include +#include + void InitMaterialEditorResources() { // Must register qt resources from other modules @@ -56,7 +67,6 @@ namespace MaterialEditor void MaterialEditorApplication::Reflect(AZ::ReflectContext* context) { Base::Reflect(context); - MaterialDocumentSettings::Reflect(context); MaterialEditorWindowSettings::Reflect(context); if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) @@ -112,8 +122,77 @@ namespace MaterialEditor void MaterialEditorApplication::CreateMainWindow() { - m_materialEditorBrowserInteractions.reset(aznew MaterialEditorBrowserInteractions); m_window.reset(aznew MaterialEditorWindow); + m_assetBrowserInteractions.reset(aznew AtomToolsFramework::AtomToolsAssetBrowserInteractions); + m_assetBrowserInteractions->RegisterContextMenuActions( + [](const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries) + { + return entries.front()->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Source; + }, + []([[maybe_unused]] QWidget* caller, QMenu* menu, const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries) + { + const bool isMaterial = AzFramework::StringFunc::Path::IsExtension( + entries.front()->GetFullPath().c_str(), AZ::RPI::MaterialSourceData::Extension); + const bool isMaterialType = AzFramework::StringFunc::Path::IsExtension( + entries.front()->GetFullPath().c_str(), AZ::RPI::MaterialTypeSourceData::Extension); + if (isMaterial || isMaterialType) + { + menu->addAction(QObject::tr("Open"), [entries]() + { + AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast( + &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, + entries.front()->GetFullPath()); + }); + + const QString createActionName = + isMaterialType ? QObject::tr("Create Material...") : QObject::tr("Create Child Material..."); + + menu->addAction(createActionName, [entries]() + { + const QString defaultPath = AtomToolsFramework::GetUniqueFileInfo( + QString(AZ::Utils::GetProjectPath().c_str()) + + AZ_CORRECT_FILESYSTEM_SEPARATOR + "Assets" + + AZ_CORRECT_FILESYSTEM_SEPARATOR + "untitled." + + AZ::RPI::MaterialSourceData::Extension).absoluteFilePath(); + + AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast( + &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::CreateDocumentFromFile, + entries.front()->GetFullPath(), + AtomToolsFramework::GetSaveFileInfo(defaultPath).absoluteFilePath().toUtf8().constData()); + }); + } + else + { + menu->addAction(QObject::tr("Open"), [entries]() + { + QDesktopServices::openUrl(QUrl::fromLocalFile(entries.front()->GetFullPath().c_str())); + }); + } + }); + + m_assetBrowserInteractions->RegisterContextMenuActions( + [](const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries) + { + return entries.front()->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Folder; + }, + [](QWidget* caller, QMenu* menu, const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries) + { + menu->addAction(QObject::tr("Create Material..."), [caller, entries]() + { + CreateMaterialDialog createDialog(entries.front()->GetFullPath().c_str(), caller); + createDialog.adjustSize(); + + if (createDialog.exec() == QDialog::Accepted && + !createDialog.m_materialFileInfo.absoluteFilePath().isEmpty() && + !createDialog.m_materialTypeFileInfo.absoluteFilePath().isEmpty()) + { + AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast( + &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::CreateDocumentFromFile, + createDialog.m_materialTypeFileInfo.absoluteFilePath().toUtf8().constData(), + createDialog.m_materialFileInfo.absoluteFilePath().toUtf8().constData()); + } + }); + }); } void MaterialEditorApplication::DestroyMainWindow() diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h index 060353e396..0cf4354f6c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.h @@ -8,10 +8,10 @@ #pragma once +#include #include #include #include -#include #include namespace MaterialEditor @@ -49,6 +49,6 @@ namespace MaterialEditor QWidget* GetAppMainWindow() override; AZStd::unique_ptr m_window; - AZStd::unique_ptr m_materialEditorBrowserInteractions; + AZStd::unique_ptr m_assetBrowserInteractions; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp index 0e6cf565e3..dead08dde9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/CreateMaterialDialog/CreateMaterialDialog.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include namespace MaterialEditor @@ -65,11 +64,10 @@ namespace MaterialEditor m_ui->m_materialTypeComboBox->model()->sort(0, Qt::AscendingOrder); - // Select the default material type from settings - auto settings = - AZ::UserSettings::CreateFind(AZ::Crc32("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL); + const AZStd::string defaultMaterialType = AtomToolsFramework::GetSettingOrDefault( + "/O3DE/Atom/MaterialEditor/CreateMaterialDialog/DefaultMaterialType", "StandardPBR"); - const int index = m_ui->m_materialTypeComboBox->findText(settings->m_defaultMaterialTypeName.c_str()); + const int index = m_ui->m_materialTypeComboBox->findText(defaultMaterialType.c_str()); if (index >= 0) { m_ui->m_materialTypeComboBox->setCurrentIndex(index); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorBrowserInteractions.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorBrowserInteractions.h deleted file mode 100644 index 31043ef0a9..0000000000 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorBrowserInteractions.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 - * - */ - -#pragma once - -#include -#include - -class QWidget; -class QMenu; -class QAction; - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - class AssetBrowserEntry; - class SourceAssetBrowserEntry; - class FolderAssetBrowserEntry; - } -} - -namespace MaterialEditor -{ - class MaterialEditorBrowserInteractions - : public AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - { - public: - AZ_CLASS_ALLOCATOR(MaterialEditorBrowserInteractions, AZ::SystemAllocator, 0); - - MaterialEditorBrowserInteractions(); - ~MaterialEditorBrowserInteractions(); - - private: - //! AssetBrowserInteractionNotificationBus::Handler overrides... - void AddContextMenuActions(QWidget* caller, QMenu* menu, const AZStd::vector& entries) override; - - void AddGenericContextMenuActions(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); - void AddContextMenuActionsForOtherSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry); - void AddContextMenuActionsForMaterialSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry); - void AddContextMenuActionsForMaterialTypeSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry); - void AddContextMenuActionsForFolder(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::FolderAssetBrowserEntry* entry); - void AddPerforceMenuActions(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); - - void UpdateSourceControlActions(bool success, AzToolsFramework::SourceControlFileInfo info); - - QWidget* m_caller = nullptr; - QAction* m_addAction = nullptr; - QAction* m_checkOutAction = nullptr; - QAction* m_undoCheckOutAction = nullptr; - QAction* m_getLatestAction = nullptr; - }; -} // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index bed28d146c..da742d498d 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -146,7 +146,7 @@ namespace MaterialEditor bool MaterialEditorWindow::GetCreateDocumentParams(AZStd::string& openPath, AZStd::string& savePath) { - CreateMaterialDialog createDialog(this); + CreateMaterialDialog createDialog(openPath.c_str(), this); createDialog.adjustSize(); if (createDialog.exec() == QDialog::Accepted && diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp index 2a061a2ed6..357dfc37e0 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.cpp @@ -14,8 +14,6 @@ namespace MaterialEditor SettingsWidget::SettingsWidget(QWidget* parent) : AtomToolsFramework::InspectorWidget(parent) { - m_documentSettings = - AZ::UserSettings::CreateFind(AZ_CRC_CE("MaterialDocumentSettings"), AZ::UserSettings::CT_GLOBAL); m_documentSystemSettings = AZ::UserSettings::CreateFind( AZ_CRC_CE("AtomToolsDocumentSystemSettings"), AZ::UserSettings::CT_GLOBAL); } @@ -29,23 +27,9 @@ namespace MaterialEditor { AddGroupsBegin(); AddDocumentSystemSettingsGroup(); - AddDocumentSettingsGroup(); AddGroupsEnd(); } - void SettingsWidget::AddDocumentSettingsGroup() - { - const AZStd::string groupName = "documentSettings"; - const AZStd::string groupDisplayName = "Document Settings"; - const AZStd::string groupDescription = "Document Settings"; - - const AZ::Crc32 saveStateKey(AZStd::string::format("SettingsWidget::DocumentSettingsGroup")); - AddGroup( - groupName, groupDisplayName, groupDescription, - new AtomToolsFramework::InspectorPropertyGroupWidget( - m_documentSettings.get(), nullptr, m_documentSettings->TYPEINFO_Uuid(), this, this, saveStateKey)); - } - void SettingsWidget::AddDocumentSystemSettingsGroup() { const AZStd::string groupName = "documentSystemSettings"; @@ -56,7 +40,7 @@ namespace MaterialEditor AddGroup( groupName, groupDisplayName, groupDescription, new AtomToolsFramework::InspectorPropertyGroupWidget( - m_documentSystemSettings.get(), nullptr, m_documentSystemSettings->TYPEINFO_Uuid(), this, this, saveStateKey)); + m_documentSystemSettings.get(), nullptr, m_documentSystemSettings->TYPEINFO_Uuid(), nullptr, this, saveStateKey)); } void SettingsWidget::Reset() @@ -64,21 +48,6 @@ namespace MaterialEditor AtomToolsFramework::InspectorRequestBus::Handler::BusDisconnect(); AtomToolsFramework::InspectorWidget::Reset(); } - - void SettingsWidget::BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) - { - AZ_UNUSED(pNode); - } - - void SettingsWidget::AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode) - { - AZ_UNUSED(pNode); - } - - void SettingsWidget::SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode) - { - AZ_UNUSED(pNode); - } } // namespace MaterialEditor //#include diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h index e7c655ee21..2642d9d55e 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/SettingsDialog/SettingsWidget.h @@ -12,7 +12,6 @@ #include #include #include -#include #endif namespace MaterialEditor @@ -20,7 +19,6 @@ namespace MaterialEditor //! Provides controls for viewing and editing settings. class SettingsWidget : public AtomToolsFramework::InspectorWidget - , private AzToolsFramework::IPropertyEditorNotify { Q_OBJECT public: @@ -32,22 +30,11 @@ namespace MaterialEditor void Populate(); private: - void AddDocumentSettingsGroup(); void AddDocumentSystemSettingsGroup(); // AtomToolsFramework::InspectorRequestBus::Handler overrides... void Reset() override; - // AzToolsFramework::IPropertyEditorNotify overrides... - void BeforePropertyModified(AzToolsFramework::InstanceDataNode* pNode) override; - void AfterPropertyModified(AzToolsFramework::InstanceDataNode* pNode) override; - void SetPropertyEditingActive([[maybe_unused]] AzToolsFramework::InstanceDataNode* pNode) override {} - void SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* pNode) override; - void SealUndoStack() override {} - void RequestPropertyContextMenu(AzToolsFramework::InstanceDataNode*, const QPoint&) override {} - void PropertySelectionChanged(AzToolsFramework::InstanceDataNode*, bool) override {} - - AZStd::intrusive_ptr m_documentSettings; AZStd::intrusive_ptr m_documentSystemSettings; }; } // namespace MaterialEditor diff --git a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake index 4e270460a6..d68e013c59 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake +++ b/Gems/Atom/Tools/MaterialEditor/Code/materialeditor_files.cmake @@ -12,10 +12,8 @@ set(FILES Source/MaterialEditorApplication.h Source/Document/MaterialDocumentRequestBus.h - Source/Document/MaterialDocumentSettings.h Source/Document/MaterialDocument.cpp Source/Document/MaterialDocument.h - Source/Document/MaterialDocumentSettings.cpp Source/Viewport/MaterialViewportModule.h Source/Viewport/MaterialViewportModule.cpp @@ -49,8 +47,6 @@ set(FILES Source/Viewport/MaterialViewportWidget.ui Source/Window/MaterialEditorWindowSettings.h - Source/Window/MaterialEditorBrowserInteractions.h - Source/Window/MaterialEditorBrowserInteractions.cpp Source/Window/MaterialEditorWindow.h Source/Window/MaterialEditorWindow.cpp Source/Window/MaterialEditorWindowSettings.cpp diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp index aa0c378ff0..2d61730c4d 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.cpp @@ -12,12 +12,16 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include +#include #include #include #include @@ -25,11 +29,13 @@ #include #include -AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT +#include +#include #include #include +#include #include -AZ_POP_DISABLE_WARNING +#include void InitShaderManagementConsoleResources() { @@ -135,9 +141,46 @@ namespace ShaderManagementConsole void ShaderManagementConsoleApplication::CreateMainWindow() { - m_assetBrowserInteractions.reset(aznew ShaderManagementConsoleBrowserInteractions); m_window.reset(aznew ShaderManagementConsoleWindow); - m_window->show(); + m_assetBrowserInteractions.reset(aznew AtomToolsFramework::AtomToolsAssetBrowserInteractions); + m_assetBrowserInteractions->RegisterContextMenuActions( + [](const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries) + { + return entries.front()->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Source; + }, + []([[maybe_unused]] QWidget* caller, QMenu* menu, const AtomToolsFramework::AtomToolsAssetBrowserInteractions::AssetBrowserEntryVector& entries) + { + if (AzFramework::StringFunc::Path::IsExtension( + entries.front()->GetFullPath().c_str(), AZ::RPI::ShaderSourceData::Extension)) + { + menu->addAction("Generate Shader Variant List", [entries]() + { + const QString script = + "@engroot@/Gems/Atom/Tools/ShaderManagementConsole/Scripts/GenerateShaderVariantListForMaterials.py"; + AZStd::vector pythonArgs{ entries.front()->GetFullPath() }; + AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast( + &AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, script.toUtf8().constData(), + pythonArgs); + }); + } + else if (AzFramework::StringFunc::Path::IsExtension( + entries.front()->GetFullPath().c_str(), AZ::RPI::ShaderVariantListSourceData::Extension)) + { + menu->addAction(QObject::tr("Open"), [entries]() + { + AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast( + &AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, + entries.front()->GetFullPath()); + }); + } + else + { + menu->addAction(QObject::tr("Open"), [entries]() + { + QDesktopServices::openUrl(QUrl::fromLocalFile(entries.front()->GetFullPath().c_str())); + }); + } + }); } void ShaderManagementConsoleApplication::DestroyMainWindow() diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h index 3bb62d0756..232f204790 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/ShaderManagementConsoleApplication.h @@ -9,11 +9,11 @@ #pragma once #include +#include #include #include #include #include -#include #include namespace ShaderManagementConsole @@ -55,6 +55,6 @@ namespace ShaderManagementConsole private: AZStd::unique_ptr m_window; - AZStd::unique_ptr m_assetBrowserInteractions; + AZStd::unique_ptr m_assetBrowserInteractions; }; } // namespace ShaderManagementConsole diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserInteractions.cpp b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserInteractions.cpp deleted file mode 100644 index ca836b1b8d..0000000000 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserInteractions.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace ShaderManagementConsole -{ - ShaderManagementConsoleBrowserInteractions::ShaderManagementConsoleBrowserInteractions() - { - using namespace AzToolsFramework::AssetBrowser; - - AssetBrowserInteractionNotificationBus::Handler::BusConnect(); - } - - ShaderManagementConsoleBrowserInteractions::~ShaderManagementConsoleBrowserInteractions() - { - AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); - } - - AzToolsFramework::AssetBrowser::SourceFileDetails ShaderManagementConsoleBrowserInteractions::GetSourceFileDetails([[maybe_unused]] const char* fullSourceFileName) - { - return AzToolsFramework::AssetBrowser::SourceFileDetails(); - } - - void ShaderManagementConsoleBrowserInteractions::AddContextMenuActions(QWidget* caller, QMenu* menu, const AZStd::vector& entries) - { - AssetBrowserEntry* entry = entries.empty() ? nullptr : entries.front(); - if (!entry) - { - return; - } - - m_caller = caller; - QObject::connect(m_caller, &QObject::destroyed, [this]() - { - m_caller = nullptr; - }); - - if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Source) - { - const auto source = azalias_cast(entry); - AddContextMenuActionsForOtherSource(caller, menu, source); - } - else if (entry->GetEntryType() == AssetBrowserEntry::AssetEntryType::Folder) - { - const auto folder = azalias_cast(entry); - AddContextMenuActionsForFolder(caller, menu, folder); - } - } - - void ShaderManagementConsoleBrowserInteractions::AddContextMenuActionsForOtherSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry) - { - menu->addAction("Open", [entry]() - { - if (AzFramework::StringFunc::Path::IsExtension(entry->GetFullPath().c_str(), AZ::RPI::ShaderVariantListSourceData::Extension)) - { - AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Broadcast(&AtomToolsFramework::AtomToolsDocumentSystemRequestBus::Events::OpenDocument, entry->GetFullPath().c_str()); - } - else - { - QDesktopServices::openUrl(QUrl::fromLocalFile(entry->GetFullPath().c_str())); - } - }); - - menu->addAction("Duplicate...", [entry]() - { - const QFileInfo duplicateFileInfo(AtomToolsFramework::GetDuplicationFileInfo(entry->GetFullPath().c_str())); - if (!duplicateFileInfo.absoluteFilePath().isEmpty()) - { - if (QFile::copy(entry->GetFullPath().c_str(), duplicateFileInfo.absoluteFilePath())) - { - QFile::setPermissions(duplicateFileInfo.absoluteFilePath(), QFile::ReadOther | QFile::WriteOther); - - // Auto add file to source control - AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEdit, - duplicateFileInfo.absoluteFilePath().toUtf8().constData(), true, [](bool, const AzToolsFramework::SourceControlFileInfo&) {}); - } - } - }); - - menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]() - { - AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str()); - }); - - menu->addSeparator(); - menu->addAction("Generate Shader Variant List", [entry]() { - const QString script = "@engroot@/Gems/Atom/Tools/ShaderManagementConsole/Scripts/GenerateShaderVariantListForMaterials.py"; - AZStd::vector pythonArgs{ entry->GetFullPath() }; - AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, script.toUtf8().constData(), pythonArgs); - }); - - menu->addAction("Run Python on Asset...", [entry]() - { - const QString script = QFileDialog::getOpenFileName(nullptr, "Run Script", QString(), QString("*.py")); - if (!script.isEmpty()) - { - AZStd::vector pythonArgs { entry->GetFullPath() }; - AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByFilenameWithArgs, script.toUtf8().constData(), pythonArgs); - } - }); - - AddPerforceMenuActions(caller, menu, entry); - } - - void ShaderManagementConsoleBrowserInteractions::AddContextMenuActionsForFolder(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::FolderAssetBrowserEntry* entry) - { - menu->addAction(AzQtComponents::fileBrowserActionName(), [entry]() - { - AzQtComponents::ShowFileOnDesktop(entry->GetFullPath().c_str()); - }); - - QAction* createFolderAction = menu->addAction(QObject::tr("Create new sub folder...")); - QObject::connect(createFolderAction, &QAction::triggered, caller, [caller, entry]() - { - bool ok; - QString newFolderName = QInputDialog::getText(caller, "Enter new folder name", "name:", QLineEdit::Normal, "NewFolder", &ok); - if (ok) - { - if (newFolderName.isEmpty()) - { - QMessageBox msgBox(QMessageBox::Icon::Critical, "Error", "Folder name can't be empty", QMessageBox::Ok, caller); - msgBox.exec(); - } - else - { - AZStd::string newFolderPath; - AzFramework::StringFunc::Path::Join(entry->GetFullPath().c_str(), newFolderName.toUtf8().constData(), newFolderPath); - QDir dir(newFolderPath.c_str()); - if (dir.exists()) - { - QMessageBox::critical(caller, "Error", "Folder with this name already exists"); - return; - } - auto result = dir.mkdir(newFolderPath.c_str()); - if (!result) - { - AZ_Error("ShaderManagementConsoleBrowser", false, "Failed to make new folder"); - return; - } - } - } - }); - } - - void ShaderManagementConsoleBrowserInteractions::AddPerforceMenuActions([[maybe_unused]] QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) - { - using namespace AzToolsFramework; - - bool isActive = false; - SourceControlConnectionRequestBus::BroadcastResult(isActive, &SourceControlConnectionRequests::IsActive); - - if (isActive) - { - menu->addSeparator(); - - AZStd::string path = entry->GetFullPath(); - AzFramework::StringFunc::Path::Normalize(path); - - QMenu* sourceControlMenu = menu->addMenu("Source Control"); - - // Update the enabled state of source control menu actions only if menu is shown - QMenu::connect(sourceControlMenu, &QMenu::aboutToShow, [this, path]() - { - SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::GetFileInfo, path.c_str(), - [this](bool success, const SourceControlFileInfo& info) { UpdateSourceControlActions(success, info); }); - }); - - // add get latest action - m_getLatestAction = sourceControlMenu->addAction("Get Latest", [path]() - { - SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::RequestLatest, path.c_str(), - [](bool, const SourceControlFileInfo&) {}); - }); - QObject::connect(m_getLatestAction, &QObject::destroyed, [this]() - { - m_getLatestAction = nullptr; - }); - m_getLatestAction->setEnabled(false); - - // add add action - m_addAction = sourceControlMenu->addAction("Add", [path]() - { - SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::RequestEdit, path.c_str(), true, - [path](bool, const SourceControlFileInfo&) - { - SourceControlThumbnailRequestBus::Broadcast(&SourceControlThumbnailRequests::FileStatusChanged, path.c_str()); - }); - }); - QObject::connect(m_addAction, &QObject::destroyed, [this]() - { - m_addAction = nullptr; - }); - m_addAction->setEnabled(false); - - // add checkout action - m_checkOutAction = sourceControlMenu->addAction("Check Out", [path]() - { - SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::RequestEdit, path.c_str(), true, - [path](bool, const SourceControlFileInfo&) - { - SourceControlThumbnailRequestBus::Broadcast(&SourceControlThumbnailRequests::FileStatusChanged, path.c_str()); - }); - }); - QObject::connect(m_checkOutAction, &QObject::destroyed, [this]() - { - m_checkOutAction = nullptr; - }); - m_checkOutAction->setEnabled(false); - - // add undo checkout action - m_undoCheckOutAction = sourceControlMenu->addAction("Undo Check Out", [path]() - { - SourceControlCommandBus::Broadcast(&SourceControlCommandBus::Events::RequestRevert, path.c_str(), - [path](bool, const SourceControlFileInfo&) - { - SourceControlThumbnailRequestBus::Broadcast(&SourceControlThumbnailRequests::FileStatusChanged, path.c_str()); - }); - }); - QObject::connect(m_undoCheckOutAction, &QObject::destroyed, [this]() - { - m_undoCheckOutAction = nullptr; - }); - m_undoCheckOutAction->setEnabled(false); - } - } - - void ShaderManagementConsoleBrowserInteractions::UpdateSourceControlActions(bool success, AzToolsFramework::SourceControlFileInfo info) - { - if (!success && m_caller) - { - QMessageBox::critical(m_caller, "Error", "Source control operation failed."); - } - if (m_getLatestAction) - { - m_getLatestAction->setEnabled(info.IsManaged() && info.HasFlag(AzToolsFramework::SCF_OutOfDate)); - } - if (m_addAction) - { - m_addAction->setEnabled(!info.IsManaged()); - } - if (m_checkOutAction) - { - m_checkOutAction->setEnabled(info.IsManaged() && info.IsReadOnly() && !info.IsLockedByOther()); - } - if (m_undoCheckOutAction) - { - m_undoCheckOutAction->setEnabled(info.IsManaged() && !info.IsReadOnly()); - } - } -} // namespace ShaderManagementConsole diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserInteractions.h b/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserInteractions.h deleted file mode 100644 index 996e755640..0000000000 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/Source/Window/ShaderManagementConsoleBrowserInteractions.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 - * - */ - -#pragma once - -#include -#include - -class QWidget; -class QMenu; -class QAction; - -namespace AzToolsFramework -{ - namespace AssetBrowser - { - class AssetBrowserEntry; - class SourceAssetBrowserEntry; - class FolderAssetBrowserEntry; - } -} - -namespace ShaderManagementConsole -{ - class ShaderManagementConsoleBrowserInteractions - : public AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - { - public: - AZ_CLASS_ALLOCATOR(ShaderManagementConsoleBrowserInteractions, AZ::SystemAllocator, 0); - - ShaderManagementConsoleBrowserInteractions(); - ~ShaderManagementConsoleBrowserInteractions(); - - private: - //////////////////////////////////////////////////////////////////////// - // AssetBrowserInteractionNotificationBus::Handler implementation - AzToolsFramework::AssetBrowser::SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override; - void AddContextMenuActions(QWidget* caller, QMenu* menu, const AZStd::vector& entries) override; - //////////////////////////////////////////////////////////////////////// - - void AddContextMenuActionsForOtherSource(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::SourceAssetBrowserEntry* entry); - void AddContextMenuActionsForFolder(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::FolderAssetBrowserEntry* entry); - void AddPerforceMenuActions(QWidget* caller, QMenu* menu, const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry); - - void UpdateSourceControlActions(bool success, AzToolsFramework::SourceControlFileInfo info); - - QWidget* m_caller = nullptr; - QAction* m_addAction = nullptr; - QAction* m_checkOutAction = nullptr; - QAction* m_undoCheckOutAction = nullptr; - QAction* m_getLatestAction = nullptr; - }; -} // namespace ShaderManagementConsole diff --git a/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsole_files.cmake b/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsole_files.cmake index dac14b7f16..332cd73b40 100644 --- a/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsole_files.cmake +++ b/Gems/Atom/Tools/ShaderManagementConsole/Code/shadermanagementconsole_files.cmake @@ -11,8 +11,6 @@ set(FILES Source/Document/ShaderManagementConsoleDocument.cpp Source/Document/ShaderManagementConsoleDocument.h - Source/Window/ShaderManagementConsoleBrowserInteractions.h - Source/Window/ShaderManagementConsoleBrowserInteractions.cpp Source/Window/ShaderManagementConsoleWindow.h Source/Window/ShaderManagementConsoleWindow.cpp Source/Window/ShaderManagementConsole.qrc