فهرست منبع

don't add gem version multiple times

misc cleanup

Signed-off-by: Alex Peterson <[email protected]>
Alex Peterson 2 سال پیش
والد
کامیت
f9e8be24a8

+ 14 - 13
Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp

@@ -109,21 +109,20 @@ namespace O3DE::ProjectManager
         GemListHeaderWidget* catalogHeaderWidget = new GemListHeaderWidget(m_proxyModel);
         connect(catalogHeaderWidget, &GemListHeaderWidget::OnRefresh, this, &GemCatalogScreen::Refresh);
 
-        constexpr int GemImageHeaderWidth = GemItemDelegate::s_itemMargins.left() + GemPreviewImageWidth +
+        constexpr int previewWidth = GemItemDelegate::s_itemMargins.left() + GemPreviewImageWidth +
                                             AdjustableHeaderWidget::s_headerTextIndent;
-        constexpr int GemVersionHeaderWidth = GemItemDelegate::s_versionSize + GemItemDelegate::s_versionSizeSpacing;
-        constexpr int GemStatusHeaderWidth = GemItemDelegate::s_statusIconSize + GemItemDelegate::s_statusButtonSpacing +
+        constexpr int versionWidth = GemItemDelegate::s_versionSize + GemItemDelegate::s_versionSizeSpacing;
+        constexpr int statusWidth = GemItemDelegate::s_statusIconSize + GemItemDelegate::s_statusButtonSpacing +
                                              GemItemDelegate::s_buttonWidth + GemItemDelegate::s_contentMargins.right();
-        constexpr int minHeaderSectionWidth = AZStd::min(GemImageHeaderWidth, AZStd::min(GemVersionHeaderWidth, GemStatusHeaderWidth));
+        constexpr int minHeaderSectionWidth = AZStd::min(previewWidth, AZStd::min(versionWidth, statusWidth));
 
-        //constexpr int itemLeftMargin = k
         AdjustableHeaderWidget* listHeaderWidget = new AdjustableHeaderWidget(
             QStringList{ tr("Gem Image"), tr("Gem Name"), tr("Gem Summary"), tr("Version"), tr("Status") },
-            QVector<int>{ GemImageHeaderWidth,
-                          GemItemDelegate::s_defaultSummaryStartX - GemImageHeaderWidth,
+            QVector<int>{ previewWidth,
+                          GemItemDelegate::s_defaultSummaryStartX - previewWidth,
                           0, // Section is set to stretch to fit
-                          GemVersionHeaderWidth,
-                          GemStatusHeaderWidth},
+                          versionWidth,
+                          statusWidth},
             minHeaderSectionWidth,
             QVector<QHeaderView::ResizeMode>{ QHeaderView::ResizeMode::Fixed,
                                               QHeaderView::ResizeMode::Interactive,
@@ -377,14 +376,16 @@ namespace O3DE::ProjectManager
             QString notification;
             if (gemStateChanged)
             {
-                QString version = GemModel::GetNewVersion(modelIndex);
-                if (version.isEmpty())
+                const GemInfo& gemInfo = GemModel::GetGemInfo(modelIndex);
+                const QString& displayName = GemModel::GetDisplayName(modelIndex);
+                const QString& newVersion = GemModel::GetNewVersion(modelIndex);
+                if (gemInfo.m_isEngineGem || (gemInfo.m_version.isEmpty() && newVersion.isEmpty()))
                 {
-                    notification = GemModel::GetDisplayName(modelIndex);
+                    notification = displayName;
                 } 
                 else
                 {
-                    notification = QString("%1 %2").arg(GemModel::GetDisplayName(modelIndex), version);
+                    notification = QString("%1 %2").arg(displayName, newVersion.isEmpty() ? gemInfo.m_version : newVersion);
                 }
 
                 if (numChangedDependencies > 0)

+ 1 - 1
Code/Tools/ProjectManager/Source/GemCatalog/GemInspector.cpp

@@ -81,7 +81,7 @@ namespace O3DE::ProjectManager
         }
     }
 
-    void GemInspector::Update(const QModelIndex& modelIndex, [[maybe_unused]] const QString& version)
+    void GemInspector::Update(const QModelIndex& modelIndex, const QString& version)
     {
         m_curModelIndex = modelIndex;
 

+ 33 - 4
Code/Tools/ProjectManager/Source/GemCatalog/GemModel.cpp

@@ -7,7 +7,6 @@
  */
 
 #include <AzCore/std/string/string.h>
-#include <AzCore/IO/Path/Path.h>
 #include <AzCore/Dependency/Dependency.h>
 #include <GemCatalog/GemModel.h>
 #include <GemCatalog/GemSortFilterProxyModel.h>
@@ -59,7 +58,38 @@ namespace O3DE::ProjectManager
         }
         QVariant gemVariant;
         gemVariant.setValue(gemInfo);
-        versionList.append(gemVariant);
+
+        // sanity check we aren't adding a gem with an existing path and version
+        int versionToReplaceIndex = -1;
+        for (int i = 0; i < versionList.size(); ++i)
+        {
+            const QVariant& existingGemVariant = versionList.at(i);
+            const GemInfo& existingGemInfo = existingGemVariant.value<GemInfo>();
+            if (existingGemInfo.m_path == gemInfo.m_path)
+            {
+                if (existingGemInfo.m_version == gemInfo.m_version)
+                {
+                    AZ_Info("ProjectManager", "Not adding GemInfo because a GemInfo with path (%s) and version (%s) already exists.",
+                        gemInfo.m_path.toUtf8().constData(),
+                        gemInfo.m_version.toUtf8().constData()
+                        );
+                    return;
+                }
+
+                // the path is the same but the version has changed, update the info
+                versionToReplaceIndex = i;
+                break;
+            }
+        }
+
+        if(versionToReplaceIndex != -1)
+        {
+            versionList.replace(versionToReplaceIndex, gemVariant);
+        }
+        else
+        {
+            versionList.append(gemVariant);
+        }
         item->setData(versionList, GemModel::RoleGemInfoVersions);
     }
 
