From 506ada2d1b8c2d190f3f313416a35703214de2f2 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Fri, 18 Nov 2016 20:00:01 -0500
Subject: [PATCH] fix dialog closing logic so that there aren't any dangling
 gfxstubs left on the Pd side

---
 pd/nw/dialog_canvas.html | 5 +----
 pd/nw/dialog_data.html   | 5 +----
 pd/nw/dialog_font.html   | 5 +----
 pd/nw/dialog_gatom.html  | 5 +----
 pd/nw/dialog_iemgui.html | 5 +----
 pd/nw/dialog_prefs.html  | 2 +-
 pd/nw/dialog_text.html   | 4 ++--
 pd/nw/pdgui.js           | 2 +-
 8 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/pd/nw/dialog_canvas.html b/pd/nw/dialog_canvas.html
index ecc295c9d..c66ca6a7b 100644
--- a/pd/nw/dialog_canvas.html
+++ b/pd/nw/dialog_canvas.html
@@ -753,10 +753,7 @@ function add_events(name) {
     // closing the Window
     gui.Window.get().on("close", function() {
         // this needs to do whatever the "cancel" button does
-        //pdgui.pdsend(name + " menuclose 0");
-        //cancel();
-        pdgui.remove_dialogwin(pd_object_callback);
-        gui.Window.get().close(true);
+        cancel();
     });
     pdgui.dialog_bindings(name);
 }
diff --git a/pd/nw/dialog_data.html b/pd/nw/dialog_data.html
index 9f7b1ba5a..1fcaf0b16 100644
--- a/pd/nw/dialog_data.html
+++ b/pd/nw/dialog_data.html
@@ -360,10 +360,7 @@ function add_events(name) {
     // closing the Window
     gui.Window.get().on("close", function () {
         // this needs to do whatever the "cancel" button does
-        //pdgui.pdsend(name, "menuclose 0");
-        //cancel();
-        pdgui.remove_dialogwin(pd_object_callback);
-        gui.Window.get().close(true);
+        cancel();
     });
     pdgui.dialog_bindings(name);
 }
diff --git a/pd/nw/dialog_font.html b/pd/nw/dialog_font.html
index d4cddce41..3cd6fd8cc 100644
--- a/pd/nw/dialog_font.html
+++ b/pd/nw/dialog_font.html
@@ -177,10 +177,7 @@ function add_events(name) {
     // closing the Window
     gui.Window.get().on("close", function () {
         // this needs to do whatever the "cancel" button does
-        //pdgui.pdsend(name, "menuclose 0");
-        //cancel();
-        pdgui.remove_dialogwin(pd_object_callback);
-        gui.Window.get().close(true);
+        cancel();
     });
     pdgui.dialog_bindings(name);
 }
diff --git a/pd/nw/dialog_gatom.html b/pd/nw/dialog_gatom.html
index 60e87cb26..fd9494713 100644
--- a/pd/nw/dialog_gatom.html
+++ b/pd/nw/dialog_gatom.html
@@ -322,10 +322,7 @@ function add_events(name) {
     // closing the Window
     gui.Window.get().on("close", function() {
         // this needs to do whatever the "cancel" button does
-        //pdgui.pdsend(name, "menuclose 0");
-        //cancel();
-        pdgui.remove_dialogwin(pd_object_callback);
-        gui.Window.get().close(true);
+        cancel(false);
     });
     pdgui.dialog_bindings(name);
 }
diff --git a/pd/nw/dialog_iemgui.html b/pd/nw/dialog_iemgui.html
index 1a22fbe50..cf20d846b 100644
--- a/pd/nw/dialog_iemgui.html
+++ b/pd/nw/dialog_iemgui.html
@@ -618,10 +618,7 @@ function add_events(name) {
     // closing the Window
     gui.Window.get().on("close", function() {
         // this needs to do whatever the "cancel" button does
-        //pdgui.pdsend(name, "menuclose 0");
-        //cancel();
-        pdgui.remove_dialogwin(pd_object_callback);
-        gui.Window.get().close(true);
+        cancel(false);
     });
     pdgui.dialog_bindings(name);
 }
diff --git a/pd/nw/dialog_prefs.html b/pd/nw/dialog_prefs.html
index 26e4082f6..e3fc34166 100644
--- a/pd/nw/dialog_prefs.html
+++ b/pd/nw/dialog_prefs.html
@@ -787,9 +787,9 @@ function add_events(name) {
 
     // closing the Window
     gui.Window.get().on("close", function() {
-        // this needs to do whatever the "cancel" button does
         pdgui.remove_dialogwin(pd_object_callback);
         gui.Window.get().close(true);
+        //cancel();
     });
     pdgui.dialog_bindings(name);
 }
diff --git a/pd/nw/dialog_text.html b/pd/nw/dialog_text.html
index e995e469c..b5bc5d5b4 100644
--- a/pd/nw/dialog_text.html
+++ b/pd/nw/dialog_text.html
@@ -139,8 +139,8 @@ function translate_form() {
 
 function close_window() {
     pdgui.pdsend(pd_object_callback, "close");
-    pdgui.remove_dialogwin(pd_object_callback);
-    gui.Window.get().close(true);
+    //pdgui.remove_dialogwin(pd_object_callback);
+    //gui.Window.get().close(true);
 }
 
 function close_from_pd(signoff) {
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index f88d4c8b6..24628ce80 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -4258,7 +4258,7 @@ function gui_text_dialog_close_from_pd(did, signoff) {
 
 function gui_remove_gfxstub(did) {
     if (dialogwin[did] !== undefined && dialogwin[did] !== null) {
-        dialogwin[did].window.close(true);
+        dialogwin[did].close(true);
         dialogwin[did] = null;
     }
 }
-- 
GitLab