[glom/glom-1-20] App_WithDoc_Gtk: Simple clipboard menu handlers: Handle GtkTextView



commit 0412bb7f3c8cfa2b6524620f467a8a7f61f99162
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Dec 29 22:37:55 2011 +0100

    App_WithDoc_Gtk: Simple clipboard menu handlers: Handle GtkTextView
    
    * glom/bakery/app_withdoc_gtk.cc: Add code to handle cut/copy/paste
    when GtkTextView is focused. This is tedious - see bug #667008 .

 ChangeLog                      |    7 +++++
 glom/bakery/app_withdoc_gtk.cc |   52 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b0fc63e..67f5940 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-12-29  Murray Cumming  <murrayc murrayc com>
 
+	App_WithDoc_Gtk: Simple clipboard menu handlers: Handle GtkTextView
+
+	* glom/bakery/app_withdoc_gtk.cc: Add code to handle cut/copy/paste
+	when GtkTextView is focused. This is tedious - see bug #667008 .
+
+2011-12-29  Murray Cumming  <murrayc murrayc com>
+
 	App_WithDoc_Gtk: Improve simple clipboard handlers.
 
 	* glom/bakery/app_withdoc_gtk.cc: Do not use C code. And therefore do
diff --git a/glom/bakery/app_withdoc_gtk.cc b/glom/bakery/app_withdoc_gtk.cc
index d161836..ccdb85e 100644
--- a/glom/bakery/app_withdoc_gtk.cc
+++ b/glom/bakery/app_withdoc_gtk.cc
@@ -26,6 +26,7 @@
 #include <gtkmm/messagedialog.h>
 #include <gtkmm/filechooserdialog.h>
 #include <gtkmm/editable.h>
+#include <gtkmm/textview.h>
 #include <giomm/file.h>
 #include <algorithm>
 #include <iostream>
@@ -577,7 +578,24 @@ void App_WithDoc_Gtk::on_menu_edit_copy_activate()
   Gtk::Editable* editable = dynamic_cast<Gtk::Editable*>(widget);
 
   if(editable)
+  {
     editable->copy_clipboard();
+    return;
+  }
+
+  //GtkTextView does not implement GtkTextView.
+  //See GTK+ bug: https://bugzilla.gnome.org/show_bug.cgi?id=667008
+  Gtk::TextView* textview = dynamic_cast<Gtk::TextView*>(widget);
+  if(textview)
+  {
+    Glib::RefPtr<Gtk::TextBuffer> buffer = textview->get_buffer();
+    if(buffer)
+    {
+      Glib::RefPtr<Gtk::Clipboard> clipboard = 
+        Gtk::Clipboard::get_for_display(get_display());
+      buffer->copy_clipboard(clipboard);
+    }
+  }
 }
 
 void App_WithDoc_Gtk::on_menu_edit_cut_activate()
@@ -586,7 +604,24 @@ void App_WithDoc_Gtk::on_menu_edit_cut_activate()
   Gtk::Editable* editable = dynamic_cast<Gtk::Editable*>(widget);
 
   if(editable)
+  {
     editable->cut_clipboard();
+    return;
+  }
+
+  //GtkTextView does not implement GtkTextView.
+  //See GTK+ bug: https://bugzilla.gnome.org/show_bug.cgi?id=667008
+  Gtk::TextView* textview = dynamic_cast<Gtk::TextView*>(widget);
+  if(textview)
+  {
+    Glib::RefPtr<Gtk::TextBuffer> buffer = textview->get_buffer();
+    if(buffer)
+    {
+      Glib::RefPtr<Gtk::Clipboard> clipboard = 
+        Gtk::Clipboard::get_for_display(get_display());
+      buffer->cut_clipboard(clipboard);
+    }
+  }
 }
 
 void App_WithDoc_Gtk::on_menu_edit_paste_activate()
@@ -595,7 +630,24 @@ void App_WithDoc_Gtk::on_menu_edit_paste_activate()
   Gtk::Editable* editable = dynamic_cast<Gtk::Editable*>(widget);
 
   if(editable)
+  {
     editable->paste_clipboard();
+    return;
+  }
+
+  //GtkTextView does not implement GtkTextView.
+  //See GTK+ bug: https://bugzilla.gnome.org/show_bug.cgi?id=667008
+  Gtk::TextView* textview = dynamic_cast<Gtk::TextView*>(widget);
+  if(textview)
+  {
+    Glib::RefPtr<Gtk::TextBuffer> buffer = textview->get_buffer();
+    if(buffer)
+    {
+      Glib::RefPtr<Gtk::Clipboard> clipboard = 
+        Gtk::Clipboard::get_for_display(get_display());
+      buffer->paste_clipboard(clipboard);
+    }
+  }
 }
 
 void App_WithDoc_Gtk::on_recent_files_activate(Gtk::RecentChooser& chooser)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]