[gnome-builder/wip/gtk4-port] libide/gui: start on check image option for preferences
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/gui: start on check image option for preferences
- Date: Tue, 5 Apr 2022 01:04:27 +0000 (UTC)
commit e1ebf55177d9d92a6da156a84f7b46a585ec2f2a
Author: Christian Hergert <chergert redhat com>
Date: Mon Apr 4 18:03:20 2022 -0700
libide/gui: start on check image option for preferences
This still needs work, but it gets plumbing in place. We may end up
switching to using an image instead, but this is a start.
src/libide/gui/ide-preferences-builtin.c | 2 +
src/libide/gui/ide-preferences-window.c | 97 ++++++++++++++++++++++++++++++++
src/libide/gui/ide-preferences-window.h | 8 ++-
src/libide/gui/style.css | 8 +++
4 files changed, 113 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/gui/ide-preferences-builtin.c b/src/libide/gui/ide-preferences-builtin.c
index c9fbceef9..95467c294 100644
--- a/src/libide/gui/ide-preferences-builtin.c
+++ b/src/libide/gui/ide-preferences-builtin.c
@@ -680,6 +680,8 @@ static const IdePreferenceGroupEntry groups[] = {
{ "plugins", "editing", 90, N_("Editing & Formatting") },
{ "plugins", "other", 500, N_("Additional") },
+ { "keyboard", "keybindings", 0, N_("Keyboard Shortcuts") },
+
{ "projects", "workspace", 0, N_("Workspace") },
{ "debug", "breakpoints", 0, N_("Breakpoints") },
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index 18b736655..4f2b3dd8b 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -965,6 +965,7 @@ ide_preferences_window_add_items (IdePreferencesWindow *self,
entry.schema_id = g_intern_string (entry.schema_id);
entry.path = g_intern_string (entry.path);
entry.key = g_intern_string (entry.key);
+ entry.value = g_intern_string (entry.value);
entry.user_data = user_data;
g_ptr_array_add (self->info.items, g_memdup2 (&entry, sizeof entry));
@@ -1058,6 +1059,102 @@ ide_preferences_window_toggle (const char *page_name,
g_settings_bind (settings, entry->key, child, "active", G_SETTINGS_BIND_DEFAULT);
}
+static gboolean
+check_get_mapping (GValue *to,
+ GVariant *from,
+ gpointer user_data)
+{
+ GVariant *expected = user_data;
+
+ if (expected == NULL)
+ {
+ if (g_variant_is_of_type (from, G_VARIANT_TYPE_BOOLEAN))
+ {
+ g_value_set_boolean (to, g_variant_get_boolean (from));
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+ if (g_variant_equal (expected, from))
+ g_value_set_boolean (to, TRUE);
+ else
+ g_value_set_boolean (to, FALSE);
+
+ return TRUE;
+}
+
+static GVariant *
+check_set_mapping (const GValue *from,
+ const GVariantType *expected_type,
+ gpointer user_data)
+{
+ GVariant *expected = user_data;
+
+ if (G_VALUE_HOLDS_BOOLEAN (from))
+ {
+ if (expected != NULL)
+ return g_variant_ref (expected);
+ else if (g_variant_type_equal (expected_type, G_VARIANT_TYPE_BOOLEAN))
+ return g_variant_new_boolean (g_value_get_boolean (from));
+ }
+
+ return NULL;
+}
+
+void
+ide_preferences_window_check (const char *page_name,
+ const IdePreferenceItemEntry *entry,
+ AdwPreferencesGroup *group,
+ gpointer user_data)
+{
+ IdePreferencesWindow *self = user_data;
+ g_autofree char *title_esc = NULL;
+ g_autofree char *subtitle_esc = NULL;
+ g_autoptr(GError) error = NULL;
+ AdwActionRow *row;
+ GtkWidget *child;
+ GSettings *settings;
+ GVariant *value;
+
+ g_return_if_fail (entry != NULL);
+ g_return_if_fail (ADW_IS_PREFERENCES_GROUP (group));
+ g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
+
+ if (!(settings = ide_preferences_window_get_settings (self, entry)))
+ return;
+
+ title_esc = g_markup_escape_text (entry->title ? entry->title : "", -1);
+ subtitle_esc = g_markup_escape_text (entry->subtitle ? entry->subtitle : "", -1);
+
+ child = g_object_new (GTK_TYPE_CHECK_BUTTON,
+ "valign", GTK_ALIGN_CENTER,
+ NULL);
+ gtk_widget_add_css_class (child, "preferences-check");
+ row = g_object_new (ADW_TYPE_ACTION_ROW,
+ "title", title_esc,
+ "subtitle", subtitle_esc,
+ "activatable-widget", child,
+ NULL);
+ adw_preferences_group_add (group, GTK_WIDGET (row));
+ adw_action_row_add_suffix (row, GTK_WIDGET (child));
+
+ if (entry->value)
+ value = g_variant_parse (NULL, entry->value, NULL, NULL, &error);
+ else
+ value = NULL;
+
+ if (error != NULL)
+ g_warning ("Failed to parse GVariant: %s", error->message);
+
+ g_settings_bind_with_mapping (settings, entry->key, child, "active",
+ G_SETTINGS_BIND_DEFAULT,
+ check_get_mapping, check_set_mapping,
+ value,
+ value ? (GDestroyNotify)g_variant_unref : NULL);
+}
+
IdePreferencesMode
ide_preferences_window_get_mode (IdePreferencesWindow *self)
{
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index e3cd99ae4..467267940 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -71,6 +71,7 @@ struct _IdePreferenceItemEntry
const char *schema_id;
const char *path;
const char *key;
+ const char *value;
/*< private >*/
gconstpointer user_data;
@@ -122,7 +123,10 @@ void ide_preferences_window_toggle (const char
const IdePreferenceItemEntry *entry,
AdwPreferencesGroup *group,
gpointer user_data);
-
-
+IDE_AVAILABLE_IN_ALL
+void ide_preferences_window_check (const char *page_name,
+ const IdePreferenceItemEntry *entry,
+ AdwPreferencesGroup *group,
+ gpointer user_data);
G_END_DECLS
diff --git a/src/libide/gui/style.css b/src/libide/gui/style.css
index 81c6c3af5..510f69c3a 100644
--- a/src/libide/gui/style.css
+++ b/src/libide/gui/style.css
@@ -9,6 +9,14 @@ window.preferences list.boxed-list.style-variant button {
window.preferences list.boxed-list.style-variant button:checked {
border-color: @theme_selected_bg_color;
}
+window.preferences list check {
+ background: none;
+ outline: none;
+ box-shadow: none;
+ border: none;
+ -gtk-icon-source: -gtk-icontheme('object-select-symbolic');
+ -gtk-icon-size: 18px;
+}
stylevariantpreview widget.wallpaper {
border-radius: 6px;
box-shadow: 0 0 9px 1px rgba(0,0,0,.2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]