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 #include <libanjuta/anjuta-shell.h>
23 #include <libanjuta/anjuta-debug.h>
24 #include <libanjuta/anjuta-encodings.h>
25 #include <libanjuta/interfaces/ianjuta-document-manager.h>
26 #include <libanjuta/interfaces/ianjuta-symbol-manager.h>
27 #include <libanjuta/interfaces/ianjuta-file.h>
28 #include <libanjuta/interfaces/ianjuta-file-savable.h>
29 #include <libanjuta/interfaces/ianjuta-editor-factory.h>
30 #include <libanjuta/interfaces/ianjuta-preferences.h>
36 #include "style-editor.h"
37 #include "text_editor.h"
39 #define PREFS_GLADE PACKAGE_DATA_DIR "/glade/anjuta-editor-scintilla.ui"
40 #define ICON_FILE "anjuta-editor-scintilla-plugin-48.png"
42 gpointer parent_class
;
45 *---------------------------------------------------------------------------*/
50 GtkWidget
* style_button
;
52 IAnjutaSymbolQuery
*query_system
;
53 IAnjutaSymbolQuery
*query_project
;
57 AnjutaPreferences
* prefs
;
60 struct _EditorPluginClass
{
61 AnjutaPluginClass parent_class
;
64 /* Keep an up to date list of type name
65 *---------------------------------------------------------------------------*/
68 update_type_list (AnjutaShell
*shell
, IAnjutaIterable
*iter
, const gchar
*name
)
75 ianjuta_iterable_first (iter
, NULL
);
76 if (ianjuta_iterable_get_length (iter
, NULL
) > 0)
78 GString
*s
= g_string_sized_new(ianjuta_iterable_get_length (iter
, NULL
) * 10);
80 IAnjutaSymbol
*symbol
= IANJUTA_SYMBOL (iter
);
81 const gchar
*sname
= ianjuta_symbol_get_string (symbol
, IANJUTA_SYMBOL_FIELD_NAME
, NULL
);
82 g_string_append(s
, sname
);
83 g_string_append_c(s
, ' ');
84 } while (ianjuta_iterable_next (iter
, NULL
));
85 list
= g_string_free(s
, FALSE
);
89 anjuta_shell_get_value (shell
, name
, &value
, NULL
);
90 if (G_VALUE_HOLDS_STRING(&value
))
92 const gchar
*value_list
= g_value_get_string (&value
);
96 anjuta_shell_remove_value (shell
, name
, NULL
);
98 else if (strcmp (list
, value_list
) == 0)
104 g_value_take_string (&value
, list
);
105 anjuta_shell_add_value (shell
, name
, &value
, NULL
);
112 g_value_init (&value
, G_TYPE_STRING
);
113 g_value_take_string (&value
, list
);
114 anjuta_shell_add_value (shell
, name
, &value
, NULL
);
117 if (G_IS_VALUE (&value
))
118 g_value_unset (&value
);
122 project_symbol_found (IAnjutaSymbolQuery
*query
, IAnjutaIterable
* symbols
, gpointer user_data
)
124 update_type_list (ANJUTA_SHELL (user_data
), symbols
, TEXT_EDITOR_PROJECT_TYPE_LIST
);
128 system_symbol_found (IAnjutaSymbolQuery
*query
, IAnjutaIterable
* symbols
, gpointer user_data
)
130 update_type_list (ANJUTA_SHELL (user_data
), symbols
, TEXT_EDITOR_SYSTEM_TYPE_LIST
);
134 on_project_symbol_scanned (IAnjutaSymbolManager
*manager
, guint process
, IAnjutaSymbolQuery
*query_project
)
136 ianjuta_symbol_query_search_all (query_project
, NULL
);
140 on_system_symbol_scanned (IAnjutaSymbolManager
*manager
, guint process
, IAnjutaSymbolQuery
*query_system
)
142 ianjuta_symbol_query_search_all (query_system
, NULL
);
146 on_style_button_clicked(GtkWidget
* button
, EditorPlugin
*plugin
)
148 StyleEditor
* se
= style_editor_new(plugin
->prefs
, plugin
->settings
);
149 style_editor_show(se
);
153 activate_plugin (AnjutaPlugin
*plugin
)
155 static IAnjutaSymbolField query_fields
[] = {
156 IANJUTA_SYMBOL_FIELD_ID
,
157 IANJUTA_SYMBOL_FIELD_NAME
,
158 IANJUTA_SYMBOL_FIELD_KIND
,
159 IANJUTA_SYMBOL_FIELD_TYPE
161 EditorPlugin
* editor
= ANJUTA_PLUGIN_EDITOR (plugin
);
162 IAnjutaSymbolManager
*manager
;
163 IAnjutaSymbolQuery
*query_project
;
164 IAnjutaSymbolQuery
*query_system
;
166 manager
= anjuta_shell_get_interface (plugin
->shell
,
167 IAnjutaSymbolManager
, NULL
);
171 ianjuta_symbol_manager_create_query (manager
,
172 IANJUTA_SYMBOL_QUERY_SEARCH_ALL
,
173 IANJUTA_SYMBOL_QUERY_DB_PROJECT
,
176 ianjuta_symbol_query_set_fields (query_project
,
177 G_N_ELEMENTS (query_fields
),
179 ianjuta_symbol_query_set_file_scope (query_project
,
180 IANJUTA_SYMBOL_QUERY_SEARCH_FS_IGNORE
, NULL
);
181 ianjuta_symbol_query_set_mode (query_project
,
182 IANJUTA_SYMBOL_QUERY_MODE_QUEUED
, NULL
);
183 ianjuta_symbol_query_set_filters (query_project
, IANJUTA_SYMBOL_TYPE_TYPEDEF
,
185 g_signal_connect (query_project
, "async-result",
186 G_CALLBACK (project_symbol_found
), plugin
->shell
);
190 ianjuta_symbol_manager_create_query (manager
,
191 IANJUTA_SYMBOL_QUERY_SEARCH_ALL
,
192 IANJUTA_SYMBOL_QUERY_DB_SYSTEM
,
195 ianjuta_symbol_query_set_fields (query_system
,
196 G_N_ELEMENTS (query_fields
),
198 ianjuta_symbol_query_set_file_scope (query_system
,
199 IANJUTA_SYMBOL_QUERY_SEARCH_FS_IGNORE
, NULL
);
200 ianjuta_symbol_query_set_mode (query_system
,
201 IANJUTA_SYMBOL_QUERY_MODE_QUEUED
, NULL
);
202 ianjuta_symbol_query_set_filters (query_system
, IANJUTA_SYMBOL_TYPE_TYPEDEF
,
205 g_signal_connect (query_system
, "async-result",
206 G_CALLBACK (system_symbol_found
), plugin
->shell
);
209 /* Get notified when scan end, to update type list */
210 g_signal_connect (G_OBJECT (manager
), "prj_scan_end", G_CALLBACK (on_project_symbol_scanned
), query_project
);
211 g_signal_connect (G_OBJECT (manager
), "sys_scan_end", G_CALLBACK (on_system_symbol_scanned
), query_system
);
213 /* Initialize type list */
214 on_project_symbol_scanned (manager
, 0, query_project
);
215 on_system_symbol_scanned (manager
, 0, query_system
);
217 /* Keep queries to be able to unref them when needed */
218 editor
->query_project
= query_project
;
219 editor
->query_system
= query_system
;
226 deactivate_plugin (AnjutaPlugin
*plugin
)
228 EditorPlugin
* editor
= ANJUTA_PLUGIN_EDITOR (plugin
);
229 IAnjutaSymbolManager
*manager
= anjuta_shell_get_interface (plugin
->shell
, IAnjutaSymbolManager
, NULL
);
231 /* Disconnect signals */
232 g_signal_handlers_disconnect_by_func (G_OBJECT (manager
), G_CALLBACK (on_project_symbol_scanned
), editor
->query_project
);
233 g_signal_handlers_disconnect_by_func (G_OBJECT (manager
), G_CALLBACK (on_system_symbol_scanned
), editor
->query_system
);
235 g_object_unref (editor
->query_project
);
236 g_object_unref (editor
->query_system
);
242 dispose (GObject
*obj
)
244 EditorPlugin
*plugin
= ANJUTA_PLUGIN_EDITOR (obj
);
246 g_object_unref (plugin
->settings
);
248 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
252 finalize (GObject
*obj
)
254 /* Finalization codes here */
255 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
259 editor_plugin_instance_init (GObject
*obj
)
261 EditorPlugin
*plugin
= ANJUTA_PLUGIN_EDITOR (obj
);
263 plugin
->settings
= g_settings_new (PREF_SCHEMA
);
264 plugin
->prefs
= NULL
;
268 editor_plugin_class_init (GObjectClass
*klass
)
270 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
272 parent_class
= g_type_class_peek_parent (klass
);
274 plugin_class
->activate
= activate_plugin
;
275 plugin_class
->deactivate
= deactivate_plugin
;
276 klass
->dispose
= dispose
;
277 klass
->finalize
= finalize
;
280 static IAnjutaEditor
*
281 itext_editor_factory_new_editor(IAnjutaEditorFactory
* factory
,
283 const gchar
* filename
,
286 AnjutaShell
*shell
= ANJUTA_PLUGIN (factory
)->shell
;
287 AnjutaStatus
*status
= anjuta_shell_get_status (shell
, NULL
);
288 /* file can be NULL, if we open a buffer, not a file */
289 gchar
* uri
= file
? g_file_get_uri (file
) : NULL
;
290 IAnjutaEditor
* editor
= IANJUTA_EDITOR(text_editor_new(status
,shell
,
297 itext_editor_factory_iface_init (IAnjutaEditorFactoryIface
*iface
)
299 iface
->new_editor
= itext_editor_factory_new_editor
;
303 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
305 GtkBuilder
* bxml
= gtk_builder_new ();
306 EditorPlugin
* plugin
= ANJUTA_PLUGIN_EDITOR (ipref
);
307 GError
* error
= NULL
;
308 if (!gtk_builder_add_from_file (bxml
, PREFS_GLADE
, &error
))
310 g_warning ("Couldn't load builder file: %s", error
->message
);
311 g_error_free (error
);
313 plugin
->prefs
= prefs
;
314 plugin
->style_button
= GTK_WIDGET (gtk_builder_get_object (bxml
, "style_button"));
315 g_signal_connect(G_OBJECT(plugin
->style_button
), "clicked",
316 G_CALLBACK(on_style_button_clicked
), plugin
);
317 anjuta_preferences_add_from_builder (prefs
,
318 bxml
, plugin
->settings
, "prefs_editor", _("Scintilla Editor"), ICON_FILE
);
319 g_object_unref(bxml
);
323 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
325 EditorPlugin
* plugin
= ANJUTA_PLUGIN_EDITOR (ipref
);
326 g_signal_handlers_disconnect_by_func(G_OBJECT(plugin
->style_button
),
327 G_CALLBACK(on_style_button_clicked
),
328 anjuta_shell_get_preferences(ANJUTA_PLUGIN(plugin
)->shell
, NULL
));
330 anjuta_preferences_remove_page(prefs
, _("Scintilla Editor"));
334 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
336 iface
->merge
= ipreferences_merge
;
337 iface
->unmerge
= ipreferences_unmerge
;
340 ANJUTA_PLUGIN_BEGIN (EditorPlugin
, editor_plugin
);
341 ANJUTA_TYPE_ADD_INTERFACE(itext_editor_factory
, IANJUTA_TYPE_EDITOR_FACTORY
);
342 ANJUTA_TYPE_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
345 ANJUTA_SIMPLE_PLUGIN (EditorPlugin
, editor_plugin
);