[anjuta/git-shell] git: Implement the Tags pane



commit fa2e074002ba9e1b52bdb5927076d9aed59cb0e6
Author: James Liggett <jrliggett cox net>
Date:   Tue Jul 20 22:48:07 2010 -0700

    git: Implement the Tags pane

 plugins/git/Makefile.am     |    4 +-
 plugins/git/anjuta-git.ui   |   76 ++++++++++++
 plugins/git/git-tags-pane.c |  285 +++++++++++++++++++++++++++++++++++++++++++
 plugins/git/git-tags-pane.h |   57 +++++++++
 plugins/git/plugin.c        |   15 +++
 plugins/git/plugin.h        |    3 +
 6 files changed, 439 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index bd22acb..78b7a74 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -195,7 +195,9 @@ libanjuta_git_la_SOURCES = \
 	git-fetch-pane.c \
 	git-fetch-pane.h \
 	git-resolve-conflicts-pane.c \
-	git-resolve-conflicts-pane.h
+	git-resolve-conflicts-pane.h \
+	git-tags-pane.c \
+	git-tags-pane.h
 
 libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui
index de0f700..cd10683 100644
--- a/plugins/git/anjuta-git.ui
+++ b/plugins/git/anjuta-git.ui
@@ -411,6 +411,14 @@
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="tags_list_model">
+    <columns>
+      <!-- column-name selected -->
+      <column type="gboolean"/>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkVBox" id="status_pane">
     <property name="visible">True</property>
     <child>
@@ -2422,4 +2430,72 @@
       </packing>
     </child>
   </object>
+  <object class="GtkVBox" id="tags_pane">
+    <property name="visible">True</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkFrame" id="frame1">
+        <property name="visible">True</property>
+        <property name="label_xalign">0</property>
+        <property name="shadow_type">none</property>
+        <child>
+          <object class="GtkAlignment" id="alignment1">
+            <property name="visible">True</property>
+            <property name="left_padding">12</property>
+            <child>
+              <object class="GtkScrolledWindow" id="scrolledwindow1">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <object class="GtkTreeView" id="tags_view">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="model">tags_list_model</property>
+                    <property name="headers_visible">False</property>
+                    <property name="headers_clickable">False</property>
+                    <property name="search_column">0</property>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+                        <property name="title">column</property>
+                        <child>
+                          <object class="GtkCellRendererToggle" id="selected_renderer"/>
+                          <attributes>
+                            <attribute name="active">0</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+                        <property name="title">column</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="name_renderer"/>
+                          <attributes>
+                            <attribute name="text">1</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child type="label">
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">&lt;b&gt;Tags:&lt;/b&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="position">0</property>
+      </packing>
+    </child>
+  </object>
 </interface>
