From 80f692118bb15de792679c99597785911fb587e8 Mon Sep 17 00:00:00 2001 From: guthadam Date: Tue, 4 May 2021 01:27:12 -0500 Subject: [PATCH 1/2] ATOM-15451 always bring material editor and foreground when launching Bus, command line option, and handler to activate material editor window Made sure that material editor action in Ly tools menu is not checked/checkable Ly editor pushes command line option to use the same RHI https://jira.agscollab.com/browse/LYN-2610 https://jira.agscollab.com/browse/ATOM-15451 https://jira.agscollab.com/browse/ATOM-13742 --- .../Window/MaterialEditorWindowRequestBus.h | 3 +++ .../Code/Source/MaterialEditorApplication.cpp | 12 ++++++++++++ .../Source/Window/MaterialEditorWindow.cpp | 6 ++++++ .../Code/Source/Window/MaterialEditorWindow.h | 1 + .../Window/MaterialEditorWindowComponent.cpp | 1 + .../Material/EditorMaterialSystemComponent.cpp | 18 +++++++++++++++++- 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h index 538777b762..55e6ddac20 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Include/Atom/Window/MaterialEditorWindowRequestBus.h @@ -28,6 +28,9 @@ namespace MaterialEditor static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; + //! Bring main window to foreground + virtual void ActivateWindow() = 0; + //! Add dockable widget in main window //! @param name title of the dockable window //! @param widget docked window content diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index ea82210814..3ffe2af1a6 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -45,6 +45,7 @@ #include #include +#include #include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT @@ -309,6 +310,13 @@ namespace MaterialEditor void MaterialEditorApplication::ProcessCommandLine(const AZ::CommandLine& commandLine) { + const AZStd::string activateWindowSwitchName = "activatewindow"; + if (commandLine.HasSwitch(activateWindowSwitchName)) + { + MaterialEditor::MaterialEditorWindowRequestBus::Broadcast( + &MaterialEditor::MaterialEditorWindowRequestBus::Handler::ActivateWindow); + } + const AZStd::string timeoputSwitchName = "timeout"; if (commandLine.HasSwitch(timeoputSwitchName)) { @@ -438,6 +446,10 @@ namespace MaterialEditor // Handle commmand line params from connected socket if (buffer.startsWith("ProcessCommandLine:")) { + // Bring the material editor to the foreground + MaterialEditor::MaterialEditorWindowRequestBus::Broadcast( + &MaterialEditor::MaterialEditorWindowRequestBus::Handler::ActivateWindow); + // Remove header and parse commands AZStd::string params(buffer.data(), buffer.size()); params = params.substr(strlen("ProcessCommandLine:")); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp index 1e116b4a22..6e47de189c 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.cpp @@ -129,6 +129,12 @@ namespace MaterialEditor MaterialEditorWindowRequestBus::Handler::BusDisconnect(); } + void MaterialEditorWindow::ActivateWindow() + { + activateWindow(); + raise(); + } + bool MaterialEditorWindow::AddDockWidget(const AZStd::string& name, QWidget* widget, uint32_t area, uint32_t orientation) { auto dockWidgetItr = m_dockWidgets.find(name); diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h index 6bd6e6b165..778e11275f 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindow.h @@ -61,6 +61,7 @@ namespace MaterialEditor private: // MaterialEditorWindowRequestBus::Handler overrides... + void ActivateWindow() override; bool AddDockWidget(const AZStd::string& name, QWidget* widget, uint32_t area, uint32_t orientation) override; void RemoveDockWidget(const AZStd::string& name) override; void SetDockWidgetVisible(const AZStd::string& name, bool visible) override; diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp index a1ff8da635..820cee30f9 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Window/MaterialEditorWindowComponent.cpp @@ -50,6 +50,7 @@ namespace MaterialEditor ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) ->Attribute(AZ::Script::Attributes::Category, "Editor") ->Attribute(AZ::Script::Attributes::Module, "materialeditor") + ->Event("ActivateWindow", &MaterialEditorWindowRequestBus::Events::ActivateWindow) ->Event("SetDockWidgetVisible", &MaterialEditorWindowRequestBus::Events::SetDockWidgetVisible) ->Event("IsDockWidgetVisible", &MaterialEditorWindowRequestBus::Events::IsDockWidgetVisible) ->Event("GetDockWidgetNames", &MaterialEditorWindowRequestBus::Events::GetDockWidgetNames) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp index c32f124456..4cf51e2f37 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -125,6 +127,17 @@ namespace AZ QStringList arguments; arguments.append(sourcePath.c_str()); + + // Bring the material editor to the foreground if running + arguments.append("--activatewindow"); + + // Use the same RHI as the main editor + AZ::Name apiName = AZ::RHI::Factory::Get().GetName(); + if (!apiName.IsEmpty()) + { + arguments.append(QString("--rhi=%1").arg(apiName.GetCStr())); + } + AtomToolsFramework::LaunchTool("MaterialEditor", ".exe", arguments); } @@ -139,7 +152,10 @@ namespace AZ { m_openMaterialEditorAction = new QAction("Material Editor"); m_openMaterialEditorAction->setShortcut(QKeySequence(Qt::Key_M)); - QObject::connect(m_openMaterialEditorAction, &QAction::triggered, m_openMaterialEditorAction, [this]() + m_openMaterialEditorAction->setCheckable(false); + m_openMaterialEditorAction->setChecked(false); + QObject::connect( + m_openMaterialEditorAction, &QAction::triggered, m_openMaterialEditorAction, [this]() { OpenInMaterialEditor(""); } From 6b1f0c53a5193bc6b26a00ffb9058a0318f815c0 Mon Sep 17 00:00:00 2001 From: guthadam Date: Tue, 4 May 2021 10:30:27 -0500 Subject: [PATCH 2/2] Injecting --activateWindow every time new process sends command line Updated comments --- .../Code/Source/MaterialEditorApplication.cpp | 10 ++++++---- .../Source/Material/EditorMaterialSystemComponent.cpp | 3 --- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp index 3ffe2af1a6..1f32c2a66b 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/MaterialEditorApplication.cpp @@ -432,10 +432,16 @@ namespace MaterialEditor // Forward commandline options to other application instance. QByteArray buffer; buffer.append("ProcessCommandLine:"); + + // Add the command line options from this process to the message, skipping the executable path for (int argi = 1; argi < m_argC; ++argi) { buffer.append(QString(m_argV[argi]).append("\n").toUtf8()); } + + // Inject command line option to always bring the main window to the foreground + buffer.append("--activatewindow\n"); + m_socket.Send(buffer); m_socket.Disconnect(); return false; @@ -446,10 +452,6 @@ namespace MaterialEditor // Handle commmand line params from connected socket if (buffer.startsWith("ProcessCommandLine:")) { - // Bring the material editor to the foreground - MaterialEditor::MaterialEditorWindowRequestBus::Broadcast( - &MaterialEditor::MaterialEditorWindowRequestBus::Handler::ActivateWindow); - // Remove header and parse commands AZStd::string params(buffer.data(), buffer.size()); params = params.substr(strlen("ProcessCommandLine:")); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp index 4cf51e2f37..e9a81f2e9f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Material/EditorMaterialSystemComponent.cpp @@ -128,9 +128,6 @@ namespace AZ QStringList arguments; arguments.append(sourcePath.c_str()); - // Bring the material editor to the foreground if running - arguments.append("--activatewindow"); - // Use the same RHI as the main editor AZ::Name apiName = AZ::RHI::Factory::Get().GetName(); if (!apiName.IsEmpty())