1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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
22 Anjuta user-defined tools requirements statement:
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
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.
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)
84 *---------------------------------------------------------------------------*/
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 /*---------------------------------------------------------------------------*/
111 GtkActionGroup
* action_group
;
114 ATPToolDialog dialog
;
115 ATPVariable variable
;
116 ATPContextList context
;
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 */
138 /*---------------------------------------------------------------------------*/
140 /* Used in dispose */
141 static gpointer parent_class
;
143 #define PREF_SCHEMA "org.gnome.anjuta.tools"
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 */
155 atp_plugin_dispose (GObject
*obj
)
157 /* Warning this function could be called several times */
158 ATPPlugin
*this = ANJUTA_PLUGIN_ATP (obj
);
160 g_object_unref (this->settings
);
161 this->settings
= NULL
;
162 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
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 */
176 atp_plugin_activate (AnjutaPlugin
*plugin
)
178 ATPPlugin
*this = ANJUTA_PLUGIN_ATP (plugin
);
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
,
187 _("Tool operations"),
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
);
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
));
209 atp_plugin_deactivate (AnjutaPlugin
*plugin
)
211 ATPPlugin
*this = ANJUTA_PLUGIN_ATP (plugin
);
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
);
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
;
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
);
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
);
268 ipreferences_unmerge(IAnjutaPreferences
* obj
, AnjutaPreferences
* prefs
, GError
** e
)
270 anjuta_preferences_remove_page (prefs
, _("Tools"));
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
);
284 ANJUTA_SIMPLE_PLUGIN (ATPPlugin
, atp_plugin
);
286 /* Access plugin variables
287 *---------------------------------------------------------------------------*/
290 atp_plugin_get_app_window (const ATPPlugin
*this)
292 return GTK_WINDOW (ANJUTA_PLUGIN (this)->shell
);
296 atp_plugin_get_action_group (const ATPPlugin
*this)
298 return this->action_group
;
302 atp_plugin_get_tool_list (const ATPPlugin
* this)
304 return &(ANJUTA_PLUGIN_ATP (this)->list
);
308 atp_plugin_get_tool_dialog (const ATPPlugin
*this)
310 return &(ANJUTA_PLUGIN_ATP (this)->dialog
);
314 atp_plugin_get_variable (const ATPPlugin
*this)
316 return &(ANJUTA_PLUGIN_ATP (this)->variable
);
320 atp_plugin_get_context_list (const ATPPlugin
*this)
322 return &(ANJUTA_PLUGIN_ATP (this)->context
);