Make a generic command-finished handler.
[anjuta-git-plugin.git] / plugins / git / git-commit-dialog.c
blobb93eeab3c5c019536246d714b6f102764ade5da5
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-commit-dialog.h"
27 static void
28 on_commit_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: Commit complete."), 5);
38 report_errors (command, return_code);
40 g_object_unref (command);
44 static void
45 on_commit_dialog_response (GtkDialog *dialog, gint response_id,
46 GitUIData *data)
48 GtkWidget *log_view;
49 gchar *log;
50 GtkWidget *log_prompt_dialog;
51 gint prompt_response;
52 GtkWidget *status_view;
53 GtkWidget *resolve_check;
54 GList *selected_paths;
55 GitCommitCommand *commit_command;
57 if (response_id == GTK_RESPONSE_OK)
59 log_view = glade_xml_get_widget (data->gxml, "log_view");
60 log = get_log_from_textview (log_view);
62 if (!g_utf8_strlen(log, -1))
64 log_prompt_dialog = gtk_message_dialog_new(GTK_WINDOW(dialog),
65 GTK_DIALOG_DESTROY_WITH_PARENT,
66 GTK_MESSAGE_INFO,
67 GTK_BUTTONS_YES_NO,
68 _("Are you sure that you want to pass an empty log message?"));
70 prompt_response = gtk_dialog_run(GTK_DIALOG (log_prompt_dialog));
71 gtk_widget_destroy (log_prompt_dialog);
73 if (prompt_response == GTK_RESPONSE_NO)
74 return;
77 status_view = glade_xml_get_widget (data->gxml, "status_view");
78 resolve_check = glade_xml_get_widget (data->gxml, "resolve_check");
79 selected_paths = anjuta_vcs_status_tree_view_get_selected (ANJUTA_VCS_STATUS_TREE_VIEW (status_view));
80 commit_command = git_commit_command_new (data->plugin->project_root_directory,
81 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (resolve_check)),
82 log,
83 selected_paths);
85 git_command_free_path_list (selected_paths);
87 create_message_view (data->plugin);
89 g_signal_connect (G_OBJECT (commit_command), "command-finished",
90 G_CALLBACK (on_commit_command_finished),
91 data->plugin);
93 g_signal_connect (G_OBJECT (commit_command), "data-arrived",
94 G_CALLBACK (on_command_info_arrived),
95 data->plugin);
97 anjuta_command_start (ANJUTA_COMMAND (commit_command));
100 gtk_widget_destroy (GTK_WIDGET (dialog));
101 git_ui_data_free (data);
104 static void
105 select_all_files (AnjutaCommand *command, guint return_code,
106 AnjutaVcsStatusTreeView *status_view)
108 anjuta_vcs_status_tree_view_select_all (status_view);
111 static void
112 commit_dialog (Git *plugin)
114 GladeXML *gxml;
115 GtkWidget *dialog;
116 GtkWidget *select_all_button;
117 GtkWidget *clear_button;
118 GtkWidget *status_view;
119 GtkWidget *status_progress_bar;
120 GitStatusCommand *status_command;
121 GitUIData *data;
123 gxml = glade_xml_new (GLADE_FILE, "commit_dialog", NULL);
125 dialog = glade_xml_get_widget (gxml, "commit_dialog");
126 select_all_button = glade_xml_get_widget (gxml, "select_all_button");
127 clear_button = glade_xml_get_widget (gxml, "clear_button");
128 status_view = glade_xml_get_widget (gxml, "status_view");
129 status_progress_bar = glade_xml_get_widget (gxml, "status_progress_bar");
131 status_command = git_status_command_new (plugin->project_root_directory);
133 g_signal_connect (G_OBJECT (select_all_button), "clicked",
134 G_CALLBACK (select_all_status_items),
135 status_view);
137 g_signal_connect (G_OBJECT (clear_button), "clicked",
138 G_CALLBACK (clear_all_status_selections),
139 status_view);
141 g_signal_connect (G_OBJECT (status_command), "command-finished",
142 G_CALLBACK (select_all_files),
143 status_view);
145 pulse_progress_bar (GTK_PROGRESS_BAR (status_progress_bar));
147 g_signal_connect (G_OBJECT (status_command), "command-finished",
148 G_CALLBACK (cancel_data_arrived_signal_disconnect),
149 status_view);
151 g_signal_connect (G_OBJECT (status_command), "command-finished",
152 G_CALLBACK (hide_pulse_progress_bar),
153 status_progress_bar);
155 g_signal_connect (G_OBJECT (status_command), "command-finished",
156 G_CALLBACK (on_command_finished),
157 NULL);
159 g_signal_connect (G_OBJECT (status_command), "data-arrived",
160 G_CALLBACK (on_status_command_data_arrived),
161 status_view);
163 g_object_weak_ref (G_OBJECT (status_view),
164 (GWeakNotify) disconnect_data_arrived_signals,
165 status_command);
167 anjuta_command_start (ANJUTA_COMMAND (status_command));
169 data = git_ui_data_new (plugin, gxml);
171 g_signal_connect(G_OBJECT (dialog), "response",
172 G_CALLBACK (on_commit_dialog_response),
173 data);
175 gtk_widget_show_all (dialog);
178 void
179 on_menu_git_commit (GtkAction *action, Git *plugin)
181 commit_dialog (plugin);