Updated Spanish translation
[anjuta-git-plugin.git] / plugins / class-inheritance / plugin.c
blob01d1cc385ba185f3db7820f517de8dab01233854
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * plugin.c
4 * Copyright (C) Massimo Cora' 2005 <maxcvs@email.it>
5 *
6 * plugin.c 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, or (at your option) any later version.
12 * plugin.c is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with plugin.c. See the file "COPYING". If not,
19 * write to: The Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include <config.h>
25 #include <libanjuta/anjuta-shell.h>
26 #include <libgnomevfs/gnome-vfs-utils.h>
27 #include <libgnome/gnome-i18n.h>
28 #include <libanjuta/interfaces/ianjuta-document-manager.h>
29 #include <libanjuta/interfaces/ianjuta-project-manager.h>
30 #include <libanjuta/anjuta-debug.h>
32 #include "plugin.h"
33 #include "class-inherit.h"
35 #define ICON_FILE "class-inheritance.png"
37 static gpointer parent_class;
39 static void
40 project_root_added (AnjutaPlugin *plugin, const gchar *name,
41 const GValue *value, gpointer user_data)
43 AnjutaClassInheritance *ci_plugin;
44 const gchar *root_uri;
46 ci_plugin = ANJUTA_PLUGIN_CLASS_INHERITANCE (plugin);
47 root_uri = g_value_get_string (value);
49 if (root_uri)
51 gchar *root_dir = gnome_vfs_get_local_path_from_uri (root_uri);
52 if (root_dir)
54 ci_plugin->top_dir = g_strdup(root_dir);
56 else
57 ci_plugin->top_dir = NULL;
58 g_free (root_dir);
60 else
61 ci_plugin->top_dir = NULL;
63 /* let's update the graph */
64 class_inheritance_update_graph (ci_plugin);
67 static void
68 project_root_removed (AnjutaPlugin *plugin, const gchar *name,
69 gpointer user_data)
71 AnjutaClassInheritance *ci_plugin;
72 ci_plugin = ANJUTA_PLUGIN_CLASS_INHERITANCE (plugin);
74 /* clean up the canvas */
75 class_inheritance_clean_canvas (ci_plugin);
77 /* destroy and re-initialize the hashtable */
78 class_inheritance_hash_table_clear (ci_plugin);
80 if (ci_plugin->top_dir)
81 g_free(ci_plugin->top_dir);
82 ci_plugin->top_dir = NULL;
85 #define REGISTER_ICON(icon, stock_id) \
86 pixbuf = gdk_pixbuf_new_from_file (icon, NULL); \
87 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf); \
88 gtk_icon_factory_add (icon_factory, stock_id, icon_set); \
89 g_object_unref (pixbuf);
91 static void
92 register_stock_icons (AnjutaPlugin *plugin)
94 AnjutaUI *ui;
95 GtkIconFactory *icon_factory;
96 GtkIconSet *icon_set;
97 GdkPixbuf *pixbuf;
98 static gboolean registered = FALSE;
100 if (registered)
101 return;
102 registered = TRUE;
104 /* Register stock icons */
105 ui = anjuta_shell_get_ui (plugin->shell, NULL);
106 icon_factory = anjuta_ui_get_icon_factory (ui);
107 REGISTER_ICON (PACKAGE_PIXMAPS_DIR"/"ICON_FILE,
108 "class-inheritance-plugin-icon");
111 static gboolean
112 activate_plugin (AnjutaPlugin *plugin)
114 AnjutaClassInheritance *class_inheritance;
115 static gboolean initialized = FALSE;
117 DEBUG_PRINT ("AnjutaClassInheritance: Activating plugin ...");
119 register_stock_icons (plugin);
121 class_inheritance = ANJUTA_PLUGIN_CLASS_INHERITANCE (plugin);
123 class_inheritance_base_gui_init (class_inheritance);
125 anjuta_shell_add_widget (plugin->shell, class_inheritance->widget,
126 "AnjutaClassInheritance", _("Inheritance Graph"),
127 "class-inheritance-plugin-icon",
128 ANJUTA_SHELL_PLACEMENT_CENTER, NULL);
129 class_inheritance->top_dir = NULL;
131 /* set up project directory watch */
132 class_inheritance->root_watch_id = anjuta_plugin_add_watch (plugin,
133 "project_root_uri",
134 project_root_added,
135 project_root_removed, NULL);
137 initialized = TRUE;
138 return TRUE;
141 static gboolean
142 deactivate_plugin (AnjutaPlugin *plugin)
144 DEBUG_PRINT ("AnjutaClassInheritance: Dectivating plugin ...");
145 AnjutaClassInheritance* class_inheritance;
146 class_inheritance = ANJUTA_PLUGIN_CLASS_INHERITANCE (plugin);
148 /* clean up the canvas [e.g. destroys it's elements */
149 class_inheritance_clean_canvas (class_inheritance);
151 /* destroy the nodestatus hash table */
152 if (class_inheritance->expansion_node_list) {
153 g_hash_table_destroy (class_inheritance->expansion_node_list);
154 class_inheritance->expansion_node_list = NULL;
157 /* Container holds the last ref to this widget so it will be destroyed as
158 * soon as removed. No need to separately destroy it. */
159 /* In most cases, only toplevel widgets (windows) require explicit
160 * destruction, because when you destroy a toplevel its children will
161 * be destroyed as well. */
162 anjuta_shell_remove_widget (plugin->shell,
163 class_inheritance->widget,
164 NULL);
166 /* Remove watches */
167 anjuta_plugin_remove_watch (plugin,
168 class_inheritance->root_watch_id,
169 TRUE);
170 return TRUE;
173 static void
174 class_inheritance_finalize (GObject *obj)
176 AnjutaClassInheritance *ci_plugin;
177 ci_plugin = ANJUTA_PLUGIN_CLASS_INHERITANCE (obj);
179 if (ci_plugin->top_dir)
180 g_free (ci_plugin->top_dir);
182 /* Finalization codes here */
183 GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (obj));
186 static void
187 class_inheritance_dispose (GObject *obj)
189 /* Disposition codes */
190 GNOME_CALL_PARENT (G_OBJECT_CLASS, dispose, (obj));
193 static void
194 class_inheritance_instance_init (GObject *obj)
196 AnjutaClassInheritance *plugin = ANJUTA_PLUGIN_CLASS_INHERITANCE (obj);
198 plugin->uiid = 0;
200 plugin->widget = NULL;
201 plugin->graph = NULL;
202 plugin->gvc = NULL;
203 plugin->expansion_node_list = NULL;
206 static void
207 class_inheritance_class_init (GObjectClass *klass)
209 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
211 parent_class = g_type_class_peek_parent (klass);
213 plugin_class->activate = activate_plugin;
214 plugin_class->deactivate = deactivate_plugin;
215 klass->finalize = class_inheritance_finalize;
216 klass->dispose = class_inheritance_dispose;
219 ANJUTA_PLUGIN_BOILERPLATE (AnjutaClassInheritance, class_inheritance);
220 ANJUTA_SIMPLE_PLUGIN (AnjutaClassInheritance, class_inheritance);