message-view: bgo #727634 - Cannot copy build output
[anjuta.git] / plugins / git / git-pull-pane.c
blob25bd62fde7f79d92dba8c696465bf8fd730260ad
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
5 *
6 * anjuta 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 * anjuta 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-pull-pane.h"
22 struct _GitPullPanePriv
24 GtkBuilder *builder;
25 GtkWidget *repository_selector;
28 G_DEFINE_TYPE (GitPullPane, git_pull_pane, GIT_TYPE_PANE);
30 static void
31 on_ok_action_activated (GtkAction *action, GitPullPane *self)
33 Git *plugin;
34 GtkToggleButton *rebase_check;
35 GtkToggleAction *no_commit_action;
36 GtkToggleAction *squash_action;
37 GtkToggleButton *append_fetch_data_check;
38 GtkToggleButton *fast_forward_commit_check;
39 GtkToggleAction *force_action;
40 GtkToggleButton *no_follow_tags_check;
41 gchar *repository;
42 GitPullCommand *pull_command;
44 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
45 rebase_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
46 "rebase_check"));
47 no_commit_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (self->priv->builder,
48 "no_commit_action"));
49 squash_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (self->priv->builder,
50 "squash_action"));
51 append_fetch_data_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
52 "append_fetch_data_check"));
53 fast_forward_commit_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
54 "fast_forward_commit_check"));
55 force_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (self->priv->builder,
56 "force_action"));
57 no_follow_tags_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
58 "no_follow_tags_check"));
60 repository = git_repository_selector_get_repository (GIT_REPOSITORY_SELECTOR (self->priv->repository_selector));
62 /* Check input. Input can only be bad if the selector is in URL mode */
63 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
64 self->priv->repository_selector,
65 repository,
66 _("Please enter a URL.")))
68 g_free (repository);
69 return;
72 pull_command = git_pull_command_new (plugin->project_root_directory,
73 repository,
74 gtk_toggle_button_get_active (rebase_check),
75 gtk_toggle_action_get_active (no_commit_action),
76 gtk_toggle_action_get_active (squash_action),
77 gtk_toggle_button_get_active (append_fetch_data_check),
78 gtk_toggle_button_get_active (fast_forward_commit_check),
79 gtk_toggle_action_get_active (force_action),
80 gtk_toggle_button_get_active (no_follow_tags_check));
82 g_free (repository);
84 git_pane_create_message_view (plugin);
86 g_signal_connect (G_OBJECT (pull_command), "data-arrived",
87 G_CALLBACK (git_pane_on_command_info_arrived),
88 plugin);
90 g_signal_connect (G_OBJECT (pull_command), "command-finished",
91 G_CALLBACK (git_pane_report_errors),
92 plugin);
94 g_signal_connect (G_OBJECT (pull_command), "command-finished",
95 G_CALLBACK (git_plugin_status_changed_emit),
96 plugin);
98 g_signal_connect (G_OBJECT (pull_command), "command-finished",
99 G_CALLBACK (g_object_unref),
100 NULL);
102 anjuta_command_start (ANJUTA_COMMAND (pull_command));
104 git_pane_remove_from_dock (GIT_PANE (self));
107 static void
108 on_remote_selected (AnjutaDockPane *pane,
109 GitRepositorySelector *repository_selector)
111 gchar *remote;
113 remote = git_remotes_pane_get_selected_remote (GIT_REMOTES_PANE (pane));
114 git_repository_selector_set_remote (repository_selector, remote);
116 g_free (remote);
119 static void
120 git_pull_pane_init (GitPullPane *self)
122 gchar *objects[] = {"pull_pane",
123 "ok_action",
124 "cancel_action",
125 "force_action",
126 "squash_action",
127 "no_commit_action",
128 NULL};
129 GError *error = NULL;
130 GtkAction *ok_action;
131 GtkAction *cancel_action;
132 GtkContainer *pull_repository_alignment;
134 self->priv = g_new0 (GitPullPanePriv, 1);
135 self->priv->builder = gtk_builder_new ();
137 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
138 objects,
139 &error))
141 g_warning ("Couldn't load builder file: %s", error->message);
142 g_error_free (error);
145 ok_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
146 "ok_action"));
147 cancel_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
148 "cancel_action"));
149 pull_repository_alignment = GTK_CONTAINER (gtk_builder_get_object (self->priv->builder,
150 "pull_repository_alignment"));
151 self->priv->repository_selector = git_repository_selector_new ();
153 gtk_container_add (pull_repository_alignment, self->priv->repository_selector);
155 g_signal_connect (G_OBJECT (ok_action), "activate",
156 G_CALLBACK (on_ok_action_activated),
157 self);
159 g_signal_connect_swapped (G_OBJECT (cancel_action), "activate",
160 G_CALLBACK (git_pane_remove_from_dock),
161 self);
164 static void
165 git_pull_pane_finalize (GObject *object)
167 GitPullPane *self;
169 self = GIT_PULL_PANE (object);
171 g_object_unref (self->priv->builder);
172 g_free (self->priv);
174 G_OBJECT_CLASS (git_pull_pane_parent_class)->finalize (object);
177 static void
178 git_pull_pane_dispose (GObject *object)
180 GitPullPane *self;
181 Git *plugin;
183 self = GIT_PULL_PANE (object);
184 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (object)));
186 g_signal_handlers_disconnect_by_func (plugin->remotes_pane,
187 on_remote_selected,
188 self->priv->repository_selector);
191 G_OBJECT_CLASS (git_pull_pane_parent_class)->dispose (object);
194 static GtkWidget *
195 git_pull_pane_get_widget (AnjutaDockPane *pane)
197 GitPullPane *self;
199 self = GIT_PULL_PANE (pane);
201 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
202 "pull_pane"));
205 static void
206 git_pull_pane_class_init (GitPullPaneClass *klass)
208 GObjectClass* object_class = G_OBJECT_CLASS (klass);
209 AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
211 object_class->finalize = git_pull_pane_finalize;
212 object_class->dispose = git_pull_pane_dispose;
213 pane_class->get_widget = git_pull_pane_get_widget;
217 AnjutaDockPane *
218 git_pull_pane_new (Git *plugin)
220 GitPullPane *self;
222 self = g_object_new (GIT_TYPE_PULL_PANE, "plugin", plugin, NULL);
224 g_signal_connect (G_OBJECT (plugin->remotes_pane), "single_selection_changed",
225 G_CALLBACK (on_remote_selected),
226 self->priv->repository_selector);
228 /* Set the contents of the selected remote label */
229 on_remote_selected (plugin->remotes_pane,
230 GIT_REPOSITORY_SELECTOR (self->priv->repository_selector));
232 return ANJUTA_DOCK_PANE (self);
235 void
236 on_pull_button_clicked (GtkAction *action, Git *plugin)
238 AnjutaDockPane *pane;
240 pane = git_pull_pane_new (plugin);
242 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "Pull",
243 _("Pull"), NULL, pane, GDL_DOCK_BOTTOM,
244 NULL, 0, NULL);