]> Pileus Git - ~andy/gtk/commitdiff
make sure the has-selection property is updated when the delection is
authorPaolo Borelli <pborelli@katamail.com>
Thu, 17 Aug 2006 01:12:02 +0000 (01:12 +0000)
committerPaolo Borelli <pborelli@src.gnome.org>
Thu, 17 Aug 2006 01:12:02 +0000 (01:12 +0000)
2006-08-17  Paolo Borelli  <pborelli@katamail.com>

* gtk/gtktextbuffer.c: make sure the has-selection property is
updated when the delection is deleted. Bug #329752
* tests/testtext.c: add a copy menu item and show how to
update its sensitivity tracking the has-selection property.

ChangeLog
ChangeLog.pre-2-10
gtk/gtktextbuffer.c
tests/testtext.c

index af578676ea3ec9c8561ca0d833c5ca8fa84b940d..79a8fae4b008553e63d3be8b52a3d103159a3078 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
+2006-08-17  Paolo Borelli  <pborelli@katamail.com>
+
+       * gtk/gtktextbuffer.c: make sure the has-selection property is
+       updated when the delection is deleted. Bug #329752
+       * tests/testtext.c: add a copy menu item and show how to
+       update its sensitivity tracking the has-selection property.
+
 2006-08-17  Michael Emmel  <mike.emmel@gmail.com>
 
-       * configure.in  
+       * configure.in:
        Changed  to use cairo-directfb.pc bug #351519
 
 2006-08-17  Kristian Rietveld  <kris@gtk.org>
index af578676ea3ec9c8561ca0d833c5ca8fa84b940d..79a8fae4b008553e63d3be8b52a3d103159a3078 100644 (file)
@@ -1,6 +1,13 @@
+2006-08-17  Paolo Borelli  <pborelli@katamail.com>
+
+       * gtk/gtktextbuffer.c: make sure the has-selection property is
+       updated when the delection is deleted. Bug #329752
+       * tests/testtext.c: add a copy menu item and show how to
+       update its sensitivity tracking the has-selection property.
+
 2006-08-17  Michael Emmel  <mike.emmel@gmail.com>
 
-       * configure.in  
+       * configure.in:
        Changed  to use cairo-directfb.pc bug #351519
 
 2006-08-17  Kristian Rietveld  <kris@gtk.org>
index fa7f4980cf783c7d29a6cb3e267bd88ef1224765..3de0d792086ed0809c70f810f8f20d0f63b01df5 100644 (file)
@@ -1388,6 +1388,8 @@ gtk_text_buffer_real_delete_range (GtkTextBuffer *buffer,
                                    GtkTextIter   *start,
                                    GtkTextIter   *end)
 {
+  gboolean has_selection;
+
   g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
   g_return_if_fail (start != NULL);
   g_return_if_fail (end != NULL);
@@ -1397,6 +1399,13 @@ gtk_text_buffer_real_delete_range (GtkTextBuffer *buffer,
   /* may have deleted the selection... */
   update_selection_clipboards (buffer);
 
+  has_selection = gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL);
+  if (has_selection != buffer->has_selection)
+    {
+      buffer->has_selection = has_selection;
+      g_object_notify (G_OBJECT (buffer), "has-selection");
+    }
+
   g_signal_emit (buffer, signals[CHANGED], 0);
   g_object_notify (G_OBJECT (buffer), "cursor-position");
 }
@@ -1854,12 +1863,6 @@ gtk_text_buffer_set_mark (GtkTextBuffer *buffer,
                                    iter,
                                    should_exist);
   
-  if (_gtk_text_btree_mark_is_insert (get_btree (buffer), mark) ||
-      _gtk_text_btree_mark_is_selection_bound (get_btree (buffer), mark))
-    {
-      update_selection_clipboards (buffer);
-    }
-
   _gtk_text_btree_get_iter_at_mark (get_btree (buffer),
                                    &location,
                                    mark);
@@ -2200,7 +2203,6 @@ gtk_text_buffer_select_range (GtkTextBuffer     *buffer,
   gtk_text_buffer_mark_set (buffer, &real_bound,
                             gtk_text_buffer_get_mark (buffer,
                                                       "selection_bound"));
-  update_selection_clipboards (buffer);
 }
 
 /*
@@ -2306,6 +2308,8 @@ gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
     {
       gboolean has_selection;
 
+      update_selection_clipboards (buffer);
+    
       has_selection = gtk_text_buffer_get_selection_bounds (buffer,
                                                             NULL,
                                                             NULL);
index 27765e165f2a0984805a77e18e5db5e8cf8171e5..5ad9304bcac6f79acfc6274432b28394a595d168 100644 (file)
@@ -1582,6 +1582,20 @@ dialog_response_callback (GtkWidget *dialog, gint response_id, gpointer data)
   gtk_widget_destroy (dialog);
 }
 
+static void
+do_copy  (gpointer callback_data,
+          guint callback_action,
+          GtkWidget *widget)
+{
+  View *view = view_from_widget (widget);
+  GtkTextBuffer *buffer;
+
+  buffer = view->buffer->buffer;
+
+  gtk_text_buffer_copy_clipboard (buffer,
+                                  gtk_clipboard_get (GDK_NONE));
+}
+
 static void
 do_search (gpointer callback_data,
            guint callback_action,
@@ -1918,6 +1932,8 @@ static GtkItemFactoryEntry menu_items[] =
   { "/File/E_xit",      "<control>Q" , do_exit,     0, NULL },
 
   { "/_Edit", NULL, 0, 0, "<Branch>" },
+  { "/Edit/Copy", NULL, do_copy, 0, NULL },
+  { "/Edit/sep1", NULL, NULL, 0, "<Separator>" },
   { "/Edit/Find...", NULL, do_search, 0, NULL },
   { "/Edit/Select All", "<control>A", do_select_all, 0, NULL }, 
 
@@ -2843,11 +2859,19 @@ line_numbers_expose (GtkWidget      *widget,
   return FALSE;
 }
 
+static void
+selection_changed (GtkTextBuffer *buffer,
+                  GParamSpec    *pspec,
+                  GtkWidget     *copy_menu)
+{
+  gtk_widget_set_sensitive (copy_menu, gtk_text_buffer_get_has_selection (buffer));
+}
+
 static View *
 create_view (Buffer *buffer)
 {
   View *view;
-  
+  GtkWidget *copy_menu;
   GtkWidget *sw;
   GtkWidget *vbox;
   
@@ -2869,6 +2893,14 @@ create_view (Buffer *buffer)
   
   gtk_item_factory_create_items (view->item_factory, G_N_ELEMENTS (menu_items), menu_items, view);
 
+  /* make the Copy menu item sensitivity update according to the selection */
+  copy_menu = gtk_item_factory_get_item (view->item_factory, "<main>/Edit/Copy");
+  gtk_widget_set_sensitive (copy_menu, gtk_text_buffer_get_has_selection (view->buffer->buffer));
+  g_signal_connect (view->buffer->buffer,
+                   "notify::has-selection",
+                   G_CALLBACK (selection_changed),
+                   copy_menu);
+
   gtk_window_add_accel_group (GTK_WINDOW (view->window), view->accel_group);
 
   vbox = gtk_vbox_new (FALSE, 0);