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  * Conversion parameters:
26  * inFile  = GtkSourceCompletion.html
27  * outPack = gsv
28  * outFile = SourceCompletion
29  * strct   = GtkSourceCompletion
30  * realStrct=
31  * ctorStrct=
32  * clss    = SourceCompletion
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_source_completion_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.ErrorG
47  * 	- glib.GException
48  * 	- glib.ListG
49  * 	- gsv.SourceCompletionContext
50  * 	- gsv.SourceCompletionInfo
51  * 	- gsv.SourceCompletionProviderIF
52  * 	- gsv.SourceView
53  * 	- gtk.TextIter
54  * structWrap:
55  * 	- GList* -> ListG
56  * 	- GtkSourceCompletionContext* -> SourceCompletionContext
57  * 	- GtkSourceCompletionInfo* -> SourceCompletionInfo
58  * 	- GtkSourceCompletionProvider* -> SourceCompletionProviderIF
59  * 	- GtkSourceView* -> SourceView
60  * 	- GtkTextIter* -> TextIter
61  * module aliases:
62  * local aliases:
63  * overrides:
64  */
65 
66 module gsv.SourceCompletion;
67 
68 public  import gsvc.gsvtypes;
69 
70 private import gsvc.gsv;
71 private import glib.ConstructionException;
72 private import gobject.ObjectG;
73 
74 private import gobject.Signals;
75 public  import gtkc.gdktypes;
76 private import glib.ErrorG;
77 private import glib.GException;
78 private import glib.ListG;
79 private import gsv.SourceCompletionContext;
80 private import gsv.SourceCompletionInfo;
81 private import gsv.SourceCompletionProviderIF;
82 private import gsv.SourceView;
83 private import gtk.TextIter;
84 
85 
86 private import gobject.ObjectG;
87 
88 /**
89  * The completion system helps the user when he writes some text, such
90  * as words, command names, functions, and suchlike. Proposals can be
91  * shown, to complete the text the user is writing. Each proposal can
92  * contain an additional piece of information, that is displayed when
93  * the "Details" button is active.
94  *
95  * Proposals are created via a GtkSourceCompletionProvider. There can
96  * be for example a provider to complete words (see
97  * GtkSourceCompletionWords), another provider for the completion of
98  * function's names, etc. To add a provider, call
99  * gtk_source_completion_add_provider().
100  *
101  * When the completion is activated, a GtkSourceCompletionContext object is
102  * created. The providers are asked whether they match the context, with
103  * gtk_source_completion_provider_match(). If a provider doesn't match the
104  * context, it will not be visible in the completion window. On the
105  * other hand, if the provider matches the context, its proposals will
106  * be displayed.
107  *
108  * When several providers match, they are all shown in the completion
109  * window, but one can switch between providers: see the
110  * "move-page" signal. It is also possible to
111  * activate the first proposals with key bindings, see the
112  * "accelerators" property.
113  *
114  * The GtkSourceCompletionProposal interface represents a proposal.
115  * The GtkSourceCompletionItem class is a simple implementation of this
116  * interface.
117  *
118  * If a proposal contains extra information (see
119  * gtk_source_completion_provider_get_info_widget()), it will be
120  * displayed in a GtkSourceCompletionInfo window, which appears when
121  * the "Details" button is clicked.
122  *
123  * A GtkSourceCompletionInfo window can also be used to display
124  * calltips. When no proposals are available, it can be useful to
125  * display extra information like a function's prototype (number of
126  * parameters, types of parameters, etc).
127  *
128  * Each GtkSourceView object is associated with a GtkSourceCompletion
129  * instance. This instance can be obtained with
130  * gtk_source_view_get_completion(). The GtkSourceView class contains also the
131  * "show-completion" signal.
132  *
133  * A same GtkSourceCompletionProvider object can be used for several
134  * GtkSourceCompletion.
135  */
136 public class SourceCompletion : ObjectG
137 {
138 	
139 	/** the main Gtk struct */
140 	protected GtkSourceCompletion* gtkSourceCompletion;
141 	
142 	
143 	/** Get the main Gtk struct */
144 	public GtkSourceCompletion* getSourceCompletionStruct()
145 	{
146 		return gtkSourceCompletion;
147 	}
148 	
149 	
150 	/** the main Gtk struct as a void* */
151 	protected override void* getStruct()
152 	{
153 		return cast(void*)gtkSourceCompletion;
154 	}
155 	
156 	/**
157 	 * Sets our main struct and passes it to the parent class
158 	 */
159 	public this (GtkSourceCompletion* gtkSourceCompletion)
160 	{
161 		super(cast(GObject*)gtkSourceCompletion);
162 		this.gtkSourceCompletion = gtkSourceCompletion;
163 	}
164 	
165 	protected override void setStruct(GObject* obj)
166 	{
167 		super.setStruct(obj);
168 		gtkSourceCompletion = cast(GtkSourceCompletion*)obj;
169 	}
170 	
171 	/**
172 	 */
173 	int[string] connectedSignals;
174 	
175 	void delegate(SourceCompletion)[] onActivateProposalListeners;
176 	/**
177 	 * The "activate-proposal" signal is a
178 	 * keybinding signal which gets emitted when the user initiates
179 	 * a proposal activation.
180 	 * Applications should not connect to it, but may emit it with
181 	 * g_signal_emit_by_name() if they need to control the proposal
182 	 * activation programmatically.
183 	 */
184 	void addOnActivateProposal(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
185 	{
186 		if ( !("activate-proposal" in connectedSignals) )
187 		{
188 			Signals.connectData(
189 			getStruct(),
190 			"activate-proposal",
191 			cast(GCallback)&callBackActivateProposal,
192 			cast(void*)this,
193 			null,
194 			connectFlags);
195 			connectedSignals["activate-proposal"] = 1;
196 		}
197 		onActivateProposalListeners ~= dlg;
198 	}
199 	extern(C) static void callBackActivateProposal(GtkSourceCompletion* completionStruct, SourceCompletion _sourceCompletion)
200 	{
201 		foreach ( void delegate(SourceCompletion) dlg ; _sourceCompletion.onActivateProposalListeners )
202 		{
203 			dlg(_sourceCompletion);
204 		}
205 	}
206 	
207 	void delegate(SourceCompletion)[] onHideListeners;
208 	/**
209 	 * Emitted when the completion window is hidden. The default handler
210 	 * will actually hide the window.
211 	 */
212 	void addOnHide(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
213 	{
214 		if ( !("hide" in connectedSignals) )
215 		{
216 			Signals.connectData(
217 			getStruct(),
218 			"hide",
219 			cast(GCallback)&callBackHide,
220 			cast(void*)this,
221 			null,
222 			connectFlags);
223 			connectedSignals["hide"] = 1;
224 		}
225 		onHideListeners ~= dlg;
226 	}
227 	extern(C) static void callBackHide(GtkSourceCompletion* completionStruct, SourceCompletion _sourceCompletion)
228 	{
229 		foreach ( void delegate(SourceCompletion) dlg ; _sourceCompletion.onHideListeners )
230 		{
231 			dlg(_sourceCompletion);
232 		}
233 	}
234 	
235 	void delegate(GtkScrollStep, gint, SourceCompletion)[] onMoveCursorListeners;
236 	/**
237 	 * The "move-cursor" signal is a keybinding
238 	 * signal which gets emitted when the user initiates a cursor
239 	 * movement.
240 	 * The Up, Down,
241 	 * PageUp, PageDown,
242 	 * Home and End keys are bound to the
243 	 * normal behavior expected by those keys.
244 	 * When step is equal to GTK_SCROLL_PAGES, the page size is defined by
245 	 * the "proposal-page-size" property. It is used for
246 	 * the PageDown and PageUp keys.
247 	 * Applications should not connect to it, but may emit it with
248 	 * g_signal_emit_by_name() if they need to control the cursor
249 	 * programmatically.
250 	 */
251 	void addOnMoveCursor(void delegate(GtkScrollStep, gint, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
252 	{
253 		if ( !("move-cursor" in connectedSignals) )
254 		{
255 			Signals.connectData(
256 			getStruct(),
257 			"move-cursor",
258 			cast(GCallback)&callBackMoveCursor,
259 			cast(void*)this,
260 			null,
261 			connectFlags);
262 			connectedSignals["move-cursor"] = 1;
263 		}
264 		onMoveCursorListeners ~= dlg;
265 	}
266 	extern(C) static void callBackMoveCursor(GtkSourceCompletion* completionStruct, GtkScrollStep step, gint num, SourceCompletion _sourceCompletion)
267 	{
268 		foreach ( void delegate(GtkScrollStep, gint, SourceCompletion) dlg ; _sourceCompletion.onMoveCursorListeners )
269 		{
270 			dlg(step, num, _sourceCompletion);
271 		}
272 	}
273 	
274 	void delegate(GtkScrollStep, gint, SourceCompletion)[] onMovePageListeners;
275 	/**
276 	 * The "move-page" signal is a keybinding
277 	 * signal which gets emitted when the user initiates a page
278 	 * movement (i.e. switches between provider pages).
279 	 * Control+Left
280 	 * is for going to the previous provider.
281 	 * Control+Right
282 	 * is for going to the next provider.
283 	 * Control+Home
284 	 * is for displaying all the providers.
285 	 * Control+End
286 	 * is for going to the last provider.
287 	 * When step is equal to GTK_SCROLL_PAGES, the page size is defined by
288 	 * the "provider-page-size" property.
289 	 * Applications should not connect to it, but may emit it with
290 	 * g_signal_emit_by_name() if they need to control the page selection
291 	 * programmatically.
292 	 */
293 	void addOnMovePage(void delegate(GtkScrollStep, gint, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
294 	{
295 		if ( !("move-page" in connectedSignals) )
296 		{
297 			Signals.connectData(
298 			getStruct(),
299 			"move-page",
300 			cast(GCallback)&callBackMovePage,
301 			cast(void*)this,
302 			null,
303 			connectFlags);
304 			connectedSignals["move-page"] = 1;
305 		}
306 		onMovePageListeners ~= dlg;
307 	}
308 	extern(C) static void callBackMovePage(GtkSourceCompletion* completionStruct, GtkScrollStep step, gint num, SourceCompletion _sourceCompletion)
309 	{
310 		foreach ( void delegate(GtkScrollStep, gint, SourceCompletion) dlg ; _sourceCompletion.onMovePageListeners )
311 		{
312 			dlg(step, num, _sourceCompletion);
313 		}
314 	}
315 	
316 	void delegate(SourceCompletionContext, SourceCompletion)[] onPopulateContextListeners;
317 	/**
318 	 * Emitted just before starting to populate the completion with providers.
319 	 * You can use this signal to add additional attributes in the context.
320 	 */
321 	void addOnPopulateContext(void delegate(SourceCompletionContext, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
322 	{
323 		if ( !("populate-context" in connectedSignals) )
324 		{
325 			Signals.connectData(
326 			getStruct(),
327 			"populate-context",
328 			cast(GCallback)&callBackPopulateContext,
329 			cast(void*)this,
330 			null,
331 			connectFlags);
332 			connectedSignals["populate-context"] = 1;
333 		}
334 		onPopulateContextListeners ~= dlg;
335 	}
336 	extern(C) static void callBackPopulateContext(GtkSourceCompletion* completionStruct, GtkSourceCompletionContext* context, SourceCompletion _sourceCompletion)
337 	{
338 		foreach ( void delegate(SourceCompletionContext, SourceCompletion) dlg ; _sourceCompletion.onPopulateContextListeners )
339 		{
340 			dlg(ObjectG.getDObject!(SourceCompletionContext)(context), _sourceCompletion);
341 		}
342 	}
343 	
344 	void delegate(SourceCompletion)[] onShowListeners;
345 	/**
346 	 * Emitted when the completion window is shown. The default handler
347 	 * will actually show the window.
348 	 */
349 	void addOnShow(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
350 	{
351 		if ( !("show" in connectedSignals) )
352 		{
353 			Signals.connectData(
354 			getStruct(),
355 			"show",
356 			cast(GCallback)&callBackShow,
357 			cast(void*)this,
358 			null,
359 			connectFlags);
360 			connectedSignals["show"] = 1;
361 		}
362 		onShowListeners ~= dlg;
363 	}
364 	extern(C) static void callBackShow(GtkSourceCompletion* completionStruct, SourceCompletion _sourceCompletion)
365 	{
366 		foreach ( void delegate(SourceCompletion) dlg ; _sourceCompletion.onShowListeners )
367 		{
368 			dlg(_sourceCompletion);
369 		}
370 	}
371 	
372 	
373 	/**
374 	 * Add a new GtkSourceCompletionProvider to the completion object. This will
375 	 * add a reference provider, so make sure to unref your own copy when you
376 	 * no longer need it.
377 	 * Params:
378 	 * provider = a GtkSourceCompletionProvider.
379 	 * Returns: TRUE if provider was successfully added, otherwise if error is provided, it will be set with the error and FALSE is returned.
380 	 * Throws: GException on failure.
381 	 */
382 	public int addProvider(SourceCompletionProviderIF provider)
383 	{
384 		// gboolean gtk_source_completion_add_provider (GtkSourceCompletion *completion,  GtkSourceCompletionProvider *provider,  GError **error);
385 		GError* err = null;
386 		
387 		auto p = gtk_source_completion_add_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderTStruct(), &err);
388 		
389 		if (err !is null)
390 		{
391 			throw new GException( new ErrorG(err) );
392 		}
393 		
394 		return p;
395 	}
396 	
397 	/**
398 	 * Remove provider from the completion.
399 	 * Params:
400 	 * provider = a GtkSourceCompletionProvider.
401 	 * Returns: TRUE if provider was successfully removed, otherwise if error is provided, it will be set with the error and FALSE is returned.
402 	 * Throws: GException on failure.
403 	 */
404 	public int removeProvider(SourceCompletionProviderIF provider)
405 	{
406 		// gboolean gtk_source_completion_remove_provider  (GtkSourceCompletion *completion,  GtkSourceCompletionProvider *provider,  GError **error);
407 		GError* err = null;
408 		
409 		auto p = gtk_source_completion_remove_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderTStruct(), &err);
410 		
411 		if (err !is null)
412 		{
413 			throw new GException( new ErrorG(err) );
414 		}
415 		
416 		return p;
417 	}
418 	
419 	/**
420 	 * Get list of providers registered on completion. The returned list is owned
421 	 * by the completion and should not be freed.
422 	 * Returns: list of GtkSourceCompletionProvider. [element-type GtkSource.CompletionProvider][transfer none]
423 	 */
424 	public ListG getProviders()
425 	{
426 		// GList * gtk_source_completion_get_providers (GtkSourceCompletion *completion);
427 		auto p = gtk_source_completion_get_providers(gtkSourceCompletion);
428 		
429 		if(p is null)
430 		{
431 			return null;
432 		}
433 		
434 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
435 	}
436 	
437 	/**
438 	 * Starts a new completion with the specified GtkSourceCompletionContext and
439 	 * a list of potential candidate providers for completion.
440 	 * It can be convenient for showing a completion on-the-fly, without the need to
441 	 * add or remove providers to the GtkSourceCompletion.
442 	 * Another solution is to add providers with
443 	 * gtk_source_completion_add_provider(), and implement
444 	 * gtk_source_completion_provider_match() for each provider.
445 	 * Params:
446 	 * providers = a list of GtkSourceCompletionProvider, or NULL. [element-type GtkSource.CompletionProvider][allow-none]
447 	 * context = The GtkSourceCompletionContext
448 	 * with which to start the completion. [transfer floating]
449 	 * Returns: TRUE if it was possible to the show completion window.
450 	 */
451 	public int show(ListG providers, SourceCompletionContext context)
452 	{
453 		// gboolean gtk_source_completion_show (GtkSourceCompletion *completion,  GList *providers,  GtkSourceCompletionContext *context);
454 		return gtk_source_completion_show(gtkSourceCompletion, (providers is null) ? null : providers.getListGStruct(), (context is null) ? null : context.getSourceCompletionContextStruct());
455 	}
456 	
457 	/**
458 	 * Hides the completion if it is active (visible).
459 	 */
460 	public void hide()
461 	{
462 		// void gtk_source_completion_hide (GtkSourceCompletion *completion);
463 		gtk_source_completion_hide(gtkSourceCompletion);
464 	}
465 	
466 	/**
467 	 * The info widget is the window where the completion displays optional extra
468 	 * information of the proposal.
469 	 * Returns: The GtkSourceCompletionInfo window associated with completion. [transfer none]
470 	 */
471 	public SourceCompletionInfo getInfoWindow()
472 	{
473 		// GtkSourceCompletionInfo * gtk_source_completion_get_info_window  (GtkSourceCompletion *completion);
474 		auto p = gtk_source_completion_get_info_window(gtkSourceCompletion);
475 		
476 		if(p is null)
477 		{
478 			return null;
479 		}
480 		
481 		return ObjectG.getDObject!(SourceCompletionInfo)(cast(GtkSourceCompletionInfo*) p);
482 	}
483 	
484 	/**
485 	 * The GtkSourceView associated with completion.
486 	 * Returns: The GtkSourceView associated with completion. [type GtkSource.View][transfer none]
487 	 */
488 	public SourceView getView()
489 	{
490 		// GtkSourceView * gtk_source_completion_get_view (GtkSourceCompletion *completion);
491 		auto p = gtk_source_completion_get_view(gtkSourceCompletion);
492 		
493 		if(p is null)
494 		{
495 			return null;
496 		}
497 		
498 		return ObjectG.getDObject!(SourceView)(cast(GtkSourceView*) p);
499 	}
500 	
501 	/**
502 	 * Create a new GtkSourceCompletionContext for completion. The position where
503 	 * the completion occurs can be specified by position. If position is NULL,
504 	 * the current cursor position will be used.
505 	 * Params:
506 	 * position = a GtkTextIter, or NULL. [allow-none]
507 	 * Returns: a new GtkSourceCompletionContext. The reference being returned is a 'floating' reference, so if you invoke gtk_source_completion_show() with this context you don't need to unref it. [transfer floating]
508 	 */
509 	public SourceCompletionContext createContext(TextIter position)
510 	{
511 		// GtkSourceCompletionContext * gtk_source_completion_create_context  (GtkSourceCompletion *completion,  GtkTextIter *position);
512 		auto p = gtk_source_completion_create_context(gtkSourceCompletion, (position is null) ? null : position.getTextIterStruct());
513 		
514 		if(p is null)
515 		{
516 			return null;
517 		}
518 		
519 		return ObjectG.getDObject!(SourceCompletionContext)(cast(GtkSourceCompletionContext*) p);
520 	}
521 	
522 	/**
523 	 * Warning
524 	 * gtk_source_completion_move_window has been deprecated since version 3.8 and should not be used in newly-written code. Use gtk_source_completion_provider_get_start_iter() instead.
525 	 * Move the completion window to a specific iter.
526 	 * Params:
527 	 * iter = a GtkTextIter.
528 	 */
529 	public void moveWindow(TextIter iter)
530 	{
531 		// void gtk_source_completion_move_window (GtkSourceCompletion *completion,  GtkTextIter *iter);
532 		gtk_source_completion_move_window(gtkSourceCompletion, (iter is null) ? null : iter.getTextIterStruct());
533 	}
534 	
535 	/**
536 	 * Block interactive completion. This can be used to disable interactive
537 	 * completion when inserting or deleting text from the buffer associated with
538 	 * the completion. Use gtk_source_completion_unblock_interactive() to enable
539 	 * interactive completion again.
540 	 */
541 	public void blockInteractive()
542 	{
543 		// void gtk_source_completion_block_interactive  (GtkSourceCompletion *completion);
544 		gtk_source_completion_block_interactive(gtkSourceCompletion);
545 	}
546 	
547 	/**
548 	 * Unblock interactive completion. This can be used after using
549 	 * gtk_source_completion_block_interactive() to enable interactive completion
550 	 * again.
551 	 */
552 	public void unblockInteractive()
553 	{
554 		// void gtk_source_completion_unblock_interactive  (GtkSourceCompletion *completion);
555 		gtk_source_completion_unblock_interactive(gtkSourceCompletion);
556 	}
557 }