[gitg] Added preference for showing history in topo order



commit 762896485f4738c95905804747b9753b9cea9fdf
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun Jan 10 01:38:16 2010 +0100

    Added preference for showing history in topo order

 data/gitg.schemas.in           |   13 +++
 gitg/gitg-preferences-dialog.c |    7 ++
 gitg/gitg-preferences.c        |   15 ++++
 gitg/gitg-preferences.ui       |   13 +++
 gitg/gitg-repository.c         |  181 +++++++++++++++++++++++-----------------
 5 files changed, 153 insertions(+), 76 deletions(-)
---
diff --git a/data/gitg.schemas.in b/data/gitg.schemas.in
index 51ab258..ac30ace 100644
--- a/data/gitg.schemas.in
+++ b/data/gitg.schemas.in
@@ -26,6 +26,19 @@
       </locale>
     </schema>
     <schema>
+      <key>/schemas/apps/gitg/preferences/view/history/topo-order</key>
+      <applyto>/apps/gitg/preferences/view/history/topo-order</applyto>
+      <owner>gitg</owner>
+      <type>bool</type>
+      <default>FALSE</default>
+      <locale name="C">
+        <short>Show History in Topological Order</short>
+        <long>Setting that indicates whether to show the history in
+        topological order.
+        </long>
+      </locale>
+    </schema>
+    <schema>
       <key>/schemas/apps/gitg/preferences/commit/message/show-right-margin</key>
       <applyto>/apps/gitg/preferences/commit/message/show-right-margin</applyto>
       <owner>gitg</owner>
diff --git a/gitg/gitg-preferences-dialog.c b/gitg/gitg-preferences-dialog.c
index bfcde9e..cb89edc 100644
--- a/gitg/gitg-preferences-dialog.c
+++ b/gitg/gitg-preferences-dialog.c
@@ -50,6 +50,7 @@ struct _GitgPreferencesDialogPrivate
 	GtkCheckButton *history_show_virtual_stash;
 	GtkCheckButton *history_show_virtual_staged;
 	GtkCheckButton *history_show_virtual_unstaged;
+	GtkCheckButton *history_topo_order;
 	GtkCheckButton *check_button_collapse_inactive;
 
 	GtkCheckButton *check_button_show_right_margin;
@@ -187,6 +188,11 @@ initialize_view(GitgPreferencesDialog *dialog)
 	                             "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");
@@ -213,6 +219,7 @@ create_preferences_dialog()
 	priv->history_show_virtual_stash = GTK_CHECK_BUTTON(gtk_builder_get_object(b, "check_button_history_show_virtual_stash"));
 	priv->history_show_virtual_staged = GTK_CHECK_BUTTON(gtk_builder_get_object(b, "check_button_history_show_virtual_staged"));
 	priv->history_show_virtual_unstaged = GTK_CHECK_BUTTON(gtk_builder_get_object(b, "check_button_history_show_virtual_unstaged"));
+	priv->history_topo_order = GTK_CHECK_BUTTON (gtk_builder_get_object (b, "check_button_history_topo_order"));
 
 	priv->check_button_collapse_inactive = GTK_CHECK_BUTTON(gtk_builder_get_object(b, "check_button_collapse_inactive"));
 	priv->table = GTK_WIDGET(gtk_builder_get_object(b, "table_collapse_inactive_lanes"));
diff --git a/gitg/gitg-preferences.c b/gitg/gitg-preferences.c
index c1d28b2..4144f79 100644
--- a/gitg/gitg-preferences.c
+++ b/gitg/gitg-preferences.c
@@ -43,6 +43,8 @@ enum
 	PROP_HISTORY_SHOW_VIRTUAL_STAGED,
 	PROP_HISTORY_SHOW_VIRTUAL_UNSTAGED,
 
+	PROP_HISTORY_TOPO_ORDER,
+
 	PROP_MESSAGE_SHOW_RIGHT_MARGIN,
 	PROP_MESSAGE_RIGHT_MARGIN_AT,
 
@@ -441,6 +443,19 @@ gitg_preferences_class_init(GitgPreferencesClass *klass)
 							      TRUE,
 							      G_PARAM_READWRITE));
 