diff --git a/plugins/git/git-tags-pane.c b/plugins/git/git-tags-pane.c
new file mode 100644
index 0000000..d8e37c7
--- /dev/null
+++ b/plugins/git/git-tags-pane.c
@@ -0,0 +1,285 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * git-shell-test
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ * 
+ * git-shell-test is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * git-shell-test is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "git-tags-pane.h"
+
+enum
+{
+	COL_SELECTED,
+	COL_NAME
+};
+
+static GtkTargetEntry drag_targets[] =
+{
+	{
+		"STRING",
+		0,
+		0
+	}
+};
+
+struct _GitTagsPanePriv
+{
+	GtkBuilder *builder;
+};
+
+
+G_DEFINE_TYPE (GitTagsPane, git_tags_pane, GIT_TYPE_PANE);
+
+static void
+on_tag_list_command_started (AnjutaCommand *command, GitTagsPane *self)
+{
+	GtkTreeView *tags_view;
+	GtkListStore *tags_list_model;
+
+	tags_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
+	                                                   "tags_view"));
+	tags_list_model = GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder,
+	                                                          "tags_list_model"));
+
+	gtk_tree_view_set_model (tags_view, NULL);
+	gtk_list_store_clear (tags_list_model);
+}
+
+static void
+on_tag_list_command_finished (AnjutaCommand *command, guint return_code, 
+                              GitTagsPane *self)
+{
+	GtkTreeView *tags_view;
+	GtkTreeModel *tags_list_model;
+
+	tags_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
+	                                                   "tags_view"));
+	tags_list_model = GTK_TREE_MODEL (gtk_builder_get_object (self->priv->builder,
+	                                                          "tags_list_model"));
+
+	gtk_tree_view_set_model (tags_view, tags_list_model);
+}
+
+static void
+on_tag_list_command_data_arrived (AnjutaCommand *command, 
+                                  GtkListStore *tags_list_model)
+{
+	GQueue *output;
+	GtkTreeIter iter;
+	gchar *name;
+
+	output = git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command));
+
+	while (g_queue_peek_head (output))
+	{
+		name = g_queue_pop_head (output);
+		gtk_list_store_append (tags_list_model, &iter);
+
+		gtk_list_store_set (tags_list_model, &iter, 
+							COL_SELECTED, FALSE,
+		                    COL_NAME, name, 
+		                    -1);
+
+		g_free (name);
+	}
+	
+}
+
+static void
+on_selected_renderer_toggled (GtkCellRendererToggle *renderer, 
+                              gchar *path, GtkTreeModel *tags_list_model)
+{
+	GtkTreeIter iter;
+	gboolean selected;
+
+	gtk_tree_model_get_iter_from_string (tags_list_model, &iter, path);
+	gtk_tree_model_get (tags_list_model, &iter, 
+	                    COL_SELECTED, &selected, 
+	                    -1);
+
+	selected = !selected;
+
+	gtk_list_store_set (GTK_LIST_STORE (tags_list_model), &iter, 0, selected,
+	                    -1);
+}
+
+static void
+on_tags_list_view_drag_data_get (GtkWidget *tags_list_view, 
+                                 GdkDragContext *drag_context,
+                                 GtkSelectionData *data,
+                                 guint info, guint time,
+                                 gpointer user_data)
+{
+	GtkTreeSelection *selection;
+	GtkTreeIter iter;
+	GtkTreeModel *tags_list_model;
+	gchar *name;
+
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tags_list_view));
+
+	if (gtk_tree_selection_count_selected_rows (selection) > 0)
+	{
+		gtk_tree_selection_get_selected (selection, &tags_list_model, 
+		                                 &iter);
+
+		gtk_tree_model_get (tags_list_model, &iter, COL_NAME, &name, -1);
+
+		gtk_selection_data_set_text (data, name, -1);
+
+		g_free (name);
+	}
+}
+
+static gboolean
+get_selected_tags (GtkTreeModel *tags_list_model, gchar *path, 
+                   GtkTreeIter *iter, GList **list)
+{
+	gboolean selected;
+	gchar *name;
+
+	gtk_tree_model_get (tags_list_model, iter, COL_SELECTED, &selected, -1);
+
+	if (selected)
+	{
+		gtk_tree_model_get (tags_list_model, iter, COL_NAME, &name, -1);
+
+		*list = g_list_append (*list, name);
+	}
+
+	return FALSE;
+}
+
+static void
+git_tags_pane_init (GitTagsPane *self)
+{
+	gchar *objects[] = {"tags_pane",
+						"tags_list_model",
+						NULL};
+	GError *error = NULL;
+	GtkTreeView *tags_view;
+	GtkListStore *tags_list_model;
+	GtkCellRenderer *selected_renderer;
+	
+	self->priv = g_new0 (GitTagsPanePriv, 1);
+	self->priv->builder = gtk_builder_new ();
+	
+
+	if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE, 
+	                                        objects, 
+	                                        &error))
+	{
+		g_warning ("Couldn't load builder file: %s", error->message);
+		g_error_free (error);
+	}
+
+	tags_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
+	                                                       "tags_view"));
+	tags_list_model = GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder,
+	                                                          "tags_list_model"));
+	selected_renderer = GTK_CELL_RENDERER (gtk_builder_get_object (self->priv->builder,
+	                                                               "selected_renderer"));
+
+	/* DND */
+	gtk_tree_view_enable_model_drag_source (tags_view,
+	                                        GDK_BUTTON1_MASK,
+	                                        drag_targets,
+	                                        G_N_ELEMENTS (drag_targets),
+	                                        GDK_ACTION_COPY);
+
+	g_signal_connect (G_OBJECT (tags_view), "drag-data-get",
+	                  G_CALLBACK (on_tags_list_view_drag_data_get),
+	                  NULL);
+
+	g_signal_connect (G_OBJECT (selected_renderer), "toggled",
+	                  G_CALLBACK (on_selected_renderer_toggled),
+	                  tags_list_model);
+}
+
+static void
+git_tags_pane_finalize (GObject *object)
+{
+	GitTagsPane *self;
+
+	self = GIT_TAGS_PANE (object);
+
+	g_object_unref (self->priv->builder);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_tags_pane_parent_class)->finalize (object);
+}
+
+static GtkWidget *
+git_tags_pane_get_widget (AnjutaDockPane *pane)
+{
+	GitTagsPane *self;
+
+	self = GIT_TAGS_PANE (pane);
+
+	return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+	                                           "tags_pane"));
+}
+
+static void
+git_tags_pane_class_init (GitTagsPaneClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
+
+	object_class->finalize = git_tags_pane_finalize;
+	pane_class->get_widget = git_tags_pane_get_widget;
+	pane_class->refresh = NULL;
+}
+
+
+AnjutaDockPane *
+git_tags_pane_new (Git *plugin)
+{
+	GitTagsPane *self;
+	GtkListStore *tags_list_model;
+	
+	self = g_object_new (GIT_TYPE_TAGS_PANE, "plugin", plugin, NULL);
+	tags_list_model = GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder,
+	                                                          "tags_list_model"));
+
+	g_signal_connect (G_OBJECT (plugin->tag_list_command), "command-started",
+	                  G_CALLBACK (on_tag_list_command_started),
+	                  self);
+
+	g_signal_connect (G_OBJECT (plugin->tag_list_command), "command-finished",
+	                  G_CALLBACK (on_tag_list_command_finished),
+	                  self);
+
+	g_signal_connect (G_OBJECT (plugin->tag_list_command), "data-arrived",
+	                  G_CALLBACK (on_tag_list_command_data_arrived),
+	                  tags_list_model);
+
+	return ANJUTA_DOCK_PANE (self);
+}
+
+GList *
+git_tags_pane_get_selected_tags (GitTagsPane *self)
+{
+	GtkTreeModel *tags_list_model;
+	GList *list;
+
+	tags_list_model = GTK_TREE_MODEL (gtk_builder_get_object (self->priv->builder,
+	                                                          "tags_list_model"));
+	list = NULL;
+
+	gtk_tree_model_foreach (tags_list_model, 
+	                        (GtkTreeModelForeachFunc) get_selected_tags, &list);
+
+	return list;
+}
\ No newline at end of file
diff --git a/plugins/git/git-tags-pane.h b/plugins/git/git-tags-pane.h
new file mode 100644
index 0000000..869e0ed
--- /dev/null
+++ b/plugins/git/git-tags-pane.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * git-shell-test
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ * 
+ * git-shell-test is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * git-shell-test is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GIT_TAGS_PANE_H_
+#define _GIT_TAGS_PANE_H_
+
+#include <glib-object.h>
+#include "git-pane.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_TAGS_PANE             (git_tags_pane_get_type ())
+#define GIT_TAGS_PANE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_TAGS_PANE, GitTagsPane))
+#define GIT_TAGS_PANE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_TAGS_PANE, GitTagsPaneClass))
+#define GIT_IS_TAGS_PANE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_TAGS_PANE))
+#define GIT_IS_TAGS_PANE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_TAGS_PANE))
+#define GIT_TAGS_PANE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_TAGS_PANE, GitTagsPaneClass))
+
+typedef struct _GitTagsPaneClass GitTagsPaneClass;
+typedef struct _GitTagsPane GitTagsPane;
+typedef struct _GitTagsPanePriv GitTagsPanePriv;
+
+struct _GitTagsPaneClass
+{
+	GitPaneClass parent_class;
+};
+
+struct _GitTagsPane
+{
+	GitPane parent_instance;
+	
+	GitTagsPanePriv *priv;
+};
+
+GType git_tags_pane_get_type (void) G_GNUC_CONST;
+AnjutaDockPane *git_tags_pane_new (Git *plugin);
+GList *git_tags_pane_get_selected_tags (GitTagsPane *self);
+
+G_END_DECLS
+
+#endif /* _GIT_TAGS_PANE_H_ */
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index ab1185f..756ba51 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -40,6 +40,7 @@
 #include "git-delete-remote-pane.h"
 #include "git-fetch-pane.h"
 #include "git-resolve-conflicts-pane.h"
