[gnome-builder/wip/gtk4-port: 163/736] libide/gui: add space for more data in pref tables




commit 953fce1df6b27d856fdf9562dd4147eb363c042a
Author: Christian Hergert <chergert redhat com>
Date:   Tue Mar 29 02:17:35 2022 -0700

    libide/gui: add space for more data in pref tables
    
    This will allow us to shove a bunch of data we can use with common
    callbacks to setup the widgets.

 src/libide/gui/ide-preferences-window.c | 13 +++++++----
 src/libide/gui/ide-preferences-window.h | 26 ++++++++-------------
 src/libide/gui/tests/test-preferences.c | 41 ++++++++++++++++-----------------
 3 files changed, 39 insertions(+), 41 deletions(-)
---
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index 3a25283a0..61a17f8a3 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -470,7 +470,7 @@ ide_preferences_window_page_activated_cb (IdePreferencesWindow *self,
 
               if (entry_matches (item->page, entry->name) &&
                   entry_matches (item->group, group->name))
-                item->callback (entry->name, item, pref_group, (gpointer)item->reserved1);
+                item->callback (entry->name, item, pref_group, (gpointer)item->user_data);
             }
 
           adw_preferences_page_add (page, pref_group);
@@ -704,7 +704,12 @@ ide_preferences_window_add_items (IdePreferencesWindow         *self,
       entry.page = g_intern_string (entry.page);
       entry.group = g_intern_string (entry.group);
       entry.name = g_intern_string (entry.name);
-      entry.reserved1 = user_data;
+      entry.title = g_intern_string (entry.title);
+      entry.subtitle = g_intern_string (entry.subtitle);
+      entry.schema_id = g_intern_string (entry.schema_id);
+      entry.path = g_intern_string (entry.path);
+      entry.key = g_intern_string (entry.key);
+      entry.user_data = user_data;
 
       g_ptr_array_add (self->info.items, g_memdup2 (&entry, sizeof entry));
     }
@@ -732,7 +737,7 @@ ide_preferences_window_add_item (IdePreferencesWindow  *self,
                                  gpointer               user_data,
                                  GDestroyNotify         user_data_destroy)
 {
-  IdePreferenceItemEntry entry;
+  IdePreferenceItemEntry entry = {0};
 
   g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
   g_return_if_fail (page != NULL);
@@ -742,7 +747,7 @@ ide_preferences_window_add_item (IdePreferencesWindow  *self,
   entry.page = g_intern_string (page);
   entry.group = g_intern_string (group);
   entry.name = g_intern_string (name);
-  entry.reserved1 = user_data;
+  entry.user_data = user_data;
 
   g_ptr_array_add (self->info.items, g_memdup2 (&entry, sizeof entry));
 
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index dec48c421..d4667aa72 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -41,12 +41,6 @@ typedef struct
   const char *icon_name;
   int priority;
   const char *title;
-
-  /*< private >*/
-  gconstpointer reserved1;
-  gconstpointer reserved2;
-  gconstpointer reserved3;
-  gconstpointer reserved4;
 } IdePreferencePageEntry;
 
 typedef struct
@@ -55,12 +49,6 @@ typedef struct
   const char *name;
   int priority;
   const char *title;
-
-  /*< private >*/
-  gconstpointer reserved1;
-  gconstpointer reserved2;
-  gconstpointer reserved3;
-  gconstpointer reserved4;
 } IdePreferenceGroupEntry;
 
 struct _IdePreferenceItemEntry
@@ -68,14 +56,20 @@ struct _IdePreferenceItemEntry
   const char *page;
   const char *group;
   const char *name;
+
   int priority;
+
   IdePreferenceCallback callback;
 
+  /* Callback specific data */
+  const char *title;
+  const char *subtitle;
+  const char *schema_id;
+  const char *path;
+  const char *key;
+
   /*< private >*/
-  gconstpointer reserved1;
-  gconstpointer reserved2;
-  gconstpointer reserved3;
-  gconstpointer reserved4;
+  gconstpointer user_data;
 };
 
 #define IDE_TYPE_PREFERENCES_WINDOW (ide_preferences_window_get_type())
