]> git.sur5r.net Git - glabels/commitdiff
Control sensitivity of paste verb
authorJim Evins <evins@snaught.com>
Thu, 3 Dec 2009 00:59:50 +0000 (19:59 -0500)
committerJim Evins <evins@snaught.com>
Thu, 3 Dec 2009 00:59:50 +0000 (19:59 -0500)
Track the availability of data on the private glabels clipboard to control
the sensitivity of the paste verb.

src/ui.c
src/ui.h
src/window.c

index f7d0e9f8be46d6029f32d32fbbf1f5a60cfaf7d3..34b1121d0736c08d793bde924d699a7124274279 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -635,7 +635,6 @@ static gchar* doc_verbs [] = {
        "/ui/MenuBar/FileMenu/FileClose",
        "/ui/MenuBar/EditMenu/EditCut",
        "/ui/MenuBar/EditMenu/EditCopy",
-       "/ui/MenuBar/EditMenu/EditPaste",
        "/ui/MenuBar/EditMenu/EditDelete",
        "/ui/MenuBar/EditMenu/EditSelectAll",
        "/ui/MenuBar/EditMenu/EditUnSelectAll",
@@ -677,6 +676,12 @@ static gchar* doc_modified_verbs [] = {
        NULL
 };
 
+static gchar* paste_verbs [] = {
+       "/ui/MenuBar/EditMenu/EditPaste",
+
+       NULL
+};
+
 static gchar* selection_verbs [] = {
        "/ui/MenuBar/EditMenu/EditCut",
        "/ui/MenuBar/EditMenu/EditCopy",
@@ -770,6 +775,7 @@ gl_ui_new (glWindow *window)
 
 
        gl_ui_util_set_verb_list_sensitive (ui, doc_verbs, FALSE);
+       gl_ui_util_set_verb_list_sensitive (ui, paste_verbs, FALSE);
 
        gl_debug (DEBUG_UI, "END");
 
@@ -821,28 +827,14 @@ gl_ui_update_all (GtkUIManager *ui,
                                       !gl_view_is_zoom_min (view));
 
        gl_ui_util_set_verb_list_sensitive (ui, selection_verbs,
-                                           !gl_label_is_selection_empty (view->label));
+                                           !gl_label_is_selection_empty (label));
 
        gl_ui_util_set_verb_list_sensitive (ui, atomic_selection_verbs,
-                                           gl_label_is_selection_atomic (view->label));
+                                           gl_label_is_selection_atomic (label));
 
        gl_ui_util_set_verb_list_sensitive (ui, multi_selection_verbs,
-                                           !gl_label_is_selection_empty (view->label)
-                                           && !gl_label_is_selection_atomic (view->label));
-
-       gl_debug (DEBUG_UI, "END");
-}
-
-
-/*****************************************************************************/
-/** Update all verbs of given UI component to "no document" state.           */
-/*****************************************************************************/
-void
-gl_ui_update_nodoc (GtkUIManager *ui)
-{
-       gl_debug (DEBUG_UI, "START");
-
-       gl_ui_util_set_verb_list_sensitive (ui, doc_verbs, FALSE);
+                                           !gl_label_is_selection_empty (label)
+                                           && !gl_label_is_selection_atomic (label));
 
        gl_debug (DEBUG_UI, "END");
 }
@@ -906,6 +898,21 @@ gl_ui_update_zoom_verbs (GtkUIManager *ui,
 }
 
 
+/*****************************************************************************/
+/** Update paste verbs of given UI component.                                */
+/*****************************************************************************/
+void
+gl_ui_update_paste_verbs (GtkUIManager      *ui,
+                          gboolean           can_paste)
+{
+       gl_debug (DEBUG_UI, "START");
+
+       gl_ui_util_set_verb_list_sensitive (ui, paste_verbs, can_paste);
+
+       gl_debug (DEBUG_UI, "END");
+}
+
+
 /*****************************************************************************/
 /** Update undo/redo verbs of given UI component.                            */
 /*****************************************************************************/
