1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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 Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gsv.SourceUndoManagerT;
26 
27 public  import gobject.Signals;
28 public  import gsvc.gsv;
29 public  import gsvc.gsvtypes;
30 public  import gtkc.gdktypes;
31 public  import std.algorithm;
32 
33 
34 /** */
35 public template SourceUndoManagerT(TStruct)
36 {
37 	/** Get the main Gtk struct */
38 	public GtkSourceUndoManager* getSourceUndoManagerStruct()
39 	{
40 		return cast(GtkSourceUndoManager*)getStruct();
41 	}
42 
43 
44 	/**
45 	 * Begin a not undoable action on the buffer. All changes between this call
46 	 * and the call to gtk_source_undo_manager_end_not_undoable_action() cannot
47 	 * be undone. This function should be re-entrant.
48 	 *
49 	 * Since: 2.10
50 	 */
51 	public void beginNotUndoableAction()
52 	{
53 		gtk_source_undo_manager_begin_not_undoable_action(getSourceUndoManagerStruct());
54 	}
55 
56 	/**
57 	 * Get whether there are redo operations available.
58 	 *
59 	 * Return: %TRUE if there are redo operations available, %FALSE otherwise
60 	 *
61 	 * Since: 2.10
62 	 */
63 	public bool canRedo()
64 	{
65 		return gtk_source_undo_manager_can_redo(getSourceUndoManagerStruct()) != 0;
66 	}
67 
68 	/**
69 	 * Emits the #GtkSourceUndoManager::can-redo-changed signal.
70 	 *
71 	 * Since: 2.10
72 	 */
73 	public void canRedoChanged()
74 	{
75 		gtk_source_undo_manager_can_redo_changed(getSourceUndoManagerStruct());
76 	}
77 
78 	/**
79 	 * Get whether there are undo operations available.
80 	 *
81 	 * Return: %TRUE if there are undo operations available, %FALSE otherwise
82 	 *
83 	 * Since: 2.10
84 	 */
85 	public bool canUndo()
86 	{
87 		return gtk_source_undo_manager_can_undo(getSourceUndoManagerStruct()) != 0;
88 	}
89 
90 	/**
91 	 * Emits the #GtkSourceUndoManager::can-undo-changed signal.
92 	 *
93 	 * Since: 2.10
94 	 */
95 	public void canUndoChanged()
96 	{
97 		gtk_source_undo_manager_can_undo_changed(getSourceUndoManagerStruct());
98 	}
99 
100 	/**
101 	 * Ends a not undoable action on the buffer.
102 	 *
103 	 * Since: 2.10
104 	 */
105 	public void endNotUndoableAction()
106 	{
107 		gtk_source_undo_manager_end_not_undoable_action(getSourceUndoManagerStruct());
108 	}
109 
110 	/**
111 	 * Perform a single redo. Calling this function when there are no redo operations
112 	 * available is an error. Use gtk_source_undo_manager_can_redo() to find out
113 	 * if there are redo operations available.
114 	 *
115 	 * Since: 2.10
116 	 */
117 	public void redo()
118 	{
119 		gtk_source_undo_manager_redo(getSourceUndoManagerStruct());
120 	}
121 
122 	/**
123 	 * Perform a single undo. Calling this function when there are no undo operations
124 	 * available is an error. Use gtk_source_undo_manager_can_undo() to find out
125 	 * if there are undo operations available.
126 	 *
127 	 * Since: 2.10
128 	 */
129 	public void undo()
130 	{
131 		gtk_source_undo_manager_undo(getSourceUndoManagerStruct());
132 	}
133 
134 	protected class OnCanRedoChangedDelegateWrapper
135 	{
136 		void delegate(SourceUndoManagerIF) dlg;
137 		gulong handlerId;
138 		ConnectFlags flags;
139 		this(void delegate(SourceUndoManagerIF) dlg, gulong handlerId, ConnectFlags flags)
140 		{
141 			this.dlg = dlg;
142 			this.handlerId = handlerId;
143 			this.flags = flags;
144 		}
145 	}
146 	protected OnCanRedoChangedDelegateWrapper[] onCanRedoChangedListeners;
147 
148 	/**
149 	 * Emitted when the ability to redo has changed.
150 	 *
151 	 * Since: 2.10
152 	 */
153 	gulong addOnCanRedoChanged(void delegate(SourceUndoManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
154 	{
155 		onCanRedoChangedListeners ~= new OnCanRedoChangedDelegateWrapper(dlg, 0, connectFlags);
156 		onCanRedoChangedListeners[onCanRedoChangedListeners.length - 1].handlerId = Signals.connectData(
157 			this,
158 			"can-redo-changed",
159 			cast(GCallback)&callBackCanRedoChanged,
160 			cast(void*)onCanRedoChangedListeners[onCanRedoChangedListeners.length - 1],
161 			cast(GClosureNotify)&callBackCanRedoChangedDestroy,
162 			connectFlags);
163 		return onCanRedoChangedListeners[onCanRedoChangedListeners.length - 1].handlerId;
164 	}
165 	
166 	extern(C) static void callBackCanRedoChanged(GtkSourceUndoManager* sourceundomanagerStruct,OnCanRedoChangedDelegateWrapper wrapper)
167 	{
168 		wrapper.dlg(wrapper.outer);
169 	}
170 	
171 	extern(C) static void callBackCanRedoChangedDestroy(OnCanRedoChangedDelegateWrapper wrapper, GClosure* closure)
172 	{
173 		wrapper.outer.internalRemoveOnCanRedoChanged(wrapper);
174 	}
175 
176 	protected void internalRemoveOnCanRedoChanged(OnCanRedoChangedDelegateWrapper source)
177 	{
178 		foreach(index, wrapper; onCanRedoChangedListeners)
179 		{
180 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
181 			{
182 				onCanRedoChangedListeners[index] = null;
183 				onCanRedoChangedListeners = std.algorithm.remove(onCanRedoChangedListeners, index);
184 				break;
185 			}
186 		}
187 	}
188 	
189 
190 	protected class OnCanUndoChangedDelegateWrapper
191 	{
192 		void delegate(SourceUndoManagerIF) dlg;
193 		gulong handlerId;
194 		ConnectFlags flags;
195 		this(void delegate(SourceUndoManagerIF) dlg, gulong handlerId, ConnectFlags flags)
196 		{
197 			this.dlg = dlg;
198 			this.handlerId = handlerId;
199 			this.flags = flags;
200 		}
201 	}
202 	protected OnCanUndoChangedDelegateWrapper[] onCanUndoChangedListeners;
203 
204 	/**
205 	 * Emitted when the ability to undo has changed.
206 	 *
207 	 * Since: 2.10
208 	 */
209 	gulong addOnCanUndoChanged(void delegate(SourceUndoManagerIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
210 	{
211 		onCanUndoChangedListeners ~= new OnCanUndoChangedDelegateWrapper(dlg, 0, connectFlags);
212 		onCanUndoChangedListeners[onCanUndoChangedListeners.length - 1].handlerId = Signals.connectData(
213 			this,
214 			"can-undo-changed",
215 			cast(GCallback)&callBackCanUndoChanged,
216 			cast(void*)onCanUndoChangedListeners[onCanUndoChangedListeners.length - 1],
217 			cast(GClosureNotify)&callBackCanUndoChangedDestroy,
218 			connectFlags);
219 		return onCanUndoChangedListeners[onCanUndoChangedListeners.length - 1].handlerId;
220 	}
221 	
222 	extern(C) static void callBackCanUndoChanged(GtkSourceUndoManager* sourceundomanagerStruct,OnCanUndoChangedDelegateWrapper wrapper)
223 	{
224 		wrapper.dlg(wrapper.outer);
225 	}
226 	
227 	extern(C) static void callBackCanUndoChangedDestroy(OnCanUndoChangedDelegateWrapper wrapper, GClosure* closure)
228 	{
229 		wrapper.outer.internalRemoveOnCanUndoChanged(wrapper);
230 	}
231 
232 	protected void internalRemoveOnCanUndoChanged(OnCanUndoChangedDelegateWrapper source)
233 	{
234 		foreach(index, wrapper; onCanUndoChangedListeners)
235 		{
236 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
237 			{
238 				onCanUndoChangedListeners[index] = null;
239 				onCanUndoChangedListeners = std.algorithm.remove(onCanUndoChangedListeners, index);
240 				break;
241 			}
242 		}
243 	}
244 	
245 }