Check that a given filename is valid before setting it on a GtkFileChooserButton
[anjuta-git-plugin.git] / plugins / symbol-browser / an_symbol_prefs.c
blobe628fa997287f99142bc77694d68739afcd6cf9a
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 an_symbol_prefs.c
4 Copyright (C) 2004 Naba Kumar
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
22 #include <sys/types.h>
23 #include <sys/wait.h>
24 #include <dirent.h>
25 #include <string.h>
26 #include <gtk/gtktreeview.h>
27 #include <gtk/gtkliststore.h>
28 #include <libgnomevfs/gnome-vfs.h>
29 #include <libanjuta/anjuta-debug.h>
30 #include <libanjuta/anjuta-launcher.h>
31 #include <libanjuta/anjuta-utils.h>
33 #include "an_symbol_prefs.h"
34 #include "tm_tagmanager.h"
36 #define GLADE_FILE PACKAGE_DATA_DIR"/glade/anjuta-symbol-browser-plugin.glade"
37 #define ICON_FILE "anjuta-symbol-browser-plugin-48.png"
38 #define LOCAL_TAGS_SUBDIR "tags/"
39 #define SYSTEM_TAGS_CACHE "system-tags.cache"
40 #define SYMBOL_BROWSER_TAGS "symbol.browser.tags"
41 #define CREATE_GLOBAL_TAGS PACKAGE_DATA_DIR"/scripts/create_global_tags.sh"
43 enum
45 COLUMN_LOAD,
46 COLUMN_NAME,
47 COLUMN_PATH,
48 N_COLUMNS
51 static void
52 update_system_tags (GList *tags_files)
54 gchar *output_file;
56 output_file = anjuta_util_get_user_cache_file_path (SYSTEM_TAGS_CACHE, NULL);
58 DEBUG_PRINT ("Recreating system tags cache: %s", output_file);
60 if (!tm_workspace_merge_global_tags (output_file, tags_files))
62 g_warning ("Error while re-creating system tags cache");
65 /* Reload tags */
66 tm_workspace_reload_global_tags(output_file);
68 g_free (output_file);
71 static void
72 update_system_tags_only_add (const gchar *tag_file)
74 GList *tags_files;
75 gchar *output_file;
77 output_file = anjuta_util_get_user_cache_file_path (SYSTEM_TAGS_CACHE, NULL);
79 DEBUG_PRINT ("Recreating system tags cache: %s", output_file);
81 tags_files = g_list_append (NULL, output_file);
82 tags_files = g_list_append (tags_files, (gpointer) tag_file);
83 if (!tm_workspace_merge_global_tags (output_file, tags_files))
85 g_warning ("Error while re-creating system tags cache");
87 /* Reload tags */
88 tm_workspace_reload_global_tags(output_file);
90 g_free (output_file);
93 static gboolean
94 str_has_suffix (const char *haystack, const char *needle)
96 const char *h, *n;
98 if (needle == NULL) {
99 return TRUE;
101 if (haystack == NULL) {
102 return needle[0] == '\0';
105 /* Eat one character at a time. */
106 h = haystack + strlen(haystack);
107 n = needle + strlen(needle);
108 do {
109 if (n == needle) {
110 return TRUE;
112 if (h == haystack) {
113 return FALSE;
115 } while (*--h == *--n);
116 return FALSE;
119 static void
120 select_loaded_tags (GtkListStore * store, AnjutaPreferences *prefs)
122 GtkTreeIter iter;
123 gchar *all_tags_path;
124 gchar **tags_paths, **tags_path;
125 GHashTable *path_hash;
127 all_tags_path = anjuta_preferences_get (prefs, SYMBOL_BROWSER_TAGS);
128 if (all_tags_path == NULL)
129 return;
131 tags_paths = g_strsplit (all_tags_path, ":", -1);
132 path_hash = g_hash_table_new (g_str_hash, g_str_equal);
133 tags_path = tags_paths;
134 while (*tags_path)
136 g_hash_table_insert (path_hash, *tags_path, *tags_path);
137 tags_path++;
140 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
144 gchar *tag_path;
146 gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
147 COLUMN_PATH, &tag_path,
148 -1);
149 if (g_hash_table_lookup (path_hash, tag_path))
150 gtk_list_store_set (store, &iter, COLUMN_LOAD, TRUE, -1);
151 else
152 gtk_list_store_set (store, &iter, COLUMN_LOAD, FALSE, -1);
153 g_free (tag_path);
155 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter));
157 g_hash_table_destroy (path_hash);
158 g_strfreev (tags_paths);
159 g_free (all_tags_path);
162 static GtkListStore *
163 create_store (AnjutaPreferences *prefs)
165 GList *node;
166 gchar *local_tags_dir;
167 GList *tags_dirs = NULL;
168 GtkListStore *store;
170 /* Create store */
171 store = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING,
172 G_TYPE_STRING);
174 local_tags_dir = anjuta_util_get_user_cache_file_path (LOCAL_TAGS_SUBDIR, NULL);
175 tags_dirs = g_list_prepend (tags_dirs, local_tags_dir);
177 /* Load the tags files */
178 node = tags_dirs;
179 while (node)
181 DIR *dir;
182 struct dirent *entry;
183 const gchar *dirname;
185 dirname = (const gchar*)node->data;
186 node = g_list_next (node);
188 dir = opendir (dirname);
189 if (!dir)
190 continue;
192 for (entry = readdir (dir); entry != NULL; entry = readdir (dir))
194 if (str_has_suffix (entry->d_name, ".anjutatags.gz"))
196 gchar *pathname;
197 gchar *tag_name;
198 GtkTreeIter iter;
200 tag_name = g_strndup (entry->d_name,
201 strlen (entry->d_name) -
202 strlen (".anjutatags.gz"));
203 pathname = g_build_filename (dirname, entry->d_name, NULL);
205 gtk_list_store_append (store, &iter);
206 gtk_list_store_set (store, &iter, COLUMN_LOAD, FALSE,
207 COLUMN_NAME, tag_name,
208 COLUMN_PATH, pathname, -1);
209 g_free (tag_name);
210 g_free (pathname);
213 closedir (dir);
215 g_list_foreach (tags_dirs, (GFunc)g_free, NULL);
216 g_list_free (tags_dirs);
218 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
219 COLUMN_NAME, GTK_SORT_ASCENDING);
220 select_loaded_tags (store, prefs);
221 return store;
224 static void
225 on_tag_load_toggled (GtkCellRendererToggle *cell, char *path_str,
226 SymbolBrowserPlugin *plugin)
228 GtkTreeIter iter;
229 GtkTreePath *path;
230 gboolean enabled;
231 AnjutaPreferences *prefs;
232 gchar *tag_path;
233 GList *enabled_paths;
234 GtkListStore *store;
235 AnjutaStatus *status;
237 status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell, NULL);
238 store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (plugin->pref_tree_view)));
239 prefs = plugin->prefs;
241 anjuta_status_busy_push (status);
243 path = gtk_tree_path_new_from_string (path_str);
244 gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
245 gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
246 COLUMN_LOAD, &enabled,
247 -1);
248 enabled = !enabled;
249 gtk_list_store_set (store, &iter, COLUMN_LOAD, enabled, -1);
250 gtk_tree_path_free (path);
252 enabled_paths = NULL;
253 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
257 gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
258 COLUMN_LOAD, &enabled,
259 COLUMN_PATH, &tag_path,
260 -1);
261 if (enabled)
262 enabled_paths = g_list_prepend (enabled_paths, tag_path);
265 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter));
268 if (enabled_paths)
270 GList *node;
271 GString *str;
272 gboolean first;
273 gchar *final_str;
275 enabled_paths = g_list_sort (enabled_paths, (GCompareFunc)strcmp);
276 node = enabled_paths;
277 str = g_string_new ("");
278 first = TRUE;
279 while (node)
281 if (first)
283 first = FALSE;
284 str = g_string_append (str, (const gchar*) node->data);
286 else
288 str = g_string_append (str, ":");
289 str = g_string_append (str, (const gchar*) node->data);
291 node = g_list_next (node);
294 /* Update preferences */
295 final_str = g_string_free (str, FALSE);
296 anjuta_preferences_set (prefs, SYMBOL_BROWSER_TAGS, final_str);
298 /* Update system tags cache */
299 if (enabled)
301 update_system_tags_only_add (tag_path);
303 else
305 update_system_tags (enabled_paths);
306 g_free (final_str);
309 else
311 /* Unset key and clear all tags */
312 anjuta_preferences_set (prefs, SYMBOL_BROWSER_TAGS, "");
314 g_list_foreach (enabled_paths, (GFunc)g_free, NULL);
315 g_list_free (enabled_paths);
316 anjuta_status_busy_pop (status);
319 static void
320 on_add_directory_clicked (GtkWidget *button, GtkListStore *store)
322 GtkTreeIter iter;
323 GtkWidget *fileselection;
324 GtkWidget *parent;
326 parent = gtk_widget_get_toplevel (button);
327 fileselection = gtk_file_chooser_dialog_new (_("Select directory"),
328 GTK_WINDOW (parent),
329 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
330 GTK_STOCK_CANCEL,
331 GTK_RESPONSE_CANCEL,
332 GTK_STOCK_OK,
333 GTK_RESPONSE_OK,
334 NULL);
335 if (gtk_dialog_run (GTK_DIALOG (fileselection)) == GTK_RESPONSE_OK)
337 GSList *dirs, *node;
339 /* Only local files since we can only create tags for local files */
340 dirs = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (fileselection));
342 node = dirs;
343 while (node)
345 gchar *dir = node->data;
346 gtk_list_store_append (store, &iter);
347 gtk_list_store_set (store, &iter, 0, dir, -1);
348 g_free (dir);
349 node = g_slist_next (node);
351 g_slist_free (dirs);
353 gtk_widget_destroy (fileselection);
356 static void
357 refresh_tags_list (SymbolBrowserPlugin *plugin)
359 GtkListStore *new_tags_store;
360 if (plugin->pref_tree_view)
362 new_tags_store = create_store (plugin->prefs);
363 gtk_tree_view_set_model (GTK_TREE_VIEW (plugin->pref_tree_view),
364 GTK_TREE_MODEL (new_tags_store));
365 g_object_unref (new_tags_store);
369 static void
370 on_create_tags_clicked (GtkButton *widget, SymbolBrowserPlugin *plugin)
372 GtkWidget *treeview, *button, *dlg, *name_entry;
373 GtkCellRenderer *renderer;
374 GtkTreeViewColumn *column;
375 GtkListStore *store;
376 AnjutaPreferences *pref;
377 GladeXML *gxml;
379 pref = plugin->prefs;
380 gxml = glade_xml_new (GLADE_FILE, "create.symbol.tags.dialog", NULL);
382 dlg = glade_xml_get_widget (gxml, "create.symbol.tags.dialog");
383 treeview = glade_xml_get_widget (gxml, "directory_list_treeview");
384 name_entry = glade_xml_get_widget (gxml, "symbol_tags_name_entry");
386 store = gtk_list_store_new (1, G_TYPE_STRING);
387 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
388 GTK_TREE_MODEL (store));
390 /* Add the column for stock treeview */
391 renderer = gtk_cell_renderer_text_new ();
392 column = gtk_tree_view_column_new_with_attributes (_("Directories to scan"),
393 renderer, "text",
395 NULL);
396 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
397 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
398 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview),
399 COLUMN_NAME);
401 button = glade_xml_get_widget (gxml, "add_directory_button");
402 g_signal_connect (G_OBJECT (button), "clicked",
403 G_CALLBACK (on_add_directory_clicked), store);
405 button = glade_xml_get_widget (gxml, "clear_list_button");
406 g_signal_connect_swapped (G_OBJECT (button), "clicked",
407 G_CALLBACK (gtk_list_store_clear), store);
409 gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (plugin->prefs));
410 while (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_OK)
412 GtkTreeIter iter;
413 gchar **argv, *tmp;
414 const gchar *name;
415 gint argc;
416 pid_t pid;
418 name = gtk_entry_get_text (GTK_ENTRY (name_entry));
420 argc = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store),
421 NULL) * 3 + 3;
423 if (name == NULL || strlen (name) <= 0 || argc <= 3)
425 /* Validation failed */
426 GtkWidget *edlg;
428 edlg = gtk_message_dialog_new (GTK_WINDOW (dlg),
429 GTK_DIALOG_DESTROY_WITH_PARENT,
430 GTK_MESSAGE_ERROR,
431 GTK_BUTTONS_CLOSE,
432 _("Please enter a name and at least one directory."));
433 gtk_dialog_run (GTK_DIALOG (edlg));
434 gtk_widget_destroy (edlg);
435 continue;
438 argv = g_new0 (gchar*, argc);
440 argv[0] = g_strdup ("anjuta-tags");
443 gchar *tmp = NULL;
444 tmp = anjuta_util_get_user_cache_file_path ("tags", name, NULL);
445 argv[1] = g_strconcat (tmp, ".anjutatags", NULL);
446 g_free (tmp);
449 argc = 2;
450 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter))
454 gchar *dir;
455 gchar *files;
457 gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
458 0, &dir, -1);
460 files = g_build_filename (dir, "*.h", NULL);
461 DEBUG_PRINT ("%d: Adding scan files '%s'", argc, files);
462 argv[argc++] = g_strconcat ("\"", files, "\"", NULL);
463 g_free (files);
465 files = g_build_filename (dir, "*", "*.h", NULL);
466 DEBUG_PRINT ("%d: Adding scan files '%s'", argc, files);
467 argv[argc++] = g_strconcat ("\"", files, "\"", NULL);
468 g_free (files);
470 files = g_build_filename (dir, "*", "*", "*.h", NULL);
471 DEBUG_PRINT ("%d: Adding scan files '%s'", argc, files);
472 argv[argc++] = g_strconcat ("\"", files, "\"", NULL);
473 g_free (files);
475 g_free (dir);
477 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter));
480 /* Create local tags directory */
482 tmp = anjuta_util_get_user_cache_file_path (LOCAL_TAGS_SUBDIR, NULL);
484 g_free (tmp);
486 /* Execute anjuta-tags to create tags for the given files */
487 if ((pid = fork()) == 0)
489 execvp (g_build_filename (PACKAGE_LIB_DIR,
490 "anjuta-tags", NULL), argv);
491 perror ("Could not execute anjuta-tags");
493 waitpid (pid, NULL, 0);
495 /* Compress the tags file */
496 if ((pid = fork()) == 0)
498 execlp ("gzip", "gzip", "-f", argv[1], NULL);
499 perror ("Could not execute gzip");
501 waitpid (pid, NULL, 0);
503 g_strfreev (argv);
505 /* Refresh the tags list */
506 refresh_tags_list (plugin);
507 break;
509 g_object_unref (store);
510 g_object_unref (gxml);
511 gtk_widget_destroy (dlg);
514 static void
515 on_add_tags_clicked (GtkWidget *button, SymbolBrowserPlugin *plugin)
517 GtkWidget *fileselection;
518 GtkWidget *parent;
519 GtkFileFilter *filter;
521 parent = gtk_widget_get_toplevel (button);
523 fileselection = gtk_file_chooser_dialog_new (_("Select directory"),
524 GTK_WINDOW (parent),
525 GTK_FILE_CHOOSER_ACTION_OPEN,
526 GTK_STOCK_CANCEL,
527 GTK_RESPONSE_CANCEL,
528 GTK_STOCK_OK,
529 GTK_RESPONSE_OK,
530 NULL);
531 filter = gtk_file_filter_new ();
532 gtk_file_filter_set_name (filter, _("Anjuta tags files"));
533 gtk_file_filter_add_pattern (filter, "*.anjutatags.gz");
534 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fileselection), filter);
536 if (gtk_dialog_run (GTK_DIALOG (fileselection)) == GTK_RESPONSE_OK)
538 GSList *uris, *node;
539 gchar *tmp;
540 pid_t pid;
542 uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (fileselection));
544 node = uris;
545 while (node)
547 gchar *dest, *src;
549 src = node->data;
551 gchar *basename;
552 basename = g_path_get_basename (src);
553 dest = anjuta_util_get_user_cache_file_path ("tags", basename, NULL);
554 g_free (basename);
557 /* Copy the tags file in local tags directory */
558 GnomeVFSURI* source_uri = gnome_vfs_uri_new(src);
559 GnomeVFSURI* dest_uri = gnome_vfs_uri_new(dest);
561 GnomeVFSResult error = gnome_vfs_xfer_uri (source_uri,
562 dest_uri,
563 GNOME_VFS_XFER_DEFAULT,
564 GNOME_VFS_XFER_ERROR_MODE_ABORT,
565 GNOME_VFS_XFER_OVERWRITE_MODE_ABORT,
566 NULL,
567 NULL);
568 if (error != GNOME_VFS_OK)
570 const gchar *err;
572 err = gnome_vfs_result_to_string (error);
573 anjuta_util_dialog_error (GTK_WINDOW (fileselection),
574 "Adding tags file '%s' failed: %s",
575 src, err);
577 gnome_vfs_uri_unref (source_uri);
578 gnome_vfs_uri_unref (dest_uri);
579 g_free (dest);
580 g_free (src);
581 node = g_slist_next (node);
583 if (uris)
585 refresh_tags_list (plugin);
587 g_slist_free (uris);
589 gtk_widget_destroy (fileselection);
592 static void
593 on_remove_tags_clicked (GtkWidget *button, SymbolBrowserPlugin *plugin)
595 GtkWidget *parent;
596 GtkTreeSelection *sel;
597 GtkTreeIter iter;
598 GtkTreeModel *model;
600 parent = gtk_widget_get_toplevel (button);
601 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (plugin->pref_tree_view));
602 if (gtk_tree_selection_get_selected (sel, &model, &iter))
604 gchar *tags_filename;
605 gtk_tree_model_get (model, &iter, 1, &tags_filename, -1);
606 if (tags_filename)
608 gchar *file_path, *path;
609 path = anjuta_util_get_user_cache_file_path ("tags", tags_filename, NULL);
610 file_path = g_strconcat (path, ".anjutatags.gz", NULL);
612 if (!g_file_test (file_path, G_FILE_TEST_EXISTS))
614 anjuta_util_dialog_error (GTK_WINDOW (parent),
615 "Can not remove tags file '%s': "
616 "You can only remove tags you created or added",
617 tags_filename);
619 else if (anjuta_util_dialog_boolean_question (GTK_WINDOW (parent),
620 "Are you sure you want to remove the tags file '%s'?",
621 tags_filename))
623 unlink (file_path);
624 refresh_tags_list (plugin);
626 g_free (file_path);
627 g_free (path);
628 g_free (tags_filename);
633 static void
634 on_message (AnjutaLauncher *launcher,
635 AnjutaLauncherOutputType output_type,
636 const gchar * mesg, gpointer user_data)
638 AnjutaStatus *status;
639 gchar **lines, **line;
640 SymbolBrowserPlugin* plugin = ANJUTA_PLUGIN_SYMBOL_BROWSER (user_data);
642 lines = g_strsplit (mesg, "\n", -1);
643 if (!lines)
644 return;
646 status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell, NULL);
648 line = lines;
649 while (*line)
651 gint packages_count;
652 gchar *pos;
654 if (sscanf (*line, "Scanning %d packages", &packages_count) == 1)
655 anjuta_status_progress_add_ticks (status, packages_count + 1);
656 else if ((pos = strstr (*line, ".anjutatags.gz")))
658 const gchar *package_name;
660 /* Get the name of the package */
661 *pos = '\0';
662 package_name = g_strrstr (*line, "/");
663 if (package_name)
665 gchar *status_mesg;
666 package_name++;
667 status_mesg = g_strdup_printf (_("Scanning package: %s"),
668 package_name);
669 anjuta_status_progress_tick (status, NULL, status_mesg);
670 g_free (status_mesg);
672 else
673 anjuta_status_progress_tick (status, NULL, *line);
675 line++;
677 g_strfreev (lines);
680 static void
681 on_system_tags_update_finished (AnjutaLauncher *launcher, gint child_pid,
682 gint status, gulong time_taken,
683 SymbolBrowserPlugin *plugin)
685 AnjutaStatus *statusbar;
686 GList *enabled_paths = NULL;
687 gchar *all_tags_path;
688 gchar **tags_paths, **tags_path;
690 all_tags_path = anjuta_preferences_get (plugin->prefs,
691 SYMBOL_BROWSER_TAGS);
692 if (all_tags_path)
694 tags_paths = g_strsplit (all_tags_path, ":", -1);
695 tags_path = tags_paths;
696 while (*tags_path)
698 enabled_paths = g_list_prepend (enabled_paths,
699 g_strdup (*tags_path));
700 tags_path++;
702 g_free (all_tags_path);
703 g_strfreev (tags_paths);
704 enabled_paths = g_list_reverse (enabled_paths);
707 /* Refresh the list */
708 refresh_tags_list(plugin);
710 /* Regenerate system-tags.cache */
711 if (enabled_paths)
713 update_system_tags (enabled_paths);
714 g_list_foreach (enabled_paths, (GFunc)g_free, NULL);
715 g_list_free (enabled_paths);
718 g_object_unref (plugin->launcher);
719 plugin->launcher = NULL;
720 statusbar = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell, NULL);
721 anjuta_status_progress_tick (statusbar, NULL,
722 _("Completed system tags generation"));
725 static void
726 on_update_global_clicked (GtkWidget *button, SymbolBrowserPlugin *plugin)
728 gchar* tmp;
729 gint pid;
731 if (plugin->launcher)
732 return; /* Already running */
734 /* Create local tags directory */
735 tmp = anjuta_util_get_user_cache_file_path (LOCAL_TAGS_SUBDIR,NULL);
736 g_free (tmp);
738 plugin->launcher = anjuta_launcher_new ();
739 g_signal_connect (G_OBJECT (plugin->launcher), "child-exited",
740 G_CALLBACK (on_system_tags_update_finished), plugin);
741 anjuta_launcher_set_buffered_output (plugin->launcher, TRUE);
742 anjuta_launcher_execute (plugin->launcher, CREATE_GLOBAL_TAGS,
743 on_message, plugin);
746 static GtkWidget *
747 prefs_page_init (SymbolBrowserPlugin *plugin)
749 GtkWidget *treeview, *button;
750 GtkCellRenderer *renderer;
751 GtkTreeViewColumn *column;
752 GtkListStore *store;
753 AnjutaPreferences *pref = plugin->prefs;
754 GladeXML *gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
756 anjuta_preferences_add_page (pref, gxml, "Symbol Browser",
757 _("Symbol Browser"), ICON_FILE);
758 treeview = glade_xml_get_widget (gxml, "tags_treeview");
760 store = create_store (pref);
761 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
762 GTK_TREE_MODEL (store));
764 /* Add the column for stock treeview */
765 renderer = gtk_cell_renderer_toggle_new ();
766 g_signal_connect (G_OBJECT (renderer), "toggled",
767 G_CALLBACK (on_tag_load_toggled), plugin);
768 column = gtk_tree_view_column_new_with_attributes (_("Load"),
769 renderer,
770 "active",
771 COLUMN_LOAD,
772 NULL);
773 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
775 renderer = gtk_cell_renderer_text_new ();
776 column = gtk_tree_view_column_new_with_attributes (_("API Tags"),
777 renderer, "text",
778 COLUMN_NAME,
779 NULL);
780 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
781 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
782 gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview),
783 COLUMN_NAME);
785 button = glade_xml_get_widget (gxml, "create_tags_button");
786 g_signal_connect (G_OBJECT (button), "clicked",
787 G_CALLBACK (on_create_tags_clicked), plugin);
789 button = glade_xml_get_widget (gxml, "add_tags_button");
790 g_signal_connect (G_OBJECT (button), "clicked",
791 G_CALLBACK (on_add_tags_clicked), plugin);
793 button = glade_xml_get_widget (gxml, "remove_tags_button");
794 g_signal_connect (G_OBJECT (button), "clicked",
795 G_CALLBACK (on_remove_tags_clicked), plugin);
797 button = glade_xml_get_widget (gxml, "update_tags_button");
798 g_signal_connect (G_OBJECT (button), "clicked",
799 G_CALLBACK (on_update_global_clicked), plugin);
802 g_object_unref (store);
803 g_object_unref (gxml);
804 return treeview;
807 static void
808 on_gconf_notify_tags_list_changed (GConfClient *gclient, guint cnxn_id,
809 GConfEntry *entry, gpointer user_data)
811 GtkListStore *store;
812 SymbolBrowserPlugin *plugin = ANJUTA_PLUGIN_SYMBOL_BROWSER (user_data);
814 if (plugin->pref_tree_view)
816 store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (plugin->pref_tree_view)));
817 select_loaded_tags (store, plugin->prefs);
821 void
822 symbol_browser_prefs_init (SymbolBrowserPlugin *plugin)
824 guint notify_id;
825 plugin->pref_tree_view = prefs_page_init (plugin);
826 g_object_add_weak_pointer (G_OBJECT (plugin->pref_tree_view),
827 (gpointer)&plugin->pref_tree_view);
828 plugin->gconf_notify_ids = NULL;
829 notify_id = anjuta_preferences_notify_add (plugin->prefs,
830 SYMBOL_BROWSER_TAGS,
831 on_gconf_notify_tags_list_changed,
832 plugin, NULL);
833 plugin->gconf_notify_ids = g_list_prepend (plugin->gconf_notify_ids,
834 GUINT_TO_POINTER (notify_id));
837 void
838 symbol_browser_prefs_finalize (SymbolBrowserPlugin *plugin)
840 GList *node;
841 node = plugin->gconf_notify_ids;
842 while (node)
844 anjuta_preferences_notify_remove (plugin->prefs,
845 GPOINTER_TO_UINT (node->data));
846 node = g_list_next (node);
848 g_list_free (plugin->gconf_notify_ids);
849 plugin->gconf_notify_ids = NULL;
851 anjuta_preferences_remove_page(plugin->prefs, _("Symbol Browser"));
854 static gboolean
855 symbol_browser_prefs_create_global_tags (gpointer user_data)
857 SymbolBrowserPlugin *plugin = ANJUTA_PLUGIN_SYMBOL_BROWSER (user_data);
858 on_update_global_clicked (NULL, plugin);
859 return FALSE; /* Stop g_idle */
862 void
863 symbol_browser_load_global_tags (gpointer plugin)
865 gchar *system_tags_path;
866 /* Load gloabal tags on gtk idle */
867 system_tags_path = anjuta_util_get_user_cache_file_path (SYSTEM_TAGS_CACHE,NULL);
868 if (!tm_workspace_load_global_tags (system_tags_path))
870 g_message ("Added idle loop to create global tags");
871 g_idle_add((GSourceFunc) symbol_browser_prefs_create_global_tags,
872 plugin);
874 g_free (system_tags_path);