[bijiben] Control+A and Esc shortcuts for main view



commit 5f04a774c2ee3719f697aa8d1e55b9a8aa8246cb
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sat Jan 19 01:39:54 2013 +0100

    Control+A and Esc shortcuts for main view
    
    Control a selects all notes when selection mode
    Escape cancels the selection mode (and still allows to escape the search bar)

 src/bjb-main-view.c      |   49 ++++++++++++++++++++++++++++++++++++++++-----
 src/bjb-search-toolbar.c |   18 +++++++---------
 2 files changed, 51 insertions(+), 16 deletions(-)
---
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 2b1d3b5..e1f297f 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -314,6 +314,41 @@ action_delete_selected_notes(GtkWidget *w,BjbMainView *view)
   g_list_free (notes);
 }
 
+/* Select all, escape */
+static gboolean
+on_key_press_event_cb (GtkWidget *widget,
+                       GdkEvent  *event,
+                       gpointer   user_data)
+{
+  BjbMainView *self = BJB_MAIN_VIEW (user_data);
+  BjbMainViewPriv *priv = self->priv;
+
+  switch (event->key.keyval)
+  {
+    case GDK_KEY_a:
+    case GDK_KEY_A:
+      if (gd_main_view_get_selection_mode (priv->view) && event->key.state & GDK_CONTROL_MASK)
+      {
+        gd_main_view_select_all (priv->view);
+        return TRUE;
+      }
+      break;
+
+    case GDK_KEY_Escape:
+      if (gd_main_view_get_selection_mode (priv->view))
+      {
+        gd_main_view_set_selection_mode (priv->view, FALSE);
+        on_selection_mode_changed (priv->main_toolbar);
+        return TRUE;
+      }
+
+    default:
+      break;
+  }
+
+  return FALSE;
+}
+
 /* Go to selection mode with right-click */
 static gboolean
 on_button_press_event_cb (GtkWidget *widget,
@@ -424,6 +459,13 @@ bjb_main_view_constructed(GObject *o)
   priv->view = gd_main_view_new (DEFAULT_VIEW);
   bjb_controller_set_main_view (priv->controller, priv->view);
 
+  g_signal_connect (priv->window, "key-press-event",
+                    G_CALLBACK (on_key_press_event_cb), self);
+  g_signal_connect (priv->view, "button-press-event",
+                    G_CALLBACK (on_button_press_event_cb), self);
+  g_signal_connect(priv->view,"item-activated",
+                   G_CALLBACK(on_item_activated),self);
+
   /* Probably move this to window_base or delete this */
   filler = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
                                    CLUTTER_BIN_ALIGNMENT_CENTER);
@@ -486,15 +528,10 @@ bjb_main_view_constructed(GObject *o)
   clutter_actor_set_x_expand (view, TRUE);
   clutter_actor_set_y_expand (view, TRUE);
 
-  gd_main_view_set_selection_mode ( priv->view, FALSE);
+  gd_main_view_set_selection_mode (priv->view, FALSE);
   gd_main_view_set_model(priv->view,
                          bjb_controller_get_model(priv->controller));
 
-  g_signal_connect (priv->view, "button-press-event",
-                    G_CALLBACK (on_button_press_event_cb), self);
-  g_signal_connect(priv->view,"item-activated",
-                   G_CALLBACK(on_item_activated),self);
-
   /* Selection Panel */
   panel = bjb_selection_toolbar_new (priv->content,priv->view,self);
   selection_bar = bjb_selection_toolbar_get_actor (panel);
diff --git a/src/bjb-search-toolbar.c b/src/bjb-search-toolbar.c
index 5b450c9..5a84b8c 100644
--- a/src/bjb-search-toolbar.c
+++ b/src/bjb-search-toolbar.c
@@ -110,7 +110,7 @@ on_key_pressed (GtkWidget *widget,GdkEvent  *event,gpointer user_data)
 {
   BjbSearchToolbar *self = BJB_SEARCH_TOOLBAR (user_data);
 
-  /* Reveal the entry is text is input. TODO add more keys not input*/
+  /* Reveal the entry is text is input. TODO add more keys not input */
   if (clutter_actor_get_opacity (self->priv->actor) == 0)
   {
     switch (event->key.keyval)
@@ -121,23 +121,21 @@ on_key_pressed (GtkWidget *widget,GdkEvent  *event,gpointer user_data)
       case GDK_KEY_Shift_R :
       case GDK_KEY_Alt_L :
       case GDK_KEY_Alt_R :
-      case GDK_KEY_Escape :
         return TRUE ;
 
       default:
-        bjb_search_toolbar_fade_in (self);
+        if (event->key.keyval != GDK_KEY_Escape)
+          bjb_search_toolbar_fade_in (self);
         return FALSE;
     }
   }
 
-  /* If there is already an entry and escape pressed, hide entry */
-  else
+  /* If there is already an entry and escape pressed, hide entry
+   * Maybe should we use gtk_widget_has_focus (widget) */
+  else if (event->key.keyval == GDK_KEY_Escape)
   {
-    if (event->key.keyval == GDK_KEY_Escape)
-    {
-      bjb_search_toolbar_fade_out (self);
-      return TRUE;
-    }
+    bjb_search_toolbar_fade_out (self);
+    return TRUE;
   }
 
   return FALSE;



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