[gnome-builder] editor: remove need for GbEditorSettings
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: remove need for GbEditorSettings
- Date: Fri, 21 Nov 2014 10:19:43 +0000 (UTC)
commit d4b59413ef197aa86e4f27cfb0b06cadeb5637fb
Author: Christian Hergert <christian hergert me>
Date: Fri Nov 21 01:26:30 2014 -0800
editor: remove need for GbEditorSettings
We can just use GSettings directly. I think it results in easier to
understand code without the extra layer of abstraction.
src/editor/gb-editor-settings-widget.c | 131 +++--
src/editor/gb-editor-settings.c | 699 ------------------------
src/editor/gb-editor-settings.h | 94 ----
src/editor/gb-editor-tab-private.h | 6 -
src/editor/gb-editor-tab.c | 1 -
src/editor/gb-editor-tab.h | 4 -
src/gnome-builder.mk | 2 -
src/preferences/gb-preferences-page-language.c | 9 +-
8 files changed, 71 insertions(+), 875 deletions(-)
---
diff --git a/src/editor/gb-editor-settings-widget.c b/src/editor/gb-editor-settings-widget.c
index 88e1d0d..f3c5824 100644
--- a/src/editor/gb-editor-settings-widget.c
+++ b/src/editor/gb-editor-settings-widget.c
@@ -18,12 +18,12 @@
#include <glib/gi18n.h>
-#include "gb-editor-settings.h"
#include "gb-editor-settings-widget.h"
struct _GbEditorSettingsWidgetPrivate
{
- GbEditorSettings *settings;
+ GSettings *settings;
+ gchar *language;
GtkCheckButton *auto_indent;
GtkCheckButton *highlight_current_line;
@@ -33,7 +33,6 @@ struct _GbEditorSettingsWidgetPrivate
GtkCheckButton *show_line_numbers;
GtkCheckButton *show_right_margin;
GtkCheckButton *smart_home_end;
-
GtkSpinButton *right_margin_position;
GtkSpinButton *tab_width;
};
@@ -43,67 +42,78 @@ G_DEFINE_TYPE_WITH_PRIVATE (GbEditorSettingsWidget, gb_editor_settings_widget,
enum {
PROP_0,
- PROP_SETTINGS,
+ PROP_LANGUAGE,
LAST_PROP
};
static GParamSpec *gParamSpecs [LAST_PROP];
-GbEditorSettings *
-gb_editor_settings_widget_get_settings (GbEditorSettingsWidget *widget)
+const gchar *
+gb_editor_settings_widget_get_language (GbEditorSettingsWidget *widget)
{
g_return_val_if_fail (GB_IS_EDITOR_SETTINGS_WIDGET (widget), NULL);
- return widget->priv->settings;
+ return widget->priv->language;
}
-static void
-gb_editor_settings_widget_set_settings (GbEditorSettingsWidget *widget,
- GbEditorSettings *settings)
+void
+gb_editor_settings_widget_set_language (GbEditorSettingsWidget *widget,
+ const gchar *language)
{
GbEditorSettingsWidgetPrivate *priv;
g_return_if_fail (GB_IS_EDITOR_SETTINGS_WIDGET (widget));
- g_return_if_fail (GB_IS_EDITOR_SETTINGS (settings));
priv = widget->priv;
- if (settings == priv->settings)
- return;
-
- g_clear_object (&priv->settings);
- priv->settings = g_object_ref (settings);
-
- g_object_bind_property (settings, "auto-indent",
- priv->auto_indent, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "highlight-current-line",
- priv->highlight_current_line, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "highlight-matching-brackets",
- priv->highlight_matching_brackets, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "insert-spaces-instead-of-tabs",
- priv->insert_spaces_instead_of_tabs, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "show-line-marks",
- priv->show_line_marks, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "show-line-numbers",
- priv->show_line_numbers, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "show-right-margin",
- priv->show_right_margin, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "smart-home-end",
- priv->smart_home_end, "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "right-margin-position",
- priv->right_margin_position, "value",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- g_object_bind_property (settings, "tab-width",
- priv->tab_width, "value",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ if (language != priv->language)
+ {
+ gchar *path;
+
+ g_free (priv->language);
+ priv->language = g_strdup (language);
+
+ g_clear_object (&priv->settings);
+
+ path = g_strdup_printf ("/org/gnome/builder/editor/language/%s/",
+ language);
+ priv->settings = g_settings_new_with_path (
+ "org.gnome.builder.editor.language", path);
+ g_free (path);
+
+ g_settings_bind (priv->settings, "auto-indent",
+ priv->auto_indent, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "highlight-current-line",
+ priv->highlight_current_line, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "highlight-matching-brackets",
+ priv->highlight_matching_brackets, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "insert-spaces-instead-of-tabs",
+ priv->insert_spaces_instead_of_tabs, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "show-line-marks",
+ priv->show_line_marks, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "show-line-numbers",
+ priv->show_line_numbers, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "show-right-margin",
+ priv->show_right_margin, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "smart-home-end",
+ priv->smart_home_end, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "right-margin-position",
+ priv->right_margin_position, "value",
+ G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (priv->settings, "tab-width",
+ priv->tab_width, "value",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_object_notify_by_pspec (G_OBJECT (widget), gParamSpecs [PROP_LANGUAGE]);
+ }
}
static void
@@ -111,6 +121,7 @@ gb_editor_settings_widget_finalize (GObject *object)
{
GbEditorSettingsWidgetPrivate *priv = GB_EDITOR_SETTINGS_WIDGET (object)->priv;
+ g_clear_pointer (&priv->language, g_free);
g_clear_object (&priv->settings);
G_OBJECT_CLASS (gb_editor_settings_widget_parent_class)->finalize (object);
@@ -126,8 +137,8 @@ gb_editor_settings_widget_get_property (GObject *object,
switch (prop_id)
{
- case PROP_SETTINGS:
- g_value_set_object (value, gb_editor_settings_widget_get_settings (self));
+ case PROP_LANGUAGE:
+ g_value_set_string (value, gb_editor_settings_widget_get_language (self));
break;
default:
@@ -145,8 +156,8 @@ gb_editor_settings_widget_set_property (GObject *object,
switch (prop_id)
{
- case PROP_SETTINGS:
- gb_editor_settings_widget_set_settings (self, g_value_get_object (value));
+ case PROP_LANGUAGE:
+ gb_editor_settings_widget_set_language (self, g_value_get_string (value));
break;
default:
@@ -178,16 +189,14 @@ gb_editor_settings_widget_class_init (GbEditorSettingsWidgetClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GbEditorSettingsWidget, smart_home_end);
gtk_widget_class_bind_template_child_private (widget_class, GbEditorSettingsWidget, tab_width);
- gParamSpecs [PROP_SETTINGS] =
- g_param_spec_object ("settings",
- _("Settings"),
- _("The settings to be configured."),
- GB_TYPE_EDITOR_SETTINGS,
- (G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
- g_object_class_install_property (object_class, PROP_SETTINGS,
- gParamSpecs [PROP_SETTINGS]);
+ gParamSpecs [PROP_LANGUAGE] =
+ g_param_spec_string ("language",
+ _("Language"),
+ _("The language to change the settings for."),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_LANGUAGE,
+ gParamSpecs [PROP_LANGUAGE]);
}
static void
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index 51aeb6a..7194b1d 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -25,7 +25,6 @@
#include "gb-animation.h"
#include "gb-box-theatric.h"
#include "gb-editor-document.h"
-#include "gb-editor-settings.h"
#include "gb-markdown-preview.h"
#include "gb-notebook.h"
#include "gb-source-change-monitor.h"
@@ -58,11 +57,6 @@ struct _GbEditorTabPrivate
GtkSourceGutterRenderer *change_renderer;
/*
- * Tab related settings.
- */
- GbEditorSettings *settings;
-
- /*
* Weak reference bindings for tracking settings.
*/
GBinding *auto_indent_binding;
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 52e6b9f..18f1a45 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -1226,7 +1226,6 @@ gb_editor_tab_dispose (GObject *object)
g_clear_object (&tab->priv->search_highlighter);
g_clear_object (&tab->priv->search_settings);
g_clear_object (&tab->priv->search_context);
- g_clear_object (&tab->priv->settings);
g_clear_object (&tab->priv->document);
G_OBJECT_CLASS (gb_editor_tab_parent_class)->dispose (object);
diff --git a/src/editor/gb-editor-tab.h b/src/editor/gb-editor-tab.h
index ed86a01..b7e2625 100644
--- a/src/editor/gb-editor-tab.h
+++ b/src/editor/gb-editor-tab.h
@@ -21,7 +21,6 @@
#include "gb-tab.h"
#include "gb-editor-document.h"
-#include "gb-editor-settings.h"
G_BEGIN_DECLS
@@ -54,9 +53,6 @@ GType gb_editor_tab_get_type (void) G_GNUC_CONST;
GtkWidget *gb_editor_tab_new (void);
GbEditorDocument *gb_editor_tab_get_document (GbEditorTab *tab);
GtkSourceFile *gb_editor_tab_get_file (GbEditorTab *tab);
-GbEditorSettings *gb_editor_tab_get_settings (GbEditorTab *tab);
-void gb_editor_tab_set_settings (GbEditorTab *tab,
- GbEditorSettings *settings);
void gb_editor_tab_set_font_desc (GbEditorTab *tab,
const PangoFontDescription *font_desc);
gboolean gb_editor_tab_get_is_default (GbEditorTab *tab);
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 3cb2fda..0358f32 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -57,8 +57,6 @@ libgnome_builder_la_SOURCES = \
src/editor/gb-editor-file-marks.h \
src/editor/gb-editor-navigation-item.c \
src/editor/gb-editor-navigation-item.h \
- src/editor/gb-editor-settings.c \
- src/editor/gb-editor-settings.h \
src/editor/gb-editor-settings-widget.c \
src/editor/gb-editor-settings-widget.h \
src/editor/gb-editor-tab.c \
diff --git a/src/preferences/gb-preferences-page-language.c b/src/preferences/gb-preferences-page-language.c
index 1eaeacb..3889cc8 100644
--- a/src/preferences/gb-preferences-page-language.c
+++ b/src/preferences/gb-preferences-page-language.c
@@ -21,7 +21,6 @@
#include <gtksourceview/gtksource.h>
#include <string.h>
-#include "gb-editor-settings.h"
#include "gb-editor-settings-widget.h"
#include "gb-preferences-page-language.h"
#include "gb-string.h"
@@ -133,7 +132,6 @@ row_selected (GtkListBox *list_box,
{
GtkSourceLanguage *lang;
GbEditorSettingsWidget *widget;
- GbEditorSettings *settings;
const gchar *lang_id;
GtkDialog *dialog;
GtkWidget *toplevel;
@@ -151,9 +149,6 @@ row_selected (GtkListBox *list_box,
return;
lang_id = gtk_source_language_get_id (lang);
- settings = gb_editor_settings_new_for_language (lang_id);
- if (!settings)
- return;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (list_box));
@@ -166,7 +161,7 @@ row_selected (GtkListBox *list_box,
content_area = gtk_dialog_get_content_area (dialog);
widget = g_object_new (GB_TYPE_EDITOR_SETTINGS_WIDGET,
"border-width", 12,
- "settings", settings,
+ "language", lang_id,
"visible", TRUE,
NULL);
gtk_container_add (GTK_CONTAINER (content_area), GTK_WIDGET (widget));
@@ -175,8 +170,6 @@ row_selected (GtkListBox *list_box,
gtk_widget_destroy (GTK_WIDGET (dialog));
gtk_list_box_unselect_row (list_box, row);
-
- g_object_unref (settings);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]