[anjuta/git-shell] git: Implement the Stash pane
- From: James Liggett <jrliggett src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/git-shell] git: Implement the Stash pane
- Date: Wed, 28 Jul 2010 07:52:05 +0000 (UTC)
commit afd411ee74f3ee8fc7edf1f767c4ffc6986fdaf8
Author: James Liggett <jrliggett cox net>
Date: Sun Jul 25 18:09:45 2010 -0700
git: Implement the Stash pane
plugins/git/Makefile.am | 4 +-
plugins/git/anjuta-git.ui | 77 +++++++++++++++
plugins/git/git-stash-pane.c | 218 ++++++++++++++++++++++++++++++++++++++++++
plugins/git/git-stash-pane.h | 58 +++++++++++
plugins/git/plugin.c | 15 +++
plugins/git/plugin.h | 3 +
6 files changed, 374 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index 048d1f0..e4ef386 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -201,7 +201,9 @@ libanjuta_git_la_SOURCES = \
git-create-tag-pane.c \
git-create-tag-pane.h \
git-delete-tags-pane.c \
- git-delete-tags-pane.h
+ git-delete-tags-pane.h \
+ git-stash-pane.h \
+ git-stash-pane.c
libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui
index d281aed..91d16a5 100644
--- a/plugins/git/anjuta-git.ui
+++ b/plugins/git/anjuta-git.ui
@@ -419,6 +419,16 @@
<column type="gchararray"/>
</columns>
</object>
+ <object class="GtkListStore" id="stash_list_model">
+ <columns>
+ <!-- column-name number -->
+ <column type="guint"/>
+ <!-- column-name message -->
+ <column type="gchararray"/>
+ <!-- column-name id -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkVBox" id="status_pane">
<property name="visible">True</property>
<child>
@@ -2744,4 +2754,71 @@
</packing>
</child>
</object>
+ <object class="GtkVBox" id="stash_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="stash_view">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="model">stash_list_model</property>
+ <property name="headers_visible">False</property>
+ <property name="headers_clickable">False</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <property name="title">column</property>
+ <child>
+ <object class="GtkCellRendererText" id="number_renderer"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn2">
+ <property name="title">column</property>
+ <child>
+ <object class="GtkCellRendererText" id="message_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"><b>Stashed Changes:</b></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-stash-pane.c b/plugins/git/git-stash-pane.c
new file mode 100644
index 0000000..8d5eac5
--- /dev/null
+++ b/plugins/git/git-stash-pane.c
@@ -0,0 +1,218 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ *
+ * anjuta 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.
+ *
+ * anjuta 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-stash-pane.h"
+
+enum
+{
+ COL_NUMBER,
+ COL_MESSAGE,
+ COL_ID
+};
+
+struct _GitStashPanePriv
+{
+ GtkBuilder *builder;
+};
+
+G_DEFINE_TYPE (GitStashPane, git_stash_pane, GIT_TYPE_PANE);
+
+static void
+on_stash_list_command_started (AnjutaCommand *command, GitStashPane *self)
+{
+ GtkTreeView *stash_view;
+ GtkListStore *stash_list_model;
+
+ stash_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
+ "stash_view"));
+ stash_list_model = GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder,
+ "stash_list_model"));
+
+ gtk_tree_view_set_model (stash_view, NULL);
+ gtk_list_store_clear (stash_list_model);
+}
+
+static void
+on_stash_list_command_finished (AnjutaCommand *command, guint return_code,
+ GitStashPane *self)
+{
+ GtkTreeView *stash_view;
+ GtkTreeModel *stash_list_model;
+
+ stash_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
+ "stash_view"));
+ stash_list_model = GTK_TREE_MODEL (gtk_builder_get_object (self->priv->builder,
+ "stash_list_model"));
+
+ gtk_tree_view_set_model (stash_view, stash_list_model);
+}
+
+static void
+on_stash_list_command_data_arrived (AnjutaCommand *command,
+ GtkListStore *stash_list_model)
+{
+ GQueue *output;
+ GtkTreeIter iter;
+ GitStash *stash;
+ guint number;
+ gchar *message;
+ gchar *id;
+
+ output = git_stash_list_command_get_output (GIT_STASH_LIST_COMMAND (command));
+
+ while (g_queue_peek_head (output))
+ {
+ gtk_list_store_append (stash_list_model, &iter);
+
+ stash = g_queue_pop_head (output);
+ number = git_stash_get_number (stash);
+ message = git_stash_get_message (stash);
+ id = git_stash_get_id (stash);
+
+ gtk_list_store_set (stash_list_model, &iter,
+ COL_NUMBER, number,
+ COL_MESSAGE, message,
+ COL_ID, id,
+ -1);
+
+ g_object_unref (stash);
+ g_free (message);
+ g_free (id);
+ }
+}
+
+static void
+git_stash_pane_init (GitStashPane *self)
+{
+ gchar *objects[] = {"stash_pane",
+ "stash_list_model",
+ NULL};
+ GError *error = NULL;
+
+ self->priv = g_new0 (GitStashPanePriv, 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);
+ }
+}
+
+static void
+git_stash_pane_finalize (GObject *object)
+{
+ GitStashPane *self;
+
+ self = GIT_STASH_PANE (object);
+
+ g_object_unref (self->priv->builder);
+ g_free (self->priv);
+
+ G_OBJECT_CLASS (git_stash_pane_parent_class)->finalize (object);
+}
+
+static GtkWidget *
+git_stash_pane_get_widget (AnjutaDockPane *pane)
+{
+ GitStashPane *self;
+
+ self = GIT_STASH_PANE (pane);
+
+ return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+ "stash_pane"));
+}
+
+static void
+git_stash_pane_class_init (GitStashPaneClass *klass)
+{
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+ AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
+
+ object_class->finalize = git_stash_pane_finalize;
+ pane_class->get_widget = git_stash_pane_get_widget;
+ pane_class->refresh = NULL;
+}
+
+
+AnjutaDockPane *
+git_stash_pane_new (Git *plugin)
+{
+ GitStashPane *self;
+ GtkListStore *stash_list_model;
+
+ self = g_object_new (GIT_TYPE_STASH_PANE, "plugin", plugin, NULL);
+ stash_list_model = GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder,
+ "stash_list_model"));
+
+ g_signal_connect (G_OBJECT (plugin->stash_list_command), "command-started",
+ G_CALLBACK (on_stash_list_command_started),
+ self);
+
+ g_signal_connect (G_OBJECT (plugin->stash_list_command), "command-finished",
+ G_CALLBACK (on_stash_list_command_finished),
+ self);
+
+ g_signal_connect (G_OBJECT (plugin->stash_list_command), "data-arrived",
+ G_CALLBACK (on_stash_list_command_data_arrived),
+ stash_list_model);
+
+ return ANJUTA_DOCK_PANE (self);
+}
+
+gchar *
+git_stash_pane_get_selected_stash_id (GitStashPane *self)
+{
+ GtkTreeView *stash_view;
+ GtkTreeSelection *selection;
+ GtkTreeModel *stash_list_model;
+ GtkTreeIter iter;
+ gchar *id;
+
+ stash_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
+ "stash_view"));
+ selection = gtk_tree_view_get_selection (stash_view);
+
+ gtk_tree_selection_get_selected (selection, &stash_list_model, &iter);
+ gtk_tree_model_get (stash_list_model, &iter, COL_ID, &id, -1);
+
+ return id;
+}
+
+guint
+git_stash_pane_get_selected_stash_number (GitStashPane *self)
+{
+ GtkTreeView *stash_view;
+ GtkTreeSelection *selection;
+ GtkTreeModel *stash_list_model;
+ GtkTreeIter iter;
+ guint number;
+
+ stash_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
+ "stash_view"));
+ selection = gtk_tree_view_get_selection (stash_view);
+
+ gtk_tree_selection_get_selected (selection, &stash_list_model, &iter);
+ gtk_tree_model_get (stash_list_model, &iter, COL_NUMBER, &number, -1);
+
+ return number;
+}
diff --git a/plugins/git/git-stash-pane.h b/plugins/git/git-stash-pane.h
new file mode 100644
index 0000000..662fc86
--- /dev/null
+++ b/plugins/git/git-stash-pane.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ *
+ * anjuta 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.
+ *
+ * anjuta 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_STASH_PANE_H_
+#define _GIT_STASH_PANE_H_
+
+#include <glib-object.h>
+#include "git-pane.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_STASH_PANE (git_stash_pane_get_type ())
+#define GIT_STASH_PANE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_STASH_PANE, GitStashPane))
+#define GIT_STASH_PANE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_STASH_PANE, GitStashPaneClass))
+#define GIT_IS_STASH_PANE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_STASH_PANE))
+#define GIT_IS_STASH_PANE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_STASH_PANE))
+#define GIT_STASH_PANE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_STASH_PANE, GitStashPaneClass))
+
+typedef struct _GitStashPaneClass GitStashPaneClass;
+typedef struct _GitStashPane GitStashPane;
+typedef struct _GitStashPanePriv GitStashPanePriv;
+
+struct _GitStashPaneClass
+{
+ GitPaneClass parent_class;
+};
+
+struct _GitStashPane
+{
+ GitPane parent_instance;
+
+ GitStashPanePriv *priv;
+};
+
+GType git_stash_pane_get_type (void) G_GNUC_CONST;
+AnjutaDockPane *git_stash_pane_new (Git *plugin);
+gchar *git_stash_pane_get_selected_stash_id (GitStashPane *self);
+guint git_stash_pane_get_selected_stash_number (GitStashPane *self);
+
+G_END_DECLS
+
+#endif /* _GIT_STASH_PANE_H_ */
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index a56866f..109b30c 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -43,6 +43,7 @@
#include "git-tags-pane.h"
#include "git-create-tag-pane.h"
#include "git-delete-tags-pane.h"
+#include "git-stash-pane.h"
AnjutaCommandBarEntry branch_entries[] =
{
@@ -284,15 +285,20 @@ on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
g_object_set (G_OBJECT (git_plugin->tag_list_command),
"working-directory", git_plugin->project_root_directory,
NULL);
+ g_object_set (G_OBJECT (git_plugin->stash_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_automatic_monitor (ANJUTA_COMMAND (git_plugin->stash_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));
+ anjuta_command_start (ANJUTA_COMMAND (git_plugin->stash_list_command));
gtk_widget_set_sensitive (git_plugin->dock, TRUE);
gtk_widget_set_sensitive (git_plugin->command_bar, TRUE);
@@ -494,6 +500,9 @@ git_activate_plugin (AnjutaPlugin *plugin)
/* Tag list command */
git_plugin->tag_list_command = git_tag_list_command_new (NULL);
+ /* Stash list command */
+ git_plugin->stash_list_command = git_stash_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",
@@ -518,6 +527,11 @@ git_activate_plugin (AnjutaPlugin *plugin)
GDL_DOCK_CENTER, remotes_entries,
G_N_ELEMENTS (remotes_entries), git_plugin);
+ git_plugin->stash_pane = git_stash_pane_new (git_plugin);
+ anjuta_dock_add_pane (ANJUTA_DOCK (git_plugin->dock), "Stash",
+ _("Stash"), NULL, git_plugin->stash_pane,
+ GDL_DOCK_CENTER, NULL, 0, NULL);
+
/* Add watches */
git_plugin->project_root_watch_id = anjuta_plugin_add_watch (plugin,
@@ -568,6 +582,7 @@ git_deactivate_plugin (AnjutaPlugin *plugin)
g_object_unref (git_plugin->commit_status_command);
g_object_unref (git_plugin->not_updated_status_command);
g_object_unref (git_plugin->remote_list_command);
+ g_object_unref (git_plugin->stash_list_command);
g_free (git_plugin->project_root_directory);
g_free (git_plugin->current_editor_filename);
diff --git a/plugins/git/plugin.h b/plugins/git/plugin.h
index 09563c5..85b7c64 100644
--- a/plugins/git/plugin.h
+++ b/plugins/git/plugin.h
@@ -39,6 +39,7 @@
#include "git-status-command.h"
#include "git-remote-list-command.h"
#include "git-tag-list-command.h"
+#include "git-stash-list-command.h"
extern GType git_get_type (GTypeModule *module);
#define ANJUTA_TYPE_PLUGIN_GIT (git_get_type (NULL))
@@ -71,6 +72,7 @@ struct _Git
AnjutaDockPane *branches_pane;
AnjutaDockPane *tags_pane;
AnjutaDockPane *remotes_pane;
+ AnjutaDockPane *stash_pane;
/* List commands for various panes.
* Keep them in the plugin so that the commands have the most direct
@@ -81,6 +83,7 @@ struct _Git
GitStatusCommand *not_updated_status_command;
GitRemoteListCommand *remote_list_command;
GitTagListCommand *tag_list_command;
+ GitStashListCommand *stash_list_command;
IAnjutaMessageView *message_view;
AnjutaCommandQueue *command_queue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]