]> www.fi.muni.cz Git - evince.git/commitdiff
Disable copy action when there isn't text selected.
authorCarlos Garcia Campos <carlosgc@gnome.org>
Tue, 27 Sep 2005 12:50:42 +0000 (12:50 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Tue, 27 Sep 2005 12:50:42 +0000 (12:50 +0000)
2005-09-27  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-view.[ch], shell/ev-window.c: Disable copy action when
there isn't text selected.

ChangeLog
shell/ev-view.c
shell/ev-view.h
shell/ev-window.c

index 7577d805789a72d9f5e2097537466949e58b67f7..21eee4a7ecb3c20d827c7e8f10fa412883c0362d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-09-27  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-view.[ch], shell/ev-window.c: Disable copy action when
+       there isn't text selected.
+
 2005-09-27  Marco Pesenti Gritti  <mpg@redhat.com>
 
        * shell/ev-view.c: (handle_link_over_xy):
index fe84912335a05511b5593967275f7f84c97a6695..6f87b6a63cb176e2c3c1d8d29de9c8dba77769fa 100644 (file)
@@ -56,6 +56,7 @@ enum {
        PROP_SIZING_MODE,
        PROP_ZOOM,
        PROP_ROTATION,
+       PROP_HAS_SELECTION,
 };
 
 enum {
@@ -1117,7 +1118,8 @@ location_in_selected_text (EvView  *view,
                if (page != selection->page)
                        continue;
                
-               if (gdk_region_point_in (selection->covered_region, x_offset, y_offset))
+               if (selection->covered_region &&
+                   gdk_region_point_in (selection->covered_region, x_offset, y_offset))
                        return TRUE;
        }
 
@@ -2332,6 +2334,10 @@ ev_view_get_property (GObject *object,
        case PROP_ROTATION:
                g_value_set_int (value, view->rotation);
                break;
+       case PROP_HAS_SELECTION:
+               g_value_set_boolean (value,
+                                    view->selection_info.selections != NULL);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        }
@@ -2478,6 +2484,13 @@ ev_view_class_init (EvViewClass *class)
                                                               360,
                                                               0,
                                                               G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_HAS_SELECTION,
+                                        g_param_spec_boolean ("has-selection",
+                                                              "Has selection",
+                                                              "The view has selections",
+                                                              FALSE,
+                                                              G_PARAM_READABLE));
 
        binding_set = gtk_binding_set_by_class (class);
 
@@ -2498,6 +2511,7 @@ ev_view_init (EvView *view)
        view->pressed_button = -1;
        view->cursor = EV_VIEW_CURSOR_NORMAL;
        view->drag_info.in_drag = FALSE;
+       view->selection_info.selections = NULL;
        view->selection_info.in_selection = FALSE;
        view->selection_info.in_drag = FALSE;
        view->selection_mode = EV_VIEW_SELECTION_TEXT;
@@ -3531,6 +3545,7 @@ merge_selection_region (EvView *view,
        g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
        view->selection_info.selections = new_list;
        ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, new_list);
+       g_object_notify (G_OBJECT (view), "has-selection");
 
        new_list_ptr = new_list;
        old_list_ptr = old_list;
@@ -3661,6 +3676,7 @@ clear_selection (EvView *view)
        g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
        view->selection_info.selections = NULL;
        view->selection_info.in_selection = FALSE;
+       g_object_notify (G_OBJECT (view), "has-selection");
 }
 
 
@@ -3695,9 +3711,16 @@ ev_view_select_all (EvView *view)
        }
 
        ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, view->selection_info.selections);
+       g_object_notify (G_OBJECT (view), "has-selection");
        gtk_widget_queue_draw (GTK_WIDGET (view));
 }
 
+gboolean
+ev_view_get_has_selection (EvView *view)
+{
+       return view->selection_info.selections != NULL;
+}
+
 static char *
 get_selected_text (EvView *ev_view)
 {
index 77914929413e52b18065eecbd19c38471bb24daf..ade26852ac8cb98e11adff6c01d85edded5896bb 100644 (file)
@@ -63,6 +63,7 @@ void          ev_view_set_document      (EvView         *view,
 /* Clipboard */
 void           ev_view_copy              (EvView         *view);
 void           ev_view_select_all        (EvView         *view);
+gboolean        ev_view_get_has_selection (EvView         *view);
 
 /* sizing and behavior */
 /* These are all orthoganal to each other, except 'presentation' trumps all
index 5b832c553af6d6b376b59d61d1b1b34bb0f75e8d..295af44e3d0d3cb8db0ad4b8ce6363488b9adc4f 100644 (file)
@@ -219,6 +219,8 @@ update_action_sensitivity (EvWindow *ev_window)
        gboolean ok_to_copy = TRUE;
        gboolean has_properties = TRUE;
        gboolean override_restrictions = FALSE;
+       gboolean can_get_text = FALSE;
+       gboolean ok_to_copy_text = FALSE;
        GConfClient *client;
 
        view = EV_VIEW (ev_window->priv->view);
@@ -263,6 +265,11 @@ update_action_sensitivity (EvWindow *ev_window)
        
        g_object_unref (client);
 
+       if (has_document && ev_document_can_get_text (document)) {
+               can_get_text = TRUE;
+               ok_to_copy_text = ev_view_get_has_selection (view);
+       }
+       
        /* File menu */
        /* "FileOpen": always sensitive */
        set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
@@ -272,8 +279,8 @@ update_action_sensitivity (EvWindow *ev_window)
 
         /* Edit menu */
        sensitive = has_pages && ev_document_can_get_text (document);
-       set_action_sensitive (ev_window, "EditCopy", sensitive && ok_to_copy);
-       set_action_sensitive (ev_window, "EditSelectAll", sensitive && ok_to_copy);
+       set_action_sensitive (ev_window, "EditCopy", sensitive && ok_to_copy_text);
+       set_action_sensitive (ev_window, "EditSelectAll", sensitive && can_get_text);
        set_action_sensitive (ev_window, "EditFind",
                              has_pages && EV_IS_DOCUMENT_FIND (document));
        set_action_sensitive (ev_window, "Slash",
@@ -2423,6 +2430,12 @@ ev_window_rotation_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *window
                                       rotation);
 }
 
+static void
+ev_window_has_selection_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *window)
+{
+       update_action_sensitivity (window);
+}
+
 static void     
 ev_window_dual_mode_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window)
 {
@@ -3459,6 +3472,10 @@ ev_window_init (EvWindow *ev_window)
                          "notify::rotation",
                          G_CALLBACK (ev_window_rotation_changed_cb),
                          ev_window);
+       g_signal_connect (ev_window->priv->view,
+                         "notify::has-selection",
+                         G_CALLBACK (ev_window_has_selection_changed_cb),
+                         ev_window);
 
        ev_window->priv->find_bar = egg_find_bar_new ();
        gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box),