Launch editor from Project Manager

This commit is contained in:
Alex Peterson
2021-05-26 13:17:16 -07:00
committed by GitHub
parent ef6ac74aa7
commit da24f4ccde
4 changed files with 96 additions and 3 deletions
@@ -31,11 +31,30 @@ namespace O3DE::ProjectManager
LabelButton::LabelButton(QWidget* parent)
: QLabel(parent)
{
m_overlayLabel = new QLabel("", this);
m_overlayLabel->setObjectName("labelButtonOverlay");
m_overlayLabel->setWordWrap(true);
m_overlayLabel->setAlignment(Qt::AlignCenter);
m_overlayLabel->setVisible(false);
}
void LabelButton::mousePressEvent([[maybe_unused]] QMouseEvent* event)
{
emit triggered();
if(m_enabled)
{
emit triggered();
}
}
void LabelButton::SetEnabled(bool enabled)
{
m_enabled = enabled;
m_overlayLabel->setVisible(!enabled);
}
void LabelButton::SetOverlayText(const QString& text)
{
m_overlayLabel->setText(text);
}
ProjectButton::ProjectButton(const QString& projectName, QWidget* parent)
@@ -99,4 +118,13 @@ namespace O3DE::ProjectManager
#endif
}
void ProjectButton::SetButtonEnabled(bool enabled)
{
m_projectImageLabel->SetEnabled(enabled);
}
void ProjectButton::SetButtonOverlayText(const QString& text)
{
m_projectImageLabel->SetOverlayText(text);
}
} // namespace O3DE::ProjectManager
@@ -32,11 +32,18 @@ namespace O3DE::ProjectManager
explicit LabelButton(QWidget* parent = nullptr);
~LabelButton() = default;
void SetEnabled(bool enabled);
void SetOverlayText(const QString& text);
signals:
void triggered();
public slots:
void mousePressEvent(QMouseEvent* event) override;
private:
QLabel* m_overlayLabel;
bool m_enabled = true;
};
class ProjectButton
@@ -49,6 +56,9 @@ namespace O3DE::ProjectManager
explicit ProjectButton(const QString& projectName, const QString& projectImage, QWidget* parent = nullptr);
~ProjectButton() = default;
void SetButtonEnabled(bool enabled);
void SetButtonOverlayText(const QString& text);
signals:
void OpenProject(const QString& projectName);
void EditProject(const QString& projectName);
@@ -14,6 +14,12 @@
#include <ProjectButtonWidget.h>
#include <PythonBindingsInterface.h>
#include <AzCore/Platform.h>
#include <AzCore/IO/SystemFile.h>
#include <AzFramework/AzFramework_Traits_Platform.h>
#include <AzFramework/Process/ProcessCommon.h>
#include <AzFramework/Process/ProcessWatcher.h>
#include <AzCore/Utils/Utils.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
@@ -27,6 +33,8 @@
#include <QListWidgetItem>
#include <QFileInfo>
#include <QScrollArea>
#include <QMessageBox>
#include <QTimer>
namespace O3DE::ProjectManager
{
@@ -127,8 +135,48 @@ namespace O3DE::ProjectManager
}
void ProjectsHomeScreen::HandleOpenProject(const QString& projectPath)
{
// Open the editor with this project open
emit NotifyCurrentProject(projectPath);
if (!projectPath.isEmpty())
{
AZ::IO::FixedMaxPath executableDirectory = AZ::Utils::GetExecutableDirectory();
AZStd::string executableFilename = "Editor";
AZ::IO::FixedMaxPath editorExecutablePath = executableDirectory / (executableFilename + AZ_TRAIT_OS_EXECUTABLE_EXTENSION);
auto cmdPath = AZ::IO::FixedMaxPathString::format("%s -regset=\"/Amazon/AzCore/Bootstrap/project_path=%s\"", editorExecutablePath.c_str(), projectPath.toStdString().c_str());
AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
processLaunchInfo.m_commandlineParameters = cmdPath;
bool launchSucceeded = AzFramework::ProcessLauncher::LaunchUnwatchedProcess(processLaunchInfo);
if (!launchSucceeded)
{
AZ_Error("ProjectManager", false, "Failed to launch editor");
QMessageBox::critical( this, tr("Error"), tr("Failed to launch the Editor, please verify the project settings are valid."));
}
else
{
// prevent the user from accidentally pressing the button while the editor is launching
// and let them know what's happening
ProjectButton* button = qobject_cast<ProjectButton*>(sender());
if (button)
{
button->SetButtonEnabled(false);
button->SetButtonOverlayText(tr("Opening Editor..."));
}
// enable the button after 3 seconds
constexpr int waitTimeInMs = 3000;
QTimer::singleShot(waitTimeInMs, this, [this, button] {
if (button)
{
button->SetButtonEnabled(true);
}
});
}
}
else
{
AZ_Error("ProjectManager", false, "Cannot open editor because an empty project path was provided");
QMessageBox::critical( this, tr("Error"), tr("Failed to launch the Editor because the project path is invalid."));
}
}
void ProjectsHomeScreen::HandleEditProject(const QString& projectPath)
{