[gitg] Use GBinding instead of homemade DataBinding.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Use GBinding instead of homemade DataBinding.
- Date: Thu, 30 Dec 2010 12:48:39 +0000 (UTC)
commit f9c70db31f9e3e5b5ecefb22a5544f99119c990c
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Dec 29 17:03:47 2010 +0100
Use GBinding instead of homemade DataBinding.
gitg/Makefile.am | 2 -
gitg/gitg-commit-view.c | 11 +-
gitg/gitg-data-binding.c | 262 ----------------------------------------
gitg/gitg-data-binding.h | 56 ---------
gitg/gitg-preferences-dialog.c | 147 +++++++++++++----------
gitg/gitg-window.c | 142 ++++++++++++----------
6 files changed, 170 insertions(+), 450 deletions(-)
---
diff --git a/gitg/Makefile.am b/gitg/Makefile.am
index 581f4d2..422dc38 100644
--- a/gitg/Makefile.am
+++ b/gitg/Makefile.am
@@ -16,7 +16,6 @@ NOINST_H_FILES = \
gitg-branch-actions.h \
gitg-cell-renderer-path.h \
gitg-commit-view.h \
- gitg-data-binding.h \
gitg-diff-line-renderer.h \
gitg-diff-view.h \
gitg-dirs.h \
@@ -43,7 +42,6 @@ gitg_SOURCES = \
gitg-branch-actions.c \
gitg-cell-renderer-path.c \
gitg-commit-view.c \
- gitg-data-binding.c \
gitg-diff-line-renderer.c \
gitg-diff-view.c \
gitg-dirs.c \
diff --git a/gitg/gitg-commit-view.c b/gitg/gitg-commit-view.c
index 7b60b5e..5b3d273 100644
--- a/gitg/gitg-commit-view.c
+++ b/gitg/gitg-commit-view.c
@@ -31,7 +31,6 @@
#include "gitg-commit-view.h"
#include "gitg-diff-view.h"
#include "gitg-preferences.h"
-#include "gitg-data-binding.h"
#include "gitg-utils.h"
#include "gseal-gtk-compat.h"
@@ -1412,11 +1411,13 @@ gitg_commit_view_parser_finished(GtkBuildable *buildable, GtkBuilder *builder)
GitgPreferences *preferences = gitg_preferences_get_default();
- gitg_data_binding_new(preferences, "message-show-right-margin",
- self->priv->comment_view, "show-right-margin");
+ g_object_bind_property (preferences, "message-show-right-margin",
+ self->priv->comment_view, "show-right-margin",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- gitg_data_binding_new(preferences, "message-right-margin-at",
- self->priv->comment_view, "right-margin-position");
+ g_object_bind_property (preferences, "message-right-margin-at",
+ self->priv->comment_view, "right-margin-position",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
self->priv->hscale_context = GTK_HSCALE(gtk_builder_get_object(builder, "hscale_context"));
gtk_range_set_value (GTK_RANGE (self->priv->hscale_context), 3);
diff --git a/gitg/gitg-preferences-dialog.c b/gitg/gitg-preferences-dialog.c
index 0619b9e..8216d66 100644
--- a/gitg/gitg-preferences-dialog.c
+++ b/gitg/gitg-preferences-dialog.c
@@ -23,7 +23,6 @@
#include "gitg-preferences-dialog.h"
#include "gitg-preferences.h"
-#include "gitg-data-binding.h"
#include "gitg-utils.h"
#include <libgitg/gitg-config.h>
@@ -125,17 +124,29 @@ on_response(GtkWidget *dialog, gint response, gpointer data)
}
static gboolean
-convert_collapsed(GValue const *source, GValue *dest, gpointer userdata)
+unconvert_collapsed (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer userdata)
{
- GitgPreferencesDialog *dialog = GITG_PREFERENCES_DIALOG(userdata);
+ return g_value_transform (source_value, target_value);
+}
- gint val = round_val(g_value_get_double(source));
+static gboolean
+convert_collapsed (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer userdata)
+{
+ GitgPreferencesDialog *dialog = GITG_PREFERENCES_DIALOG (userdata);
+ gint val = round_val (g_value_get_double (source_value));
if (val == dialog->priv->prev_value)
return FALSE;
dialog->priv->prev_value = val;
- return g_value_transform(source, dest);
+
+ return g_value_transform (source_value, target_value);
}
static void
@@ -169,63 +180,75 @@ initialize_view(GitgPreferencesDialog *dialog)
G_CALLBACK (on_check_button_show_right_margin_toggled),
dialog);
- gitg_data_binding_new_mutual(preferences,
- "history-search-filter",
- dialog->priv->history_search_filter,
- "active");
-
- gitg_data_binding_new_mutual_full(preferences,
- "history-collapse-inactive-lanes",
- dialog->priv->collapse_inactive_lanes,
- "value",
- (GitgDataBindingConversion)g_value_transform,
- convert_collapsed,
- dialog);
-
- gitg_data_binding_new_mutual(preferences,
- "history-collapse-inactive-lanes-active",
- dialog->priv->check_button_collapse_inactive,
- "active");
-
- gitg_data_binding_new_mutual(preferences,
- "history-show-virtual-stash",
- dialog->priv->history_show_virtual_stash,
- "active");
-
- gitg_data_binding_new_mutual(preferences,
- "history-show-virtual-staged",
- dialog->priv->history_show_virtual_staged,
- "active");
-
- gitg_data_binding_new_mutual(preferences,
- "history-show-virtual-unstaged",
- dialog->priv->history_show_virtual_unstaged,
- "active");
-
- gitg_data_binding_new_mutual(preferences,
- "history-topo-order",
- dialog->priv->history_topo_order,
- "active");
-
- gitg_data_binding_new_mutual(preferences,
- "message-show-right-margin",
- dialog->priv->check_button_show_right_margin,
- "active");
-
- gitg_data_binding_new_mutual(preferences,
- "message-right-margin-at",
- dialog->priv->spin_button_right_margin,
- "value");
-
- gitg_data_binding_new_mutual(preferences,
- "main-layout-vertical",
- dialog->priv->main_layout_vertical,
- "active");
-
- gitg_data_binding_new_mutual(preferences,
- "diff-external",
- dialog->priv->check_button_external_diff,
- "active");
+ g_object_bind_property (preferences,
+ "history-search-filter",
+ dialog->priv->history_search_filter,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property_full (preferences,
+ "history-collapse-inactive-lanes",
+ dialog->priv->collapse_inactive_lanes,
+ "value",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
+ unconvert_collapsed,
+ convert_collapsed,
+ dialog,
+ NULL);
+
+ g_object_bind_property (preferences,
+ "history-collapse-inactive-lanes-active",
+ dialog->priv->check_button_collapse_inactive,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "history-show-virtual-stash",
+ dialog->priv->history_show_virtual_stash,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "history-show-virtual-staged",
+ dialog->priv->history_show_virtual_staged,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "history-show-virtual-unstaged",
+ dialog->priv->history_show_virtual_unstaged,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "history-topo-order",
+ dialog->priv->history_topo_order,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "message-show-right-margin",
+ dialog->priv->check_button_show_right_margin,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "message-right-margin-at",
+ dialog->priv->spin_button_right_margin,
+ "value",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "main-layout-vertical",
+ dialog->priv->main_layout_vertical,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "diff-external",
+ dialog->priv->check_button_external_diff,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
}
static void
diff --git a/gitg/gitg-window.c b/gitg/gitg-window.c
index 7e0f012..f03f21b 100644
--- a/gitg/gitg-window.c
+++ b/gitg/gitg-window.c
@@ -30,7 +30,6 @@
#include "config.h"
-#include "gitg-data-binding.h"
#include "gitg-dirs.h"
#include "gitg-window.h"
#include "gitg-cell-renderer-path.h"
@@ -1250,42 +1249,45 @@ gitg_window_set_select_on_load (GitgWindow *window,
}
static gboolean
-convert_setting_to_inactive_max (GValue const *setting,
- GValue *value,
+convert_setting_to_inactive_max (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
gpointer userdata)
{
- g_return_val_if_fail (G_VALUE_HOLDS(setting, G_TYPE_INT), FALSE);
- g_return_val_if_fail (G_VALUE_HOLDS(value, G_TYPE_INT), FALSE);
+ g_return_val_if_fail (G_VALUE_HOLDS (source_value, G_TYPE_INT), FALSE);
+ g_return_val_if_fail (G_VALUE_HOLDS (target_value, G_TYPE_INT), FALSE);
- gint s = g_value_get_int (setting);
- g_value_set_int (value, 2 + s * 8);
+ gint s = g_value_get_int (source_value);
+ g_value_set_int (target_value, 2 + s * 8);
return TRUE;
}
static gboolean
-convert_setting_to_inactive_collapse (GValue const *setting,
- GValue *value,
+convert_setting_to_inactive_collapse (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
gpointer userdata)
{
- g_return_val_if_fail (G_VALUE_HOLDS(setting, G_TYPE_INT), FALSE);
- g_return_val_if_fail (G_VALUE_HOLDS(value, G_TYPE_INT), FALSE);
+ g_return_val_if_fail (G_VALUE_HOLDS (source_value, G_TYPE_INT), FALSE);
+ g_return_val_if_fail (G_VALUE_HOLDS (target_value, G_TYPE_INT), FALSE);
- gint s = g_value_get_int (setting);
- g_value_set_int (value, 1 + s * 3);
+ gint s = g_value_get_int (source_value);
+ g_value_set_int (target_value, 1 + s * 3);
return TRUE;
}
static gboolean
-convert_setting_to_inactive_gap (GValue const *setting,
- GValue *value,
+convert_setting_to_inactive_gap (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
gpointer userdata)
{
- g_return_val_if_fail (G_VALUE_HOLDS(setting, G_TYPE_INT), FALSE);
- g_return_val_if_fail (G_VALUE_HOLDS(value, G_TYPE_INT), FALSE);
+ g_return_val_if_fail (G_VALUE_HOLDS (source_value, G_TYPE_INT), FALSE);
+ g_return_val_if_fail (G_VALUE_HOLDS (target_value, G_TYPE_INT), FALSE);
- g_value_set_int (value, 10);
+ g_value_set_int (target_value, 10);
return TRUE;
}
@@ -1300,51 +1302,65 @@ bind_repository (GitgWindow *window)
preferences = gitg_preferences_get_default ();
- gitg_data_binding_new_full (preferences,
- "history-collapse-inactive-lanes",
- window->priv->repository,
- "inactive-max",
- convert_setting_to_inactive_max,
- window);
-
- gitg_data_binding_new (preferences,
- "history-show-virtual-stash",
- window->priv->repository,
- "show-stash");
-
- gitg_data_binding_new (preferences,
- "history-show-virtual-staged",
- window->priv->repository,
- "show-staged");
-
- gitg_data_binding_new (preferences,
- "history-show-virtual-unstaged",
- window->priv->repository,
- "show-unstaged");
-
- gitg_data_binding_new (preferences,
- "history-topo-order",
- window->priv->repository,
- "topo-order");
-
- gitg_data_binding_new_full (preferences,
- "history-collapse-inactive-lanes",
- window->priv->repository,
- "inactive-collapse",
- convert_setting_to_inactive_collapse,
- window);
-
- gitg_data_binding_new_full (preferences,
- "history-collapse-inactive-lanes",
- window->priv->repository,
- "inactive-gap",
- convert_setting_to_inactive_gap,
- window);
-
- gitg_data_binding_new (preferences,
- "history-collapse-inactive-lanes-active",
- window->priv->repository,
- "inactive-enabled");
+ g_object_bind_property_full (preferences,
+ "history-collapse-inactive-lanes",
+ window->priv->repository,
+ "inactive-max",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
+ convert_setting_to_inactive_max,
+ NULL,
+ window,
+ NULL);
+
+ g_object_bind_property (preferences,
+ "history-show-virtual-stash",
+ window->priv->repository,
+ "show-stash",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "history-show-virtual-staged",
+ window->priv->repository,
+ "show-staged",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "history-show-virtual-unstaged",
+ window->priv->repository,
+ "show-unstaged",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (preferences,
+ "history-topo-order",
+ window->priv->repository,
+ "topo-order",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property_full (preferences,
+ "history-collapse-inactive-lanes",
+ window->priv->repository,
+ "inactive-collapse",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
+ convert_setting_to_inactive_collapse,
+ NULL,
+ window,
+ NULL);
+
+ g_object_bind_property_full (preferences,
+ "history-collapse-inactive-lanes",
+ window->priv->repository,
+ "inactive-gap",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
+ convert_setting_to_inactive_gap,
+ NULL,
+ window,
+ NULL);
+
+ g_object_bind_property (preferences,
+ "history-collapse-inactive-lanes-active",
+ window->priv->repository,
+ "inactive-enabled",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]