[nautilus/wip/antoniof/make-window-slot-final: 1/2] view: Use view id macros instead of enum




commit cd83d37f08b743b075540ee02b55c160ea81e50b
Author: António Fernandes <antoniof gnome org>
Date:   Wed Jan 13 12:36:36 2021 +0000

    view: Use view id macros instead of enum
    
    The slot.files-view-mode action takes hardcoded id values. This may
    break if the ids enumeration changes.
    
    Instead, let's define the values with a macro which we can stringify.
    While we are at it, drop the unused EMPTY id.

 src/nautilus-view.h        | 14 ++++++--------
 src/nautilus-window-slot.c | 12 ++++++++----
 2 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index deeb4bb3e..677e9b53b 100644
--- a/src/nautilus-view.h
+++ b/src/nautilus-view.h
@@ -24,14 +24,12 @@
 #include "nautilus-query.h"
 #include "nautilus-toolbar-menu-sections.h"
 
-enum
-{
-    NAUTILUS_VIEW_GRID_ID,
-    NAUTILUS_VIEW_LIST_ID,
-    NAUTILUS_VIEW_EMPTY_ID,
-    NAUTILUS_VIEW_OTHER_LOCATIONS_ID,
-    NAUTILUS_VIEW_INVALID_ID,
-};
+/* Keep values in sync with the org.gnome.nautilus.FolderView schema enums: */
+#define NAUTILUS_VIEW_GRID_ID            0
+#define NAUTILUS_VIEW_LIST_ID            1
+/* Special ids, not used by GSettings schemas: */
+#define NAUTILUS_VIEW_OTHER_LOCATIONS_ID 3
+#define NAUTILUS_VIEW_INVALID_ID         4
 
 G_BEGIN_DECLS
 
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 2113a3d3e..d8b384b80 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -1039,8 +1039,7 @@ action_files_view_mode (GSimpleAction *action,
 
 const GActionEntry slot_entries[] =
 {
-    /* 4 is NAUTILUS_VIEW_INVALID_ID */
-    { "files-view-mode", NULL, "u", "uint32 4", action_files_view_mode },
+    { "files-view-mode", NULL, "u", "uint32 " G_STRINGIFY (NAUTILUS_VIEW_INVALID_ID), action_files_view_mode 
},
     { "files-view-mode-toggle", action_files_view_mode_toggle },
     { "search-visible", NULL, NULL, "false", action_search_visible },
 };
@@ -1149,8 +1148,13 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
     gtk_widget_insert_action_group (GTK_WIDGET (self),
                                     "slot",
                                     G_ACTION_GROUP (self->slot_action_group));
-    nautilus_application_set_accelerator (app, "slot.files-view-mode(uint32 1)", "<control>1");
-    nautilus_application_set_accelerator (app, "slot.files-view-mode(uint32 0)", "<control>2");
+
+    nautilus_application_set_accelerator (app,
+                                          "slot.files-view-mode(uint32 " G_STRINGIFY (NAUTILUS_VIEW_LIST_ID) 
")",
+                                          "<control>1");
+    nautilus_application_set_accelerator (app,
+                                          "slot.files-view-mode(uint32 " G_STRINGIFY (NAUTILUS_VIEW_GRID_ID) 
")",
+                                          "<control>2");
     nautilus_application_set_accelerator (app, "slot.search-visible", "<control>f");
 
     self->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID;


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