git: Use AnjutaColumnTextView in the Merge pane
[anjuta.git] / plugins / git / git-create-tag-pane.c
blob780e65e30f828eee79fc58aaae37284a4077b72b
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-create-tag-pane.h"
22 struct _GitCreateTagPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitCreateTagPane, git_create_tag_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_button_clicked (GtkButton *button, GitCreateTagPane *self)
32 Git *plugin;
33 GtkEntry *name_entry;
34 AnjutaEntry *revision_entry;
35 GtkToggleButton *force_check;
36 GtkToggleButton *sign_check;
37 GtkToggleButton *annotate_check;
38 AnjutaColumnTextView *log_view;
39 gchar *name;
40 const gchar *revision;
41 gchar *log;
42 GitTagCreateCommand *create_command;
44 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
45 name_entry = GTK_ENTRY (gtk_builder_get_object (self->priv->builder,
46 "name_entry"));
47 revision_entry = ANJUTA_ENTRY (gtk_builder_get_object (self->priv->builder,
48 "revision_entry"));
49 force_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
50 "force_check"));
51 sign_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
52 "sign_check"));
53 annotate_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
54 "annotate_check"));
55 log_view = ANJUTA_COLUMN_TEXT_VIEW (gtk_builder_get_object (self->priv->builder,
56 "log_view"));
57 name = gtk_editable_get_chars (GTK_EDITABLE (name_entry), 0, -1);
58 revision = anjuta_entry_get_text (revision_entry);
59 log = NULL;
61 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
62 GTK_WIDGET (name_entry), name,
63 _("Please enter a tag name.")))
65 g_free (name);
67 return;
70 if (g_utf8_strlen (revision, -1) == 0)
71 revision = NULL;
73 if (gtk_toggle_button_get_active (annotate_check))
75 log = anjuta_column_text_view_get_text (log_view);
77 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
78 GTK_WIDGET (log_view), log,
79 _("Please enter a log message.")))
81 g_free (name);
82 g_free (log);
84 return;
88 create_command = git_tag_create_command_new (plugin->project_root_directory,
89 name,
90 revision,
91 log,
92 gtk_toggle_button_get_active (sign_check),
93 gtk_toggle_button_get_active (force_check));
95 g_signal_connect (G_OBJECT (create_command), "command-finished",
96 G_CALLBACK (git_pane_report_errors),
97 plugin);
100 g_signal_connect (G_OBJECT (create_command), "command-finished",
101 G_CALLBACK (g_object_unref),
102 NULL);
104 anjuta_command_start (ANJUTA_COMMAND (create_command));
107 g_free (name);
108 g_free (log);
110 git_pane_remove_from_dock (GIT_PANE (self));
113 static void
114 set_widget_sensitive (GtkToggleButton *button, GtkWidget *widget)
116 gtk_widget_set_sensitive (widget,
117 gtk_toggle_button_get_active (button));
120 static void
121 git_create_tag_pane_init (GitCreateTagPane *self)
123 gchar *objects[] = {"create_tag_pane",
124 NULL};
125 GError *error = NULL;
126 GtkWidget *ok_button;
127 GtkWidget *cancel_button;
128 GtkWidget *revision_entry;
129 GtkWidget *annotate_check;
130 GtkWidget *log_view;
133 self->priv = g_new0 (GitCreateTagPanePriv, 1);
134 self->priv->builder = gtk_builder_new ();
136 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
137 objects,
138 &error))
140 g_warning ("Couldn't load builder file: %s", error->message);
141 g_error_free (error);
144 ok_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
145 "ok_button"));
146 cancel_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
147 "cancel_button"));
148 revision_entry = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
149 "revision_entry"));
150 annotate_check = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
151 "annotate_check"));
152 log_view = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
153 "log_view"));
155 g_signal_connect (G_OBJECT (ok_button), "clicked",
156 G_CALLBACK (on_ok_button_clicked),
157 self);
159 g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked",
160 G_CALLBACK (git_pane_remove_from_dock),
161 self);
163 g_signal_connect (G_OBJECT (annotate_check), "toggled",
164 G_CALLBACK (set_widget_sensitive),
165 log_view);
168 static void
169 git_create_tag_pane_finalize (GObject *object)
171 GitCreateTagPane *self;
173 self = GIT_CREATE_TAG_PANE (object);
175 g_object_unref (self->priv->builder);
176 g_free (self->priv);
178 G_OBJECT_CLASS (git_create_tag_pane_parent_class)->finalize (object);
181 static GtkWidget *
182 git_create_tag_pane_get_widget (AnjutaDockPane *pane)
184 GitCreateTagPane *self;
186 self = GIT_CREATE_TAG_PANE (pane);
188 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
189 "create_tag_pane"));
192 static void
193 git_create_tag_pane_class_init (GitCreateTagPaneClass *klass)
195 GObjectClass* object_class = G_OBJECT_CLASS (klass);
196 AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
198 object_class->finalize = git_create_tag_pane_finalize;
199 pane_class->get_widget = git_create_tag_pane_get_widget;
200 pane_class->refresh = NULL;
204 AnjutaDockPane *
205 git_create_tag_pane_new (Git *plugin)
207 return g_object_new (GIT_TYPE_CREATE_TAG_PANE, "plugin", plugin, NULL);
210 void
211 on_create_tag_button_clicked (GtkAction *action, Git *plugin)
213 AnjutaDockPane *pane;
215 pane = git_create_tag_pane_new (plugin);
217 anjuta_dock_add_pane (ANJUTA_DOCK (plugin->dock), "CreateTag",
218 _("Create Tag"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
219 NULL);