~ubuntu-branches/debian/stretch/gnome-builder/stretch

« back to all changes in this revision

Viewing changes to libide/ide-highlighter.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2015-10-11 12:38:45 UTC
  • Revision ID: package-import@ubuntu.com-20151011123845-a0hvkz01se0p1p5a
Tags: upstream-3.16.3
ImportĀ upstreamĀ versionĀ 3.16.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ide-highlighter.c
 
2
 *
 
3
 * Copyright (C) 2015 Christian Hergert <christian@hergert.me>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
#include <glib/gi18n.h>
 
19
 
 
20
#include "ide-highlighter.h"
 
21
#include "ide-internal.h"
 
22
 
 
23
typedef struct
 
24
{
 
25
  IdeHighlightEngine *engine;
 
26
} IdeHighlighterPrivate;
 
27
 
 
28
enum {
 
29
  PROP_0,
 
30
  PROP_HIGHLIGHT_ENGINE,
 
31
  LAST_PROP
 
32
};
 
33
 
 
34
static GParamSpec *gParamSpecs [LAST_PROP];
 
35
 
 
36
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (IdeHighlighter, ide_highlighter, IDE_TYPE_OBJECT)
 
37
 
 
38
/**
 
39
 * ide_highlighter_get_highlight_engine:
 
40
 * @self: A #IdeHighlighter.
 
41
 *
 
42
 * Gets the IdeHighlightEngine property.
 
43
 *
 
44
 * Returns: (transfer none): An #IdeHighlightEngine.
 
45
 */
 
46
IdeHighlightEngine *
 
47
ide_highlighter_get_highlight_engine (IdeHighlighter *self)
 
48
{
 
49
  IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
 
50
 
 
51
  g_return_val_if_fail (IDE_IS_HIGHLIGHTER (self), NULL);
 
52
 
 
53
  return priv->engine;
 
54
}
 
55
 
 
56
 
 
57
static void
 
58
ide_highlighter_get_property (GObject    *object,
 
59
                              guint       prop_id,
 
60
                              GValue     *value,
 
61
                              GParamSpec *pspec)
 
62
{
 
63
  IdeHighlighter *self = IDE_HIGHLIGHTER (object);
 
64
 
 
65
  switch (prop_id)
 
66
    {
 
67
    case PROP_HIGHLIGHT_ENGINE:
 
68
      g_value_set_object (value, ide_highlighter_get_highlight_engine (self));
 
69
      break;
 
70
 
 
71
    default:
 
72
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
73
    }
 
74
}
 
75
 
 
76
static void
 
77
ide_highlighter_dispose (GObject *object)
 
78
{
 
79
  IdeHighlighter *self = (IdeHighlighter *)object;
 
80
  IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
 
81
 
 
82
  ide_clear_weak_pointer (&priv->engine);
 
83
 
 
84
  G_OBJECT_CLASS (ide_highlighter_parent_class)->dispose (object);
 
85
}
 
86
 
 
87
static void
 
88
ide_highlighter_class_init (IdeHighlighterClass *klass)
 
89
{
 
90
 
 
91
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
92
 
 
93
  object_class->dispose = ide_highlighter_dispose;
 
94
  object_class->get_property = ide_highlighter_get_property;
 
95
 
 
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));
 
102
 
 
103
  g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 
104
}
 
105
 
 
106
static void
 
107
ide_highlighter_init (IdeHighlighter *self)
 
108
{
 
109
}
 
110
 
 
111
void
 
112
_ide_highlighter_set_highlighter_engine (IdeHighlighter     *self,
 
113
                                         IdeHighlightEngine *engine)
 
114
{
 
115
  IdeHighlighterPrivate *priv = ide_highlighter_get_instance_private (self);
 
116
 
 
117
  g_return_if_fail (IDE_IS_HIGHLIGHTER (self));
 
118
  g_return_if_fail (IDE_IS_HIGHLIGHT_ENGINE (engine));
 
119
 
 
120
  if (ide_set_weak_pointer (&priv->engine, engine))
 
121
    g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_HIGHLIGHT_ENGINE]);
 
122
}
 
123
 
 
124
/**
 
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.
 
131
 *
 
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.
 
135
 *
 
136
 * If processing the entire range was successful, then @location should be set
 
137
 * to @range_end.
 
138
 */
 
139
void
 
140
ide_highlighter_update (IdeHighlighter       *self,
 
141
                        IdeHighlightCallback  callback,
 
142
                        const GtkTextIter    *range_begin,
 
143
                        const GtkTextIter    *range_end,
 
144
                        GtkTextIter          *location)
 
145
{
 
146
  g_return_if_fail (IDE_IS_HIGHLIGHTER (self));
 
147
  g_return_if_fail (range_begin);
 
148
  g_return_if_fail (range_end);
 
149
 
 
150
  if (IDE_HIGHLIGHTER_GET_CLASS (self)->update)
 
151
    IDE_HIGHLIGHTER_GET_CLASS (self)->update (self, callback, range_begin, range_end, location);
 
152
}