ProjectsScreen.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <ProjectsScreen.h>
  9. #include <ProjectManagerDefs.h>
  10. #include <ProjectButtonWidget.h>
  11. #include <PythonBindingsInterface.h>
  12. #include <ProjectUtils.h>
  13. #include <ProjectBuilderController.h>
  14. #include <ScreensCtrl.h>
  15. #include <SettingsInterface.h>
  16. #include <AzQtComponents/Components/FlowLayout.h>
  17. #include <AzCore/Platform.h>
  18. #include <AzCore/IO/SystemFile.h>
  19. #include <AzFramework/AzFramework_Traits_Platform.h>
  20. #include <AzFramework/Process/ProcessCommon.h>
  21. #include <AzFramework/Process/ProcessWatcher.h>
  22. #include <AzCore/Utils/Utils.h>
  23. #include <QVBoxLayout>
  24. #include <QHBoxLayout>
  25. #include <QLabel>
  26. #include <QPushButton>
  27. #include <QMenu>
  28. #include <QListView>
  29. #include <QSpacerItem>
  30. #include <QListWidget>
  31. #include <QListWidgetItem>
  32. #include <QScrollArea>
  33. #include <QStackedWidget>
  34. #include <QFrame>
  35. #include <QIcon>
  36. #include <QPixmap>
  37. #include <QSettings>
  38. #include <QMessageBox>
  39. #include <QTimer>
  40. #include <QQueue>
  41. #include <QDir>
  42. #include <QGuiApplication>
  43. namespace O3DE::ProjectManager
  44. {
  45. ProjectsScreen::ProjectsScreen(QWidget* parent)
  46. : ScreenWidget(parent)
  47. {
  48. QVBoxLayout* vLayout = new QVBoxLayout();
  49. vLayout->setAlignment(Qt::AlignTop);
  50. vLayout->setContentsMargins(s_contentMargins, 0, s_contentMargins, 0);
  51. setLayout(vLayout);
  52. m_stack = new QStackedWidget(this);
  53. m_firstTimeContent = CreateFirstTimeContent();
  54. m_stack->addWidget(m_firstTimeContent);
  55. m_projectsContent = CreateProjectsContent();
  56. m_stack->addWidget(m_projectsContent);
  57. vLayout->addWidget(m_stack);
  58. connect(reinterpret_cast<ScreensCtrl*>(parent), &ScreensCtrl::NotifyBuildProject, this, &ProjectsScreen::SuggestBuildProject);
  59. // Will focus whatever button it finds so the Project tab is not focused on start-up
  60. QTimer::singleShot(0, this, [this]
  61. {
  62. QPushButton* foundButton = m_stack->currentWidget()->findChild<QPushButton*>();
  63. if (foundButton)
  64. {
  65. foundButton->setFocus();
  66. }
  67. });
  68. }
  69. ProjectsScreen::~ProjectsScreen()
  70. {
  71. }
  72. QFrame* ProjectsScreen::CreateFirstTimeContent()
  73. {
  74. QFrame* frame = new QFrame(this);
  75. frame->setObjectName("firstTimeContent");
  76. {
  77. QVBoxLayout* layout = new QVBoxLayout();
  78. layout->setContentsMargins(0, 0, 0, 0);
  79. layout->setAlignment(Qt::AlignTop);
  80. frame->setLayout(layout);
  81. QLabel* titleLabel = new QLabel(tr("Ready? Set. Create!"), this);
  82. titleLabel->setObjectName("titleLabel");
  83. layout->addWidget(titleLabel);
  84. QLabel* introLabel = new QLabel(this);
  85. introLabel->setObjectName("introLabel");
  86. introLabel->setText(tr("Welcome to O3DE! Start something new by creating a project."));
  87. layout->addWidget(introLabel);
  88. QHBoxLayout* buttonLayout = new QHBoxLayout();
  89. buttonLayout->setAlignment(Qt::AlignLeft);
  90. buttonLayout->setSpacing(s_spacerSize);
  91. // use a newline to force the text up
  92. QPushButton* createProjectButton = new QPushButton(tr("Create a Project\n"), this);
  93. createProjectButton->setObjectName("createProjectButton");
  94. buttonLayout->addWidget(createProjectButton);
  95. QPushButton* addProjectButton = new QPushButton(tr("Add a Project\n"), this);
  96. addProjectButton->setObjectName("addProjectButton");
  97. buttonLayout->addWidget(addProjectButton);
  98. connect(createProjectButton, &QPushButton::clicked, this, &ProjectsScreen::HandleNewProjectButton);
  99. connect(addProjectButton, &QPushButton::clicked, this, &ProjectsScreen::HandleAddProjectButton);
  100. layout->addLayout(buttonLayout);
  101. }
  102. return frame;
  103. }
  104. QFrame* ProjectsScreen::CreateProjectsContent()
  105. {
  106. QFrame* frame = new QFrame(this);
  107. frame->setObjectName("projectsContent");
  108. {
  109. QVBoxLayout* layout = new QVBoxLayout();
  110. layout->setAlignment(Qt::AlignTop);
  111. layout->setContentsMargins(0, 0, 0, 0);
  112. frame->setLayout(layout);
  113. QFrame* header = new QFrame(frame);
  114. QHBoxLayout* headerLayout = new QHBoxLayout();
  115. {
  116. QLabel* titleLabel = new QLabel(tr("My Projects"), this);
  117. titleLabel->setObjectName("titleLabel");
  118. headerLayout->addWidget(titleLabel);
  119. QMenu* newProjectMenu = new QMenu(this);
  120. m_createNewProjectAction = newProjectMenu->addAction("Create New Project");
  121. m_addExistingProjectAction = newProjectMenu->addAction("Add Existing Project");
  122. connect(m_createNewProjectAction, &QAction::triggered, this, &ProjectsScreen::HandleNewProjectButton);
  123. connect(m_addExistingProjectAction, &QAction::triggered, this, &ProjectsScreen::HandleAddProjectButton);
  124. QPushButton* newProjectMenuButton = new QPushButton(tr("New Project..."), this);
  125. newProjectMenuButton->setObjectName("newProjectButton");
  126. newProjectMenuButton->setMenu(newProjectMenu);
  127. newProjectMenuButton->setDefault(true);
  128. headerLayout->addWidget(newProjectMenuButton);
  129. }
  130. header->setLayout(headerLayout);
  131. layout->addWidget(header);
  132. QScrollArea* projectsScrollArea = new QScrollArea(this);
  133. QWidget* scrollWidget = new QWidget();
  134. m_projectsFlowLayout = new FlowLayout(0, s_spacerSize, s_spacerSize);
  135. scrollWidget->setLayout(m_projectsFlowLayout);
  136. projectsScrollArea->setWidget(scrollWidget);
  137. projectsScrollArea->setWidgetResizable(true);
  138. ResetProjectsContent();
  139. layout->addWidget(projectsScrollArea);
  140. }
  141. return frame;
  142. }
  143. ProjectButton* ProjectsScreen::CreateProjectButton(const ProjectInfo& project)
  144. {
  145. ProjectButton* projectButton = new ProjectButton(project, this);
  146. m_projectButtons.insert(QDir::toNativeSeparators(project.m_path), projectButton);
  147. m_projectsFlowLayout->addWidget(projectButton);
  148. connect(projectButton, &ProjectButton::OpenProject, this, &ProjectsScreen::HandleOpenProject);
  149. connect(projectButton, &ProjectButton::EditProject, this, &ProjectsScreen::HandleEditProject);
  150. connect(projectButton, &ProjectButton::EditProjectGems, this, &ProjectsScreen::HandleEditProjectGems);
  151. connect(projectButton, &ProjectButton::CopyProject, this, &ProjectsScreen::HandleCopyProject);
  152. connect(projectButton, &ProjectButton::RemoveProject, this, &ProjectsScreen::HandleRemoveProject);
  153. connect(projectButton, &ProjectButton::DeleteProject, this, &ProjectsScreen::HandleDeleteProject);
  154. connect(projectButton, &ProjectButton::BuildProject, this, &ProjectsScreen::QueueBuildProject);
  155. connect(projectButton, &ProjectButton::OpenCMakeGUI, this,
  156. [this](const ProjectInfo& projectInfo)
  157. {
  158. AZ::Outcome result = ProjectUtils::OpenCMakeGUI(projectInfo.m_path);
  159. if (!result)
  160. {
  161. QMessageBox::critical(this, tr("Failed to open CMake GUI"), result.GetError(), QMessageBox::Ok);
  162. }
  163. });
  164. return projectButton;
  165. }
  166. void ProjectsScreen::ResetProjectsContent()
  167. {
  168. RemoveInvalidProjects();
  169. // Get all projects and create a vertical scrolling list of them
  170. // Sort building and queued projects first
  171. auto projectsResult = PythonBindingsInterface::Get()->GetProjects();
  172. if (projectsResult.IsSuccess() && !projectsResult.GetValue().isEmpty())
  173. {
  174. QVector<ProjectInfo> projectsVector = projectsResult.GetValue();
  175. // If a project path is in this set then the button for it will be kept
  176. QSet<QString> keepProject;
  177. for (const ProjectInfo& project : projectsVector)
  178. {
  179. keepProject.insert(QDir::toNativeSeparators(project.m_path));
  180. }
  181. // Clear flow and delete buttons for removed projects
  182. auto projectButtonsIter = m_projectButtons.begin();
  183. while (projectButtonsIter != m_projectButtons.end())
  184. {
  185. m_projectsFlowLayout->removeWidget(projectButtonsIter.value());
  186. if (!keepProject.contains(projectButtonsIter.key()))
  187. {
  188. projectButtonsIter.value()->deleteLater();
  189. projectButtonsIter = m_projectButtons.erase(projectButtonsIter);
  190. }
  191. else
  192. {
  193. ++projectButtonsIter;
  194. }
  195. }
  196. QString buildProjectPath = "";
  197. if (m_currentBuilder)
  198. {
  199. buildProjectPath = QDir::toNativeSeparators(m_currentBuilder->GetProjectInfo().m_path);
  200. }
  201. // Put currently building project in front, then queued projects, then sorts alphabetically
  202. std::sort(projectsVector.begin(), projectsVector.end(), [buildProjectPath, this](const ProjectInfo& arg1, const ProjectInfo& arg2)
  203. {
  204. if (arg1.m_path == buildProjectPath)
  205. {
  206. return true;
  207. }
  208. else if (arg2.m_path == buildProjectPath)
  209. {
  210. return false;
  211. }
  212. bool arg1InBuildQueue = BuildQueueContainsProject(arg1.m_path);
  213. bool arg2InBuildQueue = BuildQueueContainsProject(arg2.m_path);
  214. if (arg1InBuildQueue && !arg2InBuildQueue)
  215. {
  216. return true;
  217. }
  218. else if (!arg1InBuildQueue && arg2InBuildQueue)
  219. {
  220. return false;
  221. }
  222. else
  223. {
  224. return arg1.m_displayName.toLower() < arg2.m_displayName.toLower();
  225. }
  226. });
  227. // Add any missing project buttons and restore buttons to default state
  228. for (const ProjectInfo& project : projectsVector)
  229. {
  230. ProjectButton* currentButton = nullptr;
  231. if (!m_projectButtons.contains(QDir::toNativeSeparators(project.m_path)))
  232. {
  233. currentButton = CreateProjectButton(project);
  234. m_projectButtons.insert(QDir::toNativeSeparators(project.m_path), currentButton);
  235. }
  236. else
  237. {
  238. auto projectButtonIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  239. if (projectButtonIter != m_projectButtons.end())
  240. {
  241. currentButton = projectButtonIter.value();
  242. currentButton->RestoreDefaultState();
  243. m_projectsFlowLayout->addWidget(currentButton);
  244. }
  245. }
  246. // Check whether project manager has successfully built the project
  247. if (currentButton)
  248. {
  249. bool projectBuiltSuccessfully = false;
  250. SettingsInterface::Get()->GetProjectBuiltSuccessfully(projectBuiltSuccessfully, project);
  251. if (!projectBuiltSuccessfully)
  252. {
  253. currentButton->ShowBuildRequired();
  254. }
  255. }
  256. }
  257. // Setup building button again
  258. auto buildProjectIter = m_projectButtons.find(buildProjectPath);
  259. if (buildProjectIter != m_projectButtons.end())
  260. {
  261. m_currentBuilder->SetProjectButton(buildProjectIter.value());
  262. }
  263. for (const ProjectInfo& project : m_buildQueue)
  264. {
  265. auto projectIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  266. if (projectIter != m_projectButtons.end())
  267. {
  268. projectIter.value()->SetProjectButtonAction(
  269. tr("Cancel Queued Build"),
  270. [this, project]
  271. {
  272. UnqueueBuildProject(project);
  273. SuggestBuildProjectMsg(project, false);
  274. });
  275. }
  276. }
  277. for (const ProjectInfo& project : m_requiresBuild)
  278. {
  279. auto projectIter = m_projectButtons.find(QDir::toNativeSeparators(project.m_path));
  280. if (projectIter != m_projectButtons.end())
  281. {
  282. if (project.m_buildFailed)
  283. {
  284. projectIter.value()->ShowBuildFailed(true, project.m_logUrl);
  285. }
  286. else
  287. {
  288. projectIter.value()->ShowBuildRequired();
  289. }
  290. }
  291. }
  292. }
  293. m_stack->setCurrentWidget(m_projectsContent);
  294. }
  295. ProjectManagerScreen ProjectsScreen::GetScreenEnum()
  296. {
  297. return ProjectManagerScreen::Projects;
  298. }
  299. bool ProjectsScreen::IsTab()
  300. {
  301. return true;
  302. }
  303. QString ProjectsScreen::GetTabText()
  304. {
  305. return tr("Projects");
  306. }
  307. void ProjectsScreen::paintEvent([[maybe_unused]] QPaintEvent* event)
  308. {
  309. // we paint the background here because qss does not support background cover scaling
  310. QPainter painter(this);
  311. const QSize winSize = size();
  312. const float pixmapRatio = (float)m_background.width() / m_background.height();
  313. const float windowRatio = (float)winSize.width() / winSize.height();
  314. QRect backgroundRect;
  315. if (pixmapRatio > windowRatio)
  316. {
  317. const int newWidth = (int)(winSize.height() * pixmapRatio);
  318. const int offset = (newWidth - winSize.width()) / -2;
  319. backgroundRect = QRect(offset, 0, newWidth, winSize.height());
  320. }
  321. else
  322. {
  323. const int newHeight = (int)(winSize.width() / pixmapRatio);
  324. backgroundRect = QRect(0, 0, winSize.width(), newHeight);
  325. }
  326. // Draw the background image.
  327. painter.drawPixmap(backgroundRect, m_background);
  328. // Draw a semi-transparent overlay to darken down the colors.
  329. // Use SourceOver, DestinationIn will make background transparent on Mac
  330. painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
  331. const float overlayTransparency = 0.3f;
  332. painter.fillRect(backgroundRect, QColor(0, 0, 0, static_cast<int>(255.0f * overlayTransparency)));
  333. }
  334. void ProjectsScreen::HandleNewProjectButton()
  335. {
  336. emit ResetScreenRequest(ProjectManagerScreen::CreateProject);
  337. emit ChangeScreenRequest(ProjectManagerScreen::CreateProject);
  338. }
  339. void ProjectsScreen::HandleAddProjectButton()
  340. {
  341. if (ProjectUtils::AddProjectDialog(this))
  342. {
  343. ResetProjectsContent();
  344. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  345. }
  346. }
  347. void ProjectsScreen::HandleOpenProject(const QString& projectPath)
  348. {
  349. if (!projectPath.isEmpty())
  350. {
  351. if (!WarnIfInBuildQueue(projectPath))
  352. {
  353. AZ::IO::FixedMaxPath fixedProjectPath = projectPath.toUtf8().constData();
  354. AZ::IO::FixedMaxPath editorExecutablePath = ProjectUtils::GetEditorExecutablePath(fixedProjectPath);
  355. if (editorExecutablePath.empty())
  356. {
  357. AZ_Error("ProjectManager", false, "Failed to locate editor");
  358. QMessageBox::critical(
  359. this, tr("Error"), tr("Failed to locate the Editor, please verify that it is built."));
  360. return;
  361. }
  362. auto cmdPath = AZ::IO::FixedMaxPathString::format(
  363. "%s --regset=\"/Amazon/AzCore/Bootstrap/project_path=%s\"", editorExecutablePath.c_str(),
  364. fixedProjectPath.c_str());
  365. AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
  366. processLaunchInfo.m_commandlineParameters = cmdPath;
  367. bool launchSucceeded = AzFramework::ProcessLauncher::LaunchUnwatchedProcess(processLaunchInfo);
  368. if (!launchSucceeded)
  369. {
  370. AZ_Error("ProjectManager", false, "Failed to launch editor");
  371. QMessageBox::critical(
  372. this, tr("Error"), tr("Failed to launch the Editor, please verify the project settings are valid."));
  373. }
  374. else
  375. {
  376. // prevent the user from accidentally pressing the button while the editor is launching
  377. // and let them know what's happening
  378. ProjectButton* button = qobject_cast<ProjectButton*>(sender());
  379. if (button)
  380. {
  381. button->SetLaunchButtonEnabled(false);
  382. button->SetButtonOverlayText(tr("Opening Editor..."));
  383. }
  384. // enable the button after 3 seconds
  385. constexpr int waitTimeInMs = 3000;
  386. QTimer::singleShot(
  387. waitTimeInMs, this,
  388. [button]
  389. {
  390. if (button)
  391. {
  392. button->SetLaunchButtonEnabled(true);
  393. }
  394. });
  395. }
  396. }
  397. }
  398. else
  399. {
  400. AZ_Error("ProjectManager", false, "Cannot open editor because an empty project path was provided");
  401. QMessageBox::critical( this, tr("Error"), tr("Failed to launch the Editor because the project path is invalid."));
  402. }
  403. }
  404. void ProjectsScreen::HandleEditProject(const QString& projectPath)
  405. {
  406. if (!WarnIfInBuildQueue(projectPath))
  407. {
  408. emit NotifyCurrentProject(projectPath);
  409. emit ChangeScreenRequest(ProjectManagerScreen::UpdateProject);
  410. }
  411. }
  412. void ProjectsScreen::HandleEditProjectGems(const QString& projectPath)
  413. {
  414. if (!WarnIfInBuildQueue(projectPath))
  415. {
  416. emit NotifyCurrentProject(projectPath);
  417. emit ChangeScreenRequest(ProjectManagerScreen::GemCatalog);
  418. }
  419. }
  420. void ProjectsScreen::HandleCopyProject(const ProjectInfo& projectInfo)
  421. {
  422. if (!WarnIfInBuildQueue(projectInfo.m_path))
  423. {
  424. ProjectInfo newProjectInfo(projectInfo);
  425. // Open file dialog and choose location for copied project then register copy with O3DE
  426. if (ProjectUtils::CopyProjectDialog(projectInfo.m_path, newProjectInfo, this))
  427. {
  428. ResetProjectsContent();
  429. emit NotifyBuildProject(newProjectInfo);
  430. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  431. }
  432. }
  433. }
  434. void ProjectsScreen::HandleRemoveProject(const QString& projectPath)
  435. {
  436. if (!WarnIfInBuildQueue(projectPath))
  437. {
  438. // Unregister Project from O3DE and reload projects
  439. if (ProjectUtils::UnregisterProject(projectPath))
  440. {
  441. ResetProjectsContent();
  442. emit ChangeScreenRequest(ProjectManagerScreen::Projects);
  443. }
  444. }
  445. }
  446. void ProjectsScreen::HandleDeleteProject(const QString& projectPath)
  447. {
  448. if (!WarnIfInBuildQueue(projectPath))
  449. {
  450. QMessageBox::StandardButton warningResult = QMessageBox::warning(this,
  451. tr("Delete Project"),
  452. tr("Are you sure?\nProject will be unregistered from O3DE and project directory will be deleted from your disk."),
  453. QMessageBox::No | QMessageBox::Yes);
  454. if (warningResult == QMessageBox::Yes)
  455. {
  456. QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  457. // Remove project from O3DE and delete from disk
  458. HandleRemoveProject(projectPath);
  459. ProjectUtils::DeleteProjectFiles(projectPath);
  460. QGuiApplication::restoreOverrideCursor();
  461. }
  462. }
  463. }
  464. void ProjectsScreen::SuggestBuildProjectMsg(const ProjectInfo& projectInfo, bool showMessage)
  465. {
  466. if (RequiresBuildProjectIterator(projectInfo.m_path) == m_requiresBuild.end() || projectInfo.m_buildFailed)
  467. {
  468. m_requiresBuild.append(projectInfo);
  469. }
  470. ResetProjectsContent();
  471. if (showMessage)
  472. {
  473. QMessageBox::information(this,
  474. tr("Project Should be rebuilt."),
  475. projectInfo.GetProjectDisplayName() + tr(" project likely needs to be rebuilt."));
  476. }
  477. }
  478. void ProjectsScreen::SuggestBuildProject(const ProjectInfo& projectInfo)
  479. {
  480. SuggestBuildProjectMsg(projectInfo, true);
  481. }
  482. void ProjectsScreen::QueueBuildProject(const ProjectInfo& projectInfo)
  483. {
  484. auto requiredIter = RequiresBuildProjectIterator(projectInfo.m_path);
  485. if (requiredIter != m_requiresBuild.end())
  486. {
  487. m_requiresBuild.erase(requiredIter);
  488. }
  489. if (!BuildQueueContainsProject(projectInfo.m_path))
  490. {
  491. if (m_buildQueue.empty() && !m_currentBuilder)
  492. {
  493. StartProjectBuild(projectInfo);
  494. // Projects Content is already reset in function
  495. }
  496. else
  497. {
  498. m_buildQueue.append(projectInfo);
  499. ResetProjectsContent();
  500. }
  501. }
  502. }
  503. void ProjectsScreen::UnqueueBuildProject(const ProjectInfo& projectInfo)
  504. {
  505. m_buildQueue.removeAll(projectInfo);
  506. ResetProjectsContent();
  507. }
  508. void ProjectsScreen::NotifyCurrentScreen()
  509. {
  510. if (ShouldDisplayFirstTimeContent())
  511. {
  512. m_background.load(":/Backgrounds/FtueBackground.jpg");
  513. m_stack->setCurrentWidget(m_firstTimeContent);
  514. }
  515. else
  516. {
  517. m_background.load(":/Backgrounds/DefaultBackground.jpg");
  518. ResetProjectsContent();
  519. }
  520. }
  521. bool ProjectsScreen::ShouldDisplayFirstTimeContent()
  522. {
  523. auto projectsResult = PythonBindingsInterface::Get()->GetProjects();
  524. if (!projectsResult.IsSuccess() || projectsResult.GetValue().isEmpty())
  525. {
  526. return true;
  527. }
  528. QSettings settings;
  529. bool displayFirstTimeContent = settings.value("displayFirstTimeContent", true).toBool();
  530. if (displayFirstTimeContent)
  531. {
  532. settings.setValue("displayFirstTimeContent", false);
  533. }
  534. return displayFirstTimeContent;
  535. }
  536. bool ProjectsScreen::RemoveInvalidProjects()
  537. {
  538. return PythonBindingsInterface::Get()->RemoveInvalidProjects();
  539. }
  540. bool ProjectsScreen::StartProjectBuild(const ProjectInfo& projectInfo)
  541. {
  542. if (ProjectUtils::FindSupportedCompiler(this))
  543. {
  544. QMessageBox::StandardButton buildProject = QMessageBox::information(
  545. this,
  546. tr("Building \"%1\"").arg(projectInfo.GetProjectDisplayName()),
  547. tr("Ready to build \"%1\"?").arg(projectInfo.GetProjectDisplayName()),
  548. QMessageBox::No | QMessageBox::Yes);
  549. if (buildProject == QMessageBox::Yes)
  550. {
  551. m_currentBuilder = new ProjectBuilderController(projectInfo, nullptr, this);
  552. ResetProjectsContent();
  553. connect(m_currentBuilder, &ProjectBuilderController::Done, this, &ProjectsScreen::ProjectBuildDone);
  554. connect(m_currentBuilder, &ProjectBuilderController::NotifyBuildProject, this, &ProjectsScreen::SuggestBuildProject);
  555. m_currentBuilder->Start();
  556. }
  557. else
  558. {
  559. SuggestBuildProjectMsg(projectInfo, false);
  560. return false;
  561. }
  562. return true;
  563. }
  564. return false;
  565. }
  566. void ProjectsScreen::ProjectBuildDone(bool success)
  567. {
  568. ProjectInfo currentBuilderProject;
  569. if (!success)
  570. {
  571. currentBuilderProject = m_currentBuilder->GetProjectInfo();
  572. }
  573. delete m_currentBuilder;
  574. m_currentBuilder = nullptr;
  575. if (!success)
  576. {
  577. SuggestBuildProjectMsg(currentBuilderProject, false);
  578. }
  579. if (!m_buildQueue.empty())
  580. {
  581. while (!StartProjectBuild(m_buildQueue.front()) && m_buildQueue.size() > 1)
  582. {
  583. m_buildQueue.pop_front();
  584. }
  585. m_buildQueue.pop_front();
  586. }
  587. ResetProjectsContent();
  588. }
  589. QList<ProjectInfo>::iterator ProjectsScreen::RequiresBuildProjectIterator(const QString& projectPath)
  590. {
  591. QString nativeProjPath(QDir::toNativeSeparators(projectPath));
  592. auto projectIter = m_requiresBuild.begin();
  593. for (; projectIter != m_requiresBuild.end(); ++projectIter)
  594. {
  595. if (QDir::toNativeSeparators(projectIter->m_path) == nativeProjPath)
  596. {
  597. break;
  598. }
  599. }
  600. return projectIter;
  601. }
  602. bool ProjectsScreen::BuildQueueContainsProject(const QString& projectPath)
  603. {
  604. QString nativeProjPath(QDir::toNativeSeparators(projectPath));
  605. for (const ProjectInfo& project : m_buildQueue)
  606. {
  607. if (QDir::toNativeSeparators(project.m_path) == nativeProjPath)
  608. {
  609. return true;
  610. }
  611. }
  612. return false;
  613. }
  614. bool ProjectsScreen::WarnIfInBuildQueue(const QString& projectPath)
  615. {
  616. if (BuildQueueContainsProject(projectPath))
  617. {
  618. QMessageBox::warning(
  619. this,
  620. tr("Action Temporarily Disabled!"),
  621. tr("Action not allowed on projects in build queue."));
  622. return true;
  623. }
  624. return false;
  625. }
  626. } // namespace O3DE::ProjectManager