Clean up our GSettings use a bit more

This commit is contained in:
JosephMcc 2017-01-21 18:44:15 -08:00
parent f546598d83
commit 0a9588ef63
7 changed files with 48 additions and 316 deletions

View File

@ -382,7 +382,7 @@ on_use_default_font_changed (GSettings *settings,
static void static void
setup_font_colors_page_font_section (XedPreferencesDialog *dlg) setup_font_colors_page_font_section (XedPreferencesDialog *dlg)
{ {
GSettings *settings; GObject *settings;
gboolean use_default_font; gboolean use_default_font;
gchar *system_font = NULL; gchar *system_font = NULL;
gchar *label; gchar *label;

View File

@ -69,7 +69,7 @@ struct _XedAppPrivate
GtkPageSetup *page_setup; GtkPageSetup *page_setup;
GtkPrintSettings *print_settings; GtkPrintSettings *print_settings;
GSettings *settings; GObject *settings;
GSettings *window_settings; GSettings *window_settings;
PeasExtensionSet *extensions; PeasExtensionSet *extensions;
@ -886,7 +886,7 @@ _xed_app_set_default_print_settings (XedApp *app,
app->priv->print_settings = g_object_ref (settings); app->priv->print_settings = g_object_ref (settings);
} }
GSettings * GObject *
_xed_app_get_settings (XedApp *app) _xed_app_get_settings (XedApp *app)
{ {
g_return_val_if_fail (XED_IS_APP (app), NULL); g_return_val_if_fail (XED_IS_APP (app), NULL);

View File

@ -99,7 +99,7 @@ GtkPrintSettings *_xed_app_get_default_print_settings (XedApp *app);
void _xed_app_set_default_print_settings (XedApp *app, void _xed_app_set_default_print_settings (XedApp *app,
GtkPrintSettings *settings); GtkPrintSettings *settings);
GSettings *_xed_app_get_settings (XedApp *app); GObject *_xed_app_get_settings (XedApp *app);
G_END_DECLS G_END_DECLS

View File

@ -878,51 +878,60 @@ get_default_content_type (void)
static void static void
xed_document_init (XedDocument *doc) xed_document_init (XedDocument *doc)
{ {
XedDocumentPrivate *priv;
GtkSourceStyleScheme *style_scheme; GtkSourceStyleScheme *style_scheme;
gint undo_actions;
gboolean bracket_matching;
gboolean search_hl;
xed_debug (DEBUG_DOCUMENT); xed_debug (DEBUG_DOCUMENT);
doc->priv = XED_DOCUMENT_GET_PRIVATE (doc); doc->priv = XED_DOCUMENT_GET_PRIVATE (doc);
priv = doc->priv;
doc->priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor"); priv->editor_settings = g_settings_new ("org.x.editor.preferences.editor");
doc->priv->location = NULL; priv->location = NULL;
doc->priv->untitled_number = get_untitled_number (); priv->untitled_number = get_untitled_number ();
doc->priv->metadata_info = NULL; priv->metadata_info = NULL;
doc->priv->content_type = get_default_content_type (); priv->content_type = get_default_content_type ();
doc->priv->readonly = FALSE; priv->readonly = FALSE;
doc->priv->stop_cursor_moved_emission = FALSE; priv->stop_cursor_moved_emission = FALSE;
doc->priv->last_save_was_manually = TRUE; priv->last_save_was_manually = TRUE;
doc->priv->language_set_by_user = FALSE; priv->language_set_by_user = FALSE;
doc->priv->dispose_has_run = FALSE; priv->dispose_has_run = FALSE;
doc->priv->mtime.tv_sec = 0; priv->mtime.tv_sec = 0;
doc->priv->mtime.tv_usec = 0; priv->mtime.tv_usec = 0;
g_get_current_time (&doc->priv->time_of_last_save_or_load); g_get_current_time (&doc->priv->time_of_last_save_or_load);
doc->priv->encoding = xed_encoding_get_utf8 (); priv->encoding = xed_encoding_get_utf8 ();
doc->priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT; priv->newline_type = XED_DOCUMENT_NEWLINE_TYPE_DEFAULT;
undo_actions = g_settings_get_int (doc->priv->editor_settings, XED_SETTINGS_MAX_UNDO_ACTIONS); g_settings_bind (priv->editor_settings,
bracket_matching = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_BRACKET_MATCHING); XED_SETTINGS_MAX_UNDO_ACTIONS,
search_hl = g_settings_get_boolean (doc->priv->editor_settings, XED_SETTINGS_SEARCH_HIGHLIGHTING); doc,
"max-undo-levels",
G_SETTINGS_BIND_GET);
gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), undo_actions); g_settings_bind (priv->editor_settings,
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc), bracket_matching); XED_SETTINGS_BRACKET_MATCHING,
xed_document_set_enable_search_highlighting (doc, search_hl); doc,
"highlight-matching-brackets",
G_SETTINGS_BIND_GET);
style_scheme = get_default_style_scheme (doc->priv->editor_settings); g_settings_bind (priv->editor_settings,
XED_SETTINGS_SEARCH_HIGHLIGHTING,
doc,
"enable-search-highlighting",
G_SETTINGS_BIND_GET);
style_scheme = get_default_style_scheme (priv->editor_settings);
if (style_scheme != NULL) if (style_scheme != NULL)
{ {
gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme);

View File

@ -45,12 +45,11 @@ struct _XedSettingsPrivate
GSettings *interface; GSettings *interface;
GSettings *editor; GSettings *editor;
GSettings *ui; GSettings *ui;
GSettings *plugins;
gchar *old_scheme; gchar *old_scheme;
}; };
G_DEFINE_TYPE (XedSettings, xed_settings, G_TYPE_SETTINGS) G_DEFINE_TYPE (XedSettings, xed_settings, G_TYPE_OBJECT)
static void static void
xed_settings_finalize (GObject *object) xed_settings_finalize (GObject *object)
@ -85,12 +84,6 @@ xed_settings_dispose (GObject *object)
xs->priv->ui = NULL; xs->priv->ui = NULL;
} }
if (xs->priv->plugins != NULL)
{
g_object_unref (xs->priv->plugins);
xs->priv->plugins = NULL;
}
G_OBJECT_CLASS (xed_settings_parent_class)->dispose (object); G_OBJECT_CLASS (xed_settings_parent_class)->dispose (object);
} }
@ -107,7 +100,7 @@ set_font (XedSettings *xs,
for (l = views; l != NULL; l = g_list_next (l)) for (l = views; l != NULL; l = g_list_next (l))
{ {
/* Note: we use def=FALSE to avoid XedView to query gconf */ /* Note: we use def=FALSE to avoid XedView to query dconf */
xed_view_set_font (XED_VIEW (l->data), FALSE, font); xed_view_set_font (XED_VIEW (l->data), FALSE, font);
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts); gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
@ -275,28 +268,6 @@ on_auto_save_interval_changed (GSettings *settings,
g_list_free (docs); g_list_free (docs);
} }
static void
on_undo_actions_limit_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *docs, *l;
gint ul;
g_settings_get (settings, key, "u", &ul);
ul = CLAMP (ul, -1, 250);
docs = xed_app_get_documents (xed_app_get_default ());
for (l = docs; l != NULL; l = g_list_next (l))
{
gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data), ul);
}
g_list_free (docs);
}
static void static void
on_wrap_mode_changed (GSettings *settings, on_wrap_mode_changed (GSettings *settings,
const gchar *key, const gchar *key,
@ -317,192 +288,6 @@ on_wrap_mode_changed (GSettings *settings,
g_list_free (views); g_list_free (views);
} }
static void
on_tabs_size_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *views, *l;
guint ts;
g_settings_get (settings, key, "u", &ts);
ts = CLAMP (ts, 1, 24);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
}
g_list_free (views);
}
/* FIXME: insert_spaces and line_numbers are mostly the same it just changes
the func called, maybe typedef the func and refactorize? */
static void
on_insert_spaces_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *views, *l;
gboolean spaces;
spaces = g_settings_get_boolean (settings, key);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (l->data), spaces);
}
g_list_free (views);
}
static void
on_auto_indent_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *views, *l;
gboolean enable;
enable = g_settings_get_boolean (settings, key);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data), enable);
}
g_list_free (views);
}
static void
on_display_line_numbers_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *views, *l;
gboolean line_numbers;
line_numbers = g_settings_get_boolean (settings, key);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data), line_numbers);
}
g_list_free (views);
}
static void
on_hl_current_line_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *views, *l;
gboolean hl;
hl = g_settings_get_boolean (settings, key);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data), hl);
}
g_list_free (views);
}
static void
on_bracket_matching_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *docs, *l;
gboolean enable;
enable = g_settings_get_boolean (settings, key);
docs = xed_app_get_documents (xed_app_get_default ());
for (l = docs; l != NULL; l = g_list_next (l))
{
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data), enable);
}
g_list_free (docs);
}
static void
on_display_right_margin_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *views, *l;
gboolean display;
display = g_settings_get_boolean (settings, key);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data), display);
}
g_list_free (views);
}
static void
on_right_margin_position_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *views, *l;
gint pos;
g_settings_get (settings, key, "u", &pos);
pos = CLAMP (pos, 1, 160);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data), pos);
}
g_list_free (views);
}
static void
on_smart_home_end_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GtkSourceSmartHomeEndType smart_he;
GList *views, *l;
smart_he = g_settings_get_enum (settings, key);
views = xed_app_get_views (xed_app_get_default ());
for (l = views; l != NULL; l = g_list_next (l))
{
gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data), smart_he);
}
g_list_free (views);
}
static void static void
on_syntax_highlighting_changed (GSettings *settings, on_syntax_highlighting_changed (GSettings *settings,
const gchar *key, const gchar *key,
@ -540,26 +325,6 @@ on_syntax_highlighting_changed (GSettings *settings,
} }
} }
static void
on_search_highlighting_changed (GSettings *settings,
const gchar *key,
XedSettings *xs)
{
GList *docs, *l;
gboolean enable;
enable = g_settings_get_boolean (settings, key);
docs = xed_app_get_documents (xed_app_get_default ());
for (l = docs; l != NULL; l = g_list_next (l))
{
xed_document_set_enable_search_highlighting (XED_DOCUMENT (l->data), enable);
}
g_list_free (docs);
}
static void static void
on_enable_tab_scrolling_changed (GSettings *settings, on_enable_tab_scrolling_changed (GSettings *settings,
const gchar *key, const gchar *key,
@ -597,23 +362,13 @@ xed_settings_init (XedSettings *xs)
xs->priv = XED_SETTINGS_GET_PRIVATE (xs); xs->priv = XED_SETTINGS_GET_PRIVATE (xs);
xs->priv->old_scheme = NULL; xs->priv->old_scheme = NULL;
} xs->priv->editor = g_settings_new ("org.x.editor.preferences.editor");
xs->priv->ui = g_settings_new ("org.x.editor.preferences.ui");
static void
initialize (XedSettings *xs)
{
GSettings *prefs;
prefs = g_settings_get_child (G_SETTINGS (xs), "preferences");
xs->priv->editor = g_settings_get_child (prefs, "editor");
xs->priv->ui = g_settings_get_child (prefs, "ui");
g_object_unref (prefs);
xs->priv->plugins = g_settings_get_child (G_SETTINGS (xs), "plugins");
/* Load settings */ /* Load settings */
xs->priv->interface = g_settings_new ("org.gnome.desktop.interface"); xs->priv->interface = g_settings_new ("org.gnome.desktop.interface");
g_signal_connect (xs->priv->interface, "changed", g_signal_connect (xs->priv->interface, "changed::monospace-font-name",
G_CALLBACK (on_system_font_changed), xs); G_CALLBACK (on_system_font_changed), xs);
/* editor changes */ /* editor changes */
@ -627,32 +382,8 @@ initialize (XedSettings *xs)
G_CALLBACK (on_auto_save_changed), xs); G_CALLBACK (on_auto_save_changed), xs);
g_signal_connect (xs->priv->editor, "changed::auto-save-interval", g_signal_connect (xs->priv->editor, "changed::auto-save-interval",
G_CALLBACK (on_auto_save_interval_changed), xs); G_CALLBACK (on_auto_save_interval_changed), xs);
g_signal_connect (xs->priv->editor, "changed::undo-actions-limit",
G_CALLBACK (on_undo_actions_limit_changed), xs);
g_signal_connect (xs->priv->editor, "changed::wrap-mode",
G_CALLBACK (on_wrap_mode_changed), xs);
g_signal_connect (xs->priv->editor, "changed::tabs-size",
G_CALLBACK (on_tabs_size_changed), xs);
g_signal_connect (xs->priv->editor, "changed::insert-spaces",
G_CALLBACK (on_insert_spaces_changed), xs);
g_signal_connect (xs->priv->editor, "changed::auto-indent",
G_CALLBACK (on_auto_indent_changed), xs);
g_signal_connect (xs->priv->editor, "changed::display-line-numbers",
G_CALLBACK (on_display_line_numbers_changed), xs);
g_signal_connect (xs->priv->editor, "changed::highlight-current-line",
G_CALLBACK (on_hl_current_line_changed), xs);
g_signal_connect (xs->priv->editor, "changed::bracket-matching",
G_CALLBACK (on_bracket_matching_changed), xs);
g_signal_connect (xs->priv->editor, "changed::display-right-margin",
G_CALLBACK (on_display_right_margin_changed), xs);
g_signal_connect (xs->priv->editor, "changed::right-margin-position",
G_CALLBACK (on_right_margin_position_changed), xs);
g_signal_connect (xs->priv->editor, "changed::smart-home-end",
G_CALLBACK (on_smart_home_end_changed), xs);
g_signal_connect (xs->priv->editor, "changed::syntax-highlighting", g_signal_connect (xs->priv->editor, "changed::syntax-highlighting",
G_CALLBACK (on_syntax_highlighting_changed), xs); G_CALLBACK (on_syntax_highlighting_changed), xs);
g_signal_connect (xs->priv->editor, "changed::search-highlighting",
G_CALLBACK (on_search_highlighting_changed), xs);
g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling", g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling",
G_CALLBACK (on_enable_tab_scrolling_changed), xs); G_CALLBACK (on_enable_tab_scrolling_changed), xs);
@ -672,18 +403,10 @@ xed_settings_class_init (XedSettingsClass *klass)
g_type_class_add_private (object_class, sizeof (XedSettingsPrivate)); g_type_class_add_private (object_class, sizeof (XedSettingsPrivate));
} }
GSettings * GObject *
xed_settings_new () xed_settings_new ()
{ {
XedSettings *settings; return g_object_new (XED_TYPE_SETTINGS, NULL);
settings = g_object_new (XED_TYPE_SETTINGS,
"schema", "org.x.editor",
NULL);
initialize (settings);
return G_SETTINGS (settings);
} }
gchar * gchar *

View File

@ -45,14 +45,14 @@ typedef struct _XedSettingsPrivate XedSettingsPrivate;
struct _XedSettings struct _XedSettings
{ {
GSettings parent; GObject parent;
XedSettingsPrivate *priv; XedSettingsPrivate *priv;
}; };
struct _XedSettingsClass struct _XedSettingsClass
{ {
GSettingsClass parent_class; GObjectClass parent_class;
}; };
// typedef enum { // typedef enum {
@ -64,7 +64,7 @@ struct _XedSettingsClass
GType xed_settings_get_type (void) G_GNUC_CONST; GType xed_settings_get_type (void) G_GNUC_CONST;
GSettings *xed_settings_new (void); GObject *xed_settings_new (void);
// XedLockdownMask xed_settings_get_lockdown (XedSettings *xs); // XedLockdownMask xed_settings_get_lockdown (XedSettings *xs);

View File

@ -844,7 +844,7 @@ xed_view_set_font (XedView *view,
if (def) if (def)
{ {
GSettings *settings; GObject *settings;
gchar *font; gchar *font;
settings = _xed_app_get_settings (xed_app_get_default ()); settings = _xed_app_get_settings (xed_app_get_default ());