Browse Source

Fix resetting when Marketplace is closed and re-opened

Previously, this would cause the Marketplace to freeze. We're still not entirely sure why. It seems to be a bug in Qt, but it's rather hard to deal with.

This new solution is nicer in some ways but not as neat in others.
- We're no longer clearing the content of the loader, so the QML and the package data remains in memory while the Marketplace is closed. We deem this to not be a problem, because the memory usage of this package data is only a couple of kB, nothing compared to the memory used by the slicer when it loads a model.
- On the other hand, it's now possible to programmatically change the tab there, instead of manually having to click the buttons.
- Fixes a bug where the highlighted tab of of the tab bar doesn't update when closing and re-opening the Marketplace. And a bug where there was a search bar for the manage page while it didn't work.

Contributes to issue CURA-8565.
Ghostkeeper 3 years ago
parent
commit
cd09af885d
1 changed files with 21 additions and 15 deletions
  1. 21 15
      plugins/Marketplace/resources/qml/Marketplace.qml

+ 21 - 15
plugins/Marketplace/resources/qml/Marketplace.qml

@@ -21,8 +21,14 @@ Window
     width: minimumWidth
     height: minimumHeight
 
-    // Set and unset the content. No need to keep things in memory if it's not visible.
-    onVisibleChanged: content.source = visible ? "Plugins.qml" : ""
+    onVisibleChanged:
+    {
+        pageSelectionTabBar.currentIndex = 0; //Go back to the initial tab.
+        while(contextStack.depth > 1)
+        {
+            contextStack.pop(); //Do NOT use the StackView.Immediate transition here, since it causes the window to stay empty. Seemingly a Qt bug: https://bugreports.qt.io/browse/QTBUG-60670?
+        }
+    }
 
     Connections
     {
@@ -116,33 +122,33 @@ Window
                             spacing: 0
                             background: Rectangle { color: "transparent" }
 
+                            onCurrentIndexChanged:
+                            {
+                                searchBar.text = "";
+                                searchBar.visible = currentItem.hasSearch;
+                                content.source = currentItem.sourcePage;
+                            }
+
                             PackageTypeTab
                             {
                                 id: pluginTabText
                                 width: implicitWidth
                                 text: catalog.i18nc("@button", "Plugins")
-                                onClicked:
-                                {
-                                    searchBar.text = ""
-                                    searchBar.visible = true
-                                    content.source = "Plugins.qml"
-                                }
+                                property string sourcePage: "Plugins.qml"
+                                property bool hasSearch: true
                             }
                             PackageTypeTab
                             {
                                 id: materialsTabText
                                 width: implicitWidth
                                 text: catalog.i18nc("@button", "Materials")
-                                onClicked:
-                                {
-                                    searchBar.text = ""
-                                    searchBar.visible = true
-                                    content.source = "Materials.qml"
-                                }
+                                property string sourcePage: "Materials.qml"
+                                property bool hasSearch: true
                             }
                             ManagePackagesButton
                             {
-                                onClicked: content.source = "ManagedPackages.qml"
+                                property string sourcePage: "ManagedPackages.qml"
+                                property bool hasSearch: false
                             }
                         }