[gnome-builder/wip/gtk4-port] libide/gui: add various preference helpers
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/gui: add various preference helpers
- Date: Tue, 12 Apr 2022 00:20:10 +0000 (UTC)
commit e61aef14426b491d2f9c92c2b614dabe23cd03ad
Author: Christian Hergert <chergert redhat com>
Date: Mon Apr 11 17:00:57 2022 -0700
libide/gui: add various preference helpers
And some utilities from Ide.py to make it easier to consume from Python.
src/libide/Ide.py | 41 ++++++++++++++
src/libide/gui/ide-preferences-window.c | 96 +++++++++++++++++++++++++++++++++
src/libide/gui/ide-preferences-window.h | 15 ++++++
3 files changed, 152 insertions(+)
---
diff --git a/src/libide/Ide.py b/src/libide/Ide.py
index 06a9a176a..04b932e14 100644
--- a/src/libide/Ide.py
+++ b/src/libide/Ide.py
@@ -201,3 +201,44 @@ Ide.debug = debug
Ide.info = info
Ide.message = message
Ide.warning = warning
+
+#
+# Preference Helpers
+#
+
+def add_preference_groups(window, groups):
+ for group in groups:
+ entry = Ide.PreferenceGroupEntry()
+ entry.page = group.get('page')
+ entry.name = group.get('name')
+ entry.priority = group.get('priority', 0)
+ entry.title = group.get('title', None)
+ window.add_groups([entry])
+ del entry
+
+def add_preference_items(window, items):
+ for item in items:
+ entry = Ide.PreferenceItemEntry()
+ entry.page = item.get('page')
+ entry.group = item.get('group')
+ entry.priority = item.get('priority', 0)
+ entry.title = item.get('title', None)
+ entry.subtitle = item.get('subtitle', None)
+ entry.schema_id = item.get('schema_id', None)
+ entry.key = item.get('key', None)
+ entry.path = item.get('path', None)
+ entry.value = item.get('value', None)
+
+ if item.get('kind') == 'toggle':
+ window.add_toggle(entry)
+ elif item.get('kind') == 'spin':
+ window.add_spin(entry)
+ elif item.get('kind') == 'check':
+ window.add_check(entry)
+ else:
+ Ide.critical("Unknown preference kind %s" % item.get('kind'))
+
+ del entry
+
+Ide.add_preference_groups = add_preference_groups
+Ide.add_preference_items = add_preference_items
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index e7ccd4f3b..0b0babe63 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -907,6 +907,33 @@ ide_preferences_window_add_pages (IdePreferencesWindow *self,
ide_preferences_window_queue_rebuild (self);
}
+void
+ide_preferences_window_add_group (IdePreferencesWindow *self,
+ const char *page,
+ const char *name,
+ int priority,
+ const char *title)
+{
+ IdePreferenceGroupEntry entry = {0};
+
+ g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
+
+ entry.page = page;
+ entry.name = name;
+ entry.priority = priority;
+ entry.title = title;
+
+ ide_preferences_window_add_groups (self, &entry, 1, NULL);
+}
+
+/**
+ * ide_preferences_window_add_groups:
+ * @self: a #IdePreferencesWindow
+ * @groups: (array length=n_groups): the groups to add
+ * @translation_domain: (nullable): gettext translation domain for i18n
+ *
+ * Adds the groups to the preferences window pages.
+ */
void
ide_preferences_window_add_groups (IdePreferencesWindow *self,
const IdePreferenceGroupEntry *groups,
@@ -1035,6 +1062,75 @@ ide_preferences_window_add_item (IdePreferencesWindow *self,
ide_preferences_window_queue_rebuild (self);
}
+/**
+ * ide_preferences_window_add_toggle:
+ * @self: a #IdePreferencesWindow
+ *
+ * Helper to add a toggle.
+ *
+ * This is mostly for use by language bindings such as Python.
+ */
+void
+ide_preferences_window_add_toggle (IdePreferencesWindow *self,
+ const IdePreferenceItemEntry *item)
+{
+ IdePreferenceItemEntry entry;
+
+ g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
+ g_return_if_fail (item != NULL);
+
+ entry = *item;
+ entry.callback = ide_preferences_window_toggle;
+
+ ide_preferences_window_add_items (self, &entry, 1, self, NULL);
+}
+
+/**
+ * ide_preferences_window_add_spin:
+ * @self: a #IdePreferencesWindow
+ *
+ * Helper to add a spin button.
+ *
+ * This is mostly for use by language bindings such as Python.
+ */
+void
+ide_preferences_window_add_spin (IdePreferencesWindow *self,
+ const IdePreferenceItemEntry *item)
+{
+ IdePreferenceItemEntry entry;
+
+ g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
+ g_return_if_fail (item != NULL);
+
+ entry = *item;
+ entry.callback = ide_preferences_window_spin;
+
+ ide_preferences_window_add_items (self, &entry, 1, self, NULL);
+}
+
+/**
+ * ide_preferences_window_add_check:
+ * @self: a #IdePreferencesWindow
+ *
+ * Helper to add a check image.
+ *
+ * This is mostly for use by language bindings such as Python.
+ */
+void
+ide_preferences_window_add_check (IdePreferencesWindow *self,
+ const IdePreferenceItemEntry *item)
+{
+ IdePreferenceItemEntry entry;
+
+ g_return_if_fail (IDE_IS_PREFERENCES_WINDOW (self));
+ g_return_if_fail (item != NULL);
+
+ entry = *item;
+ entry.callback = ide_preferences_window_check;
+
+ ide_preferences_window_add_items (self, &entry, 1, self, NULL);
+}
+
void
ide_preferences_window_toggle (const char *page_name,
const IdePreferenceItemEntry *entry,
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index 52fbe65ce..dbbf4b38d 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -99,6 +99,12 @@ void ide_preferences_window_add_pages (IdePreferencesWindow
gsize n_pages,
const char *translation_domain);
IDE_AVAILABLE_IN_ALL
+void ide_preferences_window_add_group (IdePreferencesWindow *self,
+ const char *page,
+ const char *name,
+ int priority,
+ const char *title);
+IDE_AVAILABLE_IN_ALL
void ide_preferences_window_add_groups (IdePreferencesWindow *self,
const IdePreferenceGroupEntry *groups,
gsize n_groups,
@@ -119,6 +125,15 @@ void ide_preferences_window_add_item (IdePreferencesWindow
gpointer user_data,
GDestroyNotify user_data_destroy);
IDE_AVAILABLE_IN_ALL
+void ide_preferences_window_add_toggle (IdePreferencesWindow *self,
+ const IdePreferenceItemEntry *item);
+IDE_AVAILABLE_IN_ALL
+void ide_preferences_window_add_spin (IdePreferencesWindow *self,
+ const IdePreferenceItemEntry *item);
+IDE_AVAILABLE_IN_ALL
+void ide_preferences_window_add_check (IdePreferencesWindow *self,
+ const IdePreferenceItemEntry *item);
+IDE_AVAILABLE_IN_ALL
void ide_preferences_window_toggle (const char *page_name,
const IdePreferenceItemEntry *entry,
AdwPreferencesGroup *group,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]