Преглед изворни кода

Refresh projects screen if there has been an update to the projects folder.

Signed-off-by: AMZN-Phil <[email protected]>
AMZN-Phil пре 3 година
родитељ
комит
54b514e028

+ 12 - 0
Code/Tools/ProjectManager/Source/ProjectsScreen.cpp

@@ -44,6 +44,7 @@
 #include <QQueue>
 #include <QDir>
 #include <QGuiApplication>
+#include <QFileSystemWatcher>
 
 namespace O3DE::ProjectManager
 {
@@ -55,6 +56,10 @@ namespace O3DE::ProjectManager
         vLayout->setContentsMargins(s_contentMargins, 0, s_contentMargins, 0);
         setLayout(vLayout);
 
+        m_fileSystemWatcher = new QFileSystemWatcher(this);
+        connect(m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &ProjectsScreen::HandleProjectDirectoryChanged);
+
+
         m_stack = new QStackedWidget(this);
 
         m_firstTimeContent = CreateFirstTimeContent();
@@ -276,6 +281,7 @@ namespace O3DE::ProjectManager
                 {
                     currentButton = CreateProjectButton(project);
                     m_projectButtons.insert(QDir::toNativeSeparators(project.m_path), currentButton);
+                    m_fileSystemWatcher->addPath(QDir::toNativeSeparators(project.m_path + '/'));
                 }
                 else
                 {
@@ -346,6 +352,12 @@ namespace O3DE::ProjectManager
         m_projectsFlowLayout->update();
     }
 
+    void ProjectsScreen::HandleProjectDirectoryChanged(const QString& /*path*/)
+    {
+        // QFileWatcher automatically stops watching the path if it was removed so we will just refresh our view
+        ResetProjectsContent();
+    }
+
     ProjectManagerScreen ProjectsScreen::GetScreenEnum()
     {
         return ProjectManagerScreen::Projects;

+ 4 - 0
Code/Tools/ProjectManager/Source/ProjectsScreen.h

@@ -19,6 +19,7 @@ QT_FORWARD_DECLARE_CLASS(QFrame)
 QT_FORWARD_DECLARE_CLASS(QStackedWidget)
 QT_FORWARD_DECLARE_CLASS(QLayout)
 QT_FORWARD_DECLARE_CLASS(FlowLayout)
+QT_FORWARD_DECLARE_CLASS(QFileSystemWatcher)
 
 namespace O3DE::ProjectManager
 {
@@ -59,6 +60,8 @@ namespace O3DE::ProjectManager
 
         void paintEvent(QPaintEvent* event) override;
 
+        void HandleProjectDirectoryChanged(const QString& path);
+
     private:
         QFrame* CreateFirstTimeContent();
         QFrame* CreateProjectsContent();
@@ -78,6 +81,7 @@ namespace O3DE::ProjectManager
         QFrame* m_firstTimeContent = nullptr;
         QFrame* m_projectsContent = nullptr;
         FlowLayout* m_projectsFlowLayout = nullptr;
+        QFileSystemWatcher* m_fileSystemWatcher = nullptr;
         QStackedWidget* m_stack = nullptr;
         QHash<QString, ProjectButton*> m_projectButtons;
         QList<ProjectInfo> m_requiresBuild;