|
@@ -7,44 +7,47 @@
|
|
|
*/
|
|
|
|
|
|
#include <Atom/RPI.Edit/Common/AssetUtils.h>
|
|
|
-#include <Atom/RPI.Edit/Material/MaterialSourceData.h>
|
|
|
-#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
|
|
|
-#include <Atom/RPI.Reflect/Material/MaterialAsset.h>
|
|
|
-#include <AtomToolsFramework/Document/AtomToolsDocumentSystemRequestBus.h>
|
|
|
+#include <AtomToolsFramework/AssetBrowser/AtomToolsAssetBrowserInteractions.h>
|
|
|
#include <AtomToolsFramework/Util/Util.h>
|
|
|
#include <AzCore/Utils/Utils.h>
|
|
|
#include <AzCore/std/string/wildcard.h>
|
|
|
#include <AzQtComponents/Utilities/DesktopUtilities.h>
|
|
|
+#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
|
|
|
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
|
|
|
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
|
|
|
#include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
|
|
|
#include <AzToolsFramework/Thumbnails/SourceControlThumbnail.h>
|
|
|
-#include <Window/CreateMaterialDialog/CreateMaterialDialog.h>
|
|
|
-#include <Window/MaterialEditorBrowserInteractions.h>
|
|
|
|
|
|
#include <QApplication>
|
|
|
#include <QClipboard>
|
|
|
#include <QDesktopServices>
|
|
|
+#include <QDir>
|
|
|
#include <QFileDialog>
|
|
|
+#include <QFileInfo>
|
|
|
#include <QInputDialog>
|
|
|
#include <QMenu>
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
-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<AzToolsFramework::AssetBrowser::AssetBrowserEntry*>& 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<const SourceAssetBrowserEntry*>(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<const FolderAssetBrowserEntry*>(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<AZStd::string_view> 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
|