message-view: bgo #727634 - Cannot copy build output
[anjuta.git] / plugins / git / git-patch-series-pane.c
blob12cf9779fb72cc4cd211ba1602e23eb89a0fde93
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-patch-series-pane.h"
22 struct _GitPatchSeriesPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitPatchSeriesPane, git_patch_series_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_action_activated (GtkAction *action, GitPatchSeriesPane *self)
32 Git *plugin;
33 AnjutaEntry *patch_series_revision_entry;
34 GtkFileChooser *folder_chooser_button;
35 GtkToggleAction *signoff_action;
36 const gchar *revision;
37 gchar *output_path;
38 GitFormatPatchCommand *format_patch_command;
40 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
41 patch_series_revision_entry = ANJUTA_ENTRY (gtk_builder_get_object (self->priv->builder,
42 "patch_series_revision_entry"));
43 folder_chooser_button = GTK_FILE_CHOOSER (gtk_builder_get_object (self->priv->builder,
44 "folder_chooser_button"));
45 signoff_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (self->priv->builder,
46 "signoff_action"));
47 revision = anjuta_entry_get_text (patch_series_revision_entry);
49 if (g_utf8_strlen (revision, -1) == 0)
50 revision = "origin";
52 output_path = gtk_file_chooser_get_filename (folder_chooser_button);
54 format_patch_command = git_format_patch_command_new (plugin->project_root_directory,
55 output_path,
56 revision,
57 gtk_toggle_action_get_active (signoff_action));
59 git_pane_create_message_view (plugin);
61 g_signal_connect (G_OBJECT (format_patch_command), "data-arrived",
62 G_CALLBACK (git_pane_on_command_info_arrived),
63 plugin);
65 g_signal_connect (G_OBJECT (format_patch_command), "command-finished",
66 G_CALLBACK (git_pane_report_errors),
67 plugin);
70 g_signal_connect (G_OBJECT (format_patch_command), "command-finished",
71 G_CALLBACK (g_object_unref),
72 NULL);
74 anjuta_command_start (ANJUTA_COMMAND (format_patch_command));
76 g_free (output_path);
78 git_pane_remove_from_dock (GIT_PANE (self));
82 static void
83 git_patch_series_pane_init (GitPatchSeriesPane *self)
85 gchar *objects[] = {"patch_series_pane",
86 "ok_action",
87 "cancel_action",
88 "signoff_action",
89 NULL};
90 GError *error = NULL;
91 GtkAction *ok_action;
92 GtkAction *cancel_action;
94 self->priv = g_new0 (GitPatchSeriesPanePriv, 1);
95 self->priv->builder = gtk_builder_new ();
97 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
98 objects,
99 &error))
101 g_warning ("Couldn't load builder file: %s", error->message);
102 g_error_free (error);
105 ok_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
106 "ok_action"));
107 cancel_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
108 "cancel_action"));
110 g_signal_connect (G_OBJECT (ok_action), "activate",
111 G_CALLBACK (on_ok_action_activated),
112 self);
114 g_signal_connect_swapped (G_OBJECT (cancel_action), "activate",
115 G_CALLBACK (git_pane_remove_from_dock),
116 self);
119 static void
120 git_patch_series_pane_finalize (GObject *object)
122 GitPatchSeriesPane *self;
124 self = GIT_PATCH_SERIES_PANE (object);
126 g_object_unref (self->priv->builder);
127 g_free (self->priv);
129 G_OBJECT_CLASS (git_patch_series_pane_parent_class)->finalize (object);
132 static GtkWidget *
133 git_patch_series_pane_get_widget (AnjutaDockPane *pane)
135 GitPatchSeriesPane *self;
137 self = GIT_PATCH_SERIES_PANE (pane);
139 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
140 "patch_series_pane"));
143 static void
144 git_patch_series_pane_class_init (GitPatchSeriesPaneClass *klass)
146 GObjectClass* object_class = G_OBJECT_CLASS (klass);
147 AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
149 object_class->finalize = git_patch_series_pane_finalize;
150 pane_class->get_widget = git_patch_series_pane_get_widget;
151 pane_class->refresh = NULL;
155 AnjutaDockPane *
156 git_patch_series_pane_new (Git *plugin)
158 return g_object_new (GIT_TYPE_PATCH_SERIES_PANE, "plugin", plugin, NULL);
161 void
162 on_patch_series_button_clicked (GtkAction *action, Git *plugin)
164 AnjutaDockPane *pane;
166 pane = git_patch_series_pane_new (plugin);
168 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "PatchSeries",
169 _("Generate Patch Series"), NULL, pane,
170 GDL_DOCK_BOTTOM, NULL, 0, NULL);