[gnome-builder] prefs: implement removing of widgets
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] prefs: implement removing of widgets
- Date: Sat, 13 Feb 2016 18:42:57 +0000 (UTC)
commit cdd49295d7a64b3d3fa80462d26a25ddf3445be7
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sat Feb 13 11:50:16 2016 +0100
prefs: implement removing of widgets
you can now use ide_preference_remove_id
with the id you get at preferences widgets creation
to remove them from the prefs ( most of the time,
during unload )
libide/ide-preferences.c | 15 ++
libide/ide-preferences.h | 257 +++++++++++-----------
libide/preferences/ide-preferences-perspective.c | 25 ++
3 files changed, 171 insertions(+), 126 deletions(-)
---
diff --git a/libide/ide-preferences.c b/libide/ide-preferences.c
index 97ff8f0..0a8f8f5 100644
--- a/libide/ide-preferences.c
+++ b/libide/ide-preferences.c
@@ -180,6 +180,21 @@ ide_preferences_add_font_button (IdePreferences *self,
return IDE_PREFERENCES_GET_IFACE (self)->add_font_button (self, page_name, group_name, schema_id, key,
title, keywords, priority);
}
+/**
+ * ide_preference_remove_id:
+ * @widget_id: An preferences widget id
+ *
+ */
+gboolean
+ide_preferences_remove_id (IdePreferences *self,
+ guint widget_id)
+{
+ g_return_val_if_fail (IDE_IS_PREFERENCES (self), FALSE);
+ g_return_val_if_fail (widget_id, FALSE);
+
+ return IDE_PREFERENCES_GET_IFACE (self)->remove_id (self, widget_id);
+}
+
void
ide_preferences_set_page (IdePreferences *self,
const gchar *page_name,
diff --git a/libide/ide-preferences.h b/libide/ide-preferences.h
index b63148a..a4b9362 100644
--- a/libide/ide-preferences.h
+++ b/libide/ide-preferences.h
@@ -31,134 +31,139 @@ struct _IdePreferencesInterface
{
GTypeInterface parent_interface;
- void (*set_page) (IdePreferences *self,
- const gchar *page_name,
- GHashTable *map);
- void (*add_page) (IdePreferences *self,
- const gchar *page_name,
- const gchar *title,
- gint priority);
- void (*add_group) (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *title,
- gint priority);
- void (*add_list_group ) (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *title,
- gint priority);
- guint (*add_radio) (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *path,
- const gchar *variant_string,
- const gchar *title,
- const gchar *subtitle,
- const gchar *keywords,
- gint priority);
- guint (*add_font_button) (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *title,
- const gchar *keywords,
- gint priority);
- guint (*add_switch) (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *path,
- const gchar *variant_string,
- const gchar *title,
- const gchar *subtitle,
- const gchar *keywords,
- gint priority);
- guint (*add_spin_button) (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *path,
- const gchar *title,
- const gchar *subtitle,
- const gchar *keywords,
- gint priority);
- guint (*add_custom) (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- GtkWidget *widget,
- const gchar *keywords,
- gint priority);
+ void (*set_page) (IdePreferences *self,
+ const gchar *page_name,
+ GHashTable *map);
+ void (*add_page) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *title,
+ gint priority);
+ void (*add_group) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *title,
+ gint priority);
+ void (*add_list_group ) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *title,
+ gint priority);
+ guint (*add_radio) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *path,
+ const gchar *variant_string,
+ const gchar *title,
+ const gchar *subtitle,
+ const gchar *keywords,
+ gint priority);
+ guint (*add_font_button) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *title,
+ const gchar *keywords,
+ gint priority);
+ guint (*add_switch) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *path,
+ const gchar *variant_string,
+ const gchar *title,
+ const gchar *subtitle,
+ const gchar *keywords,
+ gint priority);
+ guint (*add_spin_button) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *path,
+ const gchar *title,
+ const gchar *subtitle,
+ const gchar *keywords,
+ gint priority);
+ guint (*add_custom) (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ GtkWidget *widget,
+ const gchar *keywords,
+ gint priority);
+
+ gboolean (*remove_id) (IdePreferences *self,
+ guint widget_id);
};
-void ide_preferences_add_page (IdePreferences *self,
- const gchar *page_name,
- const gchar *title,
- gint priority);
-void ide_preferences_add_group (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *title,
- gint priority);
-void ide_preferences_add_list_group (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *title,
- gint priority);
-guint ide_preferences_add_radio (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *path,
- const gchar *variant_string,
- const gchar *title,
- const gchar *subtitle,
- const gchar *keywords,
- gint priority);
-guint ide_preferences_add_switch (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *path,
- const gchar *variant_string,
- const gchar *title,
- const gchar *subtitle,
- const gchar *keywords,
- gint priority);
-guint ide_preferences_add_spin_button (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *path,
- const gchar *title,
- const gchar *subtitle,
- const gchar *keywords,
- gint priority);
-guint ide_preferences_add_custom (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- GtkWidget *widget,
- const gchar *keywords,
- gint priority);
-guint ide_preferences_add_font_button (IdePreferences *self,
- const gchar *page_name,
- const gchar *group_name,
- const gchar *schema_id,
- const gchar *key,
- const gchar *title,
- const gchar *keywords,
- gint priority);
-void ide_preferences_set_page (IdePreferences *self,
- const gchar *page_name,
- GHashTable *map);
+void ide_preferences_add_page (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *title,
+ gint priority);
+void ide_preferences_add_group (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *title,
+ gint priority);
+void ide_preferences_add_list_group (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *title,
+ gint priority);
+guint ide_preferences_add_radio (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *path,
+ const gchar *variant_string,
+ const gchar *title,
+ const gchar *subtitle,
+ const gchar *keywords,
+ gint priority);
+guint ide_preferences_add_switch (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *path,
+ const gchar *variant_string,
+ const gchar *title,
+ const gchar *subtitle,
+ const gchar *keywords,
+ gint priority);
+guint ide_preferences_add_spin_button (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *path,
+ const gchar *title,
+ const gchar *subtitle,
+ const gchar *keywords,
+ gint priority);
+guint ide_preferences_add_custom (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ GtkWidget *widget,
+ const gchar *keywords,
+ gint priority);
+guint ide_preferences_add_font_button (IdePreferences *self,
+ const gchar *page_name,
+ const gchar *group_name,
+ const gchar *schema_id,
+ const gchar *key,
+ const gchar *title,
+ const gchar *keywords,
+ gint priority);
+gboolean ide_preferences_remove_id (IdePreferences *self,
+ guint widget_id);
+void ide_preferences_set_page (IdePreferences *self,
+ const gchar *page_name,
+ GHashTable *map);
G_END_DECLS
diff --git a/libide/preferences/ide-preferences-perspective.c
b/libide/preferences/ide-preferences-perspective.c
index 338bb6c..10a8d0e 100644
--- a/libide/preferences/ide-preferences-perspective.c
+++ b/libide/preferences/ide-preferences-perspective.c
@@ -738,6 +738,30 @@ ide_preferences_perspective_add_custom (IdePreferences *preferences,
return widget_id;
}
+static gboolean
+ide_preferences_perspective_remove_id (IdePreferences *preferences,
+ guint widget_id)
+{
+ IdePreferencesPerspective *self = (IdePreferencesPerspective *)preferences;
+ GtkWidget *widget;
+
+ g_assert (IDE_IS_PREFERENCES_PERSPECTIVE (self));
+ g_assert (widget_id);
+
+ widget = g_hash_table_lookup (self->widgets, GINT_TO_POINTER (widget_id));
+ if (widget != NULL)
+ {
+ if (g_hash_table_remove (self->widgets, GINT_TO_POINTER (widget_id)))
+ {
+ gtk_widget_destroy (widget);
+ return TRUE;
+ }
+ }
+
+ g_warning ("No Preferences widget with number %i could be found and thus removed.", widget_id);
+ return FALSE;
+}
+
static void
ide_preferences_perspective_set_page (IdePreferences *preferences,
const gchar *page_name,
@@ -782,6 +806,7 @@ ide_preferences_iface_init (IdePreferencesInterface *iface)
iface->add_spin_button = ide_preferences_perspective_add_spin_button;
iface->add_custom = ide_preferences_perspective_add_custom;
iface->set_page = ide_preferences_perspective_set_page;
+ iface->remove_id = ide_preferences_perspective_remove_id;
}
static gchar *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]