3
* Copyright (C) 2015 Christian Hergert <christian@hergert.me>
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include <glib/gi18n.h>
20
#include "ide-highlighter.h"
21
#include "ide-internal.h"
25
IdeHighlightEngine *engine;
26
} IdeHighlighterPrivate;
30
PROP_HIGHLIGHT_ENGINE,
34
static GParamSpec *gParamSpecs [LAST_PROP];
36
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (IdeHighlighter, ide_highlighter, IDE_TYPE_OBJECT)
39
* ide_highlighter_get_highlight_engine:
40
* @self: A #IdeHighlighter.
42
* Gets the IdeHighlightEngine property.
44
* Returns: (transfer none): An #IdeHighlightEngine.
47
ide_highlighter_get_highlight_engine (IdeHighlighter *self)
49
IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
51
g_return_val_if_fail (IDE_IS_HIGHLIGHTER (self), NULL);
58
ide_highlighter_get_property (GObject *object,
63
IdeHighlighter *self = IDE_HIGHLIGHTER (object);
67
case PROP_HIGHLIGHT_ENGINE:
68
g_value_set_object (value, ide_highlighter_get_highlight_engine (self));
72
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
77
ide_highlighter_dispose (GObject *object)
79
IdeHighlighter *self = (IdeHighlighter *)object;
80
IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
82
ide_clear_weak_pointer (&priv->engine);
84
G_OBJECT_CLASS (ide_highlighter_parent_class)->dispose (object);
88
ide_highlighter_class_init (IdeHighlighterClass *klass)
91
GObjectClass *object_class = G_OBJECT_CLASS (klass);
93
object_class->dispose = ide_highlighter_dispose;
94
object_class->get_property = ide_highlighter_get_property;
96
gParamSpecs [PROP_HIGHLIGHT_ENGINE] =
97
g_param_spec_object ("highlight-engine",
98
_("Highlight engine"),
99
_("The highlight engine of this highlighter."),
100
IDE_TYPE_HIGHLIGHT_ENGINE,
101
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
103
g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
107
ide_highlighter_init (IdeHighlighter *self)
112
_ide_highlighter_set_highlighter_engine (IdeHighlighter *self,
113
IdeHighlightEngine *engine)
115
IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
117
g_return_if_fail (IDE_IS_HIGHLIGHTER (self));
118
g_return_if_fail (IDE_IS_HIGHLIGHT_ENGINE (engine));
120
if (ide_set_weak_pointer (&priv->engine, engine))
121
g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_HIGHLIGHT_ENGINE]);
125
* ide_highlighter_update:
126
* @self: A #IdeHighlighter.
127
* @callback: (scope call): A callback to apply a given style.
128
* @range_begin: The beginning of the range to update.
129
* @range_end: The end of the range to update.
130
* @location: (out): How far the highlighter got in the update.
132
* Incrementally processes more of the buffer for highlighting. If @callback
133
* returns %IDE_HIGHLIGHT_STOP, then this vfunc should stop processing and
134
* return, having set @location to the current position of processing.
136
* If processing the entire range was successful, then @location should be set
140
ide_highlighter_update (IdeHighlighter *self,
141
IdeHighlightCallback callback,
142
const GtkTextIter *range_begin,
143
const GtkTextIter *range_end,
144
GtkTextIter *location)
146
g_return_if_fail (IDE_IS_HIGHLIGHTER (self));
147
g_return_if_fail (range_begin);
148
g_return_if_fail (range_end);
150
if (IDE_HIGHLIGHTER_GET_CLASS (self)->update)
151
IDE_HIGHLIGHTER_GET_CLASS (self)->update (self, callback, range_begin, range_end, location);