git: Use AnjutaColumnTextView in the Merge pane
[anjuta.git] / plugins / git / git-add-remote-pane.c
blob367b0417b2fe007b6c67aadceaf1df8b63f73439
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-add-remote-pane.h"
22 struct _GitAddRemotePanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitAddRemotePane, git_add_remote_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_button_clicked (GtkButton *button, GitAddRemotePane *self)
32 Git *plugin;
33 GtkEntry *name_entry;
34 GtkEntry *url_entry;
35 GtkToggleButton *fetch_check;
36 gchar *name;
37 gchar *url;
38 GitRemoteAddCommand *add_remote_command;
40 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
41 name_entry = GTK_ENTRY (gtk_builder_get_object (self->priv->builder,
42 "name_entry"));
43 url_entry = GTK_ENTRY (gtk_builder_get_object (self->priv->builder,
44 "url_entry"));
45 fetch_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
46 "fetch_check"));
47 name = gtk_editable_get_chars (GTK_EDITABLE (name_entry), 0, -1);
48 url = gtk_editable_get_chars (GTK_EDITABLE (url_entry), 0, -1);
50 if (!git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
51 GTK_WIDGET (name_entry), name,
52 _("Please enter a remote name.")) ||
53 !git_pane_check_input (GTK_WIDGET (ANJUTA_PLUGIN (plugin)->shell),
54 GTK_WIDGET (url_entry), url,
55 _("Please enter a URL")))
57 g_free (name);
58 g_free (url);
60 return;
63 add_remote_command = git_remote_add_command_new (plugin->project_root_directory,
64 name, url,
65 gtk_toggle_button_get_active (fetch_check));
67 /* Info outupt is only relevant if we're also fetching */
68 if (gtk_toggle_button_get_active (fetch_check))
70 git_pane_create_message_view (plugin);
72 g_signal_connect (G_OBJECT (add_remote_command), "data-arrived",
73 G_CALLBACK (git_pane_on_command_info_arrived),
74 plugin);
77 g_signal_connect (G_OBJECT (add_remote_command), "command-finished",
78 G_CALLBACK (git_pane_report_errors),
79 plugin);
82 g_signal_connect (G_OBJECT (add_remote_command), "command-finished",
83 G_CALLBACK (g_object_unref),
84 NULL);
86 anjuta_command_start (ANJUTA_COMMAND (add_remote_command));
89 g_free (name);
90 g_free (url);
92 git_pane_remove_from_dock (GIT_PANE (self));
95 static void
96 git_add_remote_pane_init (GitAddRemotePane *self)
98 gchar *objects[] = {"add_remote_pane",
99 NULL};
100 GError *error = NULL;
101 GtkWidget *ok_button;
102 GtkWidget *cancel_button;
104 self->priv = g_new0 (GitAddRemotePanePriv, 1);
105 self->priv->builder = gtk_builder_new ();
107 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
108 objects,
109 &error))
111 g_warning ("Couldn't load builder file: %s", error->message);
112 g_error_free (error);
115 ok_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
116 "ok_button"));
117 cancel_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
118 "cancel_button"));
120 g_signal_connect (G_OBJECT (ok_button), "clicked",
121 G_CALLBACK (on_ok_button_clicked),
122 self);
124 g_signal_connect_swapped (G_OBJECT (cancel_button), "clicked",
125 G_CALLBACK (git_pane_remove_from_dock),
126 self);
129 static void
130 git_add_remote_pane_finalize (GObject *object)
132 GitAddRemotePane *self;
134 self = GIT_ADD_REMOTE_PANE (object);
136 g_object_unref (self->priv->builder);
137 g_free (self->priv);
139 G_OBJECT_CLASS (git_add_remote_pane_parent_class)->finalize (object);
142 static GtkWidget *
143 git_add_remote_pane_get_widget (AnjutaDockPane *pane)
145 GitAddRemotePane *self;
147 self = GIT_ADD_REMOTE_PANE (pane);
149 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
150 "add_remote_pane"));
153 static void
154 git_add_remote_pane_class_init (GitAddRemotePaneClass *klass)
156 GObjectClass* object_class = G_OBJECT_CLASS (klass);
157 AnjutaDockPaneClass *pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
159 object_class->finalize = git_add_remote_pane_finalize;
160 pane_class->get_widget = git_add_remote_pane_get_widget;
161 pane_class->refresh = NULL;
165 AnjutaDockPane *
166 git_add_remote_pane_new (Git *plugin)
168 return g_object_new (GIT_TYPE_ADD_REMOTE_PANE, "plugin", plugin, NULL);
171 void
172 on_add_remote_button_clicked (GtkAction *action, Git *plugin)
174 AnjutaDockPane *pane;
176 pane = git_add_remote_pane_new (plugin);
178 anjuta_dock_add_pane (ANJUTA_DOCK (plugin->dock), "AddRemote",
179 _("Add Remote"), NULL, pane, GDL_DOCK_BOTTOM, NULL, 0,
180 NULL);