+#include "git-tags-pane.h"
 
 AnjutaCommandBarEntry branch_entries[] =
 {
@@ -249,13 +250,18 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
 	g_object_set (G_OBJECT (git_plugin->remote_list_command),
 	              "working-directory", git_plugin->project_root_directory,
 	              NULL);
+	g_object_set (G_OBJECT (git_plugin->tag_list_command),
+	              "working-directory", git_plugin->project_root_directory,
+	              NULL);
 
 	anjuta_command_start_automatic_monitor (ANJUTA_COMMAND (git_plugin->local_branch_list_command));
 	anjuta_command_start_automatic_monitor (ANJUTA_COMMAND (git_plugin->commit_status_command));
 	anjuta_command_start_automatic_monitor (ANJUTA_COMMAND (git_plugin->remote_list_command));
+	anjuta_command_start_automatic_monitor (ANJUTA_COMMAND (git_plugin->tag_list_command));
 	anjuta_command_start (ANJUTA_COMMAND (git_plugin->local_branch_list_command));
 	anjuta_command_start (ANJUTA_COMMAND (git_plugin->commit_status_command));
 	anjuta_command_start (ANJUTA_COMMAND (git_plugin->remote_list_command));
+	anjuta_command_start (ANJUTA_COMMAND (git_plugin->tag_list_command));
 	
 	gtk_widget_set_sensitive (git_plugin->dock, TRUE);
 	gtk_widget_set_sensitive (git_plugin->command_bar, TRUE);
@@ -454,6 +460,9 @@ git_activate_plugin (AnjutaPlugin *plugin)
 	                  G_CALLBACK (run_next_command),
 	                  git_plugin->not_updated_status_command);
 
