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/>.
19
#include "ide-indenter.h"
21
G_DEFINE_ABSTRACT_TYPE (IdeIndenter, ide_indenter, IDE_TYPE_OBJECT)
24
ide_indenter_class_init (IdeIndenterClass *klass)
29
ide_indenter_init (IdeIndenter *self)
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.
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.
47
* @cursor_offset may be set to jump the cursor starting from @end. Negative
50
* Returns: (transfer full): A string containing the replacement text, or %NULL.
53
ide_indenter_format (IdeIndenter *self,
54
GtkTextView *text_view,
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);
67
if (IDE_INDENTER_GET_CLASS (self)->format)
68
return IDE_INDENTER_GET_CLASS (self)->format (self,
79
* ide_indenter_is_trigger:
80
* @self: an #IdeIndenter
81
* @event: a #GdkEventKey
83
* Determines if @event should trigger an indentation request. If %TRUE is
84
* returned then ide_indenter_format() will be called.
86
* Returns: %TRUE if @event should trigger an indentation request.
89
ide_indenter_is_trigger (IdeIndenter *self,
92
g_return_val_if_fail (IDE_IS_INDENTER (self), FALSE);
93
g_return_val_if_fail (event, FALSE);
95
if (IDE_INDENTER_GET_CLASS (self)->is_trigger)
96
return IDE_INDENTER_GET_CLASS (self)->is_trigger (self, event);