Updated Spanish translation
[anjuta-git-plugin.git] / plugins / tools / plugin.c
blob75eaec29f3ea2edde5b7f56abd19793348d8e1a5
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 /*---------------------------------------------------------------------------*/
102 #define ICON_FILE "anjuta-tools-plugin.png"
103 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-tools.ui"
105 /*---------------------------------------------------------------------------*/
107 struct _ATPPlugin {
108 AnjutaPlugin parent;
109 gint uiid;
110 ATPToolList list;
111 ATPToolDialog dialog;
112 ATPVariable variable;
113 ATPContextList context;
116 struct _ATPPluginClass {
117 AnjutaPluginClass parent_class;
120 /* Call backs
121 *---------------------------------------------------------------------------*/
123 static void
124 atp_on_menu_tools_configure (GtkAction* action, ATPPlugin* plugin)
126 atp_tool_dialog_show(&plugin->dialog);
129 /*---------------------------------------------------------------------------*/
131 static GtkActionEntry actions_tools[] = {
133 "ActionMenuTools", /* Action name */
134 NULL, /* Stock icon, if any */
135 N_("_Tools"), /* Display label */
136 NULL, /* Short-cut */
137 NULL, /* Tooltip */
138 NULL /* Callback */
141 "ActionConfigureTools",
142 NULL,
143 N_("_Configure"),
144 NULL,
145 N_("Configure external tools"),
146 G_CALLBACK (atp_on_menu_tools_configure)
150 /*---------------------------------------------------------------------------*/
152 /* Used in dispose */
153 static gpointer parent_class;
155 static void
156 atp_plugin_instance_init (GObject *obj)
160 /* dispose is used to unref object created with instance_init */
162 static void
163 atp_plugin_dispose (GObject *obj)
165 /* Warning this function could be called several times */
167 GNOME_CALL_PARENT (G_OBJECT_CLASS, dispose, (G_OBJECT (obj)));
170 /* finalize used to free object created with instance init is not used */
172 static gboolean
173 atp_plugin_activate (AnjutaPlugin *plugin)
175 ATPPlugin *this = ANJUTA_PLUGIN_ATP (plugin);
176 AnjutaUI *ui;
177 GtkMenu* menu;
178 GtkWidget* sep;
180 DEBUG_PRINT ("Tools Plugin: Activating tools plugin...");
182 /* Add all our actions */
183 ui = anjuta_shell_get_ui (plugin->shell, NULL);
184 anjuta_ui_add_action_group_entries (ui, "ActionGroupTools",
185 _("Tool operations"),
186 actions_tools,
187 G_N_ELEMENTS (actions_tools),
188 GETTEXT_PACKAGE, TRUE, plugin);
189 this->uiid = anjuta_ui_merge (ui, UI_FILE);
191 /* Load tools */
192 menu = GTK_MENU (gtk_menu_item_get_submenu (GTK_MENU_ITEM (gtk_ui_manager_get_widget (GTK_UI_MANAGER(ui), MENU_PLACEHOLDER))));
194 /* Add a separator */
195 sep = gtk_separator_menu_item_new();
196 gtk_menu_shell_append (GTK_MENU_SHELL (menu), sep);
197 gtk_widget_show (sep);
199 /* Add tool menu item */
200 atp_tool_list_construct (&this->list, this);
201 atp_anjuta_tools_load (this);
202 atp_tool_list_activate (&this->list);
204 /* initialization */
205 atp_tool_dialog_construct (&this->dialog, this);
206 atp_variable_construct (&this->variable, plugin->shell);
207 atp_context_list_construct (&this->context);
209 return TRUE;
212 static gboolean
213 atp_plugin_deactivate (AnjutaPlugin *plugin)
215 ATPPlugin *this = ANJUTA_PLUGIN_ATP (plugin);
216 AnjutaUI *ui;
218 DEBUG_PRINT ("Tools Plugin: Deactivating tools plugin...");
220 atp_context_list_destroy (&this->context);
221 atp_variable_destroy (&this->variable);
222 atp_tool_dialog_destroy (&this->dialog);
223 atp_tool_list_destroy (&this->list);
225 ui = anjuta_shell_get_ui (plugin->shell, NULL);
226 anjuta_ui_unmerge (ui, this->uiid);
228 return TRUE;
231 static void
232 atp_plugin_class_init (GObjectClass *klass)
234 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
236 parent_class = g_type_class_peek_parent (klass);
238 plugin_class->activate = atp_plugin_activate;
239 plugin_class->deactivate = atp_plugin_deactivate;
240 klass->dispose = atp_plugin_dispose;
243 ANJUTA_PLUGIN_BOILERPLATE (ATPPlugin, atp_plugin);
244 ANJUTA_SIMPLE_PLUGIN (ATPPlugin, atp_plugin);
246 /* Access plugin variables
247 *---------------------------------------------------------------------------*/
249 GtkWindow*
250 atp_plugin_get_app_window (const ATPPlugin *this)
252 return GTK_WINDOW (ANJUTA_PLUGIN (this)->shell);
255 ATPToolList*
256 atp_plugin_get_tool_list (const ATPPlugin* this)
258 return &(ANJUTA_PLUGIN_ATP (this)->list);
261 ATPToolDialog*
262 atp_plugin_get_tool_dialog (const ATPPlugin *this)
264 return &(ANJUTA_PLUGIN_ATP (this)->dialog);
267 ATPVariable*
268 atp_plugin_get_variable (const ATPPlugin *this)
270 return &(ANJUTA_PLUGIN_ATP (this)->variable);
273 ATPContextList*
274 atp_plugin_get_context_list (const ATPPlugin *this)
276 return &(ANJUTA_PLUGIN_ATP (this)->context);