Put all of the UI utility functions into the "git" namespace.
[anjuta-git-plugin.git] / plugins / git / git-revert-dialog.c
blob027b57ff0cab91cb29e98acd05bbe3eb0ee15ab7
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-revert-dialog.h"
27 static void
28 on_revert_dialog_response (GtkDialog *dialog, gint response_id,
29 GitUIData *data)
31 GtkWidget *revert_revision_entry;
32 GtkWidget *revert_no_commit_check;
33 gchar *revision;
34 GitRevertCommand *revert_command;
36 if (response_id == GTK_RESPONSE_OK)
38 revert_revision_entry = glade_xml_get_widget (data->gxml,
39 "revert_revision_entry");
40 revert_no_commit_check = glade_xml_get_widget (data->gxml,
41 "revert_no_commit_check");
42 revision = gtk_editable_get_chars (GTK_EDITABLE (revert_revision_entry),
43 0, -1);
45 if (git_check_input (GTK_WIDGET (dialog), revert_revision_entry, revision,
46 _("Please enter a revision.")))
48 revert_command = git_revert_command_new (data->plugin->project_root_directory,
49 revision,
50 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (revert_no_commit_check)));
52 g_free (revision);
54 git_create_message_view (data->plugin);
56 g_signal_connect (G_OBJECT (revert_command), "command-finished",
57 G_CALLBACK (on_git_command_finished),
58 data->plugin);
60 g_signal_connect (G_OBJECT (revert_command), "data-arrived",
61 G_CALLBACK (on_git_command_info_arrived),
62 data->plugin);
64 anjuta_command_start (ANJUTA_COMMAND (revert_command));
66 else
68 g_free (revision);
69 return;
73 gtk_widget_destroy (GTK_WIDGET (dialog));
74 git_ui_data_free (data);
77 static void
78 revert_dialog (Git *plugin, const gchar *revision)
80 GladeXML *gxml;
81 GtkWidget *dialog;
82 GtkWidget *revert_revision_entry;
83 GitUIData *data;
85 gxml = glade_xml_new (GLADE_FILE, "revert_dialog", NULL);
87 dialog = glade_xml_get_widget (gxml, "revert_dialog");
88 revert_revision_entry = glade_xml_get_widget (gxml,
89 "revert_revision_entry");
91 data = git_ui_data_new (plugin, gxml);
93 if (revision)
94 gtk_entry_set_text (GTK_ENTRY (revert_revision_entry), revision);
96 g_signal_connect (G_OBJECT (dialog), "response",
97 G_CALLBACK (on_revert_dialog_response),
98 data);
100 gtk_widget_show_all (dialog);
103 void
104 on_menu_git_revert (GtkAction *action, Git *plugin)
106 revert_dialog (plugin, NULL);
109 void
110 on_log_menu_git_revert (GtkAction *action, Git *plugin)
112 GitRevision *revision;
113 gchar *sha;
115 revision = git_log_get_selected_revision (plugin);
117 if (revision)
119 sha = git_revision_get_sha (revision);
121 revert_dialog (plugin, sha);
122 g_free (sha);