Put all of the UI utility functions into the "git" namespace.
[anjuta-git-plugin.git] / plugins / git / git-switch-dialog.c
blob0167c8a82565628fa8a52df645f796410fc8da72
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-switch-dialog.h"
27 static void
28 on_checkout_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: Branch checkout complete."), 5);
38 git_report_errors (command, return_code);
40 g_object_unref (command);
44 static void
45 on_switch_dialog_response (GtkDialog *dialog, gint response_id,
46 GitBranchComboData *data)
48 GtkWidget *switch_branch_combo;
49 gchar *branch;
50 GtkTreeIter iter;
51 GitBranchCheckoutCommand *checkout_command;
53 if (response_id == GTK_RESPONSE_OK)
55 switch_branch_combo = glade_xml_get_widget (data->gxml, "switch_branch_combo");
57 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (switch_branch_combo), &iter);
58 branch = git_branch_combo_model_get_branch (data->model, &iter);
60 checkout_command = git_branch_checkout_command_new (data->plugin->project_root_directory,
61 branch);
63 g_free (branch);
65 git_create_message_view (data->plugin);
67 g_signal_connect (G_OBJECT (checkout_command), "command-finished",
68 G_CALLBACK (on_checkout_command_finished),
69 data->plugin);
71 g_signal_connect (G_OBJECT (checkout_command), "data-arrived",
72 G_CALLBACK (on_git_command_info_arrived),
73 data->plugin);
75 anjuta_command_start (ANJUTA_COMMAND (checkout_command));
78 gtk_widget_destroy (GTK_WIDGET (dialog));
79 git_branch_combo_data_free (data);
82 static void
83 switch_dialog (Git *plugin)
85 GladeXML *gxml;
86 GtkWidget *dialog;
87 GtkWidget *switch_branch_combo;
88 GtkListStore *branch_list_store;
89 GitBranchComboData *data;
90 GitBranchListCommand *list_command;
92 gxml = glade_xml_new (GLADE_FILE, "switch_dialog", NULL);
94 dialog = glade_xml_get_widget (gxml, "switch_dialog");
95 switch_branch_combo = glade_xml_get_widget (gxml, "switch_branch_combo");
96 branch_list_store = git_branch_combo_model_new ();
98 gtk_combo_box_set_model (GTK_COMBO_BOX (switch_branch_combo),
99 GTK_TREE_MODEL (branch_list_store));
100 git_branch_combo_model_setup_widget (switch_branch_combo);
102 data = git_branch_combo_data_new (branch_list_store,
103 GTK_COMBO_BOX (switch_branch_combo), gxml,
104 plugin);
106 list_command = git_branch_list_command_new (plugin->project_root_directory,
107 GIT_BRANCH_TYPE_LOCAL);
109 g_signal_connect (G_OBJECT (list_command), "data-arrived",
110 G_CALLBACK (on_git_list_branch_command_data_arrived),
111 data);
113 g_signal_connect (G_OBJECT (list_command), "command-finished",
114 G_CALLBACK (on_git_list_branch_command_finished),
115 data);
117 anjuta_command_start (ANJUTA_COMMAND (list_command));
119 g_signal_connect (G_OBJECT (dialog), "response",
120 G_CALLBACK (on_switch_dialog_response),
121 data);
123 gtk_widget_show_all (dialog);
126 void
127 on_menu_git_switch (GtkAction *action, Git *plugin)
129 switch_dialog (plugin);