Put all of the UI utility functions into the "git" namespace.
[anjuta-git-plugin.git] / plugins / git / git-add-dialog.c
blob5927c94db2afa90c89c96e7773848bef774a3e2b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
5 *
6 * anjuta is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "git-add-dialog.h"
27 static void
28 on_add_command_finished (AnjutaCommand *command, guint return_code,
29 Git *plugin)
31 AnjutaStatus *status;
33 status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell,
34 NULL);
36 anjuta_status (status, _("Git: File staged for add."), 5);
38 git_report_errors (command, return_code);
40 g_object_unref (command);
44 static void
45 on_add_dialog_response (GtkDialog *dialog, gint response_id,
46 GitUIData *data)
48 GtkWidget *add_file_chooser_button;
49 GtkWidget *force_check;
50 gchar *filename;
51 const gchar *relative_filename;
52 GitAddCommand *add_command;
54 if (response_id == GTK_RESPONSE_OK)
56 add_file_chooser_button = glade_xml_get_widget (data->gxml,
57 "add_file_chooser_button");
58 force_check = glade_xml_get_widget (data->gxml, "force_check");
59 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (add_file_chooser_button));
61 if (git_check_input (GTK_WIDGET (dialog), add_file_chooser_button, filename,
62 _("Please select a file.")))
64 relative_filename = git_get_relative_path (filename,
65 data->plugin->project_root_directory);
66 add_command = git_add_command_new_path (data->plugin->project_root_directory,
67 relative_filename,
68 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (force_check)));
70 g_free (filename);
73 g_signal_connect (G_OBJECT (add_command), "command-finished",
74 G_CALLBACK (on_add_command_finished),
75 data->plugin);
77 anjuta_command_start (ANJUTA_COMMAND (add_command));
79 else
80 return;
83 gtk_widget_destroy (GTK_WIDGET (dialog));
84 git_ui_data_free (data);
87 static void
88 add_dialog (Git *plugin, const gchar *filename)
90 GladeXML *gxml;
91 GtkWidget *dialog;
92 GtkWidget *add_file_chooser_button;
93 GitUIData *data;
95 gxml = glade_xml_new (GLADE_FILE, "add_dialog", NULL);
97 dialog = glade_xml_get_widget (gxml, "add_dialog");
98 add_file_chooser_button = glade_xml_get_widget (gxml,
99 "add_file_chooser_button");
101 if (filename)
103 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (add_file_chooser_button),
104 filename);
107 data = git_ui_data_new (plugin, gxml);
109 g_signal_connect(G_OBJECT (dialog), "response",
110 G_CALLBACK (on_add_dialog_response),
111 data);
113 gtk_widget_show_all (dialog);
116 void
117 on_menu_git_add (GtkAction *action, Git *plugin)
119 add_dialog (plugin, plugin->current_editor_filename);