message-view: bgo #727634 - Cannot copy build output
[anjuta.git] / plugins / git / git-revert-pane.c
blobc1fbc606e240c7dd01f348af880bdbeab9830d24
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * git-shell-test
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
5 *
6 * git-shell-test is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * git-shell-test is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "git-revert-pane.h"
22 struct _GitRevertPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitRevertPane, git_revert_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_action_activated (GtkAction *action, GitRevertPane *self)
32 Git *plugin;
33 AnjutaEntry *revert_commit_entry;
34 GtkToggleAction *no_commit_action;
35 gchar *commit;
36 GitRevertCommand *revert_command;
38 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
39 revert_commit_entry = ANJUTA_ENTRY (gtk_builder_get_object (self->priv->builder,
40 "revert_commit_entry"));
41 no_commit_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (self->priv->builder,
42 "no_commit_action"));
44 commit = anjuta_entry_dup_text (revert_commit_entry);
46 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
47 GTK_WIDGET (revert_commit_entry), commit,
48 _("Please enter a commit.")))
50 g_free (commit);
52 return;
55 revert_command = git_revert_command_new (plugin->project_root_directory,
56 commit,
57 gtk_toggle_action_get_active (no_commit_action));
59 g_signal_connect (G_OBJECT (revert_command), "command-finished",
60 G_CALLBACK (git_pane_report_errors),
61 plugin);
64 g_signal_connect (G_OBJECT (revert_command), "command-finished",
65 G_CALLBACK (g_object_unref),
66 NULL);
68 anjuta_command_start (ANJUTA_COMMAND (revert_command));
71 g_free (commit);
73 git_pane_remove_from_dock (GIT_PANE (self));
77 static void
78 git_revert_pane_init (GitRevertPane *self)
80 gchar *objects[] = {"revert_pane",
81 "ok_action",
82 "cancel_action",
83 "no_commit_action",
84 NULL};
85 GError *error = NULL;
86 GtkAction *ok_action;
87 GtkAction *cancel_action;
89 self->priv = g_new0 (GitRevertPanePriv, 1);
90 self->priv->builder = gtk_builder_new ();
92 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
93 objects,
94 &error))
96 g_warning ("Couldn't load builder file: %s", error->message);
97 g_error_free (error);
100 ok_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
101 "ok_action"));
102 cancel_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
103 "cancel_action"));
105 g_signal_connect (G_OBJECT (ok_action), "activate",
106 G_CALLBACK (on_ok_action_activated),
107 self);
109 g_signal_connect_swapped (G_OBJECT (cancel_action), "activate",
110 G_CALLBACK (git_pane_remove_from_dock),
111 self);
114 static void
115 git_revert_pane_finalize (GObject *object)
117 GitRevertPane *self;
119 self = GIT_REVERT_PANE (object);
121 g_object_unref (self->priv->builder);
122 g_free (self->priv);
124 G_OBJECT_CLASS (git_revert_pane_parent_class)->finalize (object);
127 static GtkWidget *
128 git_revert_pane_get_widget (AnjutaDockPane *pane)
130 GitRevertPane *self;
132 self = GIT_REVERT_PANE (pane);
134 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
135 "revert_pane"));
138 static void
139 git_revert_pane_class_init (GitRevertPaneClass *klass)
141 GObjectClass* object_class = G_OBJECT_CLASS (klass);
142 AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
144 object_class->finalize = git_revert_pane_finalize;
145 pane_class->get_widget = git_revert_pane_get_widget;
146 pane_class->refresh = NULL;
150 AnjutaDockPane *
151 git_revert_pane_new (Git *plugin)
153 return g_object_new (GIT_TYPE_REVERT_PANE, "plugin", plugin, NULL);
156 void
157 on_revert_button_clicked (GtkAction *action, Git *plugin)
159 AnjutaDockPane *pane;
161 pane = git_revert_pane_new (plugin);
163 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "Revert",
164 _("Revert"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
165 NULL);
168 void
169 on_git_log_revert_activated (GtkAction *action, Git *plugin)
171 GitRevision *revision;
172 gchar *sha;
173 GitRevertCommand *revert_command;
175 revision = git_log_pane_get_selected_revision (GIT_LOG_PANE (plugin->log_pane));
177 if (revision)
179 sha = git_revision_get_sha (revision);
180 revert_command = git_revert_command_new (plugin->project_root_directory,
181 sha, FALSE);
183 g_signal_connect (G_OBJECT (revert_command), "command-finished",
184 G_CALLBACK (git_pane_report_errors),
185 plugin);
187 g_signal_connect (G_OBJECT (revert_command), "command-finished",
188 G_CALLBACK (g_object_unref),
189 NULL);
191 anjuta_command_start (ANJUTA_COMMAND (revert_command));
193 g_free (sha);
194 g_object_unref (revision);