index fb681cc5be2bedd1c23dd27ec1d0ec7798a5d4cc..158daaf0d7aec8a90952d171955847a649114ac2 100644 (file)
--- a/src/ui.h
+++ b/src/ui.h
@@ -35,8 +35,6 @@ void          gl_ui_unref                  (GtkUIManager      *ui);
 void          gl_ui_update_all             (GtkUIManager      *ui,
                                            glView            *view);
 
-void          gl_ui_update_nodoc           (GtkUIManager      *ui);
-
 void          gl_ui_update_modified_verbs  (GtkUIManager      *ui,
                                            glLabel           *label);
 
@@ -46,6 +44,9 @@ void          gl_ui_update_selection_verbs (GtkUIManager      *ui,
 void          gl_ui_update_zoom_verbs      (GtkUIManager      *ui,
                                            glView            *view);
 
+void          gl_ui_update_paste_verbs     (GtkUIManager      *ui,
+                                            gboolean           can_paste);
+
 void          gl_ui_update_undo_redo_verbs (GtkUIManager      *ui,
                                            glLabel           *label);
 
index 42d24a589f7070fc145c99706c39a36ea2d0474c..4206dda66e503306f0042d806a5ad04d1c1c083f 100644 (file)
@@ -46,6 +46,8 @@
 #define CURSOR_INFO_WIDTH     150
 #define ZOOM_INFO_WIDTH        50
 
+#define GLABELS_CLIPBOARD gdk_atom_intern ("GLABELS", FALSE)
+
 
 /*===========================================================================*/
 /* Private globals                                                           */
@@ -94,6 +96,10 @@ static void     name_changed_cb        (glLabel       *label,
 static void     modified_changed_cb    (glLabel       *label,
                                        glWindow      *window);
 
+static void     clipboard_changed_cb   (GtkClipboard  *clipboard,
+                                        GdkEvent      *event,
+                                       glWindow      *window);
+
 
 /****************************************************************************/
 /* Boilerplate Object stuff.                                                */
@@ -333,7 +339,8 @@ void
 gl_window_set_label (glWindow    *window,
                     glLabel     *label)
 {
-       gchar *string;
+       gchar             *string;
+        GtkClipboard      *clipboard;
 
        gl_debug (DEBUG_WINDOW, "START");
 
@@ -380,6 +387,11 @@ gl_window_set_label (glWindow    *window,
        gtk_label_set_text (GTK_LABEL(window->zoom_info), string);
        g_free (string);
 
+        clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window), GLABELS_CLIPBOARD);
+        gl_ui_update_paste_verbs (window->ui,
+                                  gtk_clipboard_wait_is_text_available (clipboard));
+
+
        g_signal_connect (G_OBJECT(window->label), "selection_changed",
                          G_CALLBACK(selection_changed_cb), window);
 
@@ -401,6 +413,9 @@ gl_window_set_label (glWindow    *window,
        g_signal_connect (G_OBJECT(label), "modified_changed",
                          G_CALLBACK(modified_changed_cb), window);
 
+       g_signal_connect (G_OBJECT(clipboard), "owner_change",
+                         G_CALLBACK(clipboard_changed_cb), window);
+
        gl_debug (DEBUG_WINDOW, "END");
 }
 
@@ -631,6 +646,22 @@ modified_changed_cb (glLabel  *label,
 }
 
 
+static void
+clipboard_changed_cb (GtkClipboard *clipboard,
+                      GdkEvent     *event,
+                      glWindow     *window)
+{
+       gl_debug (DEBUG_WINDOW, "START");
+
+       g_return_if_fail (window && GL_IS_WINDOW (window));
+
+        gl_ui_update_paste_verbs (window->ui,
+                                  gtk_clipboard_wait_is_text_available (clipboard));
+
+       gl_debug (DEBUG_WINDOW, "END");
+}
+
+
 
 /*
  * Local Variables:       -- emacs