[glabels] Control sensitivity of paste verb



commit 9ad72e4b3df7122496e84af4bbc1013738145f5b
Author: Jim Evins <evins snaught com>
Date:   Wed Dec 2 19:59:50 2009 -0500

    Control sensitivity of paste verb
    
    Track the availability of data on the private glabels clipboard to control
    the sensitivity of the paste verb.

 src/ui.c     |   45 ++++++++++++++++++++++++++-------------------
 src/ui.h     |    5 +++--
 src/window.c |   33 ++++++++++++++++++++++++++++++++-
 3 files changed, 61 insertions(+), 22 deletions(-)
---
diff --git a/src/ui.c b/src/ui.c
index f7d0e9f..34b1121 100644
--- 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");
 }
@@ -907,6 +899,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.                            */
 /*****************************************************************************/
 void
diff --git a/src/ui.h b/src/ui.h
index fb681cc..158daaf 100644
--- 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);
 
diff --git a/src/window.c b/src/window.c
index 42d24a5..4206dda 100644
--- a/src/window.c
+++ b/src/window.c
@@ -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



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