1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
6 * anjuta is free software.
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)
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-bisect-dialog.h"
28 on_bisect_start_dialog_response (GtkDialog
*dialog
, gint response_id
,
31 GtkWidget
*bisect_start_revision_radio
;
32 GtkWidget
*bisect_start_bad_revision_entry
;
33 GtkWidget
*bisect_start_good_revision_entry
;
34 const gchar
*bad_revision
;
35 const gchar
*good_revision
;
36 GitBisectStartCommand
*bisect_command
;
38 if (response_id
== GTK_RESPONSE_OK
)
40 bisect_start_revision_radio
= glade_xml_get_widget (data
->gxml
,
41 "bisect_start_revision_radio");
42 bisect_start_bad_revision_entry
= glade_xml_get_widget (data
->gxml
,
43 "bisect_start_bad_revision_entry");
44 bisect_start_good_revision_entry
= glade_xml_get_widget (data
->gxml
,
45 "bisect_start_good_revision_entry");
48 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (bisect_start_revision_radio
)))
50 bad_revision
= gtk_entry_get_text (GTK_ENTRY (bisect_start_bad_revision_entry
));
52 if (!git_check_input (GTK_WIDGET (dialog
),
53 bisect_start_bad_revision_entry
,
54 bad_revision
, _("Please enter a revision.")))
60 good_revision
= gtk_entry_get_text (GTK_ENTRY (bisect_start_good_revision_entry
));
62 /* Empty revisions means don't give it to bisect. Use gtk_entry_get_text
63 * so we can re-assign the pointers to NULL without worrying about
65 if (strlen (bad_revision
) == 0)
68 if (strlen (good_revision
) == 0)
71 bisect_command
= git_bisect_start_command_new (data
->plugin
->project_root_directory
,
75 git_create_message_view (data
->plugin
);
77 g_signal_connect (G_OBJECT (bisect_command
), "command-finished",
78 G_CALLBACK (on_git_command_finished
),
81 g_signal_connect (G_OBJECT (bisect_command
), "data-arrived",
82 G_CALLBACK (on_git_command_info_arrived
),
85 anjuta_command_start (ANJUTA_COMMAND (bisect_command
));
88 gtk_widget_destroy (GTK_WIDGET (dialog
));
89 git_ui_data_free (data
);
93 on_bisect_start_revision_radio_toggled (GtkToggleButton
*toggle_button
,
96 GtkWidget
*bisect_start_dialog
;
97 GtkWidget
*bisect_start_revision_entry
;
100 bisect_start_dialog
= glade_xml_get_widget (data
->gxml
,
101 "bisect_start_dialog");
102 bisect_start_revision_entry
= glade_xml_get_widget (data
->gxml
,
103 "bisect_start_bad_revision_entry");
105 active
= gtk_toggle_button_get_active (toggle_button
);
106 gtk_widget_set_sensitive (bisect_start_revision_entry
, active
);
110 gtk_window_set_focus (GTK_WINDOW (bisect_start_dialog
),
111 bisect_start_revision_entry
);
117 bisect_start_dialog (Git
*plugin
)
121 GtkWidget
*bisect_start_revision_radio
;
124 gxml
= glade_xml_new (GLADE_FILE
, "bisect_start_dialog", NULL
);
125 dialog
= glade_xml_get_widget (gxml
, "bisect_start_dialog");
126 bisect_start_revision_radio
= glade_xml_get_widget (gxml
,
127 "bisect_start_revision_radio");
128 data
= git_ui_data_new (plugin
, gxml
);
130 g_signal_connect (G_OBJECT (dialog
), "response",
131 G_CALLBACK (on_bisect_start_dialog_response
),
134 g_signal_connect (G_OBJECT (bisect_start_revision_radio
), "toggled",
135 G_CALLBACK (on_bisect_start_revision_radio_toggled
),
138 gtk_widget_show_all (dialog
);
142 bisect_reset (Git
*plugin
)
144 GitBisectResetCommand
*bisect_command
;
146 bisect_command
= git_bisect_reset_command_new (plugin
->project_root_directory
);
148 git_create_message_view (plugin
);
150 g_signal_connect (G_OBJECT (bisect_command
), "command-finished",
151 G_CALLBACK (on_git_command_finished
),
154 g_signal_connect (G_OBJECT (bisect_command
), "data-arrived",
155 G_CALLBACK (on_git_command_info_arrived
),
158 anjuta_command_start (ANJUTA_COMMAND (bisect_command
));
162 bisect_state (Git
*plugin
, GitBisectState state
, const gchar
*revision
)
164 GitBisectStateCommand
*bisect_command
;
166 bisect_command
= git_bisect_state_command_new (plugin
->project_root_directory
,
169 git_create_message_view (plugin
);
171 g_signal_connect (G_OBJECT (bisect_command
), "command-finished",
172 G_CALLBACK (on_git_command_finished
),
175 g_signal_connect (G_OBJECT (bisect_command
), "data-arrived",
176 G_CALLBACK (on_git_command_info_arrived
),
179 anjuta_command_start (ANJUTA_COMMAND (bisect_command
));
183 update_bisect_menus (AnjutaUI
*ui
, gboolean in_bisect
)
185 GtkAction
*bisect_start_action
;
186 GtkAction
*bisect_reset_action
;
187 GtkAction
*bisect_good_action
;
188 GtkAction
*bisect_bad_action
;
189 GtkAction
*bisect_log_menu_action
;
191 bisect_start_action
= anjuta_ui_get_action (ui
, "ActionGroupGit",
192 "ActionGitBisectStart");
193 bisect_reset_action
= anjuta_ui_get_action (ui
, "ActionGroupGit",
194 "ActionGitBisectReset");
195 bisect_good_action
= anjuta_ui_get_action (ui
, "ActionGroupGit",
196 "ActionGitBisectGood");
197 bisect_bad_action
= anjuta_ui_get_action (ui
, "ActionGroupGit",
198 "ActionGitBisectBad");
199 bisect_log_menu_action
= anjuta_ui_get_action (ui
, "ActionGroupGitLog",
200 "ActionMenuGitLogBisect");
204 gtk_action_set_sensitive (bisect_start_action
, FALSE
);
205 gtk_action_set_sensitive (bisect_reset_action
, TRUE
);
206 gtk_action_set_sensitive (bisect_good_action
, TRUE
);
207 gtk_action_set_sensitive (bisect_bad_action
, TRUE
);
208 gtk_action_set_sensitive (bisect_log_menu_action
, TRUE
);
212 gtk_action_set_sensitive (bisect_start_action
, TRUE
);
213 gtk_action_set_sensitive (bisect_reset_action
, FALSE
);
214 gtk_action_set_sensitive (bisect_good_action
, FALSE
);
215 gtk_action_set_sensitive (bisect_bad_action
, FALSE
);
216 gtk_action_set_sensitive (bisect_log_menu_action
, FALSE
);
221 on_bisect_file_monitor_changed (GFileMonitor
*file_monitor
, GFile
*file
,
222 GFile
*other_file
, GFileMonitorEvent event_type
,
227 case G_FILE_MONITOR_EVENT_CREATED
:
228 /* This indicates that a bisect has started */
229 update_bisect_menus (ui
, TRUE
);
231 case G_FILE_MONITOR_EVENT_DELETED
:
232 /* This indicates that a bisect has started */
233 update_bisect_menus (ui
, FALSE
);
242 on_menu_git_bisect_start (GtkAction
*action
, Git
*plugin
)
244 bisect_start_dialog (plugin
);
248 on_menu_git_bisect_reset (GtkAction
*action
, Git
*plugin
)
250 bisect_reset (plugin
);
254 on_menu_git_bisect_good (GtkAction
*action
, Git
*plugin
)
256 bisect_state (plugin
, GIT_BISECT_STATE_GOOD
, NULL
);
260 on_menu_git_bisect_bad (GtkAction
*action
, Git
*plugin
)
262 bisect_state (plugin
, GIT_BISECT_STATE_BAD
, NULL
);
266 on_log_menu_git_bisect_good (GtkAction
*action
, Git
*plugin
)
268 GitRevision
*revision
;
271 revision
= git_log_get_selected_revision (plugin
);
275 sha
= git_revision_get_sha (revision
);
277 bisect_state (plugin
, GIT_BISECT_STATE_GOOD
, sha
);
283 on_log_menu_git_bisect_bad (GtkAction
*action
, Git
*plugin
)
285 GitRevision
*revision
;
288 revision
= git_log_get_selected_revision (plugin
);
292 sha
= git_revision_get_sha (revision
);
294 bisect_state (plugin
, GIT_BISECT_STATE_BAD
, sha
);
300 bisect_menus_init (Git
*plugin
)
303 gchar
*bisect_log_path
;
304 GFile
*bisect_log_file
;
305 GFileMonitor
*bisect_file_monitor
;
307 ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin
)->shell
, NULL
);
309 /* Git keeps a bisect log file in a project's top-level .git directory.
310 * The presence of this file indicates that a bisect is in progress.
311 * We'll monitor the creation/deletion of this file to detect the
312 * occurrence of new bisect operations and the conclusions of existing ones
313 * and update the UI accordingly. */
314 bisect_log_path
= g_strjoin (G_DIR_SEPARATOR_S
,
315 plugin
->project_root_directory
,
320 update_bisect_menus (ui
, g_file_test (bisect_log_path
, G_FILE_TEST_EXISTS
));
322 bisect_log_file
= g_file_new_for_path (bisect_log_path
);
323 bisect_file_monitor
= g_file_monitor_file (bisect_log_file
, 0, NULL
, NULL
);
325 g_signal_connect (G_OBJECT (bisect_file_monitor
), "changed",
326 G_CALLBACK (on_bisect_file_monitor_changed
),
329 g_object_unref (bisect_log_file
);
330 g_free (bisect_log_path
);
332 return bisect_file_monitor
;