Merge pull request #536 from aws-lumberyard-dev/Atom/guthadam/ATOM-15451

ATOM-15451 always bring material editor into foreground when launching
This commit is contained in:
Guthrie Adams
2021-05-04 14:20:38 -05:00
committed by GitHub
6 changed files with 39 additions and 1 deletions
@@ -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
@@ -45,6 +45,7 @@
#include <Atom/Window/MaterialEditorWindowModule.h>
#include <Atom/Window/MaterialEditorWindowFactoryRequestBus.h>
#include <Atom/Window/MaterialEditorWindowRequestBus.h>
#include <AzCore/Utils/Utils.h>
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))
{
@@ -424,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;
@@ -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);
@@ -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;
@@ -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)
@@ -23,6 +23,8 @@
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzToolsFramework/Thumbnails/ThumbnailContext.h>
#include <Atom/RHI/Factory.h>
#include <AtomToolsFramework/Util/Util.h>
#include <Material/MaterialThumbnail.h>
@@ -125,6 +127,14 @@ namespace AZ
QStringList arguments;
arguments.append(sourcePath.c_str());
// 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 +149,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("");
}