[anjuta-extras] scintilla: Refresh syntax highlight after a change



commit ae6ed3d729a3c21851757a78735af1e9e72e2206
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Fri Sep 16 22:04:26 2011 +0200

    scintilla: Refresh syntax highlight after a change

 plugins/scintilla/plugin.c       |   28 +++++++++++++++++++++++-----
 plugins/scintilla/style-editor.c |    7 ++++---
 plugins/scintilla/style-editor.h |    4 +++-
 plugins/scintilla/text_editor.c  |   17 ++++++++++++++---
 plugins/scintilla/text_editor.h  |    3 ++-
 5 files changed, 46 insertions(+), 13 deletions(-)
---
diff --git a/plugins/scintilla/plugin.c b/plugins/scintilla/plugin.c
index c92c8c9..7926c3c 100644
--- a/plugins/scintilla/plugin.c
+++ b/plugins/scintilla/plugin.c
@@ -39,7 +39,16 @@
 #define PREFS_GLADE PACKAGE_DATA_DIR "/glade/anjuta-editor-scintilla.ui"
 #define ICON_FILE "anjuta-editor-scintilla-plugin-48.png"
 
-gpointer parent_class;
+static gpointer parent_class;
+
+/* signals */
+enum
+{
+        STYLE_CHANGED,
+        LAST_SIGNAL
+};
+
+static unsigned int signals[LAST_SIGNAL] = { 0 };
 
 /* Plugin types
  *---------------------------------------------------------------------------*/
@@ -59,6 +68,9 @@ struct _EditorPlugin{
 
 struct _EditorPluginClass{
 	AnjutaPluginClass parent_class;
+
+	/* signals */
+	void (* style_changed)     ();
 };
 
 /* Keep an up to date list of type name
@@ -145,7 +157,7 @@ on_system_symbol_scanned (IAnjutaSymbolManager *manager, guint process, IAnjutaS
 static void 
 on_style_button_clicked(GtkWidget* button, EditorPlugin *plugin)
 {
-	StyleEditor* se = style_editor_new(plugin->prefs, plugin->settings);
+	StyleEditor* se = style_editor_new(ANJUTA_PLUGIN (plugin), plugin->prefs, plugin->settings);
 	style_editor_show(se);
 }
 
@@ -267,6 +279,7 @@ editor_plugin_instance_init (GObject *obj)
 static void
 editor_plugin_class_init (GObjectClass *klass) 
 {
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
 
 	parent_class = g_type_class_peek_parent (klass);
@@ -275,6 +288,13 @@ editor_plugin_class_init (GObjectClass *klass)
 	plugin_class->deactivate = deactivate_plugin;
 	klass->dispose = dispose;
 	klass->finalize = finalize;
+	
+	signals[STYLE_CHANGED] = g_signal_new ("style-changed",
+                                                G_OBJECT_CLASS_TYPE (object_class),
+                                                G_SIGNAL_RUN_FIRST,
+                                                G_STRUCT_OFFSET (EditorPluginClass, style_changed),
+                                                NULL, NULL,
+                                                g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 }
 
 static IAnjutaEditor*
@@ -283,11 +303,9 @@ itext_editor_factory_new_editor(IAnjutaEditorFactory* factory,
 								const gchar* filename, 
 								GError** error)
 {
-	AnjutaShell *shell = ANJUTA_PLUGIN (factory)->shell;
-	AnjutaStatus *status = anjuta_shell_get_status (shell, NULL);
 	/* file can be NULL, if we open a buffer, not a file */
 	gchar* uri = file ? g_file_get_uri (file) : NULL;
-	IAnjutaEditor* editor = IANJUTA_EDITOR(text_editor_new(status,shell,
+	IAnjutaEditor* editor = IANJUTA_EDITOR(text_editor_new(ANJUTA_PLUGIN (factory),
 														   uri, filename));
 	g_free(uri);
 	return editor;
diff --git a/plugins/scintilla/style-editor.c b/plugins/scintilla/style-editor.c
index 44b7542..a68a6ae 100644
--- a/plugins/scintilla/style-editor.c
+++ b/plugins/scintilla/style-editor.c
@@ -849,8 +849,7 @@ apply_styles (StyleEditor *se)
 		fclose (ofile);
 		g_free (filename);
 	}
-	g_settings_set_int (se->settings, DISABLE_SYNTAX_HILIGHTING, 1);
-	g_settings_set_int (se->settings, DISABLE_SYNTAX_HILIGHTING, 0);
+	g_signal_emit_by_name (se->plugin, "style-changed");
 }
 
 static void
@@ -959,7 +958,7 @@ create_style_editor_gui (StyleEditor * se)
 }
 
 StyleEditor *
