[anjuta] git: Implement the Reset pane



commit 353f2924d76b8430e39e7867f37b2fe23948af1e
Author: James Liggett <jrliggett cox net>
Date:   Sat Dec 18 14:36:13 2010 -0800

    git: Implement the Reset pane

 plugins/git/Makefile.am      |    4 +-
 plugins/git/anjuta-git.ui    |  151 +++++++++++++++++++++++++++++++++++++
 plugins/git/git-reset-pane.c |  169 ++++++++++++++++++++++++++++++++++++++++++
 plugins/git/git-reset-pane.h |   60 +++++++++++++++
 plugins/git/plugin.c         |    9 ++
 5 files changed, 392 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index 84d944f..70aad1c 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -221,7 +221,9 @@ libanjuta_git_la_SOURCES = \
 	git-log-data-command.c \
 	git-log-data-command.h \
 	git-revert-pane.c \
-	git-revert-pane.h
+	git-revert-pane.h \
+	git-reset-pane.c \
+	git-reset-pane.h
 	
 
 libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui
index f36196a..a0f0833 100644
--- a/plugins/git/anjuta-git.ui
+++ b/plugins/git/anjuta-git.ui
@@ -2824,4 +2824,155 @@
       </packing>
     </child>
   </object>
+  <object class="GtkVBox" id="reset_pane">
+    <property name="visible">True</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="AnjutaDropEntry" id="revision_entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="invisible_char">â?¢</property>
+                <property name="help_text">Previous commit; Drop or enter a different revision here</property>
+              </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;Revision:&lt;/b&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkFrame" id="frame2">
+        <property name="visible">True</property>
+        <property name="label_xalign">0</property>
+        <property name="shadow_type">none</property>
+        <child>
+          <object class="GtkAlignment" id="alignment2">
+            <property name="visible">True</property>
+            <property name="left_padding">12</property>
+            <child>
+              <object class="GtkVBox" id="vbox1">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkRadioButton" id="mixed_radio">
+                    <property name="label" translatable="yes">Mixed</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="soft_radio">
+                    <property name="label" translatable="yes">Soft</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">mixed_radio</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="hard_radio">
+                    <property name="label" translatable="yes">Hard</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">mixed_radio</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child type="label">
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">&lt;b&gt;Mode:&lt;/b&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkHButtonBox" id="hbuttonbox1">
+        <property name="visible">True</property>
+        <property name="spacing">5</property>
+        <property name="layout_style">end</property>
+        <child>
+          <object class="GtkButton" id="cancel_button">
+            <property name="label">gtk-cancel</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_stock">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="ok_button">
+            <property name="label">gtk-ok</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_stock">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="position">2</property>
+      </packing>
+    </child>
+  </object>
 </interface>
