From e9e494f82fd629b8edbae338dc342ec9bb0fd6d4 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Thu, 21 Jan 2016 21:52:38 -0500
Subject: [PATCH] port from pd-l2ork git:
 dec64e0cbf4ab24f5c7e33e5b3884d2cdc6dcbf9 *Reverted
 http://sourceforge.net/p/pure-data/pure-data/ci/97851b3c44b2b3839069928d90ca6185de4455c5/
 as it disables ability to address abstractions via scripting (needs further
 testing to figure out why was this disabled in the first place and then later
 reverted by Miller) *fixed way of vis-ing GOP-enabled abstractions via script

---
 pd/src/g_canvas.c | 17 ++++++++++-------
 pd/src/g_editor.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/pd/src/g_canvas.c b/pd/src/g_canvas.c
index 5a0e2bada..954cf5066 100644
--- a/pd/src/g_canvas.c
+++ b/pd/src/g_canvas.c
@@ -833,28 +833,30 @@ void canvas_redraw(t_canvas *x)
     own window. */
 void glist_menu_open(t_glist *x)
 {
-    if (glist_isvisible(x))
+    /* 20151230: moved to canvas_vis, so that scripted vis calls (e.g. via
+       [send pd-abstraction-name.pd] do proper redraws of abstractions */
+    /*if (glist_isvisible(x))
     {
         if (!glist_istoplevel(x))
         {
             t_glist *gl2 = x->gl_owner;
             if (!gl2) 
-                bug("glist_menu_open"); /* shouldn't happen but not dangerous */
+                bug("glist_menu_open"); // shouldn't happen but not dangerous
             else
             {
-                /* erase ourself in parent window */
+                // erase ourself in parent window
                 gobj_vis(&x->gl_gobj, gl2, 0);
-                /* get rid of our editor (and subeditors) */
+                // get rid of our editor (and subeditors)
                 if (x->gl_editor)
                     canvas_destroy_editor(x);
                 x->gl_havewindow = 1;
-                /* redraw ourself in parent window (blanked out this time) */
+                // redraw ourself in parent window (blanked out this time)
                 gobj_vis(&x->gl_gobj, gl2, 1);
             }
         }
         else
         {
-            /* Not sure if this needs to get ported... need to test */
+            // Not sure if this needs to get ported... need to test
             //sys_vgui("focus .x%lx\n", (t_int)x);
         }
     }
@@ -863,6 +865,7 @@ void glist_menu_open(t_glist *x)
         if (x->gl_editor)
         canvas_destroy_editor(x);
     }
+    */
     canvas_vis(x, 1);
 }
 
@@ -1424,7 +1427,7 @@ static int canvas_should_bind(t_canvas *x)
 {
         /* FIXME should have a "backwards compatible" mode */
         /* not named "Pd" && (is top level || is subpatch) */
-    return strcmp(x->gl_name->s_name, "Pd") && (!x->gl_owner || !x->gl_env);
+    return strcmp(x->gl_name->s_name, "Pd"); // && (!x->gl_owner || !x->gl_env);
 }
 
 static void canvas_bind(t_canvas *x)
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 74fd1bcb8..45f580321 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -2418,6 +2418,37 @@ void canvas_vis(t_canvas *x, t_floatarg f)
         }
         else
         {
+            // From glist_menu_open found in g_canvas.c to allow for
+            // vis scripting of GOP-enabled abstractions
+            if (glist_isvisible(x))
+            {
+                if (!glist_istoplevel(x))
+                {
+                    t_glist *gl2 = x->gl_owner;
+                    if (gl2) //changed from !gl2
+                        //bug("glist_menu_open"); /* shouldn't happen but not dangerous */
+                    //else
+                    {
+                        /* erase ourself in parent window */
+                        gobj_vis(&x->gl_gobj, gl2, 0);
+                        /* get rid of our editor (and subeditors) */
+                        if (x->gl_editor)
+                            canvas_destroy_editor(x);
+                        x->gl_havewindow = 1;
+                        /* redraw ourself in parent window (blanked out this time) */
+                        gobj_vis(&x->gl_gobj, gl2, 1);
+                    }
+                }
+                else
+                {
+                    sys_vgui("focus .x%lx\n", (t_int)x);
+                }
+            }
+            else
+            {
+                if (x->gl_editor)
+                canvas_destroy_editor(x);
+            }
             //fprintf(stderr,"new\n");
             canvas_create_editor(x);
             canvas_args_to_string(argsbuf, x);
-- 
GitLab