From 83765dcebf6e946916cdefd67bcd9d7575371ae1 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Thu, 6 Mar 2025 16:17:04 -0500
Subject: [PATCH] view-coordinator: use the view name to destroy dialogs

In the case of a unique view, we need to use the view name used in
the viewmanager to destroy the dialog. This is now provided by the
viewName parameter of the callback used when creating the dialog.

Gitlab: #1938
Change-Id: I3645fc1c7fda44eea9fde8d9d5886647820685ea
---
 src/app/ViewCoordinator.qml | 4 ++--
 src/app/ViewManager.qml     | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/app/ViewCoordinator.qml b/src/app/ViewCoordinator.qml
index b2617881..1012ac42 100644
--- a/src/app/ViewCoordinator.qml
+++ b/src/app/ViewCoordinator.qml
@@ -99,9 +99,9 @@ QtObject {
     function presentDialog(parent, path, props = {}, singleInstance = false) {
         // Open the dialog once the object is created
         let createFunc = singleInstance ? viewManager.createView : viewManager.createUniqueView;
-        return createFunc(path, parent, function (obj) {
+        return createFunc(path, parent, function (obj, viewName) {
                 const doneCb = function () {
-                    viewManager.destroyView(path);
+                    viewManager.destroyView(viewName);
                 };
                 if (obj.closed !== undefined) {
                     obj.closed.connect(doneCb);
diff --git a/src/app/ViewManager.qml b/src/app/ViewManager.qml
index f61e2669..c6db3541 100644
--- a/src/app/ViewManager.qml
+++ b/src/app/ViewManager.qml
@@ -59,7 +59,7 @@ QtObject {
         if (views.hasOwnProperty(viewName)) {
             // an instance of the view already exists
             if (cb !== null) {
-                cb(views[viewName])
+                cb(views[viewName], viewName)
             }
             return views[viewName]
         }
@@ -76,7 +76,7 @@ QtObject {
                 viewName.replace(/^.*[\\\/]/, '').replace(/\.[^/.]+$/, "")
             viewPaths[friendlyName] = viewName
             if (cb !== null) {
-                cb(obj)
+                cb(obj , viewName)
             }
             return views[viewName]
         }
@@ -103,6 +103,7 @@ QtObject {
     function destroyView(path) {
         // The view may already have been destroyed.
         if (!views.hasOwnProperty(path)) {
+            console.warn("View not found:", path, "Available views:", Object.keys(views))
             return false
         }
         views[path].destroy()
-- 
GitLab