~debian-bazaar/+junk/anjuta-bzr-debian

« back to all changes in this revision

Viewing changes to src/bazaar-menu-add.c

  • Committer: Jelmer Vernooij
  • Date: 2008-11-10 19:13:03 UTC
  • mfrom: (60.1.117 trunk)
  • Revision ID: jelmer@samba.org-20081110191303-gh3te5q0bq9owqbm
Merge new upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2
 
/*
3
 
 * Anjuta
4
 
 * Copyright (C) William Fagan 2008 
5
 
 *
6
 
 * Portions based on the Subversion plugin
7
 
 * Copyright (C) James Liggett 2007
8
 
 * Copyright (C) Johannes Schmid 2005
9
 
 *
10
 
 * Anjuta is free software.
11
 
 * 
12
 
 * You may redistribute it and/or modify it under the terms of the
13
 
 * GNU General Public License, as published by the Free Software
14
 
 * Foundation; either version 2 of the License, or (at your option)
15
 
 * any later version.
16
 
 * 
17
 
 * Anjuta is distributed in the hope that it will be useful,
18
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
 
 * See the GNU General Public License for more details.
21
 
 * 
22
 
 * You should have received a copy of the GNU General Public License
23
 
 * along with Anjuta.  If not, write to:
24
 
 *      The Free Software Foundation, Inc.,
25
 
 *      51 Franklin Street, Fifth Floor
26
 
 *      Boston, MA  02110-1301, USA.
27
 
 */
28
 
 
29
 
 
30
 
#include <libanjuta/anjuta-debug.h>
31
 
 
32
 
#include "bazaar-menu-add.h"
33
 
#include "bazaar-command-add.h"
34
 
#include "bazaar-tools-ui.h"
35
 
#include "bazaar-tools-python.h"
36
 
#include "bazaar-message-dialog.h"
37
 
#include "bazaar-list-command-unknown.h"
38
 
#include "bazaar-list-command-ignored.h"
39
 
 
40
 
void add_setup_treeview (GladeXML *gxml);
41
 
void add_unknown_file_entry (GladeXML *gxml, const gchar *filename);
42
 
void add_unknown_dir_entry (GladeXML *gxml, const gchar *filename);
43
 
void add_ignored_file_entry (GladeXML *gxml, const gchar *filename);
44
 
void add_ignored_dir_entry (GladeXML *gxml, const gchar *filename);
45
 
 
46
 
bazaar_menu_add_set_sensitive (AnjutaPlugin *plugin)
47
 
{
48
 
        GtkAction *action = NULL;
49
 
        
50
 
        action = bazaar_get_action( plugin, "ActionBazaarAdd" );
51
 
        
52
 
        gtk_action_set_sensitive (action, TRUE);
53
 
}
54
 
 
55
 
void 
56
 
bazaar_menu_add_set_insensitive (AnjutaPlugin *plugin)
57
 
{
58
 
        GtkAction *action = NULL;
59
 
        
60
 
        action = bazaar_get_action( plugin, "ActionBazaarAdd" );
61
 
        
62
 
        gtk_action_set_sensitive (action, FALSE);
63
 
}
64
 
 
65
 
static void 
66
 
unknown_received(AnjutaCommand *command, BazaarPluginData *data)
67
 
{
68
 
        GQueue *output_queue = NULL;
69
 
        gchar *item = NULL;
70
 
        
71
 
        output_queue = bazaar_list_command_get_queue (BAZAAR_LIST_COMMAND (command));
72
 
        item = g_queue_pop_head (output_queue);
73
 
        
74
 
        if (strcmp (item, "") == 0)
75
 
        {
76
 
                return;
77
 
        }
78
 
        
79
 
        if (bazaar_path_is_dir (item) == TRUE)
80
 
        {
81
 
                add_unknown_dir_entry (data->gxml, item);
82
 
        }
83
 
        {
84
 
                add_unknown_file_entry (data->gxml, item);
85
 
        }
86
 
}
87
 
 
88
 
static void 
89
 
ignored_received(AnjutaCommand *command, BazaarPluginData *data)
90
 
