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
24 #include <libanjuta/anjuta-shell.h>
25 #include <libanjuta/anjuta-debug.h>
26 #include <libanjuta/interfaces/ianjuta-editor-assist.h>
27 #include <libanjuta/interfaces/ianjuta-document.h>
28 #include <libanjuta/interfaces/ianjuta-document-manager.h>
29 #include <libanjuta/interfaces/ianjuta-preferences.h>
30 #include <libanjuta/interfaces/ianjuta-language.h>
34 #define PREFS_BUILDER PACKAGE_DATA_DIR"/glade/anjuta-parser-cxx.ui"
35 #define ICON_FILE "anjuta-parser-cxx-plugin.png"
37 /* Preferences keys */
38 #define ANJUTA_PREF_SCHEMA_PREFIX "org.gnome.anjuta."
39 #define PREF_SCHEMA "org.gnome.anjuta.plugins.parser-cxx"
41 static gpointer parent_class
;
43 /* Enable/Disable language-support */
45 install_support (ParserCxxPlugin
*parser_plugin
)
47 IAnjutaLanguage
* lang_manager
=
48 anjuta_shell_get_interface (ANJUTA_PLUGIN (parser_plugin
)->shell
,
49 IAnjutaLanguage
, NULL
);
54 if (parser_plugin
->support_installed
)
57 parser_plugin
->current_language
=
58 ianjuta_language_get_name_from_editor (lang_manager
,
59 IANJUTA_EDITOR_LANGUAGE (parser_plugin
->current_editor
), NULL
);
61 DEBUG_PRINT("Parser support installed for: %s",
62 parser_plugin
->current_language
);
64 if (parser_plugin
->current_language
&&
65 (g_str_equal (parser_plugin
->current_language
, "C" )
66 || g_str_equal (parser_plugin
->current_language
, "C++")))
68 ParserCxxAssist
*assist
;
70 g_assert (parser_plugin
->assist
== NULL
);
72 assist
= parser_cxx_assist_new (IANJUTA_EDITOR (parser_plugin
->current_editor
),
73 anjuta_shell_get_interface (
74 anjuta_plugin_get_shell (ANJUTA_PLUGIN (parser_plugin
)),
75 IAnjutaSymbolManager
, NULL
),
76 parser_plugin
->settings
);
81 parser_plugin
->assist
= assist
;
86 parser_plugin
->support_installed
= TRUE
;
90 uninstall_support (ParserCxxPlugin
*parser_plugin
)
92 if (!parser_plugin
->support_installed
)
95 if (parser_plugin
->assist
)
97 g_object_unref (parser_plugin
->assist
);
98 parser_plugin
->assist
= NULL
;
101 parser_plugin
->support_installed
= FALSE
;
105 on_editor_language_changed (IAnjutaEditor
*editor
,
106 const gchar
*new_language
,
107 ParserCxxPlugin
*plugin
)
109 uninstall_support (plugin
);
110 install_support (plugin
);
114 on_value_added_current_editor (AnjutaPlugin
*plugin
, const gchar
*name
,
115 const GValue
*value
, gpointer data
)
117 ParserCxxPlugin
*parser_plugin
;
118 IAnjutaDocument
* doc
= IANJUTA_DOCUMENT(g_value_get_object (value
));
119 parser_plugin
= ANJUTA_PLUGIN_PARSER_CXX (plugin
);
121 if (IANJUTA_IS_EDITOR(doc
))
122 parser_plugin
->current_editor
= G_OBJECT(doc
);
125 parser_plugin
->current_editor
= NULL
;
129 if (IANJUTA_IS_EDITOR(parser_plugin
->current_editor
))
130 install_support (parser_plugin
);
132 g_signal_connect (parser_plugin
->current_editor
, "language-changed",
133 G_CALLBACK (on_editor_language_changed
),
138 on_value_removed_current_editor (AnjutaPlugin
*plugin
, const gchar
*name
,
141 ParserCxxPlugin
*parser_plugin
;
142 parser_plugin
= ANJUTA_PLUGIN_PARSER_CXX (plugin
);
144 if (parser_plugin
->current_editor
)
145 g_signal_handlers_disconnect_by_func (parser_plugin
->current_editor
,
146 G_CALLBACK (on_editor_language_changed
),
149 if (IANJUTA_IS_EDITOR(parser_plugin
->current_editor
))
150 uninstall_support (parser_plugin
);
152 parser_plugin
->current_editor
= NULL
;
156 parser_cxx_plugin_activate_plugin (AnjutaPlugin
*plugin
)
158 ParserCxxPlugin
*parser_plugin
;
160 parser_plugin
= ANJUTA_PLUGIN_PARSER_CXX (plugin
);
162 DEBUG_PRINT ("%s", "AnjutaParserCxxPlugin: Activating plugin ...");
164 parser_plugin
->editor_watch_id
=
165 anjuta_plugin_add_watch (plugin
,
166 IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT
,
167 on_value_added_current_editor
,
168 on_value_removed_current_editor
,
175 parser_cxx_plugin_deactivate_plugin (AnjutaPlugin
*plugin
)
177 ParserCxxPlugin
*parser_plugin
;
178 parser_plugin
= ANJUTA_PLUGIN_PARSER_CXX (plugin
);
180 anjuta_plugin_remove_watch (plugin
,
181 parser_plugin
->editor_watch_id
,
184 DEBUG_PRINT ("%s", "AnjutaParserCxxPlugin: Deactivated plugin.");
189 parser_cxx_plugin_finalize (GObject
*obj
)
191 /* Finalization codes here */
192 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
196 parser_cxx_plugin_dispose (GObject
*obj
)
198 ParserCxxPlugin
* plugin
= ANJUTA_PLUGIN_PARSER_CXX (obj
);
200 /* Disposition codes */
201 g_object_unref (plugin
->settings
);
203 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
207 parser_cxx_plugin_instance_init (GObject
*obj
)
209 ParserCxxPlugin
*plugin
= ANJUTA_PLUGIN_PARSER_CXX (obj
);
210 plugin
->current_editor
= NULL
;
211 plugin
->current_language
= NULL
;
212 plugin
->editor_watch_id
= 0;
213 plugin
->assist
= NULL
;
214 plugin
->settings
= g_settings_new (PREF_SCHEMA
);
218 parser_cxx_plugin_class_init (GObjectClass
*klass
)
220 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
222 parent_class
= g_type_class_peek_parent (klass
);
224 plugin_class
->activate
= parser_cxx_plugin_activate_plugin
;
225 plugin_class
->deactivate
= parser_cxx_plugin_deactivate_plugin
;
226 klass
->finalize
= parser_cxx_plugin_finalize
;
227 klass
->dispose
= parser_cxx_plugin_dispose
;
230 #define PREF_WIDGET_SPACE "preferences:completion-space-after-func"
231 #define PREF_WIDGET_BRACE "preferences:completion-brace-after-func"
232 #define PREF_WIDGET_CLOSEBRACE "preferences:completion-closebrace-after-func"
233 #define PREF_WIDGET_AUTO "preferences:completion-enable"
236 on_autocompletion_toggled (GtkToggleButton
* button
,
237 ParserCxxPlugin
* plugin
)
240 gboolean sensitive
= gtk_toggle_button_get_active (button
);
242 widget
= GTK_WIDGET (gtk_builder_get_object (plugin
->bxml
, PREF_WIDGET_SPACE
));
243 gtk_widget_set_sensitive (widget
, sensitive
);
244 widget
= GTK_WIDGET (gtk_builder_get_object (plugin
->bxml
, PREF_WIDGET_BRACE
));
245 gtk_widget_set_sensitive (widget
, sensitive
);
246 widget
= GTK_WIDGET (gtk_builder_get_object (plugin
->bxml
, PREF_WIDGET_CLOSEBRACE
));
247 gtk_widget_set_sensitive (widget
, sensitive
);
251 ipreferences_merge (IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
,
254 GError
* error
= NULL
;
255 ParserCxxPlugin
* plugin
= ANJUTA_PLUGIN_PARSER_CXX (ipref
);
256 plugin
->bxml
= gtk_builder_new ();
259 /* Add preferences */
260 if (!gtk_builder_add_from_file (plugin
->bxml
, PREFS_BUILDER
, &error
))
262 g_warning ("Couldn't load builder file: %s", error
->message
);
263 g_error_free (error
);
265 anjuta_preferences_add_from_builder (prefs
,
266 plugin
->bxml
, plugin
->settings
,
267 "preferences", _("Auto-complete"),
269 toggle
= GTK_WIDGET (gtk_builder_get_object (plugin
->bxml
, PREF_WIDGET_AUTO
));
270 g_signal_connect (toggle
, "toggled", G_CALLBACK (on_autocompletion_toggled
),
272 on_autocompletion_toggled (GTK_TOGGLE_BUTTON (toggle
), plugin
);
276 ipreferences_unmerge (IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
,
279 ParserCxxPlugin
* plugin
= ANJUTA_PLUGIN_PARSER_CXX (ipref
);
280 anjuta_preferences_remove_page(prefs
, _("Auto-complete"));
281 g_object_unref (plugin
->bxml
);
285 ipreferences_iface_init (IAnjutaPreferencesIface
* iface
)
287 iface
->merge
= ipreferences_merge
;
288 iface
->unmerge
= ipreferences_unmerge
;
291 ANJUTA_PLUGIN_BEGIN (ParserCxxPlugin
, parser_cxx_plugin
);
292 ANJUTA_PLUGIN_ADD_INTERFACE (ipreferences
, IANJUTA_TYPE_PREFERENCES
);
295 ANJUTA_SIMPLE_PLUGIN (ParserCxxPlugin
, parser_cxx_plugin
);