diff --git a/plugins/git/git-reset-pane.c b/plugins/git/git-reset-pane.c
new file mode 100644
index 0000000..7e86406
--- /dev/null
+++ b/plugins/git/git-reset-pane.c
@@ -0,0 +1,169 @@
+/* -*- 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-reset-pane.h"
+
+struct _GitResetPanePriv
+{
+	GtkBuilder *builder;
+};
+
+G_DEFINE_TYPE (GitResetPane, git_reset_pane, GIT_TYPE_PANE);
+
+static void
+on_ok_button_clicked (GtkButton *button, GitResetPane *self)
+{
+	Git *plugin;
+	AnjutaEntry *revision_entry;
+	GtkToggleButton *mixed_radio;
+	GtkToggleButton *soft_radio;
+	GtkToggleButton *hard_radio;
+	const gchar *revision;
+	GitResetTreeMode mode;
+	GitResetTreeCommand *reset_command;
+
+	plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
+	revision_entry = ANJUTA_ENTRY (gtk_builder_get_object (self->priv->builder,
+	                                                       "revision_entry"));
+	mixed_radio = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                         "mixed_radio"));
+	soft_radio = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                        "soft_radio"));
+	hard_radio = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
+	                                                        "hard_radio"));
+	
+	revision = anjuta_entry_get_text (revision_entry);
+
+	if (g_utf8_strlen (revision, -1) == 0)
+		revision = GIT_RESET_TREE_PREVIOUS;
+
+	if (gtk_toggle_button_get_active (mixed_radio))
+		mode = GIT_RESET_TREE_MODE_MIXED;
+	else if (gtk_toggle_button_get_active (soft_radio))
+		mode = GIT_RESET_TREE_MODE_SOFT;
+	else
+		mode = GIT_RESET_TREE_MODE_HARD;
+
+	reset_command = git_reset_tree_command_new (plugin->project_root_directory,
+	                                            revision, mode);
+
+	g_signal_connect (G_OBJECT (reset_command), "command-finished",
+	                  G_CALLBACK (git_pane_report_errors),
+	                  plugin);
+
+
+	g_signal_connect (G_OBJECT (reset_command), "command-finished",
+	                  G_CALLBACK (g_object_unref),
+	                  NULL);
+
+	anjuta_command_start (ANJUTA_COMMAND (reset_command));
+
+
+	git_pane_remove_from_dock (GIT_PANE (self));
+}
+
+
+static void
+git_reset_pane_init (GitResetPane *self)
+{
+	gchar *objects[] = {"reset_pane",
+						NULL};
+	GError *error = NULL;
+	GtkWidget *ok_button;
+	GtkWidget *cancel_button;
+	
+
+	self->priv = g_new0 (GitResetPanePriv, 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);
+	}
+
+	ok_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, 
+	                                                "ok_button"));
+	cancel_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, 
+	                                                    "cancel_button"));
+	
+	g_signal_connect (G_OBJECT (ok_button), "clicked",
+	                  G_CALLBACK (on_ok_button_clicked),
+	                  self);
+
+	g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked",
+	                          G_CALLBACK (git_pane_remove_from_dock),
+	                          self);
+}
+
+static void
+git_reset_pane_finalize (GObject *object)
+{
+	GitResetPane *self;
+
+	self = GIT_RESET_PANE (object);
+
+	g_object_unref (self->priv->builder);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (git_reset_pane_parent_class)->finalize (object);
+}
+
+static GtkWidget *
+git_reset_pane_get_widget (AnjutaDockPane *pane)
+{
+	GitResetPane *self;
+
+	self = GIT_RESET_PANE (pane);
+
+	return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
+	                                           "reset_pane"));
+}
+
+static void
+git_reset_pane_class_init (GitResetPaneClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
+
+	object_class->finalize = git_reset_pane_finalize;
+	pane_class->get_widget = git_reset_pane_get_widget;
+	pane_class->refresh = NULL;
+}
+
+
+AnjutaDockPane *
+git_reset_pane_new (Git *plugin)
+{
+	return g_object_new (GIT_TYPE_RESET_PANE, "plugin", plugin, NULL);
+}
+
+void
+on_reset_button_clicked (GtkAction *action, Git *plugin)
+{
+	AnjutaDockPane *pane;
+
+	pane = git_reset_pane_new (plugin);
+
+	anjuta_dock_add_pane (ANJUTA_DOCK (plugin->dock), "Reset", 
+	                      _("Reset"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
+	                      NULL);
+}
\ No newline at end of file
diff --git a/plugins/git/git-reset-pane.h b/plugins/git/git-reset-pane.h
new file mode 100644
index 0000000..5f0d0e5
--- /dev/null
+++ b/plugins/git/git-reset-pane.h
@@ -0,0 +1,60 @@
+/* -*- 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_RESET_PANE_H_
+#define _GIT_RESET_PANE_H_
+
+#include <glib-object.h>
+#include <libanjuta/anjuta-entry.h>
+#include "git-pane.h"
+#include "plugin.h"
+#include "git-reset-tree-command.h"
+
+G_BEGIN_DECLS
+
+#define GIT_TYPE_RESET_PANE             (git_reset_pane_get_type ())
+#define GIT_RESET_PANE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_RESET_PANE, GitResetPane))
+#define GIT_RESET_PANE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_RESET_PANE, GitResetPaneClass))
+#define GIT_IS_RESET_PANE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_RESET_PANE))
+#define GIT_IS_RESET_PANE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_RESET_PANE))
+#define GIT_RESET_PANE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_RESET_PANE, GitResetPaneClass))
+
+typedef struct _GitResetPaneClass GitResetPaneClass;
+typedef struct _GitResetPane GitResetPane;
+typedef struct _GitResetPanePriv GitResetPanePriv;
+
+struct _GitResetPaneClass
+{
+	GitPaneClass parent_class;
+};
+
+struct _GitResetPane
+{
+	GitPane parent_instance;
+
+	GitResetPanePriv *priv;
+};
+
+GType git_reset_pane_get_type (void) G_GNUC_CONST;
+AnjutaDockPane *git_reset_pane_new (Git *plugin);
+void on_reset_button_clicked (GtkAction *action, Git *plugin);
+
+G_END_DECLS
+
+#endif /* _GIT_RESET_PANE_H_ */
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index 6467906..c01d538 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -51,6 +51,7 @@
 #include "git-clear-stash-pane.h"
 #include "git-rebase-pane.h"
 #include "git-log-pane.h"
+#include "git-reset-pane.h"
 #include "git-revert-pane.h"
 
 AnjutaCommandBarEntry branch_entries[] =
@@ -366,6 +367,14 @@ static AnjutaCommandBarEntry log_entries[] =
 	},
 	{
 		ANJUTA_COMMAND_BAR_ENTRY_BUTTON,
+		"Reset",
+		N_("Reset tree"),
+		N_("Reset tree to a previous revision"),
+		GTK_STOCK_REFRESH,
+		G_CALLBACK (on_reset_button_clicked)
+	},
+	{
+		ANJUTA_COMMAND_BAR_ENTRY_BUTTON,
 		"Revert",
 		N_("Revert commit"),
 		N_("Revert a commit"),



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