From e96df9e9943b42286e2746eed150d9c1c804470b Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Fri, 14 Aug 2015 17:52:58 -0400
Subject: [PATCH] ported: "*fixed copying dialog text and pasting it onto a
 canvas crasher" from pd-l2ork: 96e2fa5605a2d87ab99c5c2c8df9bca53c23c401

---
 pd/nw/todo.txt    | 2 ++
 pd/src/g_editor.c | 5 +++++
 pd/src/m_glob.c   | 5 +++++
 pd/src/pd.tk      | 9 +++++++--
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/pd/nw/todo.txt b/pd/nw/todo.txt
index ffbd7bd59..b7b5af2b9 100644
--- a/pd/nw/todo.txt
+++ b/pd/nw/todo.txt
@@ -253,6 +253,8 @@ Everything else: (A [x] means we've fixed it)
     will not get ported.
 [ ] same for "*fixed font positioning on 14.04+ releases"
     9edc6ca98e141174b86ebe5cdf406fe7e47845d5
+    NB: this commit affects the old GUI.  Need to revisit it with the new
+    one to see whether it's still necessary.
 [ ] same for "*fixed copying dialog text and pasting it onto a canvas crasher"
     96e2fa5605a2d87ab99c5c2c8df9bca53c23c401
 [ ] same for "*revamped arduino connectivity to use Firmata firmware and allow for"
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index f3efc7bcd..2f620ffba 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -5972,6 +5972,11 @@ static void canvas_copyfromexternalbuffer(t_canvas *x, t_symbol *s,
     }
 }
 
+void glob_clipboard_text(t_pd *dummy, float f)
+{
+    clipboard_istext = (int)f;
+}
+
 static void canvas_copy(t_canvas *x)
 {
     if (!x->gl_editor || !x->gl_editor->e_selection)
diff --git a/pd/src/m_glob.c b/pd/src/m_glob.c
index 028d46245..db6f64d6a 100644
--- a/pd/src/m_glob.c
+++ b/pd/src/m_glob.c
@@ -71,6 +71,9 @@ static void glob_perf(t_pd *dummy, float f)
     sys_perf = (f != 0);
 }
 
+// ths one lives inside g_editor so that it can access the clipboard
+extern void glob_clipboard_text(t_pd *dummy, float f);
+
 void max_default(t_pd *x, t_symbol *s, int argc, t_atom *argv)
 {
     int i;
@@ -142,6 +145,8 @@ void glob_init(void)
         gensym("version"), A_FLOAT, 0);
     class_addmethod(glob_pdobject, (t_method)glob_perf,
         gensym("perf"), A_FLOAT, 0);
+    class_addmethod(glob_pdobject, (t_method)glob_clipboard_text,
+        gensym("clipboardtext"), A_FLOAT, 0);
 #ifdef UNIX
     class_addmethod(glob_pdobject, (t_method)glob_watchdog,
         gensym("watchdog"), 0);
diff --git a/pd/src/pd.tk b/pd/src/pd.tk
index 65868a8b2..108a87685 100644
--- a/pd/src/pd.tk
+++ b/pd/src/pd.tk
@@ -1022,6 +1022,8 @@ proc pdtk_panelkeybindings {id panelname} {
     bind $id <KeyPress-Escape> [format "%s_cancel %s" $panelname $id]
     bind $id <KeyPress-Return> [format "%s_ok %s" $panelname $id]
     bind $id <$ctrl_key-Key-w> [format "%s_cancel %s" $panelname $id]
+    bind $id <$ctrl_key-Key-x> [format "menu_cut %s" $id]
+    bind $id <$ctrl_key-Key-c> [format "menu_copy %s" $id]
 }
 
 pdtk_standardkeybindings .
@@ -2021,6 +2023,7 @@ proc menu_redo {name} {
 }
 
 proc menu_cut {name} {
+	#puts stderr "menu_cut $name"
 	global copytexttocanvas
 	if {![string match .gfxstub* $name] && ![string match .printout* $name] && ![string match *entry $name]} {
 		pd [concat $name cut \;]
@@ -2029,12 +2032,13 @@ proc menu_cut {name} {
 		clipboard clear
 	} else {
 		set copytexttocanvas 1
+		pd [concat pd clipboardtext  1 \;]
 	}
 	pdtk_canvas_update_paste_menu 1
 }
 
 proc menu_copy {name} {
-	# pdtk_post menu_copy
+	#puts stderr menu_copy
 	global copytexttocanvas
 	if {![string match .gfxstub* $name] && ![string match .printout* $name] && ![string match *entry $name]} {
 	    pd [concat $name copy \;]
@@ -2042,7 +2046,8 @@ proc menu_copy {name} {
 		clipboard clear
 	} else {
 		# pdtk_post "this_is_text\n"
-		set copytexttocanvas 1
+		set clipboardtext 1
+		pd [concat pd clipboardtext 1 \;]
 	}
 	pdtk_canvas_update_paste_menu 1
 }
-- 
GitLab