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