@@ -154,7 +184,7 @@ namespace O3DE::ProjectManager
                     // make sure the gem item delegate displays the correct version info 
                     for (auto versionVariant : versionList)
                     {
-                        if (auto gemInfo = versionVariant.value<GemInfo>(); gemPath == gemInfo.m_path)
+                        if (const auto& gemInfo = versionVariant.value<GemInfo>(); gemPath == gemInfo.m_path)
                         {
                             QStandardItem* gemItem = item(modelIndex.row(), modelIndex.column());
                             AZ_Assert(gemItem, "Failed to retrieve enabled gem item from model index");
@@ -289,7 +319,6 @@ namespace O3DE::ProjectManager
             // if no version is provided, try to find the one that matches the current version
             if (version == variantVersion || (version.isEmpty() && gemVersion == variantVersion))
             {
-                // NOTE this gem info does not include any updates to m_isAdded or m_version
                 return versionVariant.value<GemInfo>();
             }
         }

+ 1 - 1
Code/Tools/ProjectManager/Source/PythonBindings.cpp

@@ -755,7 +755,7 @@ namespace O3DE::ProjectManager
             return AZ::Failure(result.GetError().c_str());
         }
 
-        // This sort will sort by display name and then by version for all gems with matching names
+        // this sorts by gem name and version
         AZStd::sort(gems.begin(), gems.end());
         return AZ::Success(AZStd::move(gems));
     }

+ 0 - 1
scripts/o3de/o3de/project_manager_interface.py

@@ -290,7 +290,6 @@ def get_all_gem_infos(project_path: pathlib.Path or None) -> list:
     # running out of
     engine_path = manifest.get_project_engine_path(project_path=project_path) if project_path else manifest.get_this_engine_path() 
     for i, gem_json_data in enumerate(all_gem_json_data):
-        logger.warning(f'{gem_json_data["path"]}')
         all_gem_json_data[i]['engine_gem'] = engine_path in gem_json_data['path'].parents
 
     return all_gem_json_data