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

gEDA-cvs: gaf.git: branch: master updated (1.5.1-20081221-214-g77a59c3)



The branch, master has been updated
       via  77a59c3af731937f5952bbb61a6faccd97a07f38 (commit)
      from  c3081930ed224394f645de4bfb51e86fa3e15e65 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 gschem/include/prototype.h |    2 +-
 gschem/src/i_basic.c       |   20 ++++++++++---
 gschem/src/x_clipboard.c   |   63 ++++++++++++++++++++++++++++++++++----------
 3 files changed, 65 insertions(+), 20 deletions(-)


=================
 Commit Messages
=================

commit 77a59c3af731937f5952bbb61a6faccd97a07f38
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Fri Feb 20 23:32:41 2009 +0000

    gschem: Update the clipboard menu item sensitivities asynchronously
    
    Spawning a sub-main loop to do this can cause reentrancy problems due
    to processing of other X events from within the sub-main loop.
    
    This could end up with states changing whilst updating menus, and
    this has been noted to cause crashes whilst moving objects.

:100644 100644 a91deba... 3504303... M	gschem/include/prototype.h
:100644 100644 45c83d0... a939e2c... M	gschem/src/i_basic.c
:100644 100644 2460f24... af965fd... M	gschem/src/x_clipboard.c

=========
 Changes
=========

commit 77a59c3af731937f5952bbb61a6faccd97a07f38
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Fri Feb 20 23:32:41 2009 +0000

    gschem: Update the clipboard menu item sensitivities asynchronously
    
    Spawning a sub-main loop to do this can cause reentrancy problems due
    to processing of other X events from within the sub-main loop.
    
    This could end up with states changing whilst updating menus, and
    this has been noted to cause crashes whilst moving objects.

diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index a91deba..3504303 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -744,7 +744,7 @@ void x_basic_warp_cursor(GtkWidget *widget, gint x, gint y);
 /* x_clipboard.c */
 void x_clipboard_init (GSCHEM_TOPLEVEL *w_current);
 void x_clipboard_finish (GSCHEM_TOPLEVEL *w_current);
-gboolean x_clipboard_usable (GSCHEM_TOPLEVEL *w_current);
+void x_clipboard_query_usable (GSCHEM_TOPLEVEL *w_current, void (*callback) (int, void *), void *userdata);
 gboolean x_clipboard_set (GSCHEM_TOPLEVEL *w_current, const GList *object_list);
 GList *x_clipboard_get (GSCHEM_TOPLEVEL *w_current);
 /* x_color.c */
diff --git a/gschem/src/i_basic.c b/gschem/src/i_basic.c
index 45c83d0..a939e2c 100644
--- a/gschem/src/i_basic.c
+++ b/gschem/src/i_basic.c
@@ -354,6 +354,20 @@ void i_update_toolbar(GSCHEM_TOPLEVEL *w_current)
   }
 }
 
+
+/*! \brief Update sensitivity of the Edit/Paste menu item
+ *
+ *  \par Function Description
+ *  Asynchronous callback to update sensitivity of the Edit/Paste
+ *  menu item.
+ */
+static void clipboard_usable_cb (int usable, void *userdata)
+{
+  GSCHEM_TOPLEVEL *w_current = userdata;
+  x_menus_sensitivity (w_current, "Edit/Paste", usable);
+}
+
+
 /*! \brief Update sensitivity of relevant menu items
  *
  *  \par Function Description
@@ -374,11 +388,7 @@ void i_update_menus(GSCHEM_TOPLEVEL *w_current)
   g_assert(w_current != NULL);
   g_assert(toplevel->page_current != NULL);
 
-  if (x_clipboard_usable (w_current)) {
-    x_menus_sensitivity(w_current, "Edit/Paste", TRUE);
-  } else {
-    x_menus_sensitivity(w_current, "Edit/Paste", FALSE);
-  }
+  x_clipboard_query_usable (w_current, clipboard_usable_cb, w_current);
 
   if (o_select_selected (w_current)) {
     /* since one or more things are selected, we set these TRUE */
diff --git a/gschem/src/x_clipboard.c b/gschem/src/x_clipboard.c
index 2460f24..af965fd 100644
--- a/gschem/src/x_clipboard.c
+++ b/gschem/src/x_clipboard.c
@@ -108,29 +108,64 @@ x_clipboard_finish (GSCHEM_TOPLEVEL *w_current)
     gtk_clipboard_store (cb);
 }
 
+struct query_usable {
+  void (*callback) (int, void *);
+  void *userdata;
+};
+
+
+/* \brief Callback for determining if any clipboard targets are pastable
+ * \par Function Description
+ *
+ * Checks if the clipboard targets match any format we recognise, then
+ * calls back into a supplied callback function which is interested in
+ * the TRUE / FALSE answer to whether we can paste from the clipboard.
+ */
+static void
+query_usable_targets_cb (GtkClipboard *clip, GdkAtom *targets, gint ntargets,
+                         gpointer data)
+{
+  struct query_usable *cbinfo = data;
+  int i;
+  int is_usable = FALSE;
+
+  for (i = 0; i < ntargets; i++) {
+    if (strcmp (gdk_atom_name (targets[i]), MIME_TYPE_SCHEMATIC) == 0) {
+      is_usable = TRUE;
+      break;
+    }
+  }
+
+  cbinfo->callback (is_usable, cbinfo->userdata);
+  g_free (cbinfo);
+}
+
+
 /* \brief Checks if the system clipboard contains schematic data.
  * \par Function Description
  * Checks whether the current owner of the system clipboard is
  * advertising gEDA schematic data.
  *
- * \param [in,out] w_current   The current GSCHEM_TOPLEVEL.
+ * The check is performed asynchronously. When a response is
+ * recieved, the provided callback is called with a TRUE / FALSE
+ * result.
  *
- * \return TRUE if the clipboard has schematic data.
+ * \param [in] w_current   The current GSCHEM_TOPLEVEL.
+ * \param [in] callback    The callback to recieve the response.
+ * \param [in] userdata    Arbitrary data to pass the callback.
  */
-gboolean
-x_clipboard_usable (GSCHEM_TOPLEVEL *w_current)
+void
+x_clipboard_query_usable (GSCHEM_TOPLEVEL *w_current,
+                          void (*callback) (int, void *), void *userdata)
 {
-  GtkClipboard *cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
-  GdkAtom *targets;
-  gint ntargets;
-  int i;
+  GtkClipboard *clip = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+  struct query_usable *cbinfo;
 
-  gtk_clipboard_wait_for_targets (cb, &targets, &ntargets);
-  for (i = 0; i < ntargets; i++) {
-    if (strcmp (gdk_atom_name (targets[i]), MIME_TYPE_SCHEMATIC) == 0)
-      return TRUE;
-  }
-  return FALSE;
+  cbinfo = g_new (struct query_usable, 1);
+  cbinfo->callback = callback;
+  cbinfo->userdata = userdata;
+
+  gtk_clipboard_request_targets (clip, query_usable_targets_cb, cbinfo);
 }
 
 /* \brief Set the contents of the system clipboard.




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs