[gedit/gnome-3-8] Directly bind settings on GeditView.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/gnome-3-8] Directly bind settings on GeditView.
- Date: Sun, 21 Apr 2013 10:52:54 +0000 (UTC)
commit b006cfea516abf246ce6640eb3ee60cbc121119e
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sat Apr 20 23:26:18 2013 +0200
Directly bind settings on GeditView.
In this way we do not have to listen on changes for the view.
Also in this way other non tracked GeditViews like the one
in tools or snippets will not have to manage the settings by
themselves.
gedit/gedit-settings.c | 230 -------------------------------------------------
gedit/gedit-view.c | 93 ++++++++++++--------
2 files changed, 55 insertions(+), 268 deletions(-)
---
diff --git a/gedit/gedit-settings.c b/gedit/gedit-settings.c
index c6fcd47..25e04c1 100644
--- a/gedit/gedit-settings.c
+++ b/gedit/gedit-settings.c
@@ -323,135 +323,6 @@ on_undo_actions_limit_changed (GSettings *settings,
}
static void
-on_wrap_mode_changed (GSettings *settings,
- const gchar *key,
- GeditSettings *gs)
-{
- GtkWrapMode wrap_mode;
- GList *views, *l;
-
- wrap_mode = g_settings_get_enum (settings, key);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_get_default ()));
-
- for (l = views; l != NULL; l = g_list_next (l))
- {
- gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data),
- wrap_mode);
- }
-
- g_list_free (views);
-}
-
-static void
-on_tabs_size_changed (GSettings *settings,
- const gchar *key,
- GeditSettings *gs)
-{
- GList *views, *l;
- guint ts;
-
- g_settings_get (settings, key, "u", &ts);
-
- ts = CLAMP (ts, 1, 24);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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);
-}
-
-static void
-on_insert_spaces_changed (GSettings *settings,
- const gchar *key,
- GeditSettings *gs)
-{
- GList *views, *l;
- gboolean spaces;
-
- spaces = g_settings_get_boolean (settings, key);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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,
- GeditSettings *gs)
-{
- GList *views, *l;
- gboolean enable;
-
- enable = g_settings_get_boolean (settings, key);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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,
- GeditSettings *gs)
-{
- GList *views, *l;
- gboolean line_numbers;
-
- line_numbers = g_settings_get_boolean (settings, key);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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,
- GeditSettings *gs)
-{
- GList *views, *l;
- gboolean hl;
-
- hl = g_settings_get_boolean (settings, key);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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,
GeditSettings *gs)
@@ -473,71 +344,6 @@ on_bracket_matching_changed (GSettings *settings,
}
static void
-on_display_right_margin_changed (GSettings *settings,
- const gchar *key,
- GeditSettings *gs)
-{
- GList *views, *l;
- gboolean display;
-
- display = g_settings_get_boolean (settings, key);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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,
- GeditSettings *gs)
-{
- GList *views, *l;
- gint pos;
-
- g_settings_get (settings, key, "u", &pos);
-
- pos = CLAMP (pos, 1, 160);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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,
- GeditSettings *gs)
-{
- GtkSourceSmartHomeEndType smart_he;
- GList *views, *l;
-
- smart_he = g_settings_get_enum (settings, key);
-
- views = gedit_app_get_views (GEDIT_APP (g_application_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
on_syntax_highlighting_changed (GSettings *settings,
const gchar *key,
GeditSettings *gs)
@@ -647,46 +453,10 @@ gedit_settings_init (GeditSettings *gs)
G_CALLBACK (on_undo_actions_limit_changed),
gs);
g_signal_connect (gs->priv->editor,
- "changed::wrap-mode",
- G_CALLBACK (on_wrap_mode_changed),
- gs);
- g_signal_connect (gs->priv->editor,
- "changed::tabs-size",
- G_CALLBACK (on_tabs_size_changed),
- gs);
- g_signal_connect (gs->priv->editor,
- "changed::insert-spaces",
- G_CALLBACK (on_insert_spaces_changed),
- gs);
- g_signal_connect (gs->priv->editor,
- "changed::auto-indent",
- G_CALLBACK (on_auto_indent_changed),
- gs);
- g_signal_connect (gs->priv->editor,
- "changed::display-line-numbers",
- G_CALLBACK (on_display_line_numbers_changed),
- gs);
- g_signal_connect (gs->priv->editor,
- "changed::highlight-current-line",
- G_CALLBACK (on_hl_current_line_changed),
- gs);
- g_signal_connect (gs->priv->editor,
"changed::bracket-matching",
G_CALLBACK (on_bracket_matching_changed),
gs);
g_signal_connect (gs->priv->editor,
- "changed::display-right-margin",
- G_CALLBACK (on_display_right_margin_changed),
- gs);
- g_signal_connect (gs->priv->editor,
- "changed::right-margin-position",
- G_CALLBACK (on_right_margin_position_changed),
- gs);
- g_signal_connect (gs->priv->editor,
- "changed::smart-home-end",
- G_CALLBACK (on_smart_home_end_changed),
- gs);
- g_signal_connect (gs->priv->editor,
"changed::syntax-highlighting",
G_CALLBACK (on_syntax_highlighting_changed),
gs);
diff --git a/gedit/gedit-view.c b/gedit/gedit-view.c
index 07cf61f..f59ae92 100644
--- a/gedit/gedit-view.c
+++ b/gedit/gedit-view.c
@@ -269,18 +269,11 @@ static void
gedit_view_constructed (GObject *object)
{
GeditView *view;
+ GeditViewPrivate *priv;
gboolean use_default_font;
- gboolean display_line_numbers;
- gboolean auto_indent;
- gboolean insert_spaces;
- gboolean display_right_margin;
- gboolean hl_current_line;
- guint tabs_size;
- guint right_margin_position;
- GtkWrapMode wrap_mode;
- GtkSourceSmartHomeEndType smart_home_end;
view = GEDIT_VIEW (object);
+ priv = view->priv;
/* Get setting values */
use_default_font = g_settings_get_boolean (view->priv->editor_settings,
@@ -306,37 +299,61 @@ gedit_view_constructed (GObject *object)
gedit_view_set_font (view, TRUE, NULL);
}
- display_line_numbers = g_settings_get_boolean (view->priv->editor_settings,
- GEDIT_SETTINGS_DISPLAY_LINE_NUMBERS);
- auto_indent = g_settings_get_boolean (view->priv->editor_settings,
- GEDIT_SETTINGS_AUTO_INDENT);
- g_settings_get (view->priv->editor_settings, GEDIT_SETTINGS_TABS_SIZE,
- "u", &tabs_size);
- insert_spaces = g_settings_get_boolean (view->priv->editor_settings,
- GEDIT_SETTINGS_INSERT_SPACES);
- display_right_margin = g_settings_get_boolean (view->priv->editor_settings,
- GEDIT_SETTINGS_DISPLAY_RIGHT_MARGIN);
- g_settings_get (view->priv->editor_settings, GEDIT_SETTINGS_RIGHT_MARGIN_POSITION,
- "u", &right_margin_position);
- hl_current_line = g_settings_get_boolean (view->priv->editor_settings,
- GEDIT_SETTINGS_HIGHLIGHT_CURRENT_LINE);
-
- wrap_mode = g_settings_get_enum (view->priv->editor_settings,
- GEDIT_SETTINGS_WRAP_MODE);
-
- smart_home_end = g_settings_get_enum (view->priv->editor_settings,
- GEDIT_SETTINGS_SMART_HOME_END);
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_DISPLAY_LINE_NUMBERS,
+ view,
+ "show-line-numbers",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_AUTO_INDENT,
+ view,
+ "auto-indent",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_TABS_SIZE,
+ view,
+ "tab-width",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_INSERT_SPACES,
+ view,
+ "insert-spaces-instead-of-tabs",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_DISPLAY_RIGHT_MARGIN,
+ view,
+ "show-right-margin",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_RIGHT_MARGIN_POSITION,
+ view,
+ "right-margin-position",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_HIGHLIGHT_CURRENT_LINE,
+ view,
+ "highlight-current-line",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_WRAP_MODE,
+ view,
+ "wrap-mode",
+ G_SETTINGS_BIND_GET);
+
+ g_settings_bind (priv->editor_settings,
+ GEDIT_SETTINGS_SMART_HOME_END,
+ view,
+ "smart-home-end",
+ G_SETTINGS_BIND_GET);
g_object_set (G_OBJECT (view),
- "wrap_mode", wrap_mode,
- "show_line_numbers", display_line_numbers,
- "auto_indent", auto_indent,
- "tab_width", tabs_size,
- "insert_spaces_instead_of_tabs", insert_spaces,
- "show_right_margin", display_right_margin,
- "right_margin_position", right_margin_position,
- "highlight_current_line", hl_current_line,
- "smart_home_end", smart_home_end,
"indent_on_tab", TRUE,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]