-style_editor_new (AnjutaPreferences *prefs, GSettings *settings)
+style_editor_new (AnjutaPlugin *plugin, AnjutaPreferences *prefs, GSettings *settings)
 {
 	StyleEditor *se;
 	se = g_new0 (StyleEditor, 1);
@@ -968,6 +967,7 @@ style_editor_new (AnjutaPreferences *prefs, GSettings *settings)
 	se->priv->dialog = NULL;
 	se->prefs = prefs;
 	se->settings = g_object_ref (settings);
+	se->plugin = g_object_ref (plugin);
 	return se;
 }
 
@@ -978,6 +978,7 @@ void style_editor_destroy (StyleEditor *se)
 		gtk_widget_destroy (se->priv->dialog);
 	g_free (se->priv);
 	g_object_unref (se->settings);
+	g_object_unref (se->plugin);
 	g_free (se);
 }
 
diff --git a/plugins/scintilla/style-editor.h b/plugins/scintilla/style-editor.h
index 68a8892..dd18430 100644
--- a/plugins/scintilla/style-editor.h
+++ b/plugins/scintilla/style-editor.h
@@ -24,6 +24,7 @@
 #  include <config.h>
 #endif
 
+#include <libanjuta/anjuta-plugin.h>
 #include <libanjuta/anjuta-preferences.h>
 #include "properties.h"
 
@@ -41,10 +42,11 @@ struct _StyleEditor
 	StyleEditorPriv *priv;
 	AnjutaPreferences *prefs;
 	GSettings *settings;
+	AnjutaPlugin *plugin;
 };
 
 StyleEditor *
-style_editor_new (AnjutaPreferences *prefs, GSettings *settings);
+style_editor_new (AnjutaPlugin *plugin, AnjutaPreferences *prefs, GSettings *settings);
 
 void style_editor_destroy (StyleEditor *se);
 
diff --git a/plugins/scintilla/text_editor.c b/plugins/scintilla/text_editor.c
index c8dfdb5..02340c9 100644
--- a/plugins/scintilla/text_editor.c
+++ b/plugins/scintilla/text_editor.c
@@ -552,12 +552,21 @@ on_shell_value_changed  (TextEditor *te, const char *name)
 	}
 }
 
+static void
+on_style_changed  (TextEditor *te)
+{
+	/* Refresh highlight */
+	text_editor_hilite (te,  te->force_pref);
+}
+
 GtkWidget *
-text_editor_new (AnjutaStatus *status, AnjutaShell *shell, const gchar *uri, const gchar *name)
+text_editor_new (AnjutaPlugin *plugin, const gchar *uri, const gchar *name)
 {
+	AnjutaShell *shell = plugin->shell;
+	AnjutaStatus *status = anjuta_shell_get_status (shell, NULL);
+	TextEditor *te = TEXT_EDITOR (gtk_widget_new (TYPE_TEXT_EDITOR, NULL));
 	gint zoom_factor;
 	static guint new_file_count;
-	TextEditor *te = TEXT_EDITOR (gtk_widget_new (TYPE_TEXT_EDITOR, NULL));
 	
 	te->status = status; 
 	te->shell = shell;
@@ -607,6 +616,8 @@ text_editor_new (AnjutaStatus *status, AnjutaShell *shell, const gchar *uri, con
 	/* 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);
+	g_signal_connect_swapped (G_OBJECT (plugin), "style-changed", G_CALLBACK(on_style_changed), te);
+
 	
 #ifdef DEBUG
 	g_object_weak_ref (G_OBJECT (te), on_te_already_destroyed, te);
@@ -3014,7 +3025,7 @@ marker_ianjuta_to_editor (IAnjutaMarkableMarker marker)
 
 static gint
 imarkable_mark (IAnjutaMarkable* editor, gint location,
-				IAnjutaMarkableMarker marker, GError** e)
+				IAnjutaMarkableMarker marker, const gchar *tooltip, GError** e)
 {
 	return text_editor_set_marker (TEXT_EDITOR (editor), location,
 								   marker_ianjuta_to_editor (marker));
diff --git a/plugins/scintilla/text_editor.h b/plugins/scintilla/text_editor.h
index 27a06c0..98febb5 100644
--- a/plugins/scintilla/text_editor.h
+++ b/plugins/scintilla/text_editor.h
@@ -29,6 +29,7 @@
 
 #include "aneditor.h"
 
+#include <libanjuta/anjuta-plugin.h>
 #include <libanjuta/anjuta-status.h>
 #include <libanjuta/anjuta-encodings.h>
 
@@ -143,7 +144,7 @@ struct _TextEditorClass
 GType text_editor_get_type (void);
 
 /* New instance of TextEditor */
-GtkWidget* text_editor_new (AnjutaStatus *status, AnjutaShell* shell, const gchar *uri,
+GtkWidget* text_editor_new (AnjutaPlugin *plugin, const gchar *uri,
 							const gchar *tab_name);
 
 /* Freeze and thaw editor */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]