[gnome-photos/wip/rishi/collection: 3/43] application, main-window: Use a GAction accelerator to cancel EDIT



commit 5bfc3398b1e9daa7fd3cc1bfedd9972a0501fb1a
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jan 31 20:23:24 2018 +0100

    application, main-window: Use a GAction accelerator to cancel EDIT

 src/photos-application.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
 src/photos-main-window.c | 20 +-------------------
 2 files changed, 44 insertions(+), 23 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 35bff30f..8daef416 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -331,6 +331,8 @@ photos_application_actions_update (PhotosApplication *self)
   gboolean can_trash;
   gboolean enable;
   gboolean selection_mode;
+  const gchar *cancel_accels[] = { "Escape", NULL };
+  const gchar *null_accels[] = { NULL };
   guint n_items = 0;
 
   item = photos_application_get_selection_or_active_item (self);
@@ -341,13 +343,50 @@ photos_application_actions_update (PhotosApplication *self)
 
   if (selection_mode)
     {
-      const gchar *selection_mode_accels[] = { "Escape", NULL };
-      gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.selection-mode", 
selection_mode_accels);
+      gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.edit-cancel", null_accels);
+
+      switch (mode)
+        {
+        case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+        case PHOTOS_WINDOW_MODE_COLLECTIONS:
+        case PHOTOS_WINDOW_MODE_FAVORITES:
+        case PHOTOS_WINDOW_MODE_OVERVIEW:
+        case PHOTOS_WINDOW_MODE_SEARCH:
+          gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.selection-mode", 
cancel_accels);
+          break;
+
+        case PHOTOS_WINDOW_MODE_NONE:
+        case PHOTOS_WINDOW_MODE_EDIT:
+        case PHOTOS_WINDOW_MODE_PREVIEW:
+        default:
+          g_assert_not_reached ();
+          break;
+        }
     }
   else
     {
-      const gchar *selection_mode_accels[] = { NULL };
-      gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.selection-mode", 
selection_mode_accels);
+      gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.selection-mode", null_accels);
+
+      switch (mode)
+        {
+        case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+        case PHOTOS_WINDOW_MODE_COLLECTIONS:
+        case PHOTOS_WINDOW_MODE_FAVORITES:
+        case PHOTOS_WINDOW_MODE_OVERVIEW:
+        case PHOTOS_WINDOW_MODE_PREVIEW:
+        case PHOTOS_WINDOW_MODE_SEARCH:
+          gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.edit-cancel", null_accels);
+          break;
+
+        case PHOTOS_WINDOW_MODE_EDIT:
+          gtk_application_set_accels_for_action (GTK_APPLICATION (self), "app.edit-cancel", cancel_accels);
+          break;
+
+        case PHOTOS_WINDOW_MODE_NONE:
+        default:
+          g_assert_not_reached ();
+          break;
+        }
     }
 
   if (mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW
diff --git a/src/photos-main-window.c b/src/photos-main-window.c
index d14e90f3..2a884a8f 100644
--- a/src/photos-main-window.c
+++ b/src/photos-main-window.c
@@ -203,21 +203,6 @@ photos_main_window_handle_back_key (PhotosMainWindow *self, GdkEventKey *event)
 }
 
 
-static gboolean
-photos_main_window_handle_key_edit (PhotosMainWindow *self, GdkEventKey *event)
-{
-  gboolean handled = FALSE;
-
-  if (event->keyval == GDK_KEY_Escape)
-    {
-      g_action_activate (self->edit_cancel, NULL);
-      handled = TRUE;
-    }
-
-  return handled;
-}
-
-
 static gboolean
 photos_main_window_handle_key_preview (PhotosMainWindow *self, GdkEventKey *event)
 {
@@ -275,16 +260,13 @@ photos_main_window_key_press_event (GtkWidget *widget, GdkEventKey *event)
     case PHOTOS_WINDOW_MODE_NONE:
     case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
     case PHOTOS_WINDOW_MODE_COLLECTIONS:
+    case PHOTOS_WINDOW_MODE_EDIT:
     case PHOTOS_WINDOW_MODE_FAVORITES:
     case PHOTOS_WINDOW_MODE_OVERVIEW:
     case PHOTOS_WINDOW_MODE_SEARCH:
       handled = GDK_EVENT_PROPAGATE;
       break;
 
-    case PHOTOS_WINDOW_MODE_EDIT:
-      handled = photos_main_window_handle_key_edit (self, event);
-      break;
-
     case PHOTOS_WINDOW_MODE_PREVIEW:
       handled = photos_main_window_handle_key_preview (self, event);
       break;


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