{
91
 
        GQueue *output_queue = NULL;
92
 
        gchar *item = NULL;
93
 
        
94
 
        output_queue = bazaar_list_command_get_queue (BAZAAR_LIST_COMMAND (command));
95
 
        item = g_queue_pop_head (output_queue);
96
 
        
97
 
        if (strcmp (item, "") == 0)
98
 
        {
99
 
                return;
100
 
        }
101
 
        
102
 
        if (bazaar_path_exists (item) == FALSE)
103
 
        {
104
 
                return;
105
 
        }
106
 
        
107
 
        if (bazaar_path_is_dir (item) == TRUE)
108
 
        {
109
 
                add_ignored_dir_entry (data->gxml, item);
110
 
        }
111
 
        {
112
 
                add_ignored_file_entry (data->gxml, item);
113
 
        }
114
 
}
115
 
 
116
 
//This isn't working atm.
117
 
/*
118
 
static gboolean
119
 
clear_ignored (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, 
120
 
                                  GtkListStore* store)
121
 
{
122
 
        
123
 
        gchar *status_text = NULL;
124
 
        printf ("a\n");
125
 
        status_text = bazaar_treeview_get_status_text (model, iter);
126
 
        
127
 
        if (strcmp (status_text, "Ignored") == 0)
128
 
        {
129
 
                gtk_list_store_remove (GTK_LIST_STORE (model), iter);
130
 
        }
131
 
        
132
 
        return FALSE;
133
 
}*/
134
 
 
135
 
void bazaar_show_ignored_toggled (GtkToggleButton *button, BazaarPluginData *data)
136
 
{
137
 
        switch (gtk_toggle_button_get_active (button))
138
 
        {
139
 
                case TRUE:                                        
140
 
                {
141
 
                        BazaarListIgnoredCommand* ignored_cmd = NULL;
142
 
                        
143
 
                        ignored_cmd = bazaar_list_ignored_command_new (data->plugin->project_root_dir); 
144
 
        
145
 
                        g_signal_connect (G_OBJECT (ignored_cmd), "data-arrived",
146
 
                                          G_CALLBACK (ignored_received), data); 
147
 
                                          
148
 
                        anjuta_command_start (ANJUTA_COMMAND (ignored_cmd));
149
 
                        break;
150
 
                }
151
 
                        
152
 
                case FALSE:
153
 
                {       
154
 
                        GtkWidget *view = NULL;
155
 
                        GtkTreeModel *model = NULL;
156
 
                        BazaarListUnknownCommand *cmd = NULL;
157
 
                        
158
 
                        view = glade_xml_get_widget(data->gxml, "bazaar-add-tree-view");
159
 
                        model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
160
 
                        
161
 
                        gtk_list_store_clear (GTK_LIST_STORE (model));
162
 
        
163
 
                        cmd = bazaar_list_unknown_command_new (data->plugin->project_root_dir);
164
 
        
165
 
                        g_signal_connect (G_OBJECT (cmd), "data-arrived",
166
 
                                          G_CALLBACK (unknown_received), data); 
167
 
                                          
168
 
                        anjuta_command_start (ANJUTA_COMMAND (cmd));
169
 
                        
170
 
                        //gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc)clear_ignored, NULL);*/
171
 
                        break;
172
 
                }
173
 
        }
174
 
}
175
 
 
176
 
static void
177
 
bazaar_on_add_command_finished (AnjutaCommand *command, guint return_code, 
178
 
                                                        BazaarPlugin *plugin)
179
 
{                                                        
180
 
        bazaar_add_command_destroy (BAZAAR_ADD_COMMAND (command));
181
 
}
182
 
 
183
 
static void
184
 
bazaar_add_signal_response (GtkDialog *dialog, gint response, 
185
 
                            BazaarPluginData* data)
186
 
