message-view: bgo #727634 - Cannot copy build output
[anjuta.git] / plugins / git / git-checkout-pane.c
blob0993273283ed55d5665982b8bab57f8e9ba424c8
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-checkout-pane.h"
22 struct _GitCheckoutPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitCheckoutPane, git_checkout_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_action_activated (GtkAction *action, GitCheckoutPane *self)
32 Git *plugin;
33 GtkToggleAction *force_action;
34 GList *paths;
35 GitCheckoutFilesCommand *checkout_command;
37 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
38 force_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (self->priv->builder,
39 "force_action"));
41 paths = git_status_pane_get_checked_not_updated_items (GIT_STATUS_PANE (plugin->status_pane),
42 ANJUTA_VCS_STATUS_ALL);
43 checkout_command = git_checkout_files_command_new (plugin->project_root_directory,
44 paths,
45 gtk_toggle_action_get_active (force_action));
47 anjuta_util_glist_strings_free (paths);
49 g_signal_connect (G_OBJECT (checkout_command), "command-finished",
50 G_CALLBACK (git_pane_report_errors),
51 plugin);
53 g_signal_connect (G_OBJECT (checkout_command), "command-finished",
54 G_CALLBACK (g_object_unref),
55 NULL);
57 anjuta_command_start (ANJUTA_COMMAND (checkout_command));
59 git_pane_remove_from_dock (GIT_PANE (self));
63 static void
64 git_checkout_pane_init (GitCheckoutPane *self)
66 gchar *objects[] = {"checkout_pane",
67 "ok_action",
68 "cancel_action",
69 "force_action",
70 NULL};
71 GError *error = NULL;
72 GtkAction *ok_action;
73 GtkAction *cancel_action;
75 self->priv = g_new0 (GitCheckoutPanePriv, 1);
76 self->priv->builder = gtk_builder_new ();
78 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
79 objects,
80 &error))
82 g_warning ("Couldn't load builder file: %s", error->message);
83 g_error_free (error);
86 ok_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
87 "ok_action"));
88 cancel_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
89 "cancel_action"));
91 g_signal_connect (G_OBJECT (ok_action), "activate",
92 G_CALLBACK (on_ok_action_activated),
93 self);
95 g_signal_connect_swapped (G_OBJECT (cancel_action), "activate",
96 G_CALLBACK (git_pane_remove_from_dock),
97 self);
100 static void
101 git_checkout_pane_finalize (GObject *object)
103 GitCheckoutPane *self;
105 self = GIT_CHECKOUT_PANE (object);
107 g_object_unref (self->priv->builder);
108 g_free (self->priv);
110 G_OBJECT_CLASS (git_checkout_pane_parent_class)->finalize (object);
113 static GtkWidget *
114 get_widget (AnjutaDockPane *pane)
116 GitCheckoutPane *self;
118 self = GIT_CHECKOUT_PANE (pane);
120 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
121 "checkout_pane"));
124 static void
125 git_checkout_pane_class_init (GitCheckoutPaneClass *klass)
127 GObjectClass* object_class = G_OBJECT_CLASS (klass);
128 AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
130 object_class->finalize = git_checkout_pane_finalize;
131 pane_class->get_widget = get_widget;
132 pane_class->refresh = NULL;
136 AnjutaDockPane *
137 git_checkout_pane_new (Git *plugin)
139 return g_object_new (GIT_TYPE_CHECKOUT_PANE, "plugin", plugin, NULL);
142 void
143 on_checkout_button_clicked (GtkAction *action, Git *plugin)
145 AnjutaDockPane *checkout_pane;
147 checkout_pane = git_checkout_pane_new (plugin);
149 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "Checkout",
150 _("Check Out Files"), NULL, checkout_pane,
151 GDL_DOCK_BOTTOM, NULL, 0, NULL);
154 void
155 on_git_status_checkout_activated (GtkAction *action, Git *plugin)
157 gchar *path;
158 GList *paths;
159 GitCheckoutFilesCommand *checkout_command;
161 path = git_status_pane_get_selected_not_updated_path (GIT_STATUS_PANE (plugin->status_pane));
163 if (path)
165 paths = g_list_append (NULL, path);
167 checkout_command = git_checkout_files_command_new (plugin->project_root_directory,
168 paths, FALSE);
170 g_signal_connect (G_OBJECT (checkout_command), "command-finished",
171 G_CALLBACK (git_pane_report_errors),
172 plugin);
174 g_signal_connect (G_OBJECT (checkout_command), "command-finished",
175 G_CALLBACK (g_object_unref),
176 NULL);
178 anjuta_util_glist_strings_free (paths);
180 anjuta_command_start (ANJUTA_COMMAND (checkout_command));