Fix Spanish translation header
[anjuta.git] / plugins / tools / plugin.c
blob6ce8d9ade5930b1cc4cea94873dfdc4fc1eed3da
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 plugin.c
4 Copyright (C) 2000 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 /**
22 Anjuta user-defined tools requirements statement:
23 Convention:
24 (M) = Must have
25 (R) = Recommended
26 (N) = Nice to have
27 (U) = Unecessary
28 (D) = Done (Implemented)
29 (P) = Partly implemented
31 User-defined tools should provide the user with a powerful mechanism to
32 do various activities customized to his needs from with the Anjuta GUI
33 framework. The tool system should also be flexible enough so that developers
34 of Anjuta can use it to easily integrate external programs in Anjuta and
35 enhance functionality of the IDE through the use of tools.
37 The following is a list of requirements and their relative pririties.
38 Progress should be tracked by marking each of the items as and when they are
39 implemented. Feel free to add/remove/reprioritize these items but please
40 discuss in the devel list before making any major changes.
42 R1: Modify GUI at program startup
43 1) (D) Add new menu items associated with external commands.
44 2) (D) Add drop-down toolbar item for easy access to all tools.
45 4) (D) Should be able to associate icons.
46 5) (D) Should be able to associate shortcuts.
47 5) (U) Should be appendable under any of the top/sub level menus.
49 R2: Command line parameters
50 1) (D) Pass variable command-line parameters to the tool.
51 2) (D) Use existing properties system to pass parameters.
52 3) (D) Ask user at run-time for parameters.
53 4) (U) Generate a dialog for asking several parameters at run time
55 R3: Working directory
56 1) (D) Specify working directory for the tool.
57 2) (D) Ability to specify property variables for working dir.
59 R4: Standard input to the tool
60 1) (D) Specify current buffer as standard input.
61 2) (D) Specify property variables as standard input.
62 3) (D) Specify list of open files as standard input.
64 R5: Output and error redirection
65 1) (D) Output to a message pane windows.
66 2) (D) Run in terminal (detached mode).
67 3) (D) Output to current/new buffer.
68 4) (D) Show output in a popup window.
69 5) (U) Try to parser error and warning messages
71 R6: Tool manipulation GUI
72 1) (D) Add/remove tools with all options.
73 2) (D) Enable/disable tool loading.
75 R7: Tool Storage
76 1) (D) Gloabal and local tool storage.
77 2) (D) Override global tools with local settings.
78 3) (N) Project specific tools (load/unload with project)
82 * Plugins functions
84 *---------------------------------------------------------------------------*/
86 #include <config.h>
88 #include "plugin.h"
90 #include "dialog.h"
91 #include "fileop.h"
92 #include "tool.h"
93 #include "editor.h"
94 #include "variable.h"
95 #include "execute.h"
97 #include <libanjuta/anjuta-shell.h>
98 #include <libanjuta/anjuta-debug.h>
100 #include <libanjuta/interfaces/ianjuta-preferences.h>
102 /*---------------------------------------------------------------------------*/
104 #define ICON_FILE "anjuta-tools-plugin-48.png"
105 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-tools.xml"
107 /*---------------------------------------------------------------------------*/
109 struct _ATPPlugin {
110 AnjutaPlugin parent;
111 GtkActionGroup* action_group;
112 gint uiid;
113 ATPToolList list;
114 ATPToolDialog dialog;
115 ATPVariable variable;
116 ATPContextList context;
118 GSettings* settings;
121 struct _ATPPluginClass {
122 AnjutaPluginClass parent_class;
125 /*---------------------------------------------------------------------------*/
127 static GtkActionEntry actions_tools[] = {
129 "ActionMenuTools", /* Action name */
130 NULL, /* Stock icon, if any */
131 N_("_Tools"), /* Display label */
132 NULL, /* Short-cut */
133 NULL, /* Tooltip */
134 NULL /* Callback */
138 /*---------------------------------------------------------------------------*/
140 /* Used in dispose */
141 static gpointer parent_class;
143 #define PREF_SCHEMA "org.gnome.anjuta.tools"
145 static void
146 atp_plugin_instance_init (GObject *obj)
148 ATPPlugin *this = ANJUTA_PLUGIN_ATP (obj);
149 this->settings = g_settings_new (PREF_SCHEMA);
152 /* dispose is used to unref object created with instance_init */
154 static void
155 atp_plugin_dispose (GObject *obj)
157 /* Warning this function could be called several times */
158 ATPPlugin *this = ANJUTA_PLUGIN_ATP (obj);
159 if (this->settings)
160 g_object_unref (this->settings);
161 this->settings = NULL;
162 G_OBJECT_CLASS (parent_class)->dispose (obj);
165 static void
166 atp_plugin_finalize (GObject *obj)
168 /* Warning this function could be called several times */
170 G_OBJECT_CLASS (parent_class)->finalize (obj);
173 /* finalize used to free object created with instance init is not used */
175 static gboolean
176 atp_plugin_activate (AnjutaPlugin *plugin)
178 ATPPlugin *this = ANJUTA_PLUGIN_ATP (plugin);
179 AnjutaUI *ui;
181 DEBUG_PRINT ("%s", "Tools Plugin: Activating tools plugin...");
183 /* Add all our actions */
184 ui = anjuta_shell_get_ui (plugin->shell, NULL);
185 this->action_group = anjuta_ui_add_action_group_entries (ui,
186 "ActionGroupTools",
187 _("Tool operations"),
188 actions_tools,
189 G_N_ELEMENTS (actions_tools),
190 GETTEXT_PACKAGE, TRUE, plugin);
191 this->uiid = anjuta_ui_merge (ui, UI_FILE);
193 /* Add tool menu item */
194 atp_tool_list_construct (&this->list, this);
195 atp_anjuta_tools_load (this);
196 atp_tool_list_activate (&this->list);
198 /* initialization */
199 atp_tool_dialog_construct (&this->dialog, this);
200 atp_variable_construct (&this->variable, plugin->shell);
201 atp_context_list_construct (&this->context);
203 atp_tool_list_activate (atp_plugin_get_tool_list (this->dialog.plugin));
205 return TRUE;
208 static gboolean
209 atp_plugin_deactivate (AnjutaPlugin *plugin)
211 ATPPlugin *this = ANJUTA_PLUGIN_ATP (plugin);
212 AnjutaUI *ui;
214 DEBUG_PRINT ("%s", "Tools Plugin: Deactivating tools plugin...");
216 atp_tool_list_deactivate (&this->list);
217 atp_context_list_destroy (&this->context);
218 atp_variable_destroy (&this->variable);
219 atp_tool_dialog_destroy (&this->dialog);
220 atp_tool_list_destroy (&this->list);
222 ui = anjuta_shell_get_ui (plugin->shell, NULL);
223 anjuta_ui_unmerge (ui, this->uiid);
225 return TRUE;
228 static void
229 atp_plugin_class_init (GObjectClass *klass)
231 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
233 parent_class = g_type_class_peek_parent (klass);
235 plugin_class->activate = atp_plugin_activate;
236 plugin_class->deactivate = atp_plugin_deactivate;
237 klass->dispose = atp_plugin_dispose;
238 klass->finalize = atp_plugin_finalize;
241 static void
242 ipreferences_merge(IAnjutaPreferences* obj, AnjutaPreferences* prefs, GError** e)
244 /* Create the tools preferences page */
245 ATPPlugin* atp_plugin;
246 GtkBuilder *bxml = gtk_builder_new ();
247 GError* error = NULL;
249 atp_plugin = ANJUTA_PLUGIN_ATP (obj);
251 /* Load glade file */
252 if (!gtk_builder_add_from_file (bxml, GLADE_FILE, &error))
254 g_warning ("Couldn't load builder file: %s", error->message);
255 g_error_free (error);
256 return;
259 atp_tool_dialog_show (&atp_plugin->dialog, bxml);
261 anjuta_preferences_add_from_builder (prefs, bxml,
262 atp_plugin->settings,
263 "Tools", _("Tools"), ICON_FILE);
264 g_object_unref (bxml);
267 static void
268 ipreferences_unmerge(IAnjutaPreferences* obj, AnjutaPreferences* prefs, GError** e)
270 anjuta_preferences_remove_page (prefs, _("Tools"));
273 static void
274 ipreferences_iface_init(IAnjutaPreferencesIface* iface)
276 iface->merge = ipreferences_merge;
277 iface->unmerge = ipreferences_unmerge;
280 ANJUTA_PLUGIN_BEGIN (ATPPlugin, atp_plugin);
281 ANJUTA_PLUGIN_ADD_INTERFACE (ipreferences, IANJUTA_TYPE_PREFERENCES);
282 ANJUTA_PLUGIN_END;
284 ANJUTA_SIMPLE_PLUGIN (ATPPlugin, atp_plugin);
286 /* Access plugin variables
287 *---------------------------------------------------------------------------*/
289 GtkWindow*
290 atp_plugin_get_app_window (const ATPPlugin *this)
292 return GTK_WINDOW (ANJUTA_PLUGIN (this)->shell);
295 GtkActionGroup*
296 atp_plugin_get_action_group (const ATPPlugin *this)
298 return this->action_group;
301 ATPToolList*
302 atp_plugin_get_tool_list (const ATPPlugin* this)
304 return &(ANJUTA_PLUGIN_ATP (this)->list);
307 ATPToolDialog*
308 atp_plugin_get_tool_dialog (const ATPPlugin *this)
310 return &(ANJUTA_PLUGIN_ATP (this)->dialog);
313 ATPVariable*
314 atp_plugin_get_variable (const ATPPlugin *this)
316 return &(ANJUTA_PLUGIN_ATP (this)->variable);
319 ATPContextList*
320 atp_plugin_get_context_list (const ATPPlugin *this)
322 return &(ANJUTA_PLUGIN_ATP (this)->context);