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.SourceCompletion;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.ListG;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gsv.SourceCompletionContext;
33 private import gsv.SourceCompletionInfo;
34 private import gsv.SourceCompletionProviderIF;
35 private import gsv.SourceView;
36 private import gsv.c.functions;
37 public  import gsv.c.types;
38 public  import gsvc.gsvtypes;
39 private import gtk.BuildableIF;
40 private import gtk.BuildableT;
41 private import gtk.TextIter;
42 private import std.algorithm;
43 
44 
45 /** */
46 public class SourceCompletion : ObjectG, BuildableIF
47 {
48 	/** the main Gtk struct */
49 	protected GtkSourceCompletion* gtkSourceCompletion;
50 
51 	/** Get the main Gtk struct */
52 	public GtkSourceCompletion* getSourceCompletionStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return gtkSourceCompletion;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected override void* getStruct()
61 	{
62 		return cast(void*)gtkSourceCompletion;
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (GtkSourceCompletion* gtkSourceCompletion, bool ownedRef = false)
69 	{
70 		this.gtkSourceCompletion = gtkSourceCompletion;
71 		super(cast(GObject*)gtkSourceCompletion, ownedRef);
72 	}
73 
74 	// add the Buildable capabilities
75 	mixin BuildableT!(GtkSourceCompletion);
76 
77 
78 	/** */
79 	public static GType getType()
80 	{
81 		return gtk_source_completion_get_type();
82 	}
83 
84 	/**
85 	 * Add a new #GtkSourceCompletionProvider to the completion object. This will
86 	 * add a reference @provider, so make sure to unref your own copy when you
87 	 * no longer need it.
88 	 *
89 	 * Params:
90 	 *     provider = a #GtkSourceCompletionProvider.
91 	 *
92 	 * Returns: %TRUE if @provider was successfully added, otherwise if @error
93 	 *     is provided, it will be set with the error and %FALSE is returned.
94 	 *
95 	 * Throws: GException on failure.
96 	 */
97 	public bool addProvider(SourceCompletionProviderIF provider)
98 	{
99 		GError* err = null;
100 
101 		auto p = gtk_source_completion_add_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0;
102 
103 		if (err !is null)
104 		{
105 			throw new GException( new ErrorG(err) );
106 		}
107 
108 		return p;
109 	}
110 
111 	/**
112 	 * Block interactive completion. This can be used to disable interactive
113 	 * completion when inserting or deleting text from the buffer associated with
114 	 * the completion. Use gtk_source_completion_unblock_interactive() to enable
115 	 * interactive completion again.
116 	 *
117 	 * This function may be called multiple times. It will continue to block
118 	 * interactive completion until gtk_source_completion_unblock_interactive()
119 	 * has been called the same number of times.
120 	 */
121 	public void blockInteractive()
122 	{
123 		gtk_source_completion_block_interactive(gtkSourceCompletion);
124 	}
125 
126 	/**
127 	 * Create a new #GtkSourceCompletionContext for @completion. The position where
128 	 * the completion occurs can be specified by @position. If @position is %NULL,
129 	 * the current cursor position will be used.
130 	 *
131 	 * Params:
132 	 *     position = a #GtkTextIter, or %NULL.
133 	 *
134 	 * Returns: a new #GtkSourceCompletionContext.
135 	 *     The reference being returned is a 'floating' reference,
136 	 *     so if you invoke gtk_source_completion_start() with this context
137 	 *     you don't need to unref it.
138 	 */
139 	public SourceCompletionContext createContext(TextIter position)
140 	{
141 		auto p = gtk_source_completion_create_context(gtkSourceCompletion, (position is null) ? null : position.getTextIterStruct());
142 
143 		if(p is null)
144 		{
145 			return null;
146 		}
147 
148 		return ObjectG.getDObject!(SourceCompletionContext)(cast(GtkSourceCompletionContext*) p);
149 	}
150 
151 	/**
152 	 * The info widget is the window where the completion displays optional extra
153 	 * information of the proposal.
154 	 *
155 	 * Returns: The #GtkSourceCompletionInfo window
156 	 *     associated with @completion.
157 	 */
158 	public SourceCompletionInfo getInfoWindow()
159 	{
160 		auto p = gtk_source_completion_get_info_window(gtkSourceCompletion);
161 
162 		if(p is null)
163 		{
164 			return null;
165 		}
166 
167 		return ObjectG.getDObject!(SourceCompletionInfo)(cast(GtkSourceCompletionInfo*) p);
168 	}
169 
170 	/**
171 	 * Get list of providers registered on @completion. The returned list is owned
172 	 * by the completion and should not be freed.
173 	 *
174 	 * Returns: list of #GtkSourceCompletionProvider.
175 	 */
176 	public ListG getProviders()
177 	{
178 		auto p = gtk_source_completion_get_providers(gtkSourceCompletion);
179 
180 		if(p is null)
181 		{
182 			return null;
183 		}
184 
185 		return new ListG(cast(GList*) p);
186 	}
187 
188 	/**
189 	 * The #GtkSourceView associated with @completion, or %NULL if the view has been
190 	 * destroyed.
191 	 *
192 	 * Returns: The #GtkSourceView associated with
193 	 *     @completion, or %NULL.
194 	 */
195 	public SourceView getView()
196 	{
197 		auto p = gtk_source_completion_get_view(gtkSourceCompletion);
198 
199 		if(p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(SourceView)(cast(GtkSourceView*) p);
205 	}
206 
207 	/**
208 	 * Hides the completion if it is active (visible).
209 	 */
210 	public void hide()
211 	{
212 		gtk_source_completion_hide(gtkSourceCompletion);
213 	}
214 
215 	/**
216 	 * Remove @provider from the completion.
217 	 *
218 	 * Params:
219 	 *     provider = a #GtkSourceCompletionProvider.
220 	 *
221 	 * Returns: %TRUE if @provider was successfully removed, otherwise if @error
222 	 *     is provided, it will be set with the error and %FALSE is returned.
223 	 *
224 	 * Throws: GException on failure.
225 	 */
226 	public bool removeProvider(SourceCompletionProviderIF provider)
227 	{
228 		GError* err = null;
229 
230 		auto p = gtk_source_completion_remove_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0;
231 
232 		if (err !is null)
233 		{
234 			throw new GException( new ErrorG(err) );
235 		}
236 
237 		return p;
238 	}
239 
240 	/**
241 	 * Starts a new completion with the specified #GtkSourceCompletionContext and
242 	 * a list of potential candidate providers for completion.
243 	 *
244 	 * It can be convenient for showing a completion on-the-fly, without the need to
245 	 * add or remove providers to the #GtkSourceCompletion.
246 	 *
247 	 * Another solution is to add providers with
248 	 * gtk_source_completion_add_provider(), and implement
249 	 * gtk_source_completion_provider_match() for each provider.
250 	 *
251 	 * Params:
252 	 *     providers = a list of #GtkSourceCompletionProvider, or %NULL.
253 	 *     context = The #GtkSourceCompletionContext
254 	 *         with which to start the completion.
255 	 *
256 	 * Returns: %TRUE if it was possible to the show completion window.
257 	 */
258 	public bool start(ListG providers, SourceCompletionContext context)
259 	{
260 		return gtk_source_completion_start(gtkSourceCompletion, (providers is null) ? null : providers.getListGStruct(), (context is null) ? null : context.getSourceCompletionContextStruct()) != 0;
261 	}
262 
263 	/**
264 	 * Unblock interactive completion. This can be used after using
265 	 * gtk_source_completion_block_interactive() to enable interactive completion
266 	 * again.
267 	 */
268 	public void unblockInteractive()
269 	{
270 		gtk_source_completion_unblock_interactive(gtkSourceCompletion);
271 	}
272 
273 	/**
274 	 * The #GtkSourceCompletion::activate-proposal signal is a
275 	 * keybinding signal which gets emitted when the user initiates
276 	 * a proposal activation.
277 	 *
278 	 * Applications should not connect to it, but may emit it with
279 	 * g_signal_emit_by_name() if they need to control the proposal
280 	 * activation programmatically.
281 	 */
282 	gulong addOnActivateProposal(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
283 	{
284 		return Signals.connect(this, "activate-proposal", dlg, connectFlags ^ ConnectFlags.SWAPPED);
285 	}
286 
287 	/**
288 	 * Emitted when the completion window is hidden. The default handler
289 	 * will actually hide the window.
290 	 */
291 	gulong addOnHide(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
292 	{
293 		return Signals.connect(this, "hide", dlg, connectFlags ^ ConnectFlags.SWAPPED);
294 	}
295 
296 	/**
297 	 * The #GtkSourceCompletion::move-cursor signal is a keybinding
298 	 * signal which gets emitted when the user initiates a cursor
299 	 * movement.
300 	 *
301 	 * The <keycap>Up</keycap>, <keycap>Down</keycap>,
302 	 * <keycap>PageUp</keycap>, <keycap>PageDown</keycap>,
303 	 * <keycap>Home</keycap> and <keycap>End</keycap> keys are bound to the
304 	 * normal behavior expected by those keys.
305 	 *
306 	 * When @step is equal to %GTK_SCROLL_PAGES, the page size is defined by
307 	 * the #GtkSourceCompletion:proposal-page-size property. It is used for
308 	 * the <keycap>PageDown</keycap> and <keycap>PageUp</keycap> keys.
309 	 *
310 	 * Applications should not connect to it, but may emit it with
311 	 * g_signal_emit_by_name() if they need to control the cursor
312 	 * programmatically.
313 	 *
314 	 * Params:
315 	 *     step = The #GtkScrollStep by which to move the cursor
316 	 *     num = The amount of steps to move the cursor
317 	 */
318 	gulong addOnMoveCursor(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
319 	{
320 		return Signals.connect(this, "move-cursor", dlg, connectFlags ^ ConnectFlags.SWAPPED);
321 	}
322 
323 	/**
324 	 * The #GtkSourceCompletion::move-page signal is a keybinding
325 	 * signal which gets emitted when the user initiates a page
326 	 * movement (i.e. switches between provider pages).
327 	 *
328 	 * <keycombo><keycap>Control</keycap><keycap>Left</keycap></keycombo>
329 	 * is for going to the previous provider.
330 	 * <keycombo><keycap>Control</keycap><keycap>Right</keycap></keycombo>
331 	 * is for going to the next provider.
332 	 * <keycombo><keycap>Control</keycap><keycap>Home</keycap></keycombo>
333 	 * is for displaying all the providers.
334 	 * <keycombo><keycap>Control</keycap><keycap>End</keycap></keycombo>
335 	 * is for going to the last provider.
336 	 *
337 	 * When @step is equal to #GTK_SCROLL_PAGES, the page size is defined by
338 	 * the #GtkSourceCompletion:provider-page-size property.
339 	 *
340 	 * Applications should not connect to it, but may emit it with
341 	 * g_signal_emit_by_name() if they need to control the page selection
342 	 * programmatically.
343 	 *
344 	 * Params:
345 	 *     step = The #GtkScrollStep by which to move the page
346 	 *     num = The amount of steps to move the page
347 	 */
348 	gulong addOnMovePage(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
349 	{
350 		return Signals.connect(this, "move-page", dlg, connectFlags ^ ConnectFlags.SWAPPED);
351 	}
352 
353 	/**
354 	 * Emitted just before starting to populate the completion with providers.
355 	 * You can use this signal to add additional attributes in the context.
356 	 *
357 	 * Params:
358 	 *     context = The #GtkSourceCompletionContext for the current completion
359 	 */
360 	gulong addOnPopulateContext(void delegate(SourceCompletionContext, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
361 	{
362 		return Signals.connect(this, "populate-context", dlg, connectFlags ^ ConnectFlags.SWAPPED);
363 	}
364 
365 	/**
366 	 * Emitted when the completion window is shown. The default handler
367 	 * will actually show the window.
368 	 */
369 	gulong addOnShow(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
370 	{
371 		return Signals.connect(this, "show", dlg, connectFlags ^ ConnectFlags.SWAPPED);
372 	}
373 }