[gnome-builder] highlighter: Expose IdeHighlightEngine to IdeHighlighter.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] highlighter: Expose IdeHighlightEngine to IdeHighlighter.
- Date: Mon, 11 May 2015 21:11:28 +0000 (UTC)
commit fe8f4c26407f84bfbfefa2e04adf824e69e14f76
Author: Dimitris Zenios <dimitris zenios gmail com>
Date: Mon May 11 21:05:49 2015 +0300
highlighter: Expose IdeHighlightEngine to IdeHighlighter.
This allow the IdeHighlight to get a hold of the IdeBuffer property in order
to do direct highlighting instead of going through update function.An example
of such situation is when we want to highlight matching xml tags
libide/ide-highlight-engine.c | 47 ++++++-----
libide/ide-highlight-engine.h | 2 +
libide/ide-highlighter.c | 142 ++++++++++++++++++++++++++++++++-
libide/ide-highlighter.h | 23 +++---
libide/ide-internal.h | 181 +++++++++++++++++++++--------------------
libide/ide-types.h | 2 +
6 files changed, 275 insertions(+), 122 deletions(-)
---
diff --git a/libide/ide-highlight-engine.c b/libide/ide-highlight-engine.c
index 4e7d374..7ae3b94 100644
--- a/libide/ide-highlight-engine.c
+++ b/libide/ide-highlight-engine.c
@@ -23,6 +23,7 @@
#include "ide-debug.h"
#include "ide-highlight-engine.h"
#include "ide-types.h"
+#include "ide-internal.h"
#define HIGHLIGHT_QUANTA_USEC 2000
#define WORK_TIMEOUT_MSEC 50
@@ -145,27 +146,6 @@ create_tag_from_style (IdeHighlightEngine *self,
return tag;
}
-static GtkTextTag *
-get_style_tag (IdeHighlightEngine *self,
- const gchar *style_name)
-{
- GtkTextTagTable *tag_table;
- GtkTextTag *tag;
-
- g_assert (IDE_IS_HIGHLIGHT_ENGINE (self));
- g_assert (style_name != NULL);
-
- tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (self->buffer));
- tag = gtk_text_tag_table_lookup (tag_table, style_name);
-
- if (tag == NULL)
- {
- tag = create_tag_from_style (self, style_name);
- self->tags = g_list_prepend (self->tags, tag);
- }
-
- return tag;
-}
static IdeHighlightResult
ide_highlight_engine_apply_style (const GtkTextIter *begin,
@@ -178,7 +158,7 @@ ide_highlight_engine_apply_style (const GtkTextIter *begin,
buffer = gtk_text_iter_get_buffer (begin);
self = g_object_get_qdata (G_OBJECT (buffer), gEngineQuark);
- tag = get_style_tag (self, style_name);
+ tag = ide_highlight_engine_get_style (self, style_name);
gtk_text_buffer_apply_tag (buffer, tag, begin, end);
@@ -682,6 +662,7 @@ ide_highlight_engine_set_highlighter (IdeHighlightEngine *self,
if (g_set_object (&self->highlighter, highlighter))
{
+ _ide_highlighter_set_highlighter_engine (highlighter, self);
ide_highlight_engine_reload (self);
g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_HIGHLIGHTER]);
}
@@ -780,3 +761,25 @@ ide_highlight_engine_invalidate (IdeHighlightEngine *self,
IDE_EXIT;
}
+
+GtkTextTag *
+ide_highlight_engine_get_style (IdeHighlightEngine *self,
+ const gchar *style_name)
+{
+ GtkTextTagTable *tag_table;
+ GtkTextTag *tag;
+
+ g_return_val_if_fail (IDE_IS_HIGHLIGHT_ENGINE (self), NULL);
+ g_return_val_if_fail (style_name != NULL, NULL);
+
+ tag_table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (self->buffer));
+ tag = gtk_text_tag_table_lookup (tag_table, style_name);
+
+ if (tag == NULL)
+ {
+ tag = create_tag_from_style (self, style_name);
+ self->tags = g_list_prepend (self->tags, tag);
+ }
+
+ return tag;
+}
diff --git a/libide/ide-highlight-engine.h b/libide/ide-highlight-engine.h
index ad5349e..5f85c32 100644
--- a/libide/ide-highlight-engine.h
+++ b/libide/ide-highlight-engine.h
@@ -37,6 +37,8 @@ void ide_highlight_engine_rebuild (IdeHighlightEngine *se
void ide_highlight_engine_invalidate (IdeHighlightEngine *self,
const GtkTextIter *begin,
const GtkTextIter *end);
+GtkTextTag *ide_highlight_engine_get_style (IdeHighlightEngine *self,
+ const gchar *style_name);
G_END_DECLS
diff --git a/libide/ide-highlighter.c b/libide/ide-highlighter.c
index edbfd63..4ab74b6 100644
--- a/libide/ide-highlighter.c
+++ b/libide/ide-highlighter.c
@@ -15,14 +15,147 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <glib/gi18n.h>
#include "ide-highlighter.h"
+#include "ide-internal.h"
+
+typedef struct
+{
+ IdeHighlightEngine *engine;
+} IdeHighlighterPrivate;
+
+enum {
+ PROP_0,
+ PROP_HIGHLIGHT_ENGINE,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (IdeHighlighter, ide_highlighter, IDE_TYPE_OBJECT)
+
+
+static void
+ide_highlighter_set_highlight_engine (IdeHighlighter *self,
+ IdeHighlightEngine *engine)
+{
+ IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_HIGHLIGHTER (self));
+ g_return_if_fail (IDE_IS_HIGHLIGHT_ENGINE (engine));
+
+ if (priv->engine != engine)
+ {
+ if (priv->engine != NULL)
+ ide_clear_weak_pointer (&priv->engine);
+
+ if (engine != NULL)
+ ide_set_weak_pointer (&priv->engine, engine);
+
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_HIGHLIGHT_ENGINE]);
+ }
+}
+
+/**
+ * ide_highlighter_get_highlight_engine:
+ * @self: A #IdeHighlighter.
+ *
+ * Gets the IdeHighlightEngine property.
+ *
+ * Returns: (transfer none): An #IdeHighlightEngine.
+ */
+IdeHighlightEngine *
+ide_highlighter_get_highlight_engine (IdeHighlighter *self)
+{
+ IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_HIGHLIGHTER (self), NULL);
+
+ return priv->engine;
+}
-G_DEFINE_ABSTRACT_TYPE (IdeHighlighter, ide_highlighter, IDE_TYPE_OBJECT)
+
+static void
+ide_highlighter_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeHighlighter *self = IDE_HIGHLIGHTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_HIGHLIGHT_ENGINE:
+ g_value_set_object (value, ide_highlighter_get_highlight_engine (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_highlighter_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeHighlighter *self = IDE_HIGHLIGHTER (object);
+
+ switch (prop_id)
+ {
+ case PROP_HIGHLIGHT_ENGINE:
+ ide_highlighter_set_highlight_engine (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_highlighter_dispose (GObject *object)
+{
+ IdeHighlighter *self = (IdeHighlighter *)object;
+
+ ide_highlighter_set_highlight_engine (self, NULL);
+
+ G_OBJECT_CLASS (ide_highlighter_parent_class)->dispose (object);
+}
+
+static void
+ide_highlighter_finalize (GObject *object)
+{
+ IdeHighlighter *self = (IdeHighlighter *)object;
+ IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
+
+ ide_clear_weak_pointer (&priv->engine);
+
+ G_OBJECT_CLASS (ide_highlighter_parent_class)->finalize (object);
+}
static void
ide_highlighter_class_init (IdeHighlighterClass *klass)
{
+
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = ide_highlighter_dispose;
+ object_class->finalize = ide_highlighter_finalize;
+ object_class->get_property = ide_highlighter_get_property;
+ object_class->set_property = ide_highlighter_set_property;
+
+ gParamSpecs [PROP_HIGHLIGHT_ENGINE] =
+ g_param_spec_object ("highlight-engine",
+ _("Highlight engine"),
+ _("The highlight engine of this highlighter."),
+ IDE_TYPE_HIGHLIGHT_ENGINE,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
+
}
static void
@@ -30,6 +163,13 @@ ide_highlighter_init (IdeHighlighter *self)
{
}
+void
+_ide_highlighter_set_highlighter_engine (IdeHighlighter *self,
+ IdeHighlightEngine *engine)
+{
+ ide_highlighter_set_highlight_engine (self, engine);
+}
+
/**
* ide_highlighter_update:
* @self: A #IdeHighlighter.
diff --git a/libide/ide-highlighter.h b/libide/ide-highlighter.h
index 4734fc5..599faab 100644
--- a/libide/ide-highlighter.h
+++ b/libide/ide-highlighter.h
@@ -24,6 +24,7 @@
#include "ide-buffer.h"
#include "ide-object.h"
#include "ide-source-view.h"
+#include "ide-types.h"
G_BEGIN_DECLS
@@ -58,18 +59,20 @@ struct _IdeHighlighterClass
* @location should be set to the position that the highlighter got to
* before yielding back to the engine.
*/
- void (*update) (IdeHighlighter *self,
- IdeHighlightCallback callback,
- const GtkTextIter *range_begin,
- const GtkTextIter *range_end,
- GtkTextIter *location);
+ void (*update) (IdeHighlighter *self,
+ IdeHighlightCallback callback,
+ const GtkTextIter *range_begin,
+ const GtkTextIter *range_end,
+ GtkTextIter *location);
};
-void ide_highlighter_update (IdeHighlighter *self,
- IdeHighlightCallback callback,
- const GtkTextIter *range_begin,
- const GtkTextIter *range_end,
- GtkTextIter *location);
+void ide_highlighter_update (IdeHighlighter *self,
+ IdeHighlightCallback callback,
+ const GtkTextIter *range_begin,
+ const GtkTextIter *range_end,
+ GtkTextIter *location);
+
+IdeHighlightEngine *ide_highlighter_get_highlight_engine (IdeHighlighter *self);
G_END_DECLS
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index a3b275c..d26b179 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -31,98 +31,101 @@
#include "ide-source-view.h"
#include "ide-source-view-mode.h"
#include "ide-symbol.h"
+#include "ide-highlight-engine.h"
G_BEGIN_DECLS
-void _ide_back_forward_list_load_async (IdeBackForwardList *self,
- GFile *file,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean _ide_back_forward_list_load_finish (IdeBackForwardList *self,
- GAsyncResult *result,
- GError **error);
-void _ide_back_forward_list_save_async (IdeBackForwardList *self,
- GFile *file,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean _ide_back_forward_list_save_finish (IdeBackForwardList *self,
- GAsyncResult *result,
- GError **error);
-IdeBackForwardItem *_ide_back_forward_list_find (IdeBackForwardList *self,
- IdeFile *file);
-void _ide_battery_monitor_init (void);
-void _ide_battery_monitor_shutdown (void);
-void _ide_buffer_set_changed_on_volume (IdeBuffer *self,
- gboolean changed_on_volume);
-gboolean _ide_buffer_get_loading (IdeBuffer *self);
-void _ide_buffer_set_loading (IdeBuffer *self,
- gboolean loading);
-void _ide_buffer_set_mtime (IdeBuffer *self,
- const GTimeVal *mtime);
-void _ide_buffer_set_read_only (IdeBuffer *buffer,
- gboolean read_only);
-void _ide_buffer_manager_reclaim (IdeBufferManager *self,
- IdeBuffer *buffer);
-void _ide_build_system_set_project_file (IdeBuildSystem *self,
- GFile *project_file);
-gboolean _ide_context_is_restoring (IdeContext *self);
-void _ide_diagnostic_add_range (IdeDiagnostic *self,
- IdeSourceRange *range);
-IdeDiagnostic *_ide_diagnostic_new (IdeDiagnosticSeverity severity,
- const gchar *text,
- IdeSourceLocation *location);
-void _ide_diagnostic_take_fixit (IdeDiagnostic *diagnostic,
- IdeFixit *fixit);
-void _ide_diagnostic_take_range (IdeDiagnostic *self,
- IdeSourceRange *range);
-void _ide_diagnostician_add_provider (IdeDiagnostician *self,
- IdeDiagnosticProvider *provider);
-void _ide_diagnostician_remove_provider (IdeDiagnostician *self,
- IdeDiagnosticProvider *provider);
-IdeDiagnostics *_ide_diagnostics_new (GPtrArray *ar);
-const gchar *_ide_file_get_content_type (IdeFile *self);
-GtkSourceFile *_ide_file_set_content_type (IdeFile *self,
- const gchar *content_type);
-GtkSourceFile *_ide_file_get_source_file (IdeFile *self);
-void _ide_file_settings_add_child (IdeFileSettings *self,
- IdeFileSettings *child);
-IdeFixit *_ide_fixit_new (IdeSourceRange *source_range,
- const gchar *replacement_text);
-void _ide_project_set_name (IdeProject *project,
- const gchar *name);
-void _ide_search_context_add_provider (IdeSearchContext *context,
- IdeSearchProvider *provider,
- gsize max_results);
-IdeSettings *_ide_settings_new (IdeContext *context,
- const gchar *schema_id,
- const gchar *relative_path,
- gboolean ignore_project_settings);
-IdeSourceRange *_ide_source_range_new (IdeSourceLocation *begin,
- IdeSourceLocation *end);
-GtkTextMark *_ide_source_view_get_scroll_mark (IdeSourceView *self);
-gboolean _ide_source_view_mode_do_event (IdeSourceViewMode *mode,
- GdkEventKey *event,
- gboolean *remove);
-IdeSourceViewMode *_ide_source_view_mode_new (GtkWidget *view,
- const char *mode,
- IdeSourceViewModeType type);
-void _ide_source_view_set_count (IdeSourceView *self,
- guint count);
-void _ide_source_view_set_modifier (IdeSourceView *self,
- gunichar modifier);
-IdeSymbol *_ide_symbol_new (const gchar *name,
- IdeSymbolKind kind,
- IdeSymbolFlags flags,
- IdeSourceLocation *declaration_location,
- IdeSourceLocation *definition_location,
- IdeSourceLocation *canonical_location);
-void _ide_thread_pool_init (void);
-IdeUnsavedFile *_ide_unsaved_file_new (GFile *file,
- GBytes *content,
- const gchar *temp_path,
- gint64 sequence);
+void _ide_back_forward_list_load_async (IdeBackForwardList *self,
+ GFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean _ide_back_forward_list_load_finish (IdeBackForwardList *self,
+ GAsyncResult *result,
+ GError **error);
+void _ide_back_forward_list_save_async (IdeBackForwardList *self,
+ GFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean _ide_back_forward_list_save_finish (IdeBackForwardList *self,
+ GAsyncResult *result,
+ GError **error);
+IdeBackForwardItem *_ide_back_forward_list_find (IdeBackForwardList *self,
+ IdeFile *file);
+void _ide_battery_monitor_init (void);
+void _ide_battery_monitor_shutdown (void);
+void _ide_buffer_set_changed_on_volume (IdeBuffer *self,
+ gboolean changed_on_volume);
+gboolean _ide_buffer_get_loading (IdeBuffer *self);
+void _ide_buffer_set_loading (IdeBuffer *self,
+ gboolean loading);
+void _ide_buffer_set_mtime (IdeBuffer *self,
+ const GTimeVal *mtime);
+void _ide_buffer_set_read_only (IdeBuffer *buffer,
+ gboolean read_only);
+void _ide_buffer_manager_reclaim (IdeBufferManager *self,
+ IdeBuffer *buffer);
+void _ide_build_system_set_project_file (IdeBuildSystem *self,
+ GFile *project_file);
+gboolean _ide_context_is_restoring (IdeContext *self);
+void _ide_diagnostic_add_range (IdeDiagnostic *self,
+ IdeSourceRange *range);
+IdeDiagnostic *_ide_diagnostic_new (IdeDiagnosticSeverity severity,
+ const gchar *text,
+ IdeSourceLocation *location);
+void _ide_diagnostic_take_fixit (IdeDiagnostic *diagnostic,
+ IdeFixit *fixit);
+void _ide_diagnostic_take_range (IdeDiagnostic *self,
+ IdeSourceRange *range);
+void _ide_diagnostician_add_provider (IdeDiagnostician *self,
+ IdeDiagnosticProvider *provider);
+void _ide_diagnostician_remove_provider (IdeDiagnostician *self,
+ IdeDiagnosticProvider *provider);
+IdeDiagnostics *_ide_diagnostics_new (GPtrArray *ar);
+const gchar *_ide_file_get_content_type (IdeFile *self);
+GtkSourceFile *_ide_file_set_content_type (IdeFile *self,
+ const gchar *content_type);
+GtkSourceFile *_ide_file_get_source_file (IdeFile *self);
+void _ide_file_settings_add_child (IdeFileSettings *self,
+ IdeFileSettings *child);
+IdeFixit *_ide_fixit_new (IdeSourceRange *source_range,
+ const gchar *replacement_text);
+void _ide_project_set_name (IdeProject *project,
+ const gchar *name);
+void _ide_search_context_add_provider (IdeSearchContext *context,
+ IdeSearchProvider *provider,
+ gsize max_results);
+IdeSettings *_ide_settings_new (IdeContext *context,
+ const gchar *schema_id,
+ const gchar *relative_path,
+ gboolean ignore_project_settings);
+IdeSourceRange *_ide_source_range_new (IdeSourceLocation *begin,
+ IdeSourceLocation *end);
+GtkTextMark *_ide_source_view_get_scroll_mark (IdeSourceView *self);
+gboolean _ide_source_view_mode_do_event (IdeSourceViewMode *mode,
+ GdkEventKey *event,
+ gboolean *remove);
+IdeSourceViewMode *_ide_source_view_mode_new (GtkWidget *view,
+ const char *mode,
+ IdeSourceViewModeType type);
+void _ide_source_view_set_count (IdeSourceView *self,
+ guint count);
+void _ide_source_view_set_modifier (IdeSourceView *self,
+ gunichar modifier);
+IdeSymbol *_ide_symbol_new (const gchar *name,
+ IdeSymbolKind kind,
+ IdeSymbolFlags flags,
+ IdeSourceLocation *declaration_location,
+ IdeSourceLocation *definition_location,
+ IdeSourceLocation *canonical_location);
+void _ide_thread_pool_init (void);
+IdeUnsavedFile *_ide_unsaved_file_new (GFile *file,
+ GBytes *content,
+ const gchar *temp_path,
+ gint64 sequence);
+void _ide_highlighter_set_highlighter_engine (IdeHighlighter *highlighter,
+ IdeHighlightEngine *highlight_engine);
G_END_DECLS
diff --git a/libide/ide-types.h b/libide/ide-types.h
index 16869e7..43ce39a 100644
--- a/libide/ide-types.h
+++ b/libide/ide-types.h
@@ -148,6 +148,8 @@ typedef struct _IdeUnsavedFile IdeUnsavedFile;
typedef struct _IdeVcs IdeVcs;
+typedef struct _IdeHighlightEngine IdeHighlightEngine;
+
G_END_DECLS
#endif /* IDE_TYPES_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]