holding pen for refactor

Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
Guthrie Adams
2021-08-11 14:55:28 -05:00
parent 2564e8f8dc
commit f1e8d37b86
23 changed files with 569 additions and 343 deletions
@@ -16,8 +16,8 @@
#include <AzQtComponents/Components/StyledDockWidget.h>
#include <AzQtComponents/Components/Widgets/TabWidget.h>
#include <QLabel>
#include <QMenuBar>
#include <QStatusBar>
#include <QToolBar>
namespace AtomToolsFramework
@@ -53,10 +53,9 @@ namespace AtomToolsFramework
virtual void SelectNextTab();
AzQtComponents::FancyDocking* m_advancedDockManager = nullptr;
QWidget* m_centralWidget = nullptr;
QMenuBar* m_menuBar = nullptr;
AzQtComponents::TabWidget* m_tabWidget = nullptr;
QStatusBar* m_statusBar = nullptr;
QLabel* m_statusMessage = nullptr;
AZStd::unordered_map<AZStd::string, AzQtComponents::StyledDockWidget*> m_dockWidgets;
};
@@ -8,20 +8,23 @@
#include <AtomToolsFrameworkModule.h>
#include <AtomToolsFrameworkSystemComponent.h>
#include <Window/AtomToolsMainWindowSystemComponent.h>
namespace AtomToolsFramework
{
AtomToolsFrameworkModule::AtomToolsFrameworkModule()
{
m_descriptors.insert(m_descriptors.end(), {
AtomToolsFrameworkSystemComponent::CreateDescriptor(),
});
AtomToolsFrameworkSystemComponent::CreateDescriptor(),
AtomToolsMainWindowSystemComponent::CreateDescriptor(),
});
}
AZ::ComponentTypeList AtomToolsFrameworkModule::GetRequiredSystemComponents() const
{
return AZ::ComponentTypeList{
azrtti_typeid<AtomToolsFrameworkSystemComponent>(),
azrtti_typeid<AtomToolsMainWindowSystemComponent>(),
};
}
}
@@ -7,6 +7,8 @@
*/
#include <AtomToolsFramework/Window/AtomToolsMainWindow.h>
#include <QStatusBar>
#include <QVBoxLayout>
namespace AtomToolsFramework
{
@@ -21,11 +23,15 @@ namespace AtomToolsFramework
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
m_statusBar = new QStatusBar(this);
m_statusBar->setObjectName("StatusBar");
statusBar()->addPermanentWidget(m_statusBar, 1);
m_statusMessage = new QLabel(statusBar());
statusBar()->addPermanentWidget(m_statusMessage, 1);
m_centralWidget = new QWidget(this);
auto centralWidget = new QWidget(this);
auto centralWidgetLayout = new QVBoxLayout(centralWidget);
centralWidgetLayout->setMargin(0);
centralWidgetLayout->setContentsMargins(0, 0, 0, 0);
centralWidget->setLayout(centralWidgetLayout);
setCentralWidget(centralWidget);
AtomToolsMainWindowRequestBus::Handler::BusConnect();
}
@@ -111,7 +117,7 @@ namespace AtomToolsFramework
void AtomToolsMainWindow::CreateTabBar()
{
m_tabWidget = new AzQtComponents::TabWidget(m_centralWidget);
m_tabWidget = new AzQtComponents::TabWidget(centralWidget());
m_tabWidget->setObjectName("TabWidget");
m_tabWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
m_tabWidget->setContentsMargins(0, 0, 0, 0);
@@ -131,6 +137,8 @@ namespace AtomToolsFramework
{
OpenTabContextMenu();
});
centralWidget()->layout()->addWidget(m_tabWidget);
}
void AtomToolsMainWindow::AddTabForDocumentId(
@@ -0,0 +1,73 @@
/*
* 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 <AtomToolsFramework/Window/AtomToolsMainWindowFactoryRequestBus.h>
#include <AtomToolsFramework/Window/AtomToolsMainWindowRequestBus.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <Window/AtomToolsMainWindowSystemComponent.h>
namespace AtomToolsFramework
{
void AtomToolsMainWindowSystemComponent::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<AtomToolsMainWindowSystemComponent, AZ::Component>()
->Version(0);
}
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<AtomToolsMainWindowFactoryRequestBus>("AtomToolsMainWindowFactoryRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Category, "Editor")
->Attribute(AZ::Script::Attributes::Module, "atomtools")
->Event("CreateMainWindow", &AtomToolsMainWindowFactoryRequestBus::Events::CreateMainWindow)
->Event("DestroyMainWindow", &AtomToolsMainWindowFactoryRequestBus::Events::DestroyMainWindow)
;
behaviorContext->EBus<AtomToolsMainWindowRequestBus>("AtomToolsMainWindowRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Category, "Editor")
->Attribute(AZ::Script::Attributes::Module, "atomtools")
->Event("ActivateWindow", &AtomToolsMainWindowRequestBus::Events::ActivateWindow)
->Event("SetDockWidgetVisible", &AtomToolsMainWindowRequestBus::Events::SetDockWidgetVisible)
->Event("IsDockWidgetVisible", &AtomToolsMainWindowRequestBus::Events::IsDockWidgetVisible)
->Event("GetDockWidgetNames", &AtomToolsMainWindowRequestBus::Events::GetDockWidgetNames)
->Event("ResizeViewportRenderTarget", &AtomToolsMainWindowRequestBus::Events::ResizeViewportRenderTarget)
->Event("LockViewportRenderTargetSize", &AtomToolsMainWindowRequestBus::Events::LockViewportRenderTargetSize)
->Event("UnlockViewportRenderTargetSize", &AtomToolsMainWindowRequestBus::Events::UnlockViewportRenderTargetSize)
;
}
}
void AtomToolsMainWindowSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC_CE("AtomToolsMainWindowSystemService"));
}
void AtomToolsMainWindowSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC_CE("AtomToolsMainWindowSystemService"));
}
void AtomToolsMainWindowSystemComponent::Init()
{
}
void AtomToolsMainWindowSystemComponent::Activate()
{
}
void AtomToolsMainWindowSystemComponent::Deactivate()
{
}
} // namespace AtomToolsFramework
@@ -0,0 +1,36 @@
/*
* 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 <AzCore/Component/Component.h>
namespace AtomToolsFramework
{
//! AtomToolsMainWindowSystemComponent is used for initialization and registration of other classes.
class AtomToolsMainWindowSystemComponent
: public AZ::Component
{
public:
AZ_COMPONENT(AtomToolsMainWindowSystemComponent, "{6E42380B-4ECD-47CF-B904-E16AB4E87D0D}");
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
private:
////////////////////////////////////////////////////////////////////////
// AZ::Component interface implementation
void Init() override;
void Activate() override;
void Deactivate() override;
////////////////////////////////////////////////////////////////////////
};
}
@@ -45,4 +45,6 @@ set(FILES
Source/Viewport/RenderViewportWidget.cpp
Source/Viewport/ModularViewportCameraController.cpp
Source/Window/AtomToolsMainWindow.cpp
Source/Window/AtomToolsMainWindowSystemComponent.cpp
Source/Window/AtomToolsMainWindowSystemComponent.h
)
@@ -25,58 +25,58 @@ namespace MaterialEditor
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
//! Signal that a material document was created
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was created
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentCreated([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document was destroyed
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was destroyed
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentDestroyed([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document was opened
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was opened
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentOpened([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document was closed
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was closed
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentClosed([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document was saved
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was saved
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentSaved([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document was selected
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was selected
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentSelected([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document was modified
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was modified
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentModified([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document dependency was modified
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document dependency was modified
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentDependencyModified([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document was modified externally
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document was modified externally
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentExternallyModified([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material document undo state was updated
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a document undo state was updated
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentUndoStateChanged([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a material property changed
//! @param documentId unique id of material document for which the notification is sent
//! Signal that a property changed
//! @param documentId unique id of document for which the notification is sent
//! @param property object containing the property value and configuration that was modified
virtual void OnDocumentPropertyValueModified([[maybe_unused]] const AZ::Uuid& documentId, [[maybe_unused]] const AtomToolsFramework::DynamicProperty& property) {}
//! Signal that the property configuration has been changed.
//! @param documentId unique id of material document for which the notification is sent
//! @param documentId unique id of document for which the notification is sent
//! @param property object containing the property value and configuration that was modified
virtual void OnDocumentPropertyConfigModified([[maybe_unused]] const AZ::Uuid& documentId, [[maybe_unused]] const AtomToolsFramework::DynamicProperty& property) {}
//! Signal that the property group visibility has been changed.
//! @param documentId unique id of material document for which the notification is sent
//! @param documentId unique id of document for which the notification is sent
//! @param groupId id of the group that changed
//! @param visible whether the property group is visible
virtual void OnDocumentPropertyGroupVisibilityChanged([[maybe_unused]] const AZ::Uuid& documentId, [[maybe_unused]] const AZ::Name& groupId, [[maybe_unused]] bool visible) {}
@@ -39,10 +39,10 @@ namespace MaterialEditor
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
typedef AZ::Uuid BusIdType;
//! Get absolute path of material source file
//! Get absolute path of document
virtual AZStd::string_view GetAbsolutePath() const = 0;
//! Get relative path of material source file
//! Get relative path of document
virtual AZStd::string_view GetRelativePath() const = 0;
//! Get material asset created by MaterialDocument
@@ -72,52 +72,52 @@ namespace MaterialEditor
//! Modify material property value
virtual void SetPropertyValue(const AZ::Name& propertyFullName, const AZStd::any& value) = 0;
//! Load source material and related data
//! @param loadPath Absolute path of material to load
//! Load document and related data
//! @param loadPath Absolute path of document to load
virtual bool Open(AZStd::string_view loadPath) = 0;
//! Reload document preserving edits
virtual bool Rebuild() = 0;
//! Save material to source file
//! Save document to file
virtual bool Save() = 0;
//! Save material to a new source file
//! @param savePath Absolute path where material is saved
//! Save document copy
//! @param savePath Absolute path where document is saved
virtual bool SaveAsCopy(AZStd::string_view savePath) = 0;
//! Save material to a new source file as a child of the open material
//! @param savePath Absolute path where material is saved
virtual bool SaveAsChild(AZStd::string_view savePath) = 0;
//! Close material document and reset its data
//! Close document and reset its data
virtual bool Close() = 0;
//! Material is loaded
//! document is loaded
virtual bool IsOpen() const = 0;
//! Material has changes pending
//! document has changes pending
virtual bool IsModified() const = 0;
//! Can the document be saved
virtual bool IsSavable() const = 0;
//! Returns true if there are reversible modifications to the material document
//! Returns true if there are reversible modifications to the document
virtual bool CanUndo() const = 0;
//! Returns true if there are changes that were reversed and can be re-applied to the material document
//! Returns true if there are changes that were reversed and can be re-applied to the document
virtual bool CanRedo() const = 0;
//! Restores the previous state of the material document
//! Restores the previous state of the document
virtual bool Undo() = 0;
//! Restores the next state of the material document
//! Restores the next state of the document
virtual bool Redo() = 0;
//! Signal that property editing is about to begin, like beginning to drag a slider control
//! Signal that editing is about to begin, like beginning to drag a slider control
virtual bool BeginEdit() = 0;
//! Signal that property editing has completed, like after releasing the mouse button after continuously dragging a slider control
//! Signal that editing has completed, like after releasing the mouse button after continuously dragging a slider control
virtual bool EndEdit() = 0;
};
@@ -23,53 +23,53 @@ namespace MaterialEditor
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//! Create a material document object
//! @return Uuid of new material document, or null Uuid if failed
//! Create a document object
//! @return Uuid of new document, or null Uuid if failed
virtual AZ::Uuid CreateDocument() = 0;
//! Destroy a material document object with the specified id
//! Destroy a document object with the specified id
//! @return true if Uuid was found and removed, otherwise false
virtual bool DestroyDocument(const AZ::Uuid& documentId) = 0;
//! Open a material document for editing
//! @param sourcePath material document to open.
//! @return unique id of new material document if successful, otherwise null Uuid
//! Open a document for editing
//! @param sourcePath document to open.
//! @return unique id of new document if successful, otherwise null Uuid
virtual AZ::Uuid OpenDocument(AZStd::string_view sourcePath) = 0;
//! Create a new document by specifying a source and prompting the user for destination path.
//! If the source file is a material type then this results in creating a new material based on that type.
//! If the source file is a material this results in creating a child material with the source file as its parent.
//! @param sourcePath material document to open.
//! @param sourcePath document to open.
//! @param targetPath location where document is saved.
//! @return unique id of new material document if successful, otherwise null Uuid
//! @return unique id of new document if successful, otherwise null Uuid
virtual AZ::Uuid CreateDocumentFromFile(AZStd::string_view sourcePath, AZStd::string_view targetPath) = 0;
//! Close the specified material document
//! @param documentId unique id of material document to close
//! Close the specified document
//! @param documentId unique id of document to close
virtual bool CloseDocument(const AZ::Uuid& documentId) = 0;
//! Close all material documents
//! Close all documents
virtual bool CloseAllDocuments() = 0;
//! Close all material documents except for documentId
//! @param documentId unique id of material document to not close
//! Close all documents except for documentId
//! @param documentId unique id of document to not close
virtual bool CloseAllDocumentsExcept(const AZ::Uuid& documentId) = 0;
//! Save the specified material document
//! @param documentId unique id of material document to save
//! Save the specified document
//! @param documentId unique id of document to save
virtual bool SaveDocument(const AZ::Uuid& documentId) = 0;
//! Save the specified material document to a different file
//! @param documentId unique id of material document to save
//! Save the specified document to a different file
//! @param documentId unique id of document to save
//! @param targetPath location where document is saved.
virtual bool SaveDocumentAsCopy(const AZ::Uuid& documentId, AZStd::string_view targetPath) = 0;
//! Save the specified material document to a different file, referencing the original material as its parent
//! @param documentId unique id of material document to save
//! Save the specified document to a different file, referencing the original material as its parent
//! @param documentId unique id of document to save
//! @param targetPath location where document is saved.
virtual bool SaveDocumentAsChild(const AZ::Uuid& documentId, AZStd::string_view targetPath) = 0;
//! Save all material documents
//! Save all documents
virtual bool SaveAllDocuments() = 0;
};
@@ -189,7 +189,7 @@ namespace MaterialEditor
if (m_settings->m_showReloadDocumentPrompt &&
(QMessageBox::question(QApplication::activeWindow(),
QString("Material document was externally modified"),
QString("Document was externally modified"),
QString("Would you like to reopen the document:\n%1?").arg(documentPath.c_str()),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes))
{
@@ -203,7 +203,7 @@ namespace MaterialEditor
if (!openResult)
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be opened"),
QApplication::activeWindow(), QString("Document could not be opened"),
QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId);
}
@@ -216,7 +216,7 @@ namespace MaterialEditor
if (m_settings->m_showReloadDocumentPrompt &&
(QMessageBox::question(QApplication::activeWindow(),
QString("Material document dependencies have changed"),
QString("Document dependencies have changed"),
QString("Would you like to update the document with these changes:\n%1?").arg(documentPath.c_str()),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes))
{
@@ -230,7 +230,7 @@ namespace MaterialEditor
if (!openResult)
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be opened"),
QApplication::activeWindow(), QString("Document could not be opened"),
QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId);
}
@@ -284,7 +284,7 @@ namespace MaterialEditor
if (isModified)
{
auto selection = QMessageBox::question(QApplication::activeWindow(),
QString("Material document has unsaved changes"),
QString("Document has unsaved changes"),
QString("Do you want to save changes to\n%1?").arg(documentPath.c_str()),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (selection == QMessageBox::Cancel)
@@ -309,7 +309,7 @@ namespace MaterialEditor
if (!closeResult)
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be closed"),
QApplication::activeWindow(), QString("Document could not be closed"),
QString("Failed to close: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -353,18 +353,18 @@ namespace MaterialEditor
bool MaterialDocumentSystemComponent::SaveDocument(const AZ::Uuid& documentId)
{
AZStd::string saveMaterialPath;
MaterialDocumentRequestBus::EventResult(saveMaterialPath, documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath);
AZStd::string saveDocumentPath;
MaterialDocumentRequestBus::EventResult(saveDocumentPath, documentId, &MaterialDocumentRequestBus::Events::GetAbsolutePath);
if (saveMaterialPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveMaterialPath))
if (saveDocumentPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveDocumentPath))
{
return false;
}
const QFileInfo saveInfo(saveMaterialPath.c_str());
const QFileInfo saveInfo(saveDocumentPath.c_str());
if (saveInfo.exists() && !saveInfo.isWritable())
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be overwritten:\n%1").arg(saveMaterialPath.c_str()));
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Document could not be overwritten:\n%1").arg(saveDocumentPath.c_str()));
return false;
}
@@ -375,8 +375,8 @@ namespace MaterialEditor
if (!result)
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.GetDump().c_str()));
QApplication::activeWindow(), QString("Document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveDocumentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -385,28 +385,28 @@ namespace MaterialEditor
bool MaterialDocumentSystemComponent::SaveDocumentAsCopy(const AZ::Uuid& documentId, AZStd::string_view targetPath)
{
AZStd::string saveMaterialPath = targetPath;
if (saveMaterialPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveMaterialPath))
AZStd::string saveDocumentPath = targetPath;
if (saveDocumentPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveDocumentPath))
{
return false;
}
const QFileInfo saveInfo(saveMaterialPath.c_str());
const QFileInfo saveInfo(saveDocumentPath.c_str());
if (saveInfo.exists() && !saveInfo.isWritable())
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be overwritten:\n%1").arg(saveMaterialPath.c_str()));
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Document could not be overwritten:\n%1").arg(saveDocumentPath.c_str()));
return false;
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool result = false;
MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsCopy, saveMaterialPath);
MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsCopy, saveDocumentPath);
if (!result)
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.GetDump().c_str()));
QApplication::activeWindow(), QString("Document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveDocumentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -415,28 +415,28 @@ namespace MaterialEditor
bool MaterialDocumentSystemComponent::SaveDocumentAsChild(const AZ::Uuid& documentId, AZStd::string_view targetPath)
{
AZStd::string saveMaterialPath = targetPath;
if (saveMaterialPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveMaterialPath))
AZStd::string saveDocumentPath = targetPath;
if (saveDocumentPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveDocumentPath))
{
return false;
}
const QFileInfo saveInfo(saveMaterialPath.c_str());
const QFileInfo saveInfo(saveDocumentPath.c_str());
if (saveInfo.exists() && !saveInfo.isWritable())
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be overwritten:\n%1").arg(saveMaterialPath.c_str()));
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Document could not be overwritten:\n%1").arg(saveDocumentPath.c_str()));
return false;
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool result = false;
MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsChild, saveMaterialPath);
MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsChild, saveDocumentPath);
if (!result)
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.GetDump().c_str()));
QApplication::activeWindow(), QString("Document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveDocumentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -467,7 +467,7 @@ namespace MaterialEditor
if (!AzFramework::StringFunc::Path::Normalize(requestedPath))
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document path is invalid:\n%1").arg(requestedPath.c_str()));
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Document path is invalid:\n%1").arg(requestedPath.c_str()));
return AZ::Uuid::CreateNull();
}
@@ -476,9 +476,9 @@ namespace MaterialEditor
{
for (const auto& documentPair : m_documentMap)
{
AZStd::string openMaterialPath;
MaterialDocumentRequestBus::EventResult(openMaterialPath, documentPair.first, &MaterialDocumentRequestBus::Events::GetAbsolutePath);
if (openMaterialPath == requestedPath)
AZStd::string openDocumentPath;
MaterialDocumentRequestBus::EventResult(openDocumentPath, documentPair.first, &MaterialDocumentRequestBus::Events::GetAbsolutePath);
if (openDocumentPath == requestedPath)
{
MaterialDocumentNotificationBus::Broadcast(&MaterialDocumentNotificationBus::Events::OnDocumentOpened, documentPair.first);
return documentPair.first;
@@ -493,7 +493,7 @@ namespace MaterialEditor
if (documentId.IsNull())
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be created"),
QApplication::activeWindow(), QString("Document could not be created"),
QString("Failed to create: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return AZ::Uuid::CreateNull();
}
@@ -505,7 +505,7 @@ namespace MaterialEditor
if (!openResult)
{
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be opened"),
QApplication::activeWindow(), QString("Document could not be opened"),
QString("Failed to open: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.GetDump().c_str()));
MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::DestroyDocument, documentId);
return AZ::Uuid::CreateNull();
@@ -36,8 +36,6 @@ AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnin
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QVBoxLayout>
#include <QVariant>
#include <QWindow>
AZ_POP_DISABLE_WARNING
@@ -77,20 +75,13 @@ namespace MaterialEditor
m_toolBar->setObjectName("ToolBar");
addToolBar(m_toolBar);
m_materialViewport = new MaterialViewportWidget(m_centralWidget);
m_materialViewport->setObjectName("Viewport");
m_materialViewport->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
CreateMenu();
CreateTabBar();
QVBoxLayout* vl = new QVBoxLayout(m_centralWidget);
vl->setMargin(0);
vl->setContentsMargins(0, 0, 0, 0);
vl->addWidget(m_tabWidget);
vl->addWidget(m_materialViewport);
m_centralWidget->setLayout(vl);
setCentralWidget(m_centralWidget);
m_materialViewport = new MaterialViewportWidget(centralWidget());
m_materialViewport->setObjectName("Viewport");
m_materialViewport->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
centralWidget()->layout()->addWidget(m_materialViewport);
AddDockWidget("Asset Browser", new MaterialBrowserWidget, Qt::BottomDockWidgetArea, Qt::Vertical);
AddDockWidget("Inspector", new MaterialInspector, Qt::RightDockWidgetArea, Qt::Horizontal);
@@ -200,7 +191,7 @@ namespace MaterialEditor
// Create a new tab for the document ID and assign it's label to the file name of the document.
AddTabForDocumentId(documentId, filename, absolutePath, [this]{
// The tab widget requires a dummy page per tab
auto contentWidget = new QWidget(m_centralWidget);
auto contentWidget = new QWidget(centralWidget());
contentWidget->setContentsMargins(0, 0, 0, 0);
contentWidget->setFixedSize(0, 0);
return contentWidget;
@@ -247,8 +238,8 @@ namespace MaterialEditor
const QString documentPath = GetDocumentPath(documentId);
if (!documentPath.isEmpty())
{
const QString status = QString("Material closed: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"White\">%1</font>").arg(status));
const QString status = QString("Document closed: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"White\">%1</font>").arg(status));
}
}
@@ -258,7 +249,7 @@ namespace MaterialEditor
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Material closed: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"White\">%1</font>").arg(status));
m_statusMessage->setText(QString("<font color=\"White\">%1</font>").arg(status));
}
void MaterialEditorWindow::OnDocumentModified(const AZ::Uuid& documentId)
@@ -296,8 +287,8 @@ namespace MaterialEditor
UpdateTabForDocumentId(documentId, filename, absolutePath, isModified);
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Material closed: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"White\">%1</font>").arg(status));
const QString status = QString("Document closed: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"White\">%1</font>").arg(status));
}
void MaterialEditorWindow::CreateMenu()
@@ -341,8 +332,8 @@ namespace MaterialEditor
if (!result)
{
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Failed to save material: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"Red\">%1</font>").arg(status));
const QString status = QString("Failed to save document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::Save);
@@ -355,8 +346,8 @@ namespace MaterialEditor
documentId, AtomToolsFramework::GetSaveFileInfo(documentPath).absoluteFilePath().toUtf8().constData());
if (!result)
{
const QString status = QString("Failed to save material: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"Red\">%1</font>").arg(status));
const QString status = QString("Failed to save document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::SaveAs);
@@ -369,8 +360,8 @@ namespace MaterialEditor
documentId, AtomToolsFramework::GetSaveFileInfo(documentPath).absoluteFilePath().toUtf8().constData());
if (!result)
{
const QString status = QString("Failed to save material: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"Red\">%1</font>").arg(status));
const QString status = QString("Failed to save document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
});
@@ -379,8 +370,8 @@ namespace MaterialEditor
MaterialDocumentSystemRequestBus::BroadcastResult(result, &MaterialDocumentSystemRequestBus::Events::SaveAllDocuments);
if (!result)
{
const QString status = QString("Failed to save materials.");
m_statusBar->setWindowIconText(QString("<font color=\"Red\">%1</font>").arg(status));
const QString status = QString("Failed to save documents.");
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
});
@@ -425,8 +416,8 @@ namespace MaterialEditor
if (!result)
{
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Failed to perform Undo in material: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"Red\">%1</font>").arg(status));
const QString status = QString("Failed to perform Undo on document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::Undo);
@@ -437,8 +428,8 @@ namespace MaterialEditor
if (!result)
{
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Failed to perform Undo in material: %1").arg(documentPath);
m_statusBar->setWindowIconText(QString("<font color=\"Red\">%1</font>").arg(status));
const QString status = QString("Failed to perform Redo on document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::Redo);
@@ -30,47 +30,24 @@ namespace MaterialEditor
serialize->Class<MaterialEditorWindowComponent, AZ::Component>()
->Version(0);
}
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus>("MaterialEditorWindowAtomRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Category, "Editor")
->Attribute(AZ::Script::Attributes::Module, "materialeditor")
->Event("CreateMaterialEditorWindow", &AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus::Events::CreateMainWindow)
->Event("DestroyMaterialEditorWindow", &AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus::Events::DestroyMainWindow)
;
behaviorContext->EBus<AtomToolsFramework::AtomToolsMainWindowRequestBus>("MaterialEditorWindowRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Category, "Editor")
->Attribute(AZ::Script::Attributes::Module, "materialeditor")
->Event("ActivateWindow", &AtomToolsFramework::AtomToolsMainWindowRequestBus::Events::ActivateWindow)
->Event("SetDockWidgetVisible", &AtomToolsFramework::AtomToolsMainWindowRequestBus::Events::SetDockWidgetVisible)
->Event("IsDockWidgetVisible", &AtomToolsFramework::AtomToolsMainWindowRequestBus::Events::IsDockWidgetVisible)
->Event("GetDockWidgetNames", &AtomToolsFramework::AtomToolsMainWindowRequestBus::Events::GetDockWidgetNames)
->Event("ResizeViewportRenderTarget", &AtomToolsFramework::AtomToolsMainWindowRequestBus::Events::ResizeViewportRenderTarget)
->Event("LockViewportRenderTargetSize", &AtomToolsFramework::AtomToolsMainWindowRequestBus::Events::LockViewportRenderTargetSize)
->Event("UnlockViewportRenderTargetSize", &AtomToolsFramework::AtomToolsMainWindowRequestBus::Events::UnlockViewportRenderTargetSize)
;
}
}
void MaterialEditorWindowComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("AssetBrowserService", 0x1e54fffb));
required.push_back(AZ_CRC("PropertyManagerService", 0x63a3d7ad));
required.push_back(AZ_CRC("SourceControlService", 0x67f338fd));
required.push_back(AZ_CRC_CE("AssetBrowserService"));
required.push_back(AZ_CRC_CE("PropertyManagerService"));
required.push_back(AZ_CRC_CE("SourceControlService"));
required.push_back(AZ_CRC_CE("AtomToolsMainWindowSystemService"));
}
void MaterialEditorWindowComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("MaterialEditorWindowService", 0xb6e7d922));
provided.push_back(AZ_CRC_CE("MaterialEditorWindowService"));
}
void MaterialEditorWindowComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("MaterialEditorWindowService", 0xb6e7d922));
incompatible.push_back(AZ_CRC_CE("MaterialEditorWindowService"));
}
void MaterialEditorWindowComponent::Init()
@@ -6,6 +6,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
"""
import azlmbr.bus
import azlmbr.atomtools
import azlmbr.materialeditor
import azlmbr.name
import azlmbr.render
@@ -122,12 +123,12 @@ def CaptureScreenshot(screenshotOutputPath):
def ResizeViewport(width, height):
# This locks the size of the render target to the desired resolution
azlmbr.materialeditor.MaterialEditorWindowRequestBus(azlmbr.bus.Broadcast, 'LockViewportRenderTargetSize', width, height)
azlmbr.atomtools.AtomToolsMainWindowRequestBus(azlmbr.bus.Broadcast, 'LockViewportRenderTargetSize', width, height)
# This resizes the window to closely match the render target resolution so it doesn't appear stretched while the script is running
azlmbr.materialeditor.MaterialEditorWindowRequestBus(azlmbr.bus.Broadcast, 'ResizeViewportRenderTarget', width, height)
azlmbr.atomtools.AtomToolsMainWindowRequestBus(azlmbr.bus.Broadcast, 'ResizeViewportRenderTarget', width, height)
def ReleaseViewportResolutionLock():
azlmbr.materialeditor.MaterialEditorWindowRequestBus(azlmbr.bus.Broadcast, 'UnlockViewportRenderTargetSize')
azlmbr.atomtools.AtomToolsMainWindowRequestBus(azlmbr.bus.Broadcast, 'UnlockViewportRenderTargetSize')
def GenerateMaterialScreenshot(materialName,
uniqueSuffix="",
@@ -10,6 +10,9 @@
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/std/any.h>
#include <AtomToolsFramework/DynamicProperty/DynamicProperty.h>
#include <AtomToolsFramework/DynamicProperty/DynamicPropertyGroup.h>
namespace ShaderManagementConsole
{
class ShaderManagementConsoleDocumentNotifications
@@ -47,9 +50,33 @@ namespace ShaderManagementConsole
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentModified([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a document dependency was modified
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentDependencyModified([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a document was modified externally
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentExternallyModified([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a document undo state was updated
//! @param documentId unique id of document for which the notification is sent
virtual void OnDocumentUndoStateChanged([[maybe_unused]] const AZ::Uuid& documentId) {}
//! Signal that a property changed
//! @param documentId unique id of document for which the notification is sent
//! @param property object containing the property value and configuration that was modified
virtual void OnDocumentPropertyValueModified([[maybe_unused]] const AZ::Uuid& documentId, [[maybe_unused]] const AtomToolsFramework::DynamicProperty& property) {}
//! Signal that the property configuration has been changed.
//! @param documentId unique id of document for which the notification is sent
//! @param property object containing the property value and configuration that was modified
virtual void OnDocumentPropertyConfigModified([[maybe_unused]] const AZ::Uuid& documentId, [[maybe_unused]] const AtomToolsFramework::DynamicProperty& property) {}
//! Signal that the property group visibility has been changed.
//! @param documentId unique id of document for which the notification is sent
//! @param groupId id of the group that changed
//! @param visible whether the property group is visible
virtual void OnDocumentPropertyGroupVisibilityChanged([[maybe_unused]] const AZ::Uuid& documentId, [[maybe_unused]] const AZ::Name& groupId, [[maybe_unused]] bool visible) {}
};
using ShaderManagementConsoleDocumentNotificationBus = AZ::EBus<ShaderManagementConsoleDocumentNotifications>;
@@ -18,7 +18,6 @@
namespace ShaderManagementConsole
{
using ShaderManagementConsoleDocumentResult = AZ::Outcome<AZStd::string, AZStd::string>;
class ShaderManagementConsoleDocumentRequests
: public AZ::EBusTraits
@@ -48,17 +47,17 @@ namespace ShaderManagementConsole
//! Load document and related data
//! @param loadPath Absolute path of document to load
virtual ShaderManagementConsoleDocumentResult Open(AZStd::string_view loadPath) = 0;
virtual bool Open(AZStd::string_view loadPath) = 0;
//! Save document to file
virtual ShaderManagementConsoleDocumentResult Save() = 0;
virtual bool Save() = 0;
//! Save document copy
//! @param savePath Absolute path where document is saved
virtual ShaderManagementConsoleDocumentResult SaveAsCopy(AZStd::string_view savePath) = 0;
virtual bool SaveAsCopy(AZStd::string_view savePath) = 0;
//! Close document and reset its data
virtual ShaderManagementConsoleDocumentResult Close() = 0;
virtual bool Close() = 0;
//! document is loaded
virtual bool IsOpen() const = 0;
@@ -29,9 +29,9 @@ namespace ShaderManagementConsole
virtual bool DestroyDocument(const AZ::Uuid& documentId) = 0;
//! Open a document for editing
//! @param path document to edit.
//! @param sourcePath document to open.
//! @return unique id of new document if successful, otherwise null Uuid
virtual AZ::Uuid OpenDocument(AZStd::string_view path) = 0;
virtual AZ::Uuid OpenDocument(AZStd::string_view sourcePath) = 0;
//! Close the specified document
//! @param documentId unique id of document to close
@@ -40,13 +40,18 @@ namespace ShaderManagementConsole
//! Close all documents
virtual bool CloseAllDocuments() = 0;
//! Close all documents except for documentId
//! @param documentId unique id of document to not close
virtual bool CloseAllDocumentsExcept(const AZ::Uuid& documentId) = 0;
//! Save the specified document
//! @param documentId unique id of document to save
virtual bool SaveDocument(const AZ::Uuid& documentId) = 0;
//! Save the specified document to a different file
//! @param documentId unique id of document to save
virtual bool SaveDocumentAsCopy(const AZ::Uuid& documentId) = 0;
//! @param targetPath location where document is saved.
virtual bool SaveDocumentAsCopy(const AZ::Uuid& documentId, AZStd::string_view targetPath) = 0;
//! Save all documents
virtual bool SaveAllDocuments() = 0;
@@ -28,6 +28,7 @@ namespace ShaderManagementConsole
{
ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentDestroyed, m_id);
ShaderManagementConsoleDocumentRequestBus::Handler::BusDisconnect();
Clear();
}
const AZ::Uuid& ShaderManagementConsoleDocument::GetId() const
@@ -71,19 +72,21 @@ namespace ShaderManagementConsole
return m_shaderVariantListSourceData.m_shaderVariants[index];
}
ShaderManagementConsoleDocumentResult ShaderManagementConsoleDocument::Open(AZStd::string_view loadPath)
bool ShaderManagementConsoleDocument::Open(AZStd::string_view loadPath)
{
Clear();
m_absolutePath = loadPath;
if (!AzFramework::StringFunc::Path::Normalize(m_absolutePath))
{
return AZ::Failure(AZStd::string::format("Document path could not be normalized: '%s'.", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Document path could not be normalized: '%s'.", m_absolutePath.c_str());
return false;
}
if (AzFramework::StringFunc::Path::IsRelative(m_absolutePath.c_str()))
{
return AZ::Failure(AZStd::string::format("Document path must be absolute: '%s'.", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Document path must be absolute: '%s'.", m_absolutePath.c_str());
return false;
}
if (AzFramework::StringFunc::Path::IsExtension(m_absolutePath.c_str(), AZ::RPI::ShaderVariantListSourceData::Extension))
@@ -91,7 +94,8 @@ namespace ShaderManagementConsole
// Load the shader config data and create a shader config asset from it
if (!AZ::RPI::JsonUtils::LoadObjectFromFile(m_absolutePath, m_shaderVariantListSourceData))
{
return AZ::Failure(AZStd::string::format("Failed loading shader variant list data: '%s.'", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Failed loading shader variant list data: '%s.'", m_absolutePath.c_str());
return false;
}
}
@@ -103,13 +107,15 @@ namespace ShaderManagementConsole
watchFolder);
if (!result)
{
return AZ::Failure(AZStd::string::format("Could not find source data: '%s'.", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Could not find source data: '%s'.", m_absolutePath.c_str());
return false;
}
m_relativePath = m_shaderVariantListSourceData.m_shaderFilePath;
if (!AzFramework::StringFunc::Path::Normalize(m_relativePath))
{
return AZ::Failure(AZStd::string::format("Shader path could not be normalized: '%s'.", m_relativePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Shader path could not be normalized: '%s'.", m_relativePath.c_str());
return false;
}
AZStd::string shaderPath = m_relativePath;
@@ -118,27 +124,32 @@ namespace ShaderManagementConsole
m_shaderAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::ShaderAsset>(shaderPath.c_str());
if (!m_shaderAsset)
{
return AZ::Failure(AZStd::string::format("Could not load shader asset: %s.", shaderPath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Could not load shader asset: %s.", shaderPath.c_str());
return false;
}
ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentOpened, m_id);
return AZ::Success(AZStd::string::format("Document loaded: '%s'", m_absolutePath.c_str()));
AZ_TracePrintf("ShaderManagementConsoleDocument", "Document loaded: '%s'", m_absolutePath.c_str());
return true;
}
ShaderManagementConsoleDocumentResult ShaderManagementConsoleDocument::Save()
bool ShaderManagementConsoleDocument::Save()
{
if (!IsOpen())
{
return AZ::Failure(AZStd::string::format("Document is not open to be saved: '%s'.", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Document is not open to be saved: '%s'.", m_absolutePath.c_str());
return false;
}
if (!IsSavable())
{
return AZ::Failure(AZStd::string::format("Document can not be saved: '%s'.", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Document can not be saved: '%s'.", m_absolutePath.c_str());
return false;
}
return AZ::Failure(AZStd::string::format("%s is not implemented!", __FUNCTION__));
AZ_Error("ShaderManagementConsoleDocument", false, "%s is not implemented!", __FUNCTION__);
return false;
// Auto add or checkout saved file
//AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEdit,
@@ -147,28 +158,33 @@ namespace ShaderManagementConsole
//ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentSaved, m_id);
//return AZ::Success(AZStd::string::format("Document saved: %s", m_absolutePath.data()));
//AZ_TracePrintf("ShaderManagementConsoleDocument", "Document saved: %s", m_absolutePath.data());
//return true;
}
ShaderManagementConsoleDocumentResult ShaderManagementConsoleDocument::SaveAsCopy(AZStd::string_view savePath)
bool ShaderManagementConsoleDocument::SaveAsCopy(AZStd::string_view savePath)
{
if (!IsOpen())
{
return AZ::Failure(AZStd::string::format("Document is not open to be saved: '%s'.", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Document is not open to be saved: '%s'.", m_absolutePath.c_str());
return false;
}
if (!IsSavable())
{
return AZ::Failure(AZStd::string::format("Document can not be saved: '%s'.", m_absolutePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Document can not be saved: '%s'.", m_absolutePath.c_str());
return false;
}
AZStd::string normalizedSavePath = savePath;
if (!AzFramework::StringFunc::Path::Normalize(normalizedSavePath))
{
return AZ::Failure(AZStd::string::format("Document save path could not be normalized: '%s'.", normalizedSavePath.c_str()));
AZ_Error("ShaderManagementConsoleDocument", false, "Document save path could not be normalized: '%s'.", normalizedSavePath.c_str());
return false;
}
return AZ::Failure(AZStd::string::format("%s is not implemented!", __FUNCTION__));
AZ_Error("ShaderManagementConsoleDocument", false, "%s is not implemented!", __FUNCTION__);
return false;
// Auto add or checkout saved file
//AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEdit,
@@ -177,19 +193,22 @@ namespace ShaderManagementConsole
//ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentSaved, m_id);
//return AZ::Success(AZStd::string::format("Document saved: %s", normalizedSavePath.c_str()));
//AZ_TracePrintf("ShaderManagementConsoleDocument", "Document saved: %s", normalizedSavePath.c_str());
//return true;
}
ShaderManagementConsoleDocumentResult ShaderManagementConsoleDocument::Close()
bool ShaderManagementConsoleDocument::Close()
{
if (!IsOpen())
{
return AZ::Failure(AZStd::string("Document is not open"));
AZ_Error("ShaderManagementConsoleDocument", false, "Document is not open");
return false;
}
Clear();
ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentClosed, m_id);
return AZ::Success(AZStd::string("Document was closed"));
AZ_TracePrintf("ShaderManagementConsoleDocument", "Document was closed");
return true;
}
bool ShaderManagementConsoleDocument::IsOpen() const
@@ -269,5 +288,9 @@ namespace ShaderManagementConsole
{
m_absolutePath.clear();
m_relativePath.clear();
m_shaderVariantListSourceData = {};
m_shaderAsset = {};
m_undoHistory = {};
m_undoHistoryIndex = {};
}
} // namespace ShaderManagementConsole
@@ -41,10 +41,10 @@ namespace ShaderManagementConsole
const AZ::RPI::ShaderOptionDescriptor& GetShaderOptionDescriptor(size_t index) const override;
size_t GetShaderVariantCount() const override;
const AZ::RPI::ShaderVariantListSourceData::VariantInfo& GetShaderVariantInfo(size_t index) const override;
ShaderManagementConsoleDocumentResult Open(AZStd::string_view loadPath) override;
ShaderManagementConsoleDocumentResult Save() override;
ShaderManagementConsoleDocumentResult SaveAsCopy(AZStd::string_view savePath) override;
ShaderManagementConsoleDocumentResult Close() override;
bool Open(AZStd::string_view loadPath) override;
bool Save() override;
bool SaveAsCopy(AZStd::string_view savePath) override;
bool Close() override;
bool IsOpen() const override;
bool IsModified() const override;
bool IsSavable() const override;
@@ -8,9 +8,11 @@
#include <Document/ShaderManagementConsoleDocumentSystemComponent.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AtomToolsFramework/Debug/TraceRecorder.h>
#include <AtomToolsFramework/Util/Util.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzFramework/Asset/AssetSystemBus.h>
#include <AzFramework/StringFunc/StringFunc.h>
@@ -67,6 +69,7 @@ namespace ShaderManagementConsole
->Event("OpenDocument", &ShaderManagementConsoleDocumentSystemRequestBus::Events::OpenDocument)
->Event("CloseDocument", &ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseDocument)
->Event("CloseAllDocuments", &ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseAllDocuments)
->Event("CloseAllDocumentsExcept", &ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseAllDocumentsExcept)
->Event("SaveDocument", &ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveDocument)
->Event("SaveDocumentAsCopy", &ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveDocumentAsCopy)
->Event("SaveAllDocuments", &ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveAllDocuments)
@@ -152,9 +155,9 @@ namespace ShaderManagementConsole
return m_documentMap.erase(documentId) != 0;
}
AZ::Uuid ShaderManagementConsoleDocumentSystemComponent::OpenDocument(AZStd::string_view path)
AZ::Uuid ShaderManagementConsoleDocumentSystemComponent::OpenDocument(AZStd::string_view sourcePath)
{
return OpenDocumentImpl(path, true);
return OpenDocumentImpl(sourcePath, true);
}
bool ShaderManagementConsoleDocumentSystemComponent::CloseDocument(const AZ::Uuid& documentId)
@@ -163,26 +166,46 @@ namespace ShaderManagementConsole
ShaderManagementConsoleDocumentRequestBus::EventResult(isOpen, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::IsOpen);
if (!isOpen)
{
// immediately destroy unopened documents
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::DestroyDocument, documentId);
return true;
}
AZStd::string documentPath;
ShaderManagementConsoleDocumentRequestBus::EventResult(documentPath, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::GetAbsolutePath);
bool isModified = false;
ShaderManagementConsoleDocumentRequestBus::EventResult(isModified, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::IsModified);
if (isModified)
{
if (QMessageBox::question(QApplication::activeWindow(), "document has unsaved changes", "Would you like to close anyway?",
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
auto selection = QMessageBox::question(QApplication::activeWindow(),
QString("Document has unsaved changes"),
QString("Do you want to save changes to\n%1?").arg(documentPath.c_str()),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (selection == QMessageBox::Cancel)
{
AZ_TracePrintf("ShaderManagementConsoleDocument", "Close document canceled: %s", documentPath.c_str());
return false;
}
if (selection == QMessageBox::Yes)
{
if (!SaveDocument(documentId))
{
AZ_Error("ShaderManagementConsoleDocument", false, "Close document failed because document was not saved: %s", documentPath.c_str());
return false;
}
}
}
ShaderManagementConsoleDocumentResult closeResult = AZ::Success(AZStd::string("There is no active document"));
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool closeResult = true;
ShaderManagementConsoleDocumentRequestBus::EventResult(closeResult, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::Close);
if (!closeResult)
{
QMessageBox::critical(QApplication::activeWindow(), "Failed to close document",
QString::fromUtf8(closeResult.GetError().data(), (int)closeResult.GetError().size()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Document could not be closed"),
QString("Failed to close: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -205,60 +228,83 @@ namespace ShaderManagementConsole
return result;
}
bool ShaderManagementConsoleDocumentSystemComponent::CloseAllDocumentsExcept(const AZ::Uuid& documentId)
{
bool result = true;
auto documentMap = m_documentMap;
for (const auto& documentPair : documentMap)
{
if (documentPair.first != documentId)
{
if (!CloseDocument(documentPair.first))
{
result = false;
}
}
}
return result;
}
bool ShaderManagementConsoleDocumentSystemComponent::SaveDocument(const AZ::Uuid& documentId)
{
AZStd::string documentPath;
ShaderManagementConsoleDocumentRequestBus::EventResult(documentPath, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::GetAbsolutePath);
AZStd::string saveDocumentPath;
ShaderManagementConsoleDocumentRequestBus::EventResult(saveDocumentPath, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::GetAbsolutePath);
const QFileInfo saveInfo(documentPath.c_str());
if (saveInfo.absoluteFilePath().isEmpty())
if (saveDocumentPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveDocumentPath))
{
return false;
}
const QFileInfo saveInfo(saveDocumentPath.c_str());
if (saveInfo.exists() && !saveInfo.isWritable())
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Unable to save document. File can not be overwritten."));
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Document could not be overwritten:\n%1").arg(saveDocumentPath.c_str()));
return false;
}
ShaderManagementConsoleDocumentResult result = AZ::Failure(AZStd::string("There is no active document"));
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool result = false;
ShaderManagementConsoleDocumentRequestBus::EventResult(result, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::Save);
if (!result)
{
QMessageBox::critical(QApplication::activeWindow(), "document not saved",
QString::fromUtf8(result.GetError().data(), (int)result.GetError().size()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveDocumentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
AZ_TracePrintf("ShaderManagementConsole", "%s\n", result.GetValue().c_str());
return true;
}
bool ShaderManagementConsoleDocumentSystemComponent::SaveDocumentAsCopy(const AZ::Uuid& documentId)
bool ShaderManagementConsoleDocumentSystemComponent::SaveDocumentAsCopy(const AZ::Uuid& documentId, AZStd::string_view targetPath)
{
AZStd::string documentPath;
ShaderManagementConsoleDocumentRequestBus::EventResult(documentPath, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::GetAbsolutePath);
const QFileInfo& saveInfo = AtomToolsFramework::GetSaveFileInfo(documentPath.c_str());
if (saveInfo.absoluteFilePath().isEmpty())
AZStd::string saveDocumentPath = targetPath;
if (saveDocumentPath.empty() || !AzFramework::StringFunc::Path::Normalize(saveDocumentPath))
{
return false;
}
AZStd::string saveDocumentPath = saveInfo.absoluteFilePath().toUtf8().constData();
AzFramework::StringFunc::Path::Normalize(saveDocumentPath);
const QFileInfo saveInfo(saveDocumentPath.c_str());
if (saveInfo.exists() && !saveInfo.isWritable())
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Document could not be overwritten:\n%1").arg(saveDocumentPath.c_str()));
return false;
}
ShaderManagementConsoleDocumentResult result = AZ::Failure(AZStd::string("There is no active document"));
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool result = false;
ShaderManagementConsoleDocumentRequestBus::EventResult(result, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::SaveAsCopy, saveDocumentPath);
if (!result)
{
QMessageBox::critical(QApplication::activeWindow(), "document copy not saved",
QString::fromUtf8(result.GetError().data(), (int)result.GetError().size()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveDocumentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
AZ_TracePrintf("ShaderManagementConsole", "%s\n", result.GetValue().c_str());
return true;
}
@@ -276,13 +322,17 @@ namespace ShaderManagementConsole
return result;
}
AZ::Uuid ShaderManagementConsoleDocumentSystemComponent::OpenDocumentImpl(AZStd::string_view path, bool checkIfAlreadyOpen)
AZ::Uuid ShaderManagementConsoleDocumentSystemComponent::OpenDocumentImpl(AZStd::string_view sourcePath, bool checkIfAlreadyOpen)
{
AZStd::string requestedPath = path;
if (requestedPath.empty() || !AzFramework::StringFunc::Path::Normalize(requestedPath))
AZStd::string requestedPath = sourcePath;
if (requestedPath.empty())
{
QMessageBox::critical(QApplication::activeWindow(), "document path is invalid",
QString::fromUtf8(requestedPath.data(), (int)requestedPath.size()));
return AZ::Uuid::CreateNull();
}
if (!AzFramework::StringFunc::Path::Normalize(requestedPath))
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Document path is invalid:\n%1").arg(requestedPath.c_str()));
return AZ::Uuid::CreateNull();
}
@@ -301,21 +351,27 @@ namespace ShaderManagementConsole
}
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
AZ::Uuid documentId = AZ::Uuid::CreateNull();
ShaderManagementConsoleDocumentSystemRequestBus::BroadcastResult(documentId, &ShaderManagementConsoleDocumentSystemRequestBus::Events::CreateDocument);
if (documentId.IsNull())
{
QMessageBox::critical(QApplication::activeWindow(), "Failed to create document",
QString::fromUtf8(requestedPath.data(), (int)requestedPath.size()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Document could not be created"),
QString("Failed to create: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return AZ::Uuid::CreateNull();
}
ShaderManagementConsoleDocumentResult openResult = AZ::Failure(AZStd::string("Failed to open document"));
traceRecorder.GetDump().clear();
bool openResult = false;
ShaderManagementConsoleDocumentRequestBus::EventResult(openResult, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::Open, requestedPath);
if (!openResult)
{
QMessageBox::critical(QApplication::activeWindow(), "Failed to open document",
QString::fromUtf8(openResult.GetError().data(), (int)openResult.GetError().size()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Document could not be opened"),
QString("Failed to open: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.GetDump().c_str()));
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::DestroyDocument, documentId);
return AZ::Uuid::CreateNull();
}
@@ -53,16 +53,18 @@ namespace ShaderManagementConsole
// ShaderManagementConsoleDocumentSystemRequestBus::Handler overrides...
AZ::Uuid CreateDocument() override;
bool DestroyDocument(const AZ::Uuid& documentId) override;
AZ::Uuid OpenDocument(AZStd::string_view path) override;
AZ::Uuid OpenDocument(AZStd::string_view sourcePath) override;
bool CloseDocument(const AZ::Uuid& documentId) override;
bool CloseAllDocuments() override;
bool CloseAllDocumentsExcept(const AZ::Uuid& documentId) override;
bool SaveDocument(const AZ::Uuid& documentId) override;
bool SaveDocumentAsCopy(const AZ::Uuid& documentId) override;
bool SaveDocumentAsCopy(const AZ::Uuid& documentId, AZStd::string_view targetPath) override;
bool SaveAllDocuments() override;
////////////////////////////////////////////////////////////////////////
AZ::Uuid OpenDocumentImpl(AZStd::string_view path, bool checkIfAlreadyOpen);
AZ::Uuid OpenDocumentImpl(AZStd::string_view sourcePath, bool checkIfAlreadyOpen);
AZStd::unordered_map<AZ::Uuid, AZStd::shared_ptr<ShaderManagementConsoleDocument>> m_documentMap;
const size_t m_maxMessageBoxLineCount = 15;
};
}
@@ -8,6 +8,8 @@
#include <AzCore/Name/Name.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzQtComponents/Components/StyleManager.h>
#include <AzQtComponents/Components/WindowDecorationWrapper.h>
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzToolsFramework/PythonTerminal/ScriptTermDialog.h>
@@ -23,11 +25,8 @@ AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnin
#include <QCloseEvent>
#include <QFileDialog>
#include <QHeaderView>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
#include <QVBoxLayout>
#include <QVariant>
#include <QWindow>
AZ_POP_DISABLE_WARNING
@@ -36,6 +35,14 @@ namespace ShaderManagementConsole
ShaderManagementConsoleWindow::ShaderManagementConsoleWindow(QWidget* parent /* = 0 */)
: AtomToolsFramework::AtomToolsMainWindow(parent)
{
resize(1280, 1024);
// Among other things, we need the window wrapper to save the main window size, position, and state
auto mainWindowWrapper =
new AzQtComponents::WindowDecorationWrapper(AzQtComponents::WindowDecorationWrapper::OptionAutoTitleBarButtons);
mainWindowWrapper->setGuest(this);
mainWindowWrapper->enableSaveRestoreGeometry("O3DE", "ShaderManagementConsole", "mainWindowGeometry");
setWindowTitle("Shader Management Console");
setObjectName("ShaderManagementConsoleWindow");
@@ -47,16 +54,14 @@ namespace ShaderManagementConsole
CreateMenu();
CreateTabBar();
QVBoxLayout* vl = new QVBoxLayout(m_centralWidget);
vl->setMargin(0);
vl->setContentsMargins(0, 0, 0, 0);
vl->addWidget(m_tabWidget);
m_centralWidget->setLayout(vl);
setCentralWidget(m_centralWidget);
AddDockWidget("Asset Browser", new ShaderManagementConsoleBrowserWidget, Qt::BottomDockWidgetArea, Qt::Vertical);
AddDockWidget("Python Terminal", new AzToolsFramework::CScriptTermDialog, Qt::BottomDockWidgetArea, Qt::Horizontal);
SetDockWidgetVisible("Python Terminal", false);
// Restore geometry and show the window
mainWindowWrapper->showFromSettings();
ShaderManagementConsoleDocumentNotificationBus::Handler::BusConnect();
OnDocumentOpened(AZ::Uuid::CreateNull());
}
@@ -103,8 +108,7 @@ namespace ShaderManagementConsole
// Create a new tab for the document ID and assign it's label to the file name of the document.
AddTabForDocumentId(documentId, filename, absolutePath, [this, documentId]{
// The document tab contains a table view.
auto contentWidget = new QTableView(m_centralWidget);
contentWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
auto contentWidget = new QTableView(centralWidget());
contentWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
contentWidget->setModel(CreateDocumentContent(documentId));
return contentWidget;
@@ -142,11 +146,22 @@ namespace ShaderManagementConsole
activateWindow();
raise();
const QString documentPath = GetDocumentPath(documentId);
if (!documentPath.isEmpty())
{
const QString status = QString("Document closed: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"White\">%1</font>").arg(status));
}
}
void ShaderManagementConsoleWindow::OnDocumentClosed(const AZ::Uuid& documentId)
{
RemoveTabForDocumentId(documentId);
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Document closed: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"White\">%1</font>").arg(status));
}
void ShaderManagementConsoleWindow::OnDocumentModified(const AZ::Uuid& documentId)
@@ -182,6 +197,10 @@ namespace ShaderManagementConsole
AZStd::string filename;
AzFramework::StringFunc::Path::GetFullFileName(absolutePath.c_str(), filename);
UpdateTabForDocumentId(documentId, filename, absolutePath, isModified);
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Document closed: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"White\">%1</font>").arg(status));
}
void ShaderManagementConsoleWindow::CreateMenu()
@@ -206,8 +225,47 @@ namespace ShaderManagementConsole
m_menuFile->addSeparator();
m_actionSave = m_menuFile->addAction("&Save", [this]() {
const AZ::Uuid documentId = GetDocumentIdFromTab(m_tabWidget->currentIndex());
bool result = false;
ShaderManagementConsoleDocumentSystemRequestBus::BroadcastResult(result, &ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveDocument, documentId);
if (!result)
{
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Failed to save document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::Save);
m_actionSaveAsCopy = m_menuFile->addAction("Save &As...", [this]() {
const AZ::Uuid documentId = GetDocumentIdFromTab(m_tabWidget->currentIndex());
const QString documentPath = GetDocumentPath(documentId);
bool result = false;
ShaderManagementConsoleDocumentSystemRequestBus::BroadcastResult(result, &ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveDocumentAsCopy,
documentId, AtomToolsFramework::GetSaveFileInfo(documentPath).absoluteFilePath().toUtf8().constData());
if (!result)
{
const QString status = QString("Failed to save document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::SaveAs);
m_actionSaveAll = m_menuFile->addAction("Save A&ll", [this]() {
bool result = false;
ShaderManagementConsoleDocumentSystemRequestBus::BroadcastResult(result, &ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveAllDocuments);
if (!result)
{
const QString status = QString("Failed to save documents.");
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
});
m_menuFile->addSeparator();
m_actionClose = m_menuFile->addAction("&Close", [this]() {
CloseDocumentForTab(m_tabWidget->currentIndex());
const AZ::Uuid documentId = GetDocumentIdFromTab(m_tabWidget->currentIndex());
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseDocument, documentId);
}, QKeySequence::Close);
m_actionCloseAll = m_menuFile->addAction("Close All", [this]() {
@@ -215,23 +273,8 @@ namespace ShaderManagementConsole
});
m_actionCloseOthers = m_menuFile->addAction("Close Others", [this]() {
CloseAllExceptDocumentForTab(m_tabWidget->currentIndex());
});
m_menuFile->addSeparator();
m_actionSave = m_menuFile->addAction("&Save", [this]() {
const AZ::Uuid documentId = GetDocumentIdFromTab(m_tabWidget->currentIndex());
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveDocument, documentId);
}, QKeySequence::Save);
m_actionSaveAsCopy = m_menuFile->addAction("Save &As...", [this]() {
const AZ::Uuid documentId = GetDocumentIdFromTab(m_tabWidget->currentIndex());
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveDocumentAsCopy, documentId);
}, QKeySequence::SaveAs);
m_actionSaveAll = m_menuFile->addAction("Save A&ll", [this]() {
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::SaveAllDocuments);
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseAllDocumentsExcept, documentId);
});
m_menuFile->addSeparator();
@@ -254,37 +297,46 @@ namespace ShaderManagementConsole
m_actionUndo = m_menuEdit->addAction("&Undo", [this]() {
const AZ::Uuid documentId = GetDocumentIdFromTab(m_tabWidget->currentIndex());
ShaderManagementConsoleDocumentRequestBus::Event(documentId, &ShaderManagementConsoleDocumentRequestBus::Events::Undo);
bool result = false;
ShaderManagementConsoleDocumentRequestBus::EventResult(result, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::Undo);
if (!result)
{
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Failed to perform Undo on document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::Undo);
m_actionRedo = m_menuEdit->addAction("&Redo", [this]() {
const AZ::Uuid documentId = GetDocumentIdFromTab(m_tabWidget->currentIndex());
ShaderManagementConsoleDocumentRequestBus::Event(documentId, &ShaderManagementConsoleDocumentRequestBus::Events::Redo);
bool result = false;
ShaderManagementConsoleDocumentRequestBus::EventResult(result, documentId, &ShaderManagementConsoleDocumentRequestBus::Events::Redo);
if (!result)
{
const QString documentPath = GetDocumentPath(documentId);
const QString status = QString("Failed to perform Redo on document: %1").arg(documentPath);
m_statusMessage->setText(QString("<font color=\"Red\">%1</font>").arg(status));
}
}, QKeySequence::Redo);
m_menuEdit->addSeparator();
m_actionSettings = m_menuEdit->addAction("&Preferences...", [this]() {
m_actionSettings = m_menuEdit->addAction("&Settings...", [this]() {
}, QKeySequence::Preferences);
m_actionSettings->setEnabled(false);
m_menuView = m_menuBar->addMenu("&View");
m_actionAssetBrowser = m_menuView->addAction(
"&Asset Browser",
[this]()
{
const AZStd::string label = "Asset Browser";
SetDockWidgetVisible(label, !IsDockWidgetVisible(label));
});
m_actionAssetBrowser = m_menuView->addAction("&Asset Browser", [this]() {
const AZStd::string label = "Asset Browser";
SetDockWidgetVisible(label, !IsDockWidgetVisible(label));
});
m_actionPythonTerminal = m_menuView->addAction("Python &Terminal", [this]() {
const AZStd::string label = "Python Terminal";
SetDockWidgetVisible(label, !IsDockWidgetVisible(label));
});
m_actionPythonTerminal = m_menuView->addAction(
"Python &Terminal",
[this]()
{
const AZStd::string label = "Python Terminal";
SetDockWidgetVisible(label, !IsDockWidgetVisible(label));
});
m_menuView->addSeparator();
@@ -313,14 +365,23 @@ namespace ShaderManagementConsole
// When the last tab is removed tabIndex will be -1 and the document ID will be null
// This should automatically clear the active document
connect(m_tabWidget, &QTabWidget::currentChanged, this, [this](int tabIndex) {
SelectDocumentForTab(tabIndex);
const AZ::Uuid documentId = GetDocumentIdFromTab(tabIndex);
ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentOpened, documentId);
});
connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, [this](int tabIndex) {
CloseDocumentForTab(tabIndex);
const AZ::Uuid documentId = GetDocumentIdFromTab(tabIndex);
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseDocument, documentId);
});
}
QString ShaderManagementConsoleWindow::GetDocumentPath(const AZ::Uuid& documentId) const
{
AZStd::string absolutePath;
ShaderManagementConsoleDocumentRequestBus::EventResult(absolutePath, documentId, &ShaderManagementConsoleDocumentRequestBus::Handler::GetAbsolutePath);
return absolutePath.c_str();
}
void ShaderManagementConsoleWindow::OpenTabContextMenu()
{
const QTabBar* tabBar = m_tabWidget->tabBar();
@@ -332,51 +393,22 @@ namespace ShaderManagementConsole
QMenu tabMenu;
const QString selectActionName = (currentTabIndex == clickedTabIndex) ? "Select in Browser" : "Select";
tabMenu.addAction(selectActionName, [this, clickedTabIndex]() {
SelectDocumentForTab(clickedTabIndex);
const AZ::Uuid documentId = GetDocumentIdFromTab(clickedTabIndex);
ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentOpened, documentId);
});
tabMenu.addAction("Close", [this, clickedTabIndex]() {
CloseDocumentForTab(clickedTabIndex);
const AZ::Uuid documentId = GetDocumentIdFromTab(clickedTabIndex);
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseDocument, documentId);
});
auto closeOthersAction = tabMenu.addAction("Close Others", [this, clickedTabIndex]() {
CloseAllExceptDocumentForTab(clickedTabIndex);
const AZ::Uuid documentId = GetDocumentIdFromTab(clickedTabIndex);
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseAllDocumentsExcept, documentId);
});
closeOthersAction->setEnabled(tabBar->count() > 1);
tabMenu.exec(QCursor::pos());
}
}
void ShaderManagementConsoleWindow::SelectDocumentForTab(const int tabIndex)
{
const AZ::Uuid documentId = GetDocumentIdFromTab(tabIndex);
ShaderManagementConsoleDocumentNotificationBus::Broadcast(&ShaderManagementConsoleDocumentNotificationBus::Events::OnDocumentOpened, documentId);
}
void ShaderManagementConsoleWindow::CloseDocumentForTab(const int tabIndex)
{
const AZ::Uuid documentId = GetDocumentIdFromTab(tabIndex);
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseDocument, documentId);
}
void ShaderManagementConsoleWindow::CloseAllExceptDocumentForTab(const int tabIndex)
{
AZStd::vector<AZ::Uuid> documentIdsToClose;
documentIdsToClose.reserve(m_tabWidget->count());
const AZ::Uuid documentIdToKeepOpen = GetDocumentIdFromTab(tabIndex);
for (int tabI = 0; tabI < m_tabWidget->count(); ++tabI)
{
const AZ::Uuid documentId = GetDocumentIdFromTab(tabI);
if (documentId != documentIdToKeepOpen)
{
documentIdsToClose.push_back(documentId);
}
}
for (const AZ::Uuid& documentId : documentIdsToClose)
{
ShaderManagementConsoleDocumentSystemRequestBus::Broadcast(&ShaderManagementConsoleDocumentSystemRequestBus::Events::CloseDocument, documentId);
}
}
QStandardItemModel* ShaderManagementConsoleWindow::CreateDocumentContent(const AZ::Uuid& documentId)
{
AZStd::unordered_set<AZStd::string> optionNames;
@@ -52,11 +52,10 @@ namespace ShaderManagementConsole
void CreateMenu() override;
void CreateTabBar() override;
void OpenTabContextMenu() override;
void SelectDocumentForTab(const int tabIndex);
void CloseDocumentForTab(const int tabIndex);
void CloseAllExceptDocumentForTab(const int tabIndex);
QString GetDocumentPath(const AZ::Uuid& documentId) const;
void OpenTabContextMenu() override;
void closeEvent(QCloseEvent* closeEvent) override;
@@ -44,14 +44,6 @@ namespace ShaderManagementConsole
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus>("ShaderManagementConsoleWindowRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Editor")
->Attribute(AZ::Script::Attributes::Module, "shadermanagementconsole")
->Event("CreateShaderManagementConsoleWindow", &AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus::Events::CreateMainWindow)
->Event("DestroyShaderManagementConsoleWindow", &AtomToolsFramework::AtomToolsMainWindowFactoryRequestBus::Events::DestroyMainWindow)
;
behaviorContext->EBus<ShaderManagementConsoleRequestBus>("ShaderManagementConsoleRequestBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Editor")
@@ -65,19 +57,20 @@ namespace ShaderManagementConsole
void ShaderManagementConsoleWindowComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("AssetBrowserService", 0x1e54fffb));
required.push_back(AZ_CRC("PropertyManagerService", 0x63a3d7ad));
required.push_back(AZ_CRC("SourceControlService", 0x67f338fd));
required.push_back(AZ_CRC_CE("AssetBrowserService"));
required.push_back(AZ_CRC_CE("PropertyManagerService"));
required.push_back(AZ_CRC_CE("SourceControlService"));
required.push_back(AZ_CRC_CE("AtomToolsMainWindowSystemService"));
}
void ShaderManagementConsoleWindowComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("ShaderManagementConsoleWindowService", 0xb6e7d922));
provided.push_back(AZ_CRC_CE("ShaderManagementConsoleWindowService"));
}
void ShaderManagementConsoleWindowComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("ShaderManagementConsoleWindowService", 0xb6e7d922));
incompatible.push_back(AZ_CRC_CE("ShaderManagementConsoleWindowService"));
}
void ShaderManagementConsoleWindowComponent::Init()