{
187
 
        if (response == GTK_RESPONSE_OK)
188
 
        {
189
 
                GtkWidget *tree_view = NULL;
190
 
                BazaarMessageDialog* msg_dialog = NULL;
191
 
                BazaarAddCommand *add_command = NULL;
192
 
                GList *selected_files = NULL;
193
 
                
194
 
                tree_view = glade_xml_get_widget(data->gxml, "bazaar-add-tree-view");
195
 
                msg_dialog = bazaar_message_dialog_new ();
196
 
                
197
 
                selected_files = bazaar_tree_view_get_checked_filenames (GTK_TREE_VIEW (tree_view));
198
 
                
199
 
                if (g_list_length (selected_files) == 0 )
200
 
                {
201
 
                        bazaar_message_dialog_add_error (msg_dialog, "Nothing To Do", "There is no files selected to add.");
202
 
                }
203
 
                
204
 
                add_command = bazaar_add_command_new (data->plugin->project_root_dir, selected_files);
205
 
                
206
 
                g_signal_connect (G_OBJECT (add_command), "command-finished",
207
 
                                                  G_CALLBACK (bazaar_on_add_command_finished),
208
 
                                                  data->plugin);
209
 
                                                  
210
 
                if ( bazaar_message_dialog_is_needed(msg_dialog) == TRUE )
211
 
                {
212
 
                        gint result;
213
 
                        
214
 
                        result = bazaar_message_dialog_run(msg_dialog) != GTK_RESPONSE_YES;
215
 
                        
216
 
                        if ( result != GTK_RESPONSE_YES )
217
 
                        {
218
 
                                /* Free Memory */
219
 
                                gtk_widget_destroy (GTK_WIDGET(msg_dialog));
220
 
                                return;
221
 
                        }
222
 
                }
223
 
                
224
 
                anjuta_command_start (ANJUTA_COMMAND (add_command));
225
 
        }
226
 
        
227
 
        gtk_widget_destroy (GTK_WIDGET (dialog));
228
 
        bazaar_data_free (data);
229
 
}
230
 
 
231
 
 
232
 
static void
233
 
bazaar_add_dialog(GtkAction* action, BazaarPlugin* plugin, gchar* filename)
234
 
{
235
 
        GladeXML *gxml = NULL;
236
 
        GtkWidget *dialog_box = NULL;
237
 
        GtkWidget *tree_view = NULL;
238
 
        GtkWidget *clear_button = NULL;
239
 
        GtkWidget *select_all_button = NULL;
240
 
        GtkWidget *show_ignored_toggle = NULL;
241
 
        BazaarPluginData *data = NULL;
242
 
        BazaarListUnknownCommand* unknown_cmd = NULL;
243
 
        
244
 
        gxml = glade_xml_new (GLADE_FILE, "bazaar-add-dialog", NULL);
245
 
        dialog_box = glade_xml_get_widget (gxml, "bazaar-add-dialog");
246
 
        tree_view = glade_xml_get_widget (gxml, "bazaar-add-tree-view");
247
 
        clear_button = glade_xml_get_widget (gxml, "bazaar-add-clear-button");
248
 
        select_all_button = glade_xml_get_widget (gxml, "bazaar-add-select-all-button");
249
 
        show_ignored_toggle = glade_xml_get_widget (gxml, "bazaar-add-show-ignored-toggle");
250
 
        data = bazaar_data_new (plugin, gxml);
251
 
        unknown_cmd = bazaar_list_unknown_command_new (plugin->project_root_dir);
252
 
        
253
 
        g_signal_connect (G_OBJECT (unknown_cmd), "data-arrived",
254
 
                                          G_CALLBACK (unknown_received), data); 
255
 
                                          
256
 
        anjuta_command_start (ANJUTA_COMMAND (unknown_cmd));
257
 
        
258
 
        add_setup_treeview (gxml);
259
 
        
260
 
        g_signal_connect (G_OBJECT(dialog_box), "response", 
261
 
                                          G_CALLBACK (bazaar_add_signal_response), data);
262
 
                                          
263
 
        g_signal_connect (G_OBJECT(show_ignored_toggle), "toggled",
264
 
                                          G_CALLBACK (bazaar_show_ignored_toggled), data);
265
 
                                          
266
 
        bazaar_tie_button_to_check_all (GTK_BUTTON (select_all_button), GTK_TREE_VIEW (tree_view));
267
 
        bazaar_tie_button_to_uncheck_all (GTK_BUTTON (clear_button), GTK_TREE_VIEW (tree_view));
268
 
        
269
 
        gtk_widget_show (dialog_box);
270
 
}
271
 
 
272
 
void 
273
 
bazaar_on_menu_add (GtkAction* action, BazaarPlugin* plugin)
274
 
{
275
 
        bazaar_add_dialog (action, plugin, plugin->current_filename);
276
 
}
277
 
 
278
 
void add_setup_treeview (GladeXML *gxml)
279
 