+	install_property_binding(PROP_HISTORY_TOPO_ORDER,
+							 "view/history",
+							 "topo-order", 
+							 wrap_get_boolean,
+							 wrap_set_boolean);
+
+	g_object_class_install_property(object_class, PROP_HISTORY_TOPO_ORDER,
+					 g_param_spec_boolean("history-topo-order",
+							      "HISTORY_TOPO_ORDER",
+							      "Whether to load history in topological order",
+							      FALSE,
+							      G_PARAM_READWRITE));
+
 	install_style_properties(object_class, PROP_STYLE_TEXT_FOREGROUND, "text");
 	install_style_properties(object_class, PROP_STYLE_ADDED_LINE_FOREGROUND, "added-line");
 	install_style_properties(object_class, PROP_STYLE_REMOVED_LINE_FOREGROUND, "removed-line");
diff --git a/gitg/gitg-preferences.ui b/gitg/gitg-preferences.ui
index 846a829..7d0126d 100644
--- a/gitg/gitg-preferences.ui
+++ b/gitg/gitg-preferences.ui
@@ -182,6 +182,7 @@
                               <object class="GtkCheckButton" id="check_button_history_show_virtual_unstaged">
                                 <property name="label" translatable="yes">Show unstaged changes in history</property>
                                 <property name="can_focus">True</property>
+                                <property name="visible">True</property>
                                 <property name="receives_default">False</property>
                                 <property name="draw_indicator">True</property>
                               </object>
@@ -189,6 +190,18 @@
                                 <property name="position">5</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkCheckButton" id="check_button_history_topo_order">
+                                <property name="label" translatable="yes">Show history in topological order</property>
+                                <property name="can_focus">True</property>
+                                <property name="visible">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="position">6</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="position">1</property>
diff --git a/gitg/gitg-repository.c b/gitg/gitg-repository.c
index 068ea10..6d29f7b 100644
--- a/gitg/gitg-repository.c
+++ b/gitg/gitg-repository.c
@@ -894,6 +894,106 @@ on_update_virtual(GObject *object, GParamSpec *spec, GitgRepository *repository)
 	gitg_repository_reload (repository);
 }
 
+static gchar **
+copy_strv (gchar const **ptr, gint argc)
+{
+	GPtrArray *ret = g_ptr_array_new ();
+	gint i = 0;
+
+	while (ptr && ((argc >= 0 && i < argc) || (argc < 0 && ptr[i])))
+	{
+		g_ptr_array_add (ret, g_strdup (ptr[i]));
+		++i;
+	}
+
+	g_ptr_array_add (ret, NULL);
+	return (gchar **)g_ptr_array_free (ret, FALSE);
+}
+
+static gboolean
+has_left_right(gchar const **av, int argc)
+{
+	int i;
+
+	for (i = 0; i < argc; ++i)
+		if (strcmp(av[i], "--left-right") == 0)
+			return TRUE;
+
+	return FALSE;
+}
+
+static void
+build_log_args(GitgRepository *self, gint argc, gchar const **av)
+{
+	GitgPreferences *preferences = gitg_preferences_get_default ();
+	gboolean topoorder;
+
+	g_object_get (preferences, "history-topo-order", &topoorder, NULL);
+
+	gchar **argv = g_new0(gchar *, 6 + topoorder + (argc > 0 ? argc - 1 : 0));
+
+	argv[0] = g_strdup("log");
+
+	if (has_left_right(av, argc))
+	{
+		argv[1] = g_strdup("--pretty=format:%H\x01%an\x01%s\x01%P\x01%at\x01%m");
+	}
+	else
+	{
+		argv[1] = g_strdup("--pretty=format:%H\x01%an\x01%s\x01%P\x01%at");
+	}
+
+	argv[2] = g_strdup ("--encoding=UTF-8");
+	gint start = 3;
+
+	if (topoorder)
+	{
+		argv[3] = g_strdup ("--topo-order");
+		++start;
+	}
+
+	gchar *head = NULL;
+
+	if (argc <= 0)
+	{
+		head = gitg_repository_parse_ref(self, "HEAD");
+
+		if (head)
+		{
+			argv[start] = g_strdup("HEAD");
+		}
+
+		g_free(head);
+	}
+	else
+	{
+		int i;
+
+		for (i = 0; i < argc; ++i)
+		{
+			argv[start + i] = g_strdup(av[i]);
+		}
+	}
+
+	g_strfreev(self->priv->last_args);
+	self->priv->last_args = argv;
+
+	gchar **newselection = copy_strv (av, argc);
+
+	g_strfreev (self->priv->selection);
+	self->priv->selection = newselection;
+}
+
+static void
+on_update_topo_order(GObject *object, GParamSpec *spec, GitgRepository *repository)
+{
+	build_log_args (repository,
+	                g_strv_length (repository->priv->selection),
+	                (gchar const **)repository->priv->selection);
+
+	gitg_repository_reload (repository);
+}
+
 static void
 initialize_bindings(GitgRepository *repository)
 {
@@ -933,6 +1033,11 @@ initialize_bindings(GitgRepository *repository)
 	                 "notify::history-show-virtual-staged",
 	                 G_CALLBACK(on_update_virtual),
 	                 repository);
+
+	g_signal_connect(preferences, 
+	                 "notify::history-topo-order",
+	                 G_CALLBACK(on_update_topo_order),
+	                 repository);
 }
 
 static void
@@ -1000,18 +1105,6 @@ gitg_repository_get_loader(GitgRepository *self)
 }
 
 static gboolean
-has_left_right(gchar const **av, int argc)
-{
-	int i;
-
-	for (i = 0; i < argc; ++i)
-		if (strcmp(av[i], "--left-right") == 0)
-			return TRUE;
-
-	return FALSE;
-}
-
-static gboolean
 reload_revisions(GitgRepository *repository, GError **error)
 {
 	if (repository->priv->working_ref)
@@ -1027,70 +1120,6 @@ reload_revisions(GitgRepository *repository, GError **error)
 	return gitg_repository_run_commandv(repository, repository->priv->loader, error, "log", "--pretty=format:%H\x01%an\x01%s\x01%at", "--encoding=UTF-8", "-g", "refs/stash", NULL);
 }
 
-static gchar **
-copy_strv (gchar const **ptr, gint argc)
-{
-	GPtrArray *ret = g_ptr_array_new ();
-	gint i = 0;
-
-	while (ptr && ((argc >= 0 && i < argc) || (argc < 0 && ptr[i])))
-	{
-		g_ptr_array_add (ret, g_strdup (ptr[i]));
-		++i;
-	}
-
-	g_ptr_array_add (ret, NULL);
-	return (gchar **)g_ptr_array_free (ret, FALSE);
-}
-
-static void
-build_log_args(GitgRepository *self, gint argc, gchar const **av)
-{
-	gchar **argv = g_new0(gchar *, 6 + (argc > 0 ? argc - 1 : 0));
-
-	argv[0] = g_strdup("log");
-
-	if (has_left_right(av, argc))
-	{
-		argv[1] = g_strdup("--pretty=format:%H\x01%an\x01%s\x01%P\x01%at\x01%m");
-	}
-	else
-	{
-		argv[1] = g_strdup("--pretty=format:%H\x01%an\x01%s\x01%P\x01%at");
-	}
-
-	argv[2] = g_strdup ("--encoding=UTF-8");
-
-	gchar *head = NULL;
-
-	if (argc <= 0)
-	{
-		head = gitg_repository_parse_ref(self, "HEAD");
-
-		if (head)
-		{
-			argv[3] = g_strdup("HEAD");
-		}
-
-		g_free(head);
-	}
-	else
-	{
-		int i;
-
-		for (i = 0; i < argc; ++i)
-		{
-			argv[3 + i] = g_strdup(av[i]);
-		}
-	}
-
-	g_strfreev(self->priv->last_args);
-	self->priv->last_args = argv;
-
-	g_strfreev (self->priv->selection);
-	self->priv->selection = copy_strv (av, argc);
-}
-
 static gchar *
 load_current_ref(GitgRepository *self)
 {



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