[nautilus] batch-rename-dialog: simplify key_press_event if's



commit d147f25692e2ea5beeb92d51b7ec4036ff408a09
Author: Carlos Soriano <csoriano gnome org>
Date:   Mon Aug 29 11:08:45 2016 +0200

    batch-rename-dialog: simplify key_press_event if's
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768311

 src/nautilus-batch-rename-dialog.c |  220 +++++++++++++++++-------------------
 1 files changed, 106 insertions(+), 114 deletions(-)
---
diff --git a/src/nautilus-batch-rename-dialog.c b/src/nautilus-batch-rename-dialog.c
index d1a4c28..31432a0 100644
--- a/src/nautilus-batch-rename-dialog.c
+++ b/src/nautilus-batch-rename-dialog.c
@@ -2288,7 +2288,7 @@ on_key_press_event (GtkWidget    *widget,
         gboolean entry_has_selection;
         gint start;
         gint end;
-        gboolean tag_removed;
+        gboolean tag_removed = FALSE;
         TagData *tag_data;
         gint minimum_tag_position;
         GAction *action;
@@ -2319,7 +2319,6 @@ on_key_press_event (GtkWidget    *widget,
                 old_entry_text = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
 
                 minimum_tag_position = G_MAXINT;
-                tag_removed = FALSE;
 
                 tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
                 if (tag_data->set) {
@@ -2601,125 +2600,118 @@ on_key_press_event (GtkWidget    *widget,
                 if ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) &&
                     tag_removed)
                         return GDK_EVENT_STOP;
+        } else {
+                if (remove_tag (dialog,
+                                ORIGINAL_FILE_NAME,
+                                "add-original-file-name-tag",
+                                keyval,
+                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                CREATION_DATE,
+                                                "add-creation-date-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                NUMBERING,
+                                                "add-numbering-tag-zero",
+                                                keyval,
+                                                gdk_event->key.is_modifier)) {
+                        tag_removed = TRUE;
+                        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                           "add-numbering-tag-one");
+                        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
 
-                return GDK_EVENT_PROPAGATE;
-        }
-
-        tag_removed = FALSE;
-
-        if (remove_tag (dialog,
-                        ORIGINAL_FILE_NAME,
-                        "add-original-file-name-tag",
-                        keyval,
-                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        CREATION_DATE,
-                                        "add-creation-date-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        NUMBERING,
-                                        "add-numbering-tag-zero",
-                                        keyval,
-                                        gdk_event->key.is_modifier)) {
-                tag_removed = TRUE;
-                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                                                   "add-numbering-tag-one");
-                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
-                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                                                   "add-numbering-tag-two");
-                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-        }
+                        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                           "add-numbering-tag-two");
+                        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+                }
 
-        if (!tag_removed && remove_tag (dialog,
-                                        NUMBERING0,
-                                        "add-numbering-tag-one",
-                                        keyval,
-                                        gdk_event->key.is_modifier)) {
-                tag_removed = TRUE;
-                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                                                   "add-numbering-tag-zero");
-                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+                if (!tag_removed && remove_tag (dialog,
+                                                NUMBERING0,
+                                                "add-numbering-tag-one",
+                                                keyval,
+                                                gdk_event->key.is_modifier)) {
+                        tag_removed = TRUE;
+                        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                           "add-numbering-tag-zero");
+                        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
 
-                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                                                   "add-numbering-tag-two");
-                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-        }
+                        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                           "add-numbering-tag-two");
+                        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+                }
 
-        if (!tag_removed && remove_tag (dialog,
-                                        NUMBERING00,
-                                        "add-numbering-tag-two",
-                                        keyval,
-                                        gdk_event->key.is_modifier)) {
-                tag_removed = TRUE;
-                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                                                   "add-numbering-tag-one");
-                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+                if (!tag_removed && remove_tag (dialog,
+                                                NUMBERING00,
+                                                "add-numbering-tag-two",
+                                                keyval,
+                                                gdk_event->key.is_modifier)) {
+                        tag_removed = TRUE;
+                        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                           "add-numbering-tag-one");
+                        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
 
-                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                                                   "add-numbering-tag-zero");
-                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-        }
+                        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                           "add-numbering-tag-zero");
+                        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+                }
 
-        if (!tag_removed && remove_tag (dialog,
-                                        CAMERA_MODEL,
-                                        "add-equipment-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        SEASON_NUMBER,
-                                        "add-season-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        EPISODE_NUMBER,
-                                        "add-episode-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        TRACK_NUMBER,
-                                        "add-track-number-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        ARTIST_NAME,
-                                        "add-artist-name-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        TITLE,
-                                        "add-title-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (!tag_removed && remove_tag (dialog,
-                                        ALBUM_NAME,
-                                        "add-album-name-tag",
-                                        keyval,
-                                        gdk_event->key.is_modifier))
-                tag_removed = TRUE;
-
-        if (tag_removed) {
-                if (keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace)
+                if (!tag_removed && remove_tag (dialog,
+                                                CAMERA_MODEL,
+                                                "add-equipment-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                SEASON_NUMBER,
+                                                "add-season-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                EPISODE_NUMBER,
+                                                "add-episode-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                TRACK_NUMBER,
+                                                "add-track-number-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                ARTIST_NAME,
+                                                "add-artist-name-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                TITLE,
+                                                "add-title-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (!tag_removed && remove_tag (dialog,
+                                                ALBUM_NAME,
+                                                "add-album-name-tag",
+                                                keyval,
+                                                gdk_event->key.is_modifier))
+                        tag_removed = TRUE;
+
+                if (tag_removed && (keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace)) {
                         return GDK_EVENT_STOP;
-
-                return GDK_EVENT_PROPAGATE;
+                }
         }
 
         return GDK_EVENT_PROPAGATE;


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