File: gtksourceundomanager.c

package info (click to toggle)
libgedit-gtksourceview 299.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 7,536 kB
  • sloc: ansic: 48,501; xml: 2,620; perl: 206; sh: 51; yacc: 45; makefile: 35; cobol: 20; objc: 19; javascript: 16; fortran: 14; python: 13; cpp: 8; ml: 3
file content (283 lines) | stat: -rw-r--r-- 7,738 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * This file is part of GtkSourceView
 *
 * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
 * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
 * Copyright (C) 2002-2005  Paolo Maggi
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>
#include <stdlib.h>
#include <string.h>

#include "gtksourceundomanager.h"

/**
 * SECTION:undomanager
 * @short_description: Undo manager interface for GtkSourceView
 * @title: GtkSourceUndoManager
 * @see_also: #GtkTextBuffer, #GtkSourceView
 *
 * For most uses it isn't needed to use #GtkSourceUndoManager. #GtkSourceBuffer
 * already provides an API and a default implementation for the undo/redo.
 *
 * For specific needs, the #GtkSourceUndoManager interface can be implemented to
 * provide custom undo management. Use gtk_source_buffer_set_undo_manager() to
 * install a custom undo manager for a particular #GtkSourceBuffer.
 *
 * Use gtk_source_undo_manager_can_undo_changed() and
 * gtk_source_undo_manager_can_redo_changed() when respectively the undo state
 * or redo state of the undo stack has changed.
 *
 * Since: 2.10
 */

enum
{
	CAN_UNDO_CHANGED,
	CAN_REDO_CHANGED,
	N_SIGNALS
};

static guint signals[N_SIGNALS];

typedef GtkSourceUndoManagerIface GtkSourceUndoManagerInterface;

G_DEFINE_INTERFACE (GtkSourceUndoManager, gtk_source_undo_manager, G_TYPE_OBJECT)

static gboolean
gtk_source_undo_manager_can_undo_default (GtkSourceUndoManager *manager)
{
	return FALSE;
}

static gboolean
gtk_source_undo_manager_can_redo_default (GtkSourceUndoManager *manager)
{
	return FALSE;
}

static void
gtk_source_undo_manager_undo_default (GtkSourceUndoManager *manager)
{
}

static void
gtk_source_undo_manager_redo_default (GtkSourceUndoManager *manager)
{
}

static void
gtk_source_undo_manager_begin_not_undoable_action_default (GtkSourceUndoManager *manager)
{
}

static void
gtk_source_undo_manager_end_not_undoable_action_default (GtkSourceUndoManager *manager)
{
}

static void
gtk_source_undo_manager_default_init (GtkSourceUndoManagerIface *iface)
{
	iface->can_undo = gtk_source_undo_manager_can_undo_default;
	iface->can_redo = gtk_source_undo_manager_can_redo_default;

	iface->undo = gtk_source_undo_manager_undo_default;
	iface->redo = gtk_source_undo_manager_redo_default;

	iface->begin_not_undoable_action = gtk_source_undo_manager_begin_not_undoable_action_default;
	iface->end_not_undoable_action = gtk_source_undo_manager_end_not_undoable_action_default;

	/**
	 * GtkSourceUndoManager::can-undo-changed:
	 * @manager: The #GtkSourceUndoManager
	 *
	 * Emitted when the ability to undo has changed.
	 *
	 * Since: 2.10
	 *
	 */
	signals[CAN_UNDO_CHANGED] =
		g_signal_new ("can-undo-changed",
			      G_TYPE_FROM_INTERFACE (iface),
			      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
			      G_STRUCT_OFFSET (GtkSourceUndoManagerIface, can_undo_changed),
			      NULL, NULL, NULL,
			      G_TYPE_NONE,
			      0);

	/**
	 * GtkSourceUndoManager::can-redo-changed:
	 * @manager: The #GtkSourceUndoManager
	 *
	 * Emitted when the ability to redo has changed.
	 *
	 * Since: 2.10
	 *
	 */
	signals[CAN_REDO_CHANGED] =
		g_signal_new ("can-redo-changed",
			      G_TYPE_FROM_INTERFACE (iface),
			      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
			      G_STRUCT_OFFSET (GtkSourceUndoManagerIface, can_redo_changed),
			      NULL, NULL, NULL,
			      G_TYPE_NONE,
			      0);
}

