Updated Spanish translation
[anjuta-git-plugin.git] / plugins / class-inheritance / plugin.c
blobd2d3a310a32464616c597fea2b7a03076e21a064
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 * 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, 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 "anjuta-class-inheritance-plugin-48.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 static void
86 register_stock_icons (AnjutaPlugin *plugin)
88 static gboolean registered = FALSE;
90 if (registered)
91 return;
92 registered = TRUE;
94 BEGIN_REGISTER_ICON (plugin);
95 REGISTER_ICON (PACKAGE_PIXMAPS_DIR"/"ICON_FILE,
96 "class-inheritance-plugin-icon");
97 END_REGISTER_ICON;
100 static gboolean
101 activate_plugin (AnjutaPlugin *plugin)
103 AnjutaClassInheritance *class_inheritance;
104 static gboolean initialized = FALSE;
106 DEBUG_PRINT ("AnjutaClassInheritance: Activating plugin ...");
108 register_stock_icons (plugin);
110 class_inheritance = ANJUTA_PLUGIN_CLASS_INHERITANCE (plugin);
112 class_inheritance_base_gui_init (class_inheritance);
114 anjuta_shell_add_widget (plugin->shell, class_inheritance->widget,
115 "AnjutaClassInheritance", _("Inheritance Graph"),
116 "class-inheritance-plugin-icon",
117 ANJUTA_SHELL_PLACEMENT_CENTER, NULL);
118 class_inheritance->top_dir = NULL;
120 /* set up project directory watch */
121 class_inheritance->root_watch_id = anjuta_plugin_add_watch (plugin,
122 "project_root_uri",
123 project_root_added,
124 project_root_removed, NULL);
126 initialized = TRUE;
127 return TRUE;
130 static gboolean
131 deactivate_plugin (AnjutaPlugin *plugin)
133 DEBUG_PRINT ("AnjutaClassInheritance: Dectivating plugin ...");
134 AnjutaClassInheritance* class_inheritance;
135 class_inheritance = ANJUTA_PLUGIN_CLASS_INHERITANCE (plugin);
137 /* clean up the canvas [e.g. destroys it's elements */
138 class_inheritance_clean_canvas (class_inheritance);
140 /* destroy the nodestatus hash table */
141 if (class_inheritance->expansion_node_list) {
142 g_hash_table_destroy (class_inheritance->expansion_node_list);
143 class_inheritance->expansion_node_list = NULL;
146 /* Container holds the last ref to this widget so it will be destroyed as
147 * soon as removed. No need to separately destroy it. */
148 /* In most cases, only toplevel widgets (windows) require explicit
149 * destruction, because when you destroy a toplevel its children will
150 * be destroyed as well. */
151 anjuta_shell_remove_widget (plugin->shell,
152 class_inheritance->widget,
153 NULL);
155 /* Remove watches */
156 anjuta_plugin_remove_watch (plugin,
157 class_inheritance->root_watch_id,
158 TRUE);
159 return TRUE;
162 static void
163 class_inheritance_finalize (GObject *obj)
165 AnjutaClassInheritance *ci_plugin;
166 ci_plugin = ANJUTA_PLUGIN_CLASS_INHERITANCE (obj);
168 if (ci_plugin->top_dir)
169 g_free (ci_plugin->top_dir);
171 /* Finalization codes here */
172 GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (obj));
175 static void
176 class_inheritance_dispose (GObject *obj)
178 /* Disposition codes */
179 GNOME_CALL_PARENT (G_OBJECT_CLASS, dispose, (obj));
182 static void
183 class_inheritance_instance_init (GObject *obj)
185 AnjutaClassInheritance *plugin = ANJUTA_PLUGIN_CLASS_INHERITANCE (obj);
187 plugin->uiid = 0;
189 plugin->widget = NULL;
190 plugin->graph = NULL;
191 plugin->gvc = NULL;
192 plugin->expansion_node_list = NULL;
195 static void
196 class_inheritance_class_init (GObjectClass *klass)
198 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
200 parent_class = g_type_class_peek_parent (klass);
202 plugin_class->activate = activate_plugin;
203 plugin_class->deactivate = deactivate_plugin;
204 klass->finalize = class_inheritance_finalize;
205 klass->dispose = class_inheritance_dispose;
208 ANJUTA_PLUGIN_BOILERPLATE (AnjutaClassInheritance, class_inheritance);
209 ANJUTA_SIMPLE_PLUGIN (AnjutaClassInheritance, class_inheritance);