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

« back to all changes in this revision

Viewing changes to libide/ide-indenter.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-indenter.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
 
 
19
#include "ide-indenter.h"
 
20
 
 
21
G_DEFINE_ABSTRACT_TYPE (IdeIndenter, ide_indenter, IDE_TYPE_OBJECT)
 
22
 
 
23
static void
 
24
ide_indenter_class_init (IdeIndenterClass *klass)
 
25
{
 
26
}
 
27
 
 
28
static void
 
29
ide_indenter_init (IdeIndenter *self)
 
30
{
 
31
}
 
32
 
 
33
/**
 
34
 * ide_indenter_format:
 
35
 * @text_view: A #GtkTextView
 
36
 * @begin: A #GtkTextIter for the beginning region of text to replace.
 
37
 * @end: A #GtkTextIter for the end region of text to replace.
 
38
 * @cursor_offset: The offset in characters from @end to place the cursor.
 
39
 *   Negative values are okay.
 
40
 * @event: The #GdkEventKey that triggered the event.
 
41
 *
 
42
 * This function performs an indentation for the key press activated by @event.
 
43
 * The implementation is free to move the @begin and @end iters to swallow
 
44
 * adjacent content. The result, a string, is the contents that will replace
 
45
 * the content inbetween @begin and @end.
 
46
 *
 
47
 * @cursor_offset may be set to jump the cursor starting from @end. Negative
 
48
 * values are allowed.
 
49
 *
 
50
 * Returns: (transfer full): A string containing the replacement text, or %NULL.
 
51
 */
 
52
gchar *
 
53
ide_indenter_format (IdeIndenter *self,
 
54
                     GtkTextView *text_view,
 
55
                     GtkTextIter *begin,
 
56
                     GtkTextIter *end,
 
57
                     gint        *cursor_offset,
 
58
                     GdkEventKey *event)
 
59
{
 
60
  g_return_val_if_fail (IDE_IS_INDENTER (self), NULL);
 
61
  g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
 
62
  g_return_val_if_fail (begin, NULL);
 
63
  g_return_val_if_fail (end, NULL);
 
64
  g_return_val_if_fail (cursor_offset, NULL);
 
65
  g_return_val_if_fail (event, NULL);
 
66
 
 
67
  if (IDE_INDENTER_GET_CLASS (self)->format)
 
68
    return IDE_INDENTER_GET_CLASS (self)->format (self,
 
69
                                                  text_view,
 
70
                                                  begin,
 
71
                                                  end,
 
72
                                                  cursor_offset,
 
73
                                                  event);
 
74
 
 
75
  return NULL;
 
76
}
 
77
 
 
78
/**
 
79
 * ide_indenter_is_trigger:
 
80
 * @self: an #IdeIndenter
 
81
 * @event: a #GdkEventKey
 
82
 *
 
83
 * Determines if @event should trigger an indentation request. If %TRUE is
 
84
 * returned then ide_indenter_format() will be called.
 
85
 *
 
86
 * Returns: %TRUE if @event should trigger an indentation request.
 
87
 */
 
88
gboolean
 
89
ide_indenter_is_trigger (IdeIndenter *self,
 
90
                         GdkEventKey *event)
 
91
{
 
92
  g_return_val_if_fail (IDE_IS_INDENTER (self), FALSE);
 
93
  g_return_val_if_fail (event, FALSE);
 
94
 
 
95
  if (IDE_INDENTER_GET_CLASS (self)->is_trigger)
 
96
    return IDE_INDENTER_GET_CLASS (self)->is_trigger (self, event);
 
97
 
 
98
  return FALSE;
 
99
}