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




commit e35233bc24c8ec457fa0b4b700a3ef8810f55760
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 | 13 +++++++++----
 2 files changed, 15 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..4673134f6 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 },
 };
@@ -1127,6 +1126,7 @@ static void
 nautilus_window_slot_init (NautilusWindowSlot *self)
 {
     GApplication *app;
+
     app = g_application_get_default ();
 
     g_signal_connect (nautilus_trash_monitor_get (),
@@ -1149,8 +1149,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]