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

Re: gEDA-dev: [PATCH] gschem: Visual feedback for keyboard commands



On Thu, May 31, 2007 at 08:51:50PM +0100, Peter TB Brett wrote:
> For a quick nasty hack, why not make the relevant w_current string the data 
> argument to clear_keyaccel_string?

Because then you'll loudly complain that it's a "quick nasty hack"? :)

I was just preparing a patch using that idea when your mail came. So
here it is. Everything works fine, as in the first patch.

-- 
Ivan Stankovic, ivan.stankovic@fer.hr

"Protect your digital freedom and privacy, eliminate DRM, 
learn more at http://www.defectivebydesign.org/what_is_drm"

---
 gschem/include/globals.h |    3 ++
 gschem/src/g_keys.c      |   55 +++++++++++++++++++++++++++++++++++++++++++--
 gschem/src/i_basic.c     |    8 ++++++
 3 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/gschem/include/globals.h b/gschem/include/globals.h
index bff096b..0e1c1c9 100644
--- a/gschem/include/globals.h
+++ b/gschem/include/globals.h
@@ -29,6 +29,9 @@ extern GdkVisual *visual;
 extern GdkColor white;
 extern GdkColor black;
 
+/* used for visual feedback when pressing keyboard accelerators */
+extern gchar *current_keyaccel_string;
+
 #if 0
 extern GdkColor red;
 extern GdkColor green;
diff --git a/gschem/src/g_keys.c b/gschem/src/g_keys.c
index 03602a4..928ea34 100644
--- a/gschem/src/g_keys.c
+++ b/gschem/src/g_keys.c
@@ -40,6 +40,8 @@
 #include <dmalloc.h>
 #endif
 
+gchar *current_keyaccel_string = NULL;
+
 /*! \todo Finish function documentation!!!
  *  \brief
  *  \par Function Description
@@ -69,6 +71,21 @@ int g_keys_execute(int state, int keyval)
     return 0;
   }
 
+  if(strcmp(key_name, "Escape") == 0) {
+     g_free(current_keyaccel_string);
+     current_keyaccel_string = NULL;
+  } else {
+     if(current_keyaccel_string) {
+        gchar *tmp = current_keyaccel_string;
+        current_keyaccel_string = g_strdup_printf("%s%s", tmp, key_name);
+        g_free(tmp);
+     }
+     else
+        current_keyaccel_string = g_strdup(key_name);
+  }
+
+  i_show_state(global_window_current, NULL);
+
   if (state & GDK_SHIFT_MASK) {
     modifier = g_strdup_printf("\"Shift ");
   } else if (state & GDK_CONTROL_MASK) {
@@ -142,14 +159,46 @@ g_keys_dump_keymap (void)
   return ret;
 }
 
-/*! \brief
+/*! \brief Clear the current key accelerator string
+ *
+ *  \par Function Description
+ *  This function clears the current keyboard accelerator
+ *  string in the status bar of the relevant toplevel.
+ *  Called after the action specifed by the keyboard
+ *  accelerator is executed and the associated timeout interval
+ *  has passed.
  *
+ *  \param [in] data a pointer to the toplevel
  */
+static gboolean clear_keyaccel_string(gpointer data)
+{
+   TOPLEVEL *w = global_window_current;
+
+   g_free(current_keyaccel_string);
+   current_keyaccel_string = NULL;
+
+   /* Find out if the toplevel is present... */
+   while(w->prev)
+      w = w->prev;
+
+   while(w) {
+      if(w == (TOPLEVEL *) data) {
+         /* ... it is, update its status bar */
+         i_show_state(w, NULL);
+         break;
+      }
+      w = w->next;
+   }
+
+   return FALSE;
+}
+
 #define DEFINE_G_KEYS(name)				\
 SCM g_keys_ ## name(void)				\
 {							\
-	i_callback_ ## name(global_window_current, 0, NULL);	\
-	return SCM_BOOL_T;				\
+   g_timeout_add(400, clear_keyaccel_string, global_window_current); \
+   i_callback_ ## name(global_window_current, 0, NULL); \
+   return SCM_BOOL_T;				\
 }
 
 /*! \brief test-comment
diff --git a/gschem/src/i_basic.c b/gschem/src/i_basic.c
index a86a68a..d89dbee 100644
--- a/gschem/src/i_basic.c
+++ b/gschem/src/i_basic.c
@@ -183,6 +183,14 @@ void i_show_state(TOPLEVEL *w_current, const char *message)
 
   what_to_say = g_strjoinv(" - ", (gchar **) array + i);
 
+  if(current_keyaccel_string) {
+     gchar *p = what_to_say;
+
+     what_to_say = g_strdup_printf("%s \t\t %s", current_keyaccel_string,
+           what_to_say);
+     g_free(p);
+  }
+
   i_update_status(w_current, what_to_say);
   g_free(what_to_say);
 }
-- 
1.5.2



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