diff --git a/src/libide/gui/tests/test-preferences.c b/src/libide/gui/tests/test-preferences.c
index 7bba01f8c..18182787b 100644
--- a/src/libide/gui/tests/test-preferences.c
+++ b/src/libide/gui/tests/test-preferences.c
@@ -64,23 +64,22 @@ static const IdePreferenceItemEntry items[] = {
 };
 
 static const IdePreferenceItemEntry lang_items[] = {
-  { "languages/*", "general", "trim", 0, toggle_cb, NULL, "Trim Trailing Whitespace", "Upon saving, trailing 
whitepsace from modified lines will be trimmed." },
-  { "languages/*", "general", "overwrite", 0, toggle_cb, NULL, "Overwrite Braces", "Overwrite closing 
braces" },
-  { "languages/*", "general", "insert-matching", 0, toggle_cb, NULL, "Insert Matching Brace", "Insert 
matching character for [[(\"'" },
-  { "languages/*", "general", "insert-trailing", 0, toggle_cb, NULL, "Insert Trailing Newline", "Ensure 
files end with a newline" },
-
-  { "languages/*", "margins", "show-right-margin", 0, toggle_cb, NULL, "Show right margin", "Display a 
margin in the editor to indicate maximum desired width" },
-  { "languages/*", "margins", "right-margin", 0, spin_cb, NULL, "Right margin position", "The position of 
the right margin in characters" },
-
-  { "languages/*", "spacing", "before-parens", 0, toggle_cb, NULL, "Prefer a space before opening 
parentheses" },
-  { "languages/*", "spacing", "before-brackets", 0, toggle_cb, NULL, "Prefer a space before opening 
brackets" },
-  { "languages/*", "spacing", "before-braces", 0, toggle_cb, NULL, "Prefer a space before opening braces" },
-  { "languages/*", "spacing", "before-angles", 0, toggle_cb, NULL, "Prefer a space before opening angles" },
-
-  { "languages/*", "indentation", "tab-width", 0, spin_cb, NULL, "Tab width", "Width of a tab character in 
spaces" },
-  { "languages/*", "indentation", "insert-spaces", 0, toggle_cb, NULL, "Insert spaces instead of tabs", 
"Prefer spaces over tabs" },
-  { "languages/*", "indentation", "auto-indent", 0, toggle_cb, NULL, "Automatically Indent", "Format source 
code as you type" },
-
+  { "languages/*", "general", "trim", 0, toggle_cb, "Trim Trailing Whitespace", "Upon saving, trailing 
whitepsace from modified lines will be trimmed." },
+  { "languages/*", "general", "overwrite", 0, toggle_cb, "Overwrite Braces", "Overwrite closing braces" },
+  { "languages/*", "general", "insert-matching", 0, toggle_cb, "Insert Matching Brace", "Insert matching 
character for [[(\"'" },
+  { "languages/*", "general", "insert-trailing", 0, toggle_cb, "Insert Trailing Newline", "Ensure files end 
with a newline" },
+
+  { "languages/*", "margins", "show-right-margin", 0, toggle_cb, "Show right margin", "Display a margin in 
the editor to indicate maximum desired width" },
+  { "languages/*", "margins", "right-margin", 0, spin_cb, "Right margin position", "The position of the 
right margin in characters" },
+
+  { "languages/*", "spacing", "before-parens", 0, toggle_cb, "Prefer a space before opening parentheses" },
+  { "languages/*", "spacing", "before-brackets", 0, toggle_cb, "Prefer a space before opening brackets" },
+  { "languages/*", "spacing", "before-braces", 0, toggle_cb, "Prefer a space before opening braces" },
+  { "languages/*", "spacing", "before-angles", 0, toggle_cb, "Prefer a space before opening angles" },
+
+  { "languages/*", "indentation", "tab-width", 0, spin_cb, "Tab width", "Width of a tab character in spaces" 
},
+  { "languages/*", "indentation", "insert-spaces", 0, toggle_cb, "Insert spaces instead of tabs", "Prefer 
spaces over tabs" },
+  { "languages/*", "indentation", "auto-indent", 0, toggle_cb, "Automatically Indent", "Format source code 
as you type" },
 };
 
 static int
@@ -284,8 +283,8 @@ toggle_cb (const char                   *page,
                         "valign", GTK_ALIGN_CENTER,
                         NULL);
   row = g_object_new (ADW_TYPE_ACTION_ROW,
-                      "title", item->reserved2,
-                      "subtitle", item->reserved3,
+                      "title", item->title,
+                      "subtitle", item->subtitle,
                       "activatable-widget", child,
                       NULL);
   adw_preferences_group_add (pref_group, GTK_WIDGET (row));
@@ -305,8 +304,8 @@ spin_cb (const char                   *page,
                         "valign", GTK_ALIGN_CENTER,
                         NULL);
   row = g_object_new (ADW_TYPE_ACTION_ROW,
-                      "title", item->reserved2,
-                      "subtitle", item->reserved3,
+                      "title", item->title,
+                      "subtitle", item->subtitle,
                       "activatable-widget", child,
                       NULL);
   adw_preferences_group_add (pref_group, GTK_WIDGET (row));


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