/**
 * gtk_source_undo_manager_can_undo:
 * @manager: a #GtkSourceUndoManager.
 *
 * Get whether there are undo operations available.
 *
 * Returns: %TRUE if there are undo operations available, %FALSE otherwise
 *
 * Since: 2.10
 */
gboolean
gtk_source_undo_manager_can_undo (GtkSourceUndoManager *manager)
{
	g_return_val_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager), FALSE);

	return GTK_SOURCE_UNDO_MANAGER_GET_INTERFACE (manager)->can_undo (manager);
}

/**
 * gtk_source_undo_manager_can_redo:
 * @manager: a #GtkSourceUndoManager.
 *
 * Get whether there are redo operations available.
 *
 * Returns: %TRUE if there are redo operations available, %FALSE otherwise
 *
 * Since: 2.10
 */
gboolean
gtk_source_undo_manager_can_redo (GtkSourceUndoManager *manager)
{
	g_return_val_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager), FALSE);

	return GTK_SOURCE_UNDO_MANAGER_GET_INTERFACE (manager)->can_redo (manager);
}

/**
 * gtk_source_undo_manager_undo:
 * @manager: a #GtkSourceUndoManager.
 *
 * Perform a single undo. Calling this function when there are no undo operations
 * available is an error. Use gtk_source_undo_manager_can_undo() to find out
 * if there are undo operations available.
 *
 * Since: 2.10
 */
void
gtk_source_undo_manager_undo (GtkSourceUndoManager *manager)
{
	g_return_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager));

	GTK_SOURCE_UNDO_MANAGER_GET_INTERFACE (manager)->undo (manager);
}

/**
 * gtk_source_undo_manager_redo:
 * @manager: a #GtkSourceUndoManager.
 *
 * Perform a single redo. Calling this function when there are no redo operations
 * available is an error. Use gtk_source_undo_manager_can_redo() to find out
 * if there are redo operations available.
 *
 * Since: 2.10
 */
void
gtk_source_undo_manager_redo (GtkSourceUndoManager *manager)
{
	g_return_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager));

	GTK_SOURCE_UNDO_MANAGER_GET_INTERFACE (manager)->redo (manager);
}

/**
 * gtk_source_undo_manager_begin_not_undoable_action:
 * @manager: a #GtkSourceUndoManager.
 *
 * Begin a not undoable action on the buffer. All changes between this call
 * and the call to gtk_source_undo_manager_end_not_undoable_action() cannot
 * be undone. This function should be re-entrant.
 *
 * Since: 2.10
 */
void
gtk_source_undo_manager_begin_not_undoable_action (GtkSourceUndoManager *manager)
{
	g_return_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager));

	GTK_SOURCE_UNDO_MANAGER_GET_INTERFACE (manager)->begin_not_undoable_action (manager);
}

/**
 * gtk_source_undo_manager_end_not_undoable_action:
 * @manager: a #GtkSourceUndoManager.
 *
 * Ends a not undoable action on the buffer.
 *
 * Since: 2.10
 */
void
gtk_source_undo_manager_end_not_undoable_action (GtkSourceUndoManager *manager)
{
	g_return_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager));

	GTK_SOURCE_UNDO_MANAGER_GET_INTERFACE (manager)->end_not_undoable_action (manager);
}

/**
 * gtk_source_undo_manager_can_undo_changed:
 * @manager: a #GtkSourceUndoManager.
 *
 * Emits the #GtkSourceUndoManager::can-undo-changed signal.
 *
 * Since: 2.10
 **/
void
gtk_source_undo_manager_can_undo_changed (GtkSourceUndoManager *manager)
{
	g_return_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager));

	g_signal_emit (manager, signals[CAN_UNDO_CHANGED], 0);
}

/**
 * gtk_source_undo_manager_can_redo_changed:
 * @manager: a #GtkSourceUndoManager.
 *
 * Emits the #GtkSourceUndoManager::can-redo-changed signal.
 *
 * Since: 2.10
 **/
void
gtk_source_undo_manager_can_redo_changed (GtkSourceUndoManager *manager)
{
	g_return_if_fail (GTK_SOURCE_IS_UNDO_MANAGER (manager));

	g_signal_emit (manager, signals[CAN_REDO_CHANGED], 0);
}