{
280
 
        GtkWidget *main_treeview = NULL;
281
 
        GtkListStore *tree_store = NULL;
282
 
        GtkCellRenderer *renderer = NULL;
283
 
        
284
 
        main_treeview = glade_xml_get_widget (gxml, "bazaar-add-tree-view");
285
 
 
286
 
        tree_store = bazaar_treeview_get_new_store ();
287
 
        
288
 
        gtk_tree_view_set_model (GTK_TREE_VIEW (main_treeview), GTK_TREE_MODEL (tree_store));   
289
 
 
290
 
        bazaar_treeview_add_check_column (GTK_TREE_VIEW (main_treeview));
291
 
        bazaar_treeview_add_filename_column (GTK_TREE_VIEW (main_treeview));
292
 
        bazaar_treeview_add_status_column (GTK_TREE_VIEW (main_treeview));
293
 
}
294
 
 
295
 
void add_unknown_file_entry (GladeXML *gxml, const gchar *filename)
296
 
{
297
 
        GtkWidget *main_treeview = NULL;
298
 
        GtkTreeIter *iter = NULL;
299
 
        
300
 
        main_treeview = glade_xml_get_widget (gxml, "bazaar-add-tree-view");
301
 
        
302
 
        iter = bazaar_treeview_get_new_item (GTK_TREE_VIEW (main_treeview));
303
 
        
304
 
        bazaar_treeview_set_check (GTK_TREE_VIEW (main_treeview), iter, FALSE);
305
 
        bazaar_treeview_set_file (GTK_TREE_VIEW (main_treeview), iter, filename);
306
 
        bazaar_treeview_set_status_unknown (GTK_TREE_VIEW (main_treeview), iter);
307
 
}
308
 
 
309
 
void add_unknown_dir_entry (GladeXML *gxml, const gchar *filename)
310
 
{
311
 
        GtkWidget *main_treeview = NULL;
312
 
        GtkTreeIter *iter = NULL;
313
 
        
314
 
        main_treeview = glade_xml_get_widget (gxml, "bazaar-add-tree-view");
315
 
        
316
 
        iter = bazaar_treeview_get_new_item (GTK_TREE_VIEW (main_treeview));
317
 
        
318
 
        bazaar_treeview_set_check (GTK_TREE_VIEW (main_treeview), iter, FALSE);
319
 
        bazaar_treeview_set_dir (GTK_TREE_VIEW (main_treeview), iter, filename);
320
 
        bazaar_treeview_set_status_unknown (GTK_TREE_VIEW (main_treeview), iter);
321
 
}
322
 
 
323
 
void add_ignored_file_entry (GladeXML *gxml, const gchar *filename)
324
 
{
325
 
        GtkWidget *main_treeview = NULL;
326
 
        GtkTreeIter *iter = NULL;
327
 
        
328
 
        main_treeview = glade_xml_get_widget (gxml, "bazaar-add-tree-view");
329
 
        
330
 
        iter = bazaar_treeview_get_new_item (GTK_TREE_VIEW (main_treeview));
331
 
        
332
 
        bazaar_treeview_set_check (GTK_TREE_VIEW (main_treeview), iter, FALSE);
333
 
        bazaar_treeview_set_file (GTK_TREE_VIEW (main_treeview), iter, filename);
334
 
        bazaar_treeview_set_status_ignored (GTK_TREE_VIEW (main_treeview), iter);
335
 
}
336
 
 
337
 
void add_ignored_dir_entry (GladeXML *gxml, const gchar *filename)
338
 
{
339
 
        GtkWidget *main_treeview = NULL;
340
 
        GtkTreeIter *iter = NULL;
341
 
        
342
 
        main_treeview = glade_xml_get_widget (gxml, "bazaar-add-tree-view");
343
 
        
344
 
        iter = bazaar_treeview_get_new_item (GTK_TREE_VIEW (main_treeview));
345
 
        
346
 
        bazaar_treeview_set_check (GTK_TREE_VIEW (main_treeview), iter, FALSE);
347
 
        bazaar_treeview_set_dir (GTK_TREE_VIEW (main_treeview), iter, filename);
348
 
        bazaar_treeview_set_status_ignored (GTK_TREE_VIEW (main_treeview), iter);
349
 
}