+	/* Tag list command */
+	git_plugin->tag_list_command = git_tag_list_command_new (NULL);
+
 	/* Add the panes to the dock */
 	git_plugin->status_pane = git_status_pane_new (git_plugin);
 	anjuta_dock_add_pane (ANJUTA_DOCK (git_plugin->dock), "Status",
@@ -467,11 +476,17 @@ git_activate_plugin (AnjutaPlugin *plugin)
 	                      GDL_DOCK_CENTER, branch_entries, 
 	                      G_N_ELEMENTS (branch_entries), git_plugin);
 
+	git_plugin->tags_pane = git_tags_pane_new (git_plugin);
+	anjuta_dock_add_pane (ANJUTA_DOCK (git_plugin->dock), "Tags", _("Tags"),
+	                      NULL, git_plugin->tags_pane, GDL_DOCK_CENTER,
+	                      NULL, 0, NULL);
+	
 	git_plugin->remotes_pane = git_remotes_pane_new (git_plugin);
 	anjuta_dock_add_pane (ANJUTA_DOCK (git_plugin->dock), "Remotes", 
 	                      _("Remotes"), NULL, git_plugin->remotes_pane,
 	                      GDL_DOCK_CENTER, remotes_entries, 
 	                      G_N_ELEMENTS (remotes_entries), git_plugin);
+
 	
 	/* Add watches */
 	git_plugin->project_root_watch_id = anjuta_plugin_add_watch (plugin,
diff --git a/plugins/git/plugin.h b/plugins/git/plugin.h
index 89d29e7..09563c5 100644
--- a/plugins/git/plugin.h
+++ b/plugins/git/plugin.h
@@ -38,6 +38,7 @@
 #include "git-branch-list-command.h"
 #include "git-status-command.h"
 #include "git-remote-list-command.h"
+#include "git-tag-list-command.h"
 
 extern GType git_get_type (GTypeModule *module);
 #define ANJUTA_TYPE_PLUGIN_GIT         (git_get_type (NULL))
@@ -68,6 +69,7 @@ struct _Git
 	/* Dock panes */
 	AnjutaDockPane *status_pane;
 	AnjutaDockPane *branches_pane;
+	AnjutaDockPane *tags_pane;
 	AnjutaDockPane *remotes_pane;
 
 	/* List commands for various panes. 
@@ -78,6 +80,7 @@ struct _Git
 	GitStatusCommand *commit_status_command;
 	GitStatusCommand *not_updated_status_command;
 	GitRemoteListCommand *remote_list_command;
+	GitTagListCommand *tag_list_command;
 	
 	IAnjutaMessageView *message_view;
 	AnjutaCommandQueue *command_queue;



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