[anjuta-extras] scintilla: Get type names for highlighting using async functions
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [anjuta-extras] scintilla: Get type names for highlighting using async functions
- Date: Sat, 1 Aug 2009 16:45:22 +0000 (UTC)
commit 804a3464815a45aaba99eb1e260e2502147ac0ce
Author: Sébastien Granjoux <seb sfo free fr>
Date: Sat Aug 1 18:42:21 2009 +0200
scintilla: Get type names for highlighting using async functions
plugins/scintilla/plugin.c | 123 +++++++++++++++++++++++++++++++
plugins/scintilla/plugin.h | 6 ++-
plugins/scintilla/text_editor.c | 153 +++++++++++++++++----------------------
plugins/scintilla/text_editor.h | 9 +--
4 files changed, 197 insertions(+), 94 deletions(-)
---
diff --git a/plugins/scintilla/plugin.c b/plugins/scintilla/plugin.c
index 350eb5a..2ed134a 100644
--- a/plugins/scintilla/plugin.c
+++ b/plugins/scintilla/plugin.c
@@ -23,6 +23,7 @@
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/anjuta-encodings.h>
#include <libanjuta/interfaces/ianjuta-document-manager.h>
+#include <libanjuta/interfaces/ianjuta-symbol-manager.h>
#include <libanjuta/interfaces/ianjuta-file.h>
#include <libanjuta/interfaces/ianjuta-file-savable.h>
#include <libanjuta/interfaces/ianjuta-editor-factory.h>
@@ -40,6 +41,113 @@
gpointer parent_class;
+/* Keep an up to date list of type name
+ *---------------------------------------------------------------------------*/
+
+static void
+update_type_list (AnjutaShell *shell, IAnjutaIterable *iter, const gchar *name)
+{
+ gchar *list = NULL;
+ GValue value = {0,};
+
+ if (iter)
+ {
+ ianjuta_iterable_first (iter, NULL);
+ if (ianjuta_iterable_get_length (iter, NULL) > 0)
+ {
+ GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
+ do {
+ IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
+ const gchar *sname = ianjuta_symbol_get_name (symbol, NULL);
+ g_string_append(s, sname);
+ g_string_append_c(s, ' ');
+ } while (ianjuta_iterable_next (iter, NULL));
+ list = g_string_free(s, FALSE);
+ }
+ g_object_unref (iter);
+ }
+
+ anjuta_shell_get_value (shell, name, &value, NULL);
+ if (G_VALUE_HOLDS_STRING(&value))
+ {
+ const gchar *value_list = g_value_get_string (&value);
+
+ if (list == NULL)
+ {
+ anjuta_shell_remove_value (shell, name, NULL);
+ }
+ else if (strcmp (list, value_list) == 0)
+ {
+ g_free (list);
+ }
+ else
+ {
+ g_value_take_string (&value, list);
+ anjuta_shell_add_value (shell, name, &value, NULL);
+ }
+ }
+ else
+ {
+ if (list != NULL)
+ {
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_take_string (&value, list);
+ anjuta_shell_add_value (shell, name, &value, NULL);
+ }
+ }
+ g_value_unset (&value);
+}
+
+static void
+project_symbol_found (guint search_id, IAnjutaIterable *iter, gpointer user_data)
+{
+ update_type_list (ANJUTA_SHELL (user_data), iter, TEXT_EDITOR_PROJECT_TYPE_LIST);
+}
+
+static void
+system_symbol_found (guint search_id, IAnjutaIterable *iter, gpointer user_data)
+{
+ update_type_list (ANJUTA_SHELL (user_data), iter, TEXT_EDITOR_SYSTEM_TYPE_LIST);
+}
+
+static void
+on_project_symbol_scanned (IAnjutaSymbolManager *manager, guint process, AnjutaShell *shell)
+{
+ /* Re-scan project symbols */
+ ianjuta_symbol_manager_search_project_async (manager,
+ IANJUTA_SYMBOL_TYPE_TYPEDEF,
+ TRUE,
+ IANJUTA_SYMBOL_FIELD_SIMPLE,
+ "%",
+ IANJUTA_SYMBOL_MANAGER_SEARCH_FS_IGNORE,
+ -1,
+ -1,
+ NULL,
+ NULL,
+ project_symbol_found,
+ shell,
+ NULL);
+}
+
+static void
+on_system_symbol_scanned (IAnjutaSymbolManager *manager, guint process, AnjutaShell *shell)
+{
+ /* Re-scan system symbols */
+ ianjuta_symbol_manager_search_system_async (manager,
+ IANJUTA_SYMBOL_TYPE_TYPEDEF,
+ TRUE,
+ IANJUTA_SYMBOL_FIELD_SIMPLE,
+ "%",
+ IANJUTA_SYMBOL_MANAGER_SEARCH_FS_IGNORE,
+ -1,
+ -1,
+ NULL,
+ NULL,
+ system_symbol_found,
+ shell,
+ NULL);
+}
+
static void
on_style_button_clicked(GtkWidget* button, AnjutaPreferences* prefs)
{
@@ -50,12 +158,27 @@ on_style_button_clicked(GtkWidget* button, AnjutaPreferences* prefs)
static gboolean
activate_plugin (AnjutaPlugin *plugin)
{
+ IAnjutaSymbolManager *manager = anjuta_shell_get_interface (plugin->shell, IAnjutaSymbolManager, NULL);
+
+ /* Get notified when scan end, to update type list */
+ g_signal_connect (G_OBJECT (manager), "prj_scan_end", G_CALLBACK (on_project_symbol_scanned), plugin->shell);
+ g_signal_connect (G_OBJECT (manager), "sys_scan_end", G_CALLBACK (on_system_symbol_scanned), plugin->shell);
+
+ /* Initialize type list */
+ on_project_symbol_scanned (manager, 0, plugin->shell);
+ on_system_symbol_scanned (manager, 0, plugin->shell);
+
return TRUE;
}
static gboolean
deactivate_plugin (AnjutaPlugin *plugin)
{
+ IAnjutaSymbolManager *manager = anjuta_shell_get_interface (plugin->shell, IAnjutaSymbolManager, NULL);
+
+ /* Disconnect signals */
+ g_signal_handlers_disconnect_by_func (G_OBJECT (manager), G_CALLBACK (on_project_symbol_scanned), plugin->shell);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (manager), G_CALLBACK (on_system_symbol_scanned), plugin->shell);
return TRUE;
}
diff --git a/plugins/scintilla/plugin.h b/plugins/scintilla/plugin.h
index 1781e1c..ec16fde 100644
--- a/plugins/scintilla/plugin.h
+++ b/plugins/scintilla/plugin.h
@@ -34,10 +34,14 @@ typedef struct _EditorPluginClass EditorPluginClass;
struct _EditorPlugin{
AnjutaPlugin parent;
-
+
GtkWidget* style_button;
};
struct _EditorPluginClass{
AnjutaPluginClass parent_class;
};
+
+/* Up to date list of type names, used by scintilla for highlighting */
+#define TEXT_EDITOR_SYSTEM_TYPE_LIST "editor_system_type_list"
+#define TEXT_EDITOR_PROJECT_TYPE_LIST "editor_project_type_list"
diff --git a/plugins/scintilla/text_editor.c b/plugins/scintilla/text_editor.c
index a0408e6..1402b49 100644
--- a/plugins/scintilla/text_editor.c
+++ b/plugins/scintilla/text_editor.c
@@ -32,6 +32,7 @@
#include <gdk/gdk.h>
#include <errno.h>
+#include "plugin.h"
#include <libanjuta/resources.h>
#include <libanjuta/anjuta-utils.h>
#include <libanjuta/anjuta-encodings.h>
@@ -111,8 +112,7 @@ static GHashTable *supported_languages_by_lexer = NULL;
static void text_editor_finalize (GObject *obj);
static void text_editor_dispose (GObject *obj);
-static void text_editor_hilite_one (TextEditor * te, AnEditorID editor,
- gboolean force);
+static void text_editor_hilite_one (TextEditor * te, AnEditorID editor);
static GtkVBoxClass *parent_class;
@@ -127,6 +127,7 @@ text_editor_instance_init (TextEditor *te)
te->monitor = NULL;
te->preferences = NULL;
te->force_hilite = NULL;
+ te->force_pref = FALSE;
te->freeze_count = 0;
te->current_line = 0;
te->popup_menu = NULL;
@@ -259,7 +260,7 @@ text_editor_add_view (TextEditor *te)
G_CALLBACK (on_text_editor_scintilla_focus_in), te);
initialize_markers (te, scintilla);
- text_editor_hilite_one (te, editor_id, FALSE);
+ text_editor_hilite_one (te, editor_id);
text_editor_set_line_number_width (te);
if (current_line)
@@ -510,6 +511,19 @@ text_editor_update_monitor (TextEditor *te, gboolean disable_it)
}
}
+static void
+on_shell_value_changed (TextEditor *te, const char *name)
+{
+ g_return_if_fail (name != NULL);
+
+ if ((strcmp (name, TEXT_EDITOR_PROJECT_TYPE_LIST) == 0) ||
+ (strcmp (name, TEXT_EDITOR_SYSTEM_TYPE_LIST) == 0))
+ {
+ /* Type names list has changed, so refresh highlight */
+ text_editor_hilite (te, te->force_pref);
+ }
+}
+
GtkWidget *
text_editor_new (AnjutaStatus *status, AnjutaPreferences *eo, AnjutaShell *shell, const gchar *uri, const gchar *name)
{
@@ -562,6 +576,10 @@ text_editor_new (AnjutaStatus *status, AnjutaPreferences *eo, AnjutaShell *shell
zoom_factor = anjuta_preferences_get_int (te->preferences, TEXT_ZOOM_FACTOR);
/* DEBUG_PRINT ("%s", "Initializing zoom factor to: %d", zoom_factor); */
text_editor_set_zoom_factor (te, zoom_factor);
+
+ /* Get type name notification */
+ g_signal_connect_swapped (G_OBJECT (shell), "value-added", G_CALLBACK (on_shell_value_changed), te);
+ g_signal_connect_swapped (G_OBJECT (shell), "value-removed", G_CALLBACK (on_shell_value_changed), te);
#ifdef DEBUG
g_object_weak_ref (G_OBJECT (te), on_te_already_destroyed, te);
@@ -573,6 +591,10 @@ void
text_editor_dispose (GObject *obj)
{
TextEditor *te = TEXT_EDITOR (obj);
+
+ /* Disconnect signal */
+ g_signal_handlers_disconnect_by_func (te->shell, G_CALLBACK (on_shell_value_changed), te);
+
if (te->monitor)
{
text_editor_update_monitor (te, TRUE);
@@ -669,111 +691,70 @@ text_editor_set_hilite_type (TextEditor * te, const gchar *file_extension)
}
static void
-text_editor_hilite_one (TextEditor * te, AnEditorID editor_id,
- gboolean override_by_pref)
+text_editor_hilite_one (TextEditor * te, AnEditorID editor_id)
{
- /* If syntax highlighting is disabled ... */
- if (override_by_pref &&
- anjuta_preferences_get_bool (ANJUTA_PREFERENCES (te->preferences),
+ const gchar *name = NULL;
+ gchar *basename = NULL;
+
+ /* syntax highlighting is disabled if te->force_pref && pref is disabled */
+ if (!te->force_pref ||
+ !anjuta_preferences_get_bool (ANJUTA_PREFERENCES (te->preferences),
DISABLE_SYNTAX_HILIGHTING))
{
- aneditor_command (editor_id, ANE_SETHILITE, (glong) "plain.txt", 0);
- }
- else if (te->force_hilite)
- {
- aneditor_command (editor_id, ANE_SETHILITE, (glong) te->force_hilite, 0);
- }
- else if (te->uri)
- {
- gchar *basename, *typedef_hl[2];
- basename = g_path_get_basename (te->uri);
- text_editor_get_typedef_hl (te, typedef_hl);
- aneditor_command (editor_id, ANE_SETHILITE, (glong) basename, (glong) typedef_hl);
- if (typedef_hl[0] != NULL)
- g_free (typedef_hl[0]);
- if (typedef_hl[1] != NULL)
- g_free (typedef_hl[1]);
- g_free (basename);
+ if (te->force_hilite)
+ {
+ name = te->force_hilite;
+ }
+ else if (te->uri)
+ {
+ basename = g_path_get_basename (te->uri);
+ name = basename;
+ }
+ else if (te->filename)
+ {
+ name = te->filename;
+ }
}
- else if (te->filename)
+
+ if (name == NULL)
{
- aneditor_command (editor_id, ANE_SETHILITE, (glong) te->filename, 0);
+ /* No syntax higlight */
+ aneditor_command (editor_id, ANE_SETHILITE, (glong) "plain.txt", (glong) 0);
}
else
{
- aneditor_command (editor_id, ANE_SETHILITE, (glong) "plain.txt", 0);
- }
+ const gchar *typedef_hl[2];
+ GValue sys_value = {0,};
+ GValue prj_value = {0,};
+
+ anjuta_shell_get_value (te->shell, TEXT_EDITOR_SYSTEM_TYPE_LIST, &sys_value, NULL);
+ typedef_hl[0] = G_VALUE_HOLDS_STRING(&sys_value) ? g_value_get_string (&sys_value) : NULL;
+
+ anjuta_shell_get_value (te->shell, TEXT_EDITOR_PROJECT_TYPE_LIST, &prj_value, NULL);
+ typedef_hl[1] = G_VALUE_HOLDS_STRING(&prj_value) ? g_value_get_string (&prj_value) : NULL;
+
+ aneditor_command (editor_id, ANE_SETHILITE, (glong) name, (glong) typedef_hl);
+ if (G_IS_VALUE (&sys_value)) g_value_unset (&sys_value);
+ if (G_IS_VALUE (&prj_value)) g_value_unset (&prj_value);
+ }
+ g_free (basename);
}
void
text_editor_hilite (TextEditor * te, gboolean override_by_pref)
{
GList *node;
-
+
+ te->force_pref = override_by_pref;
node = te->views;
while (node)
{
- text_editor_hilite_one (te, GPOINTER_TO_INT (node->data),
- override_by_pref);
+ text_editor_hilite_one (te, GPOINTER_TO_INT (node->data));
node = g_list_next (node);
}
}
void
-text_editor_get_typedef_hl (TextEditor * te, gchar **typedef_hl)
-{
- IAnjutaSymbolManager *manager = anjuta_shell_get_interface (te->shell,
- IAnjutaSymbolManager, NULL);
- IAnjutaIterable *iter;
-
- /* Get global typedefs */
- iter = ianjuta_symbol_manager_search (manager, IANJUTA_SYMBOL_TYPE_TYPEDEF,
- TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,
- NULL, TRUE, TRUE, TRUE, -1, -1, NULL);
- if (iter)
- {
- ianjuta_iterable_first (iter, NULL);
- if (ianjuta_iterable_get_length (iter, NULL) > 0)
- {
- GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
- do {
- IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
- const gchar *sname = ianjuta_symbol_get_name (symbol, NULL);
- g_string_append(s, sname);
- g_string_append_c(s, ' ');
- } while (ianjuta_iterable_next (iter, NULL));
- typedef_hl[0] = g_string_free(s, FALSE);
- }
- g_object_unref (iter);
- }
- else
- typedef_hl[0] = NULL;
-
- /* Get local typedefs */
- iter = ianjuta_symbol_manager_search (manager, IANJUTA_SYMBOL_TYPE_TYPEDEF,
- TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,
- NULL, TRUE, TRUE, FALSE, -1, -1, NULL);
- if (iter)
- {
- ianjuta_iterable_first (iter, NULL);
- if (ianjuta_iterable_get_length (iter, NULL) > 0)
- {
- GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
- do {
- IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
- const gchar *sname = ianjuta_symbol_get_name (symbol, NULL);
- g_string_append(s, sname);
- g_string_append_c(s, ' ');
- } while (ianjuta_iterable_next (iter, NULL));
- typedef_hl[1] = g_string_free(s, FALSE);
- }
- g_object_unref (iter);
- }
- else
- typedef_hl[1] = NULL;
-}
-
-void
text_editor_set_zoom_factor (TextEditor * te, gint zfac)
{
text_editor_command (te, ANE_SETZOOM, zfac, 0);
diff --git a/plugins/scintilla/text_editor.h b/plugins/scintilla/text_editor.h
index 1339f2f..3b4dc16 100644
--- a/plugins/scintilla/text_editor.h
+++ b/plugins/scintilla/text_editor.h
@@ -68,7 +68,8 @@ struct _TextEditor
/* File extension that will be used to force hilite type */
gchar *force_hilite;
-
+ gboolean force_pref;
+
glong current_line;
AnjutaPreferences *preferences;
@@ -150,12 +151,6 @@ void text_editor_set_hilite_type (TextEditor * te, const gchar *file_extension);
void text_editor_hilite (TextEditor *te, gboolean force);
/*
- * Get list of global (in typedef_hl[0]) and local (in typedef_hl[1]) type
- * names
- */
-void text_editor_get_typedef_hl (TextEditor * te, gchar **typedef_hl);
-
-/*
* Set the zoom factor. Zoom factor basically increases or decreases the
* text font size by a factor of (2*zfac)
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]