1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
plugin.c
Copyright (C) 2000 Naba Kumar
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
Anjuta user-defined tools requirements statement:
Convention:
(M) = Must have
(R) = Recommended
(N) = Nice to have
(U) = Unecessary
(D) = Done (Implemented)
(P) = Partly implemented
User-defined tools should provide the user with a powerful mechanism to
do various activities customized to his needs from with the Anjuta GUI
framework. The tool system should also be flexible enough so that developers
of Anjuta can use it to easily integrate external programs in Anjuta and
enhance functionality of the IDE through the use of tools.
The following is a list of requirements and their relative pririties.
Progress should be tracked by marking each of the items as and when they are
implemented. Feel free to add/remove/reprioritize these items but please
discuss in the devel list before making any major changes.
R1: Modify GUI at program startup
1) (D) Add new menu items associated with external commands.
2) (D) Add drop-down toolbar item for easy access to all tools.
4) (D) Should be able to associate icons.
5) (D) Should be able to associate shortcuts.
5) (U) Should be appendable under any of the top/sub level menus.
R2: Command line parameters
1) (D) Pass variable command-line parameters to the tool.
2) (D) Use existing properties system to pass parameters.
3) (D) Ask user at run-time for parameters.
4) (U) Generate a dialog for asking several parameters at run time
R3: Working directory
1) (D) Specify working directory for the tool.
2) (D) Ability to specify property variables for working dir.
R4: Standard input to the tool
1) (D) Specify current buffer as standard input.
2) (D) Specify property variables as standard input.
3) (D) Specify list of open files as standard input.
R5: Output and error redirection
1) (D) Output to a message pane windows.
2) (D) Run in terminal (detached mode).
3) (D) Output to current/new buffer.
4) (D) Show output in a popup window.
5) (U) Try to parser error and warning messages
R6: Tool manipulation GUI
1) (D) Add/remove tools with all options.
2) (D) Enable/disable tool loading.
R7: Tool Storage
1) (D) Gloabal and local tool storage.
2) (D) Override global tools with local settings.
3) (N) Project specific tools (load/unload with project)
*/
/*
* Plugins functions
*
*---------------------------------------------------------------------------*/
#include <config.h>
#include "plugin.h"
#include "dialog.h"
#include "fileop.h"
#include "tool.h"
#include "editor.h"
#include "variable.h"
#include "execute.h"
#include <libanjuta/anjuta-shell.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/interfaces/ianjuta-preferences.h>
/*---------------------------------------------------------------------------*/
#define ICON_FILE "anjuta-tools-plugin-48.png"
#define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-tools.xml"
/*---------------------------------------------------------------------------*/
struct _ATPPlugin {
AnjutaPlugin parent;
GtkActionGroup* action_group;
gint uiid;
ATPToolList list;
ATPToolDialog dialog;
ATPVariable variable;
ATPContextList context;
GSettings* settings;
};
struct _ATPPluginClass {
AnjutaPluginClass parent_class;
};
/*---------------------------------------------------------------------------*/
static GtkActionEntry actions_tools[] = {
{
"ActionMenuTools", /* Action name */
NULL, /* Stock icon, if any */
N_("_Tools"), /* Display label */
NULL, /* Short-cut */
NULL, /* Tooltip */
NULL /* Callback */
}
};
/*---------------------------------------------------------------------------*/
/* Used in dispose */
static gpointer parent_class;
#define PREF_SCHEMA "org.gnome.anjuta.tools"
static void
atp_plugin_instance_init (GObject *obj)
{
ATPPlugin *this = ANJUTA_PLUGIN_ATP (obj);
this->settings = g_settings_new (PREF_SCHEMA);
}
/* dispose is used to unref object created with instance_init */
static void
atp_plugin_dispose (GObject *obj)
{
/* Warning this function could be called several times */
ATPPlugin *this = ANJUTA_PLUGIN_ATP (obj);
if (this->settings)
g_object_unref (this->settings);
this->settings = NULL;
G_OBJECT_CLASS (parent_class)->dispose (obj);
}
static void
atp_plugin_finalize (GObject *obj)
{
/* Warning this function could be called several times */
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
/* finalize used to free object created with instance init is not used */
static gboolean
atp_plugin_activate (AnjutaPlugin *plugin)
{
ATPPlugin *this = ANJUTA_PLUGIN_ATP (plugin);
AnjutaUI *ui;
DEBUG_PRINT ("%s", "Tools Plugin: Activating tools plugin...");
/* Add all our actions */
ui = anjuta_shell_get_ui (plugin->shell, NULL);
this->action_group = anjuta_ui_add_action_group_entries (ui,
"ActionGroupTools",
_("Tool operations"),
actions_tools,
G_N_ELEMENTS (actions_tools),
GETTEXT_PACKAGE, TRUE, plugin);
this->uiid = anjuta_ui_merge (ui, UI_FILE);
/* Add tool menu item */
atp_tool_list_construct (&this->list, this);
atp_anjuta_tools_load (this);
atp_tool_list_activate (&this->list);
/* initialization */
atp_tool_dialog_construct (&this->dialog, this);
atp_variable_construct (&this->variable, plugin->shell);
atp_context_list_construct (&this->context);
atp_tool_list_activate (atp_plugin_get_tool_list (this->dialog.plugin));
return TRUE;
}
static gboolean
atp_plugin_deactivate (AnjutaPlugin *plugin)
{
ATPPlugin *this = ANJUTA_PLUGIN_ATP (plugin);
AnjutaUI *ui;
DEBUG_PRINT ("%s", "Tools Plugin: Deactivating tools plugin...");
atp_tool_list_deactivate (&this->list);
atp_context_list_destroy (&this->context);
atp_variable_destroy (&this->variable);
atp_tool_dialog_destroy (&this->dialog);
atp_tool_list_destroy (&this->list);
ui = anjuta_shell_get_ui (plugin->shell, NULL);
anjuta_ui_unmerge (ui, this->uiid);
return TRUE;
}
static void
atp_plugin_class_init (GObjectClass *klass)
{
AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
plugin_class->activate = atp_plugin_activate;
plugin_class->deactivate = atp_plugin_deactivate;
klass->dispose = atp_plugin_dispose;
klass->finalize = atp_plugin_finalize;
}
static void
ipreferences_merge(IAnjutaPreferences* obj, AnjutaPreferences* prefs, GError** e)
{
/* Create the tools preferences page */
ATPPlugin* atp_plugin;
GtkBuilder *bxml = gtk_builder_new ();
GError* error = NULL;
atp_plugin = ANJUTA_PLUGIN_ATP (obj);
/* Load glade file */
if (!gtk_builder_add_from_file (bxml, GLADE_FILE, &error))
{
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
return;
}
atp_tool_dialog_show (&atp_plugin->dialog, bxml);
anjuta_preferences_add_from_builder (prefs, bxml,
atp_plugin->settings,
"Tools", _("Tools"), ICON_FILE);
g_object_unref (bxml);
}
static void
ipreferences_unmerge(IAnjutaPreferences* obj, AnjutaPreferences* prefs, GError** e)
{
anjuta_preferences_remove_page (prefs, _("Tools"));
}
static void
ipreferences_iface_init(IAnjutaPreferencesIface* iface)
{
iface->merge = ipreferences_merge;
iface->unmerge = ipreferences_unmerge;
}
ANJUTA_PLUGIN_BEGIN (ATPPlugin, atp_plugin);
ANJUTA_PLUGIN_ADD_INTERFACE (ipreferences, IANJUTA_TYPE_PREFERENCES);
ANJUTA_PLUGIN_END;
ANJUTA_SIMPLE_PLUGIN (ATPPlugin, atp_plugin);
/* Access plugin variables
*---------------------------------------------------------------------------*/
GtkWindow*
atp_plugin_get_app_window (const ATPPlugin *this)
{
return GTK_WINDOW (ANJUTA_PLUGIN (this)->shell);
}
GtkActionGroup*
atp_plugin_get_action_group (const ATPPlugin *this)
{
return this->action_group;
}
ATPToolList*
atp_plugin_get_tool_list (const ATPPlugin* this)
{
return &(ANJUTA_PLUGIN_ATP (this)->list);
}
ATPToolDialog*
atp_plugin_get_tool_dialog (const ATPPlugin *this)
{
return &(ANJUTA_PLUGIN_ATP (this)->dialog);
}
ATPVariable*
atp_plugin_get_variable (const ATPPlugin *this)
{
return &(ANJUTA_PLUGIN_ATP (this)->variable);
}
ATPContextList*
atp_plugin_get_context_list (const ATPPlugin *this)
{
return &(ANJUTA_PLUGIN_ATP (this)->context);
}
|