[gitg] Added preferences for showing of virtual commits and lane collapsing



commit 73a161c0cf653e0e04ca3fc551f13c07154450c5
Author: Jesse van den Kieboom <jesse icecrew nl>
Date:   Wed Apr 22 00:36:58 2009 +0200

    Added preferences for showing of virtual commits and lane collapsing
---
 gitg/gitg-lanes.c              |   60 ++++++++++++++++---------
 gitg/gitg-preferences-dialog.c |   98 +++++++++++++++++----------------------
 gitg/gitg-preferences.c        |   18 +++++++-
 gitg/gitg-preferences.xml      |    3 +-
 gitg/gitg-repository.c         |   66 +++++++++++++++++++++++++--
 5 files changed, 162 insertions(+), 83 deletions(-)

diff --git a/gitg/gitg-lanes.c b/gitg/gitg-lanes.c
index 38aac48..f8fcd0e 100644
--- a/gitg/gitg-lanes.c
+++ b/gitg/gitg-lanes.c
@@ -31,7 +31,8 @@ enum
 	PROP_0,
 	PROP_INACTIVE_MAX,
 	PROP_INACTIVE_COLLAPSE,
-	PROP_INACTIVE_GAP
+	PROP_INACTIVE_GAP,
+	PROP_INACTIVE_ENABLED
 };
 
 typedef struct
@@ -67,6 +68,7 @@ struct _GitgLanesPrivate
 	gint inactive_max;
 	gint inactive_collapse;
 	gint inactive_gap;
+	gboolean inactive_enabled;
 };
 
 G_DEFINE_TYPE(GitgLanes, gitg_lanes, G_TYPE_OBJECT)
@@ -160,6 +162,9 @@ gitg_lanes_set_property(GObject *object, guint prop_id, const GValue *value, GPa
 		case PROP_INACTIVE_GAP:
 			self->priv->inactive_gap = g_value_get_int(value);
 		break;
+		case PROP_INACTIVE_ENABLED:
+			self->priv->inactive_enabled = g_value_get_boolean(value);
+		break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 		break;
@@ -182,6 +187,9 @@ gitg_lanes_get_property(GObject *object, guint prop_id, GValue *value, GParamSpe
 		case PROP_INACTIVE_GAP:
 			g_value_set_int(value, self->priv->inactive_gap);
 		break;
+		case PROP_INACTIVE_ENABLED:
+			g_value_set_boolean(value, self->priv->inactive_enabled);
+		break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 		break;
@@ -199,30 +207,37 @@ gitg_lanes_class_init(GitgLanesClass *klass)
 	
 	g_object_class_install_property(object_class, PROP_INACTIVE_MAX,
 					 g_param_spec_int("inactive-max",
-							      "INACTIVE_MAX",
-							      "Maximum inactivity on a lane before collapsing",
-							      1,
-							      G_MAXINT,
-							      30,
-							      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+							          "INACTIVE_MAX",
+							          "Maximum inactivity on a lane before collapsing",
+							          1,
+							          G_MAXINT,
+							          30,
+							          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
 	g_object_class_install_property(object_class, PROP_INACTIVE_COLLAPSE,
 					 g_param_spec_int("inactive-collapse",
-							      "INACTIVE_COLLAPSE",
-							      "Number of revisions to collapse",
-							      1,
-							      G_MAXINT,
-							      10,
-							      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+							          "INACTIVE_COLLAPSE",
+							          "Number of revisions to collapse",
+							          1,
+							          G_MAXINT,
+							          10,
+							          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
 	g_object_class_install_property(object_class, PROP_INACTIVE_GAP,
 					 g_param_spec_int("inactive-gap",
-							      "INACTIVE_GAP",
-							      "Minimum of revisions to leave between collapse and expand",
-							      1,
-							      G_MAXINT,
-							      10,
-							      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+							          "INACTIVE_GAP",
+							          "Minimum of revisions to leave between collapse and expand",
+							          1,
+							          G_MAXINT,
+							          10,
+							          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+	g_object_class_install_property(object_class, PROP_INACTIVE_ENABLED,
+					 g_param_spec_boolean("inactive-enabled",
+							              "INACTIVE_ENABLED",
+							              "Lane collapsing enabled",
+							              TRUE,
+							              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
 	g_type_class_add_private(object_class, sizeof(GitgLanesPrivate));
 }
@@ -627,8 +642,11 @@ gitg_lanes_next(GitgLanes *lanes, GitgRevision *next, gint8 *nextpos)
 	GSList *res;
 	gchar const *myhash = gitg_revision_get_hash(next);
 
-	collapse_lanes(lanes);
-	expand_lanes(lanes, next);
+	if (lanes->priv->inactive_enabled)
+	{
+		collapse_lanes(lanes);
+		expand_lanes(lanes, next);
+	}
 
 	mylane = find_lane_by_hash(lanes, myhash, nextpos);
 
diff --git a/gitg/gitg-preferences-dialog.c b/gitg/gitg-preferences-dialog.c
index 8f3d394..c689e44 100644
--- a/gitg/gitg-preferences-dialog.c
+++ b/gitg/gitg-preferences-dialog.c
@@ -44,11 +44,11 @@ struct _GitgPreferencesDialogPrivate
 {
 	GtkCheckButton *history_search_filter;
 	GtkAdjustment *collapse_inactive_lanes;
-	GtkHScale *hscale_collapse_inactive_lanes;
 	GtkCheckButton *history_show_virtual_stash;
 	GtkCheckButton *history_show_virtual_staged;
 	GtkCheckButton *history_show_virtual_unstaged;
 	GtkCheckButton *check_button_collapse_inactive;
+	GtkWidget *table;
 
 	gint prev_value;
 };
@@ -92,19 +92,6 @@ on_response(GtkWidget *dialog, gint response, gpointer data)
 }
 
 static gboolean
-convert_collapsed_from(GValue const *source, GValue *dest, gpointer userdata)
-{
-	GitgPreferencesDialog *dialog = GITG_PREFERENCES_DIALOG(userdata);
-	gint val = g_value_get_int(source);
-	
-	gtk_widget_set_sensitive(GTK_WIDGET(dialog->priv->hscale_collapse_inactive_lanes),
-	                         val != 0);
-	
-	g_value_set_double(dest, (gdouble)val);
-	return TRUE;
-}
-
-static gboolean
 convert_collapsed(GValue const *source, GValue *dest, gpointer userdata)
 {
 	GitgPreferencesDialog *dialog = GITG_PREFERENCES_DIALOG(userdata);
@@ -118,54 +105,55 @@ convert_collapsed(GValue const *source, GValue *dest, gpointer userdata)
 	return g_value_transform(source, dest);
 }
 
-static gboolean
-convert_collapsed_to_active(GValue const *source, GValue *dest, gpointer userdata)
-{
-	gboolean v = g_value_get_boolean(source);
-	
-	if (v)
-		g_value_set_int(dest, 2);
-	else
-		g_value_set_int(dest, 0);
-	
-	return TRUE;
-}
-
-static gboolean
-convert_collapsed_from_active(GValue const *source, GValue *dest, gpointer userdata)
+static void
+on_collapse_inactive_toggled(GtkToggleButton *button, GitgPreferencesDialog *dialog)
 {
-	g_value_set_boolean(dest, FALSE);	
-	return TRUE;
+	gboolean active = gtk_toggle_button_get_active (button);
+	gtk_widget_set_sensitive(dialog->priv->table, active);
 }
 
 static void
 initialize_view(GitgPreferencesDialog *dialog)
 {
 	GitgPreferences *preferences = gitg_preferences_get_default();
-	
-	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",
-						              convert_collapsed_from,
-						              convert_collapsed,
-						              dialog);
-
-	gitg_data_binding_new_mutual_full(preferences, "history-collapse-inactive-lanes",
-						              dialog->priv->check_button_collapse_inactive, "active",
-						              convert_collapsed_from_active,
-						              convert_collapsed_to_active,
-						              dialog);
-
-	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");
+	g_signal_connect (dialog->priv->check_button_collapse_inactive,
+	                  "toggled",
+	                  G_CALLBACK (on_collapse_inactive_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");
 }
 
 static void
@@ -186,7 +174,7 @@ create_preferences_dialog()
 	priv->history_show_virtual_unstaged = GTK_CHECK_BUTTON(gtk_builder_get_object(b, "check_button_history_show_virtual_unstaged"));
 	
 	priv->check_button_collapse_inactive = GTK_CHECK_BUTTON(gtk_builder_get_object(b, "check_button_collapse_inactive"));
-	priv->hscale_collapse_inactive_lanes = GTK_HSCALE(gtk_builder_get_object(b, "hscale_collapse_inactive_lanes"));
+	priv->table = GTK_WIDGET(gtk_builder_get_object(b, "table_collapse_inactive_lanes"));
 	
 	priv->prev_value = (gint)gtk_adjustment_get_value(priv->collapse_inactive_lanes);
 	g_signal_connect(preferences_dialog, "response", G_CALLBACK(on_response), NULL);
diff --git a/gitg/gitg-preferences.c b/gitg/gitg-preferences.c
index 2beab58..1446f51 100644
--- a/gitg/gitg-preferences.c
+++ b/gitg/gitg-preferences.c
@@ -35,7 +35,10 @@ enum
 	PROP_0,
 	
 	PROP_HISTORY_SEARCH_FILTER,
+
+	PROP_HISTORY_COLLAPSE_INACTIVE_LANES_ACTIVE,
 	PROP_HISTORY_COLLAPSE_INACTIVE_LANES,
+
 	PROP_HISTORY_SHOW_VIRTUAL_STASH,
 	PROP_HISTORY_SHOW_VIRTUAL_STAGED,
 	PROP_HISTORY_SHOW_VIRTUAL_UNSTAGED,
@@ -314,6 +317,19 @@ gitg_preferences_class_init(GitgPreferencesClass *klass)
 							      FALSE,
 							      G_PARAM_READWRITE));
 
+	install_property_binding(PROP_HISTORY_COLLAPSE_INACTIVE_LANES_ACTIVE, 
+							 "view/history",
+							 "collapse-inactive-lanes-active", 
+							 wrap_get_boolean,
+							 wrap_set_boolean);
+
+	g_object_class_install_property(object_class, PROP_HISTORY_COLLAPSE_INACTIVE_LANES_ACTIVE,
+					 g_param_spec_boolean("history-collapse-inactive-lanes-active",
+							      "HISTORY_COLLAPSE_INACTIVE_LANES_ACTIVE",
+							      "Collapsing inactive lanes active",
+							      TRUE,
+							      G_PARAM_READWRITE));
+
 	install_property_binding(PROP_HISTORY_COLLAPSE_INACTIVE_LANES, 
 							 "view/history",
 							 "collapse-inactive-lanes", 
@@ -324,7 +340,7 @@ gitg_preferences_class_init(GitgPreferencesClass *klass)
 					 g_param_spec_int("history-collapse-inactive-lanes",
 							      "HISTORY_COLLAPSE_INACTIVE_LANES",
 							      "Rule for collapsing inactive lanes",
-							      -1,
+							      0,
 							      5,
 							      2,
 							      G_PARAM_READWRITE));
diff --git a/gitg/gitg-preferences.xml b/gitg/gitg-preferences.xml
index 2dc611d..d8e823c 100644
--- a/gitg/gitg-preferences.xml
+++ b/gitg/gitg-preferences.xml
@@ -82,13 +82,14 @@
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
                                 <property name="draw_indicator">True</property>
+                                <property name="active">True</property>
                               </object>
                               <packing>
                                 <property name="position">1</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkTable" id="table2">
+                              <object class="GtkTable" id="table_collapse_inactive_lanes">
                                 <property name="visible">True</property>
                                 <property name="n_rows">2</property>
                                 <property name="n_columns">2</property>
diff --git a/gitg/gitg-repository.c b/gitg/gitg-repository.c
index bfdd52b..439057d 100644
--- a/gitg/gitg-repository.c
+++ b/gitg/gitg-repository.c
@@ -337,6 +337,8 @@ do_clear(GitgRepository *repository, gboolean emit)
 	/* clear hash tables */
 	g_hash_table_remove_all(repository->priv->hashtable);
 	g_hash_table_remove_all(repository->priv->refs);
+	
+	gitg_color_reset();
 }
 
 static void
@@ -484,6 +486,14 @@ on_loader_end_loading(GitgRunner *object, gboolean cancelled, GitgRepository *re
 		return;
 
 	LoadStage current = repository->priv->load_stage++;
+	GitgPreferences *preferences = gitg_preferences_get_default();
+	gboolean show_unstaged;
+	gboolean show_staged;
+	
+	g_object_get(preferences, 
+	             "history-show-virtual-staged", &show_staged, 
+	             "history-show-virtual-unstaged", &show_unstaged,
+	             NULL);
 
 	switch (current)
 	{
@@ -497,7 +507,7 @@ on_loader_end_loading(GitgRunner *object, gboolean cancelled, GitgRepository *re
 			if (current == LOAD_STAGE_STAGED)
 			{
 				/* Check if there are unstaged changes */
-				if (gitg_runner_get_exit_status(object) != 0)
+				if (show_staged && gitg_runner_get_exit_status(object) != 0)
 				{
 					add_dummy_commit(repository, TRUE);
 				}
@@ -512,7 +522,7 @@ on_loader_end_loading(GitgRunner *object, gboolean cancelled, GitgRepository *re
 		}
 		break;
 		case LOAD_STAGE_UNSTAGED:
-			if (gitg_runner_get_exit_status(object) != 0)
+			if (show_unstaged && gitg_runner_get_exit_status(object) != 0)
 			{
 				add_dummy_commit(repository, FALSE);
 			}
@@ -529,6 +539,13 @@ static void
 loader_update_stash(GitgRepository *repository, gchar **buffer)
 {
 	gchar *line;
+	GitgPreferences *preferences = gitg_preferences_get_default();
+	gboolean show_stash;
+	
+	g_object_get(preferences, "history-show-virtual-stash", &show_stash, NULL);
+
+	if (!show_stash)
+		return;
 	
 	while ((line = *buffer++) != NULL)
 	{
@@ -685,8 +702,27 @@ convert_setting_to_inactive_gap(GValue const *setting, GValue *value, gpointer u
 	return TRUE;
 }
 
+static gboolean
+convert_setting_to_inactive_enabled(GValue const *setting, GValue *value, gpointer userdata)
+{
+	g_return_val_if_fail(G_VALUE_HOLDS(setting, G_TYPE_BOOLEAN), FALSE);
+	g_return_val_if_fail(G_VALUE_HOLDS(value, G_TYPE_BOOLEAN), FALSE);
+
+	gboolean s = g_value_get_boolean(setting);
+	g_value_set_boolean(value, s);
+	
+	prepare_relane(GITG_REPOSITORY(userdata));	
+	return TRUE;
+}
+
 static void
-initialize_lanes_bindings(GitgRepository *repository)
+on_update_virtual(GObject *object, GParamSpec *spec, GitgRepository *repository)
+{
+	gitg_repository_reload (repository);
+}
+
+static void
+initialize_bindings(GitgRepository *repository)
 {
 	GitgPreferences *preferences = gitg_preferences_get_default();
 	
@@ -703,7 +739,27 @@ initialize_lanes_bindings(GitgRepository *repository)
 	gitg_data_binding_new_full(preferences, "history-collapse-inactive-lanes",
 							   repository->priv->lanes, "inactive-gap",
 							   convert_setting_to_inactive_gap,
-							   repository);							   
+							   repository);		
+
+	gitg_data_binding_new_full(preferences, "history-collapse-inactive-lanes-active",
+	                           repository->priv->lanes, "inactive-enabled",
+	                           convert_setting_to_inactive_enabled,
+	                           repository);	
+
+	g_signal_connect(preferences, 
+	                 "notify::history-show-virtual-stash",
+	                 G_CALLBACK(on_update_virtual),
+	                 repository);
+
+	g_signal_connect(preferences, 
+	                 "notify::history-show-virtual-unstaged",
+	                 G_CALLBACK(on_update_virtual),
+	                 repository);
+
+	g_signal_connect(preferences, 
+	                 "notify::history-show-virtual-staged",
+	                 G_CALLBACK(on_update_virtual),
+	                 repository);
 }
 
 static void
@@ -726,7 +782,7 @@ gitg_repository_init(GitgRepository *object)
 	g_signal_connect(object->priv->loader, "update", G_CALLBACK(on_loader_update), object);
 	g_signal_connect(object->priv->loader, "end-loading", G_CALLBACK(on_loader_end_loading), object);
 	
-	initialize_lanes_bindings(object);
+	initialize_bindings(object);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]