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  = GtkSourceSearchContext.html
27  * outPack = gsv
28  * outFile = SourceSearchContext
29  * strct   = GtkSourceSearchContext
30  * realStrct=
31  * ctorStrct=
32  * clss    = SourceSearchContext
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_source_search_context_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * 	- gio.AsyncResultIF
50  * 	- gio.Cancellable
51  * 	- gtk.TextIter
52  * 	- gsv.SourceBuffer
53  * 	- gsv.SourceSearchSettings
54  * structWrap:
55  * 	- GAsyncResult* -> AsyncResultIF
56  * 	- GCancellable* -> Cancellable
57  * 	- GError* -> ErrorG
58  * 	- GtkSourceBuffer* -> SourceBuffer
59  * 	- GtkSourceSearchSettings* -> SourceSearchSettings
60  * 	- GtkTextIter* -> TextIter
61  * module aliases:
62  * local aliases:
63  * overrides:
64  */
65 
66 module gsv.SourceSearchContext;
67 
68 public  import gsvc.gsvtypes;
69 
70 private import gsvc.gsv;
71 private import glib.ConstructionException;
72 private import gobject.ObjectG;
73 
74 
75 private import glib.Str;
76 private import glib.ErrorG;
77 private import glib.GException;
78 private import gio.AsyncResultIF;
79 private import gio.Cancellable;
80 private import gtk.TextIter;
81 private import gsv.SourceBuffer;
82 private import gsv.SourceSearchSettings;
83 
84 
85 
86 private import gobject.ObjectG;
87 
88 /**
89  * A GtkSourceSearchContext is used for the search and replace in a
90  * GtkSourceBuffer. The search settings are represented by a
91  * GtkSourceSearchSettings object, that can be shared between several
92  * GtkSourceSearchContexts. A buffer can contain several search
93  * contexts at the same time, but at most one search context per buffer can
94  * highlight its search occurrences.
95  *
96  * The total number of search occurrences can be retrieved with
97  * gtk_source_search_context_get_occurrences_count(). To know the position of a
98  * certain match, use gtk_source_search_context_get_occurrence_position().
99  *
100  * The buffer is scanned asynchronously, so it doesn't block the user interface.
101  * For each search, the buffer is scanned at most once. After that, navigating
102  * through the occurrences doesn't require to re-scan the buffer entirely.
103  *
104  * To search forward, use gtk_source_search_context_forward() or
105  * gtk_source_search_context_forward_async() for the asynchronous version.
106  * The backward search is done similarly. To replace a search match, or all
107  * matches, use gtk_source_search_context_replace() and
108  * gtk_source_search_context_replace_all().
109  *
110  * The search occurrences are highlighted by default. To disable it, use
111  * gtk_source_search_context_set_highlight(). You can enable the search
112  * highlighting for several GtkSourceSearchContexts attached to the
113  * same buffer. But currently, the same highlighting style is applied.
114  * Note that the "highlight" property is in the
115  * GtkSourceSearchContext class, not GtkSourceSearchSettings. The purpose is
116  * to bind the appearance settings to only one buffer. A
117  * GtkSourceSearchSettings object can be bound to several buffers.
118  *
119  * In the GtkSourceView source code, there is an example of how to use the
120  * search and replace API: see the tests/test-search.c file. It is a mini
121  * application for the search and replace, with a basic user interface.
122  */
123 public class SourceSearchContext : ObjectG
124 {
125 	
126 	/** the main Gtk struct */
127 	protected GtkSourceSearchContext* gtkSourceSearchContext;
128 	
129 	
130 	public GtkSourceSearchContext* getSourceSearchContextStruct()
131 	{
132 		return gtkSourceSearchContext;
133 	}
134 	
135 	
136 	/** the main Gtk struct as a void* */
137 	protected override void* getStruct()
138 	{
139 		return cast(void*)gtkSourceSearchContext;
140 	}
141 	
142 	/**
143 	 * Sets our main struct and passes it to the parent class
144 	 */
145 	public this (GtkSourceSearchContext* gtkSourceSearchContext)
146 	{
147 		super(cast(GObject*)gtkSourceSearchContext);
148 		this.gtkSourceSearchContext = gtkSourceSearchContext;
149 	}
150 	
151 	protected override void setStruct(GObject* obj)
152 	{
153 		super.setStruct(obj);
154 		gtkSourceSearchContext = cast(GtkSourceSearchContext*)obj;
155 	}
156 	
157 	/**
158 	 */
159 	
160 	/**
161 	 * Creates a new search context, associated with buffer, and customized with
162 	 * settings. If settings is NULL, a new GtkSourceSearchSettings object will
163 	 * be created, that you can retrieve with
164 	 * gtk_source_search_context_get_settings().
165 	 * Params:
166 	 * buffer = a GtkSourceBuffer.
167 	 * settings = a GtkSourceSearchSettings, or NULL. [allow-none]
168 	 * Throws: ConstructionException GTK+ fails to create the object.
169 	 */
170 	public this (SourceBuffer buffer, SourceSearchSettings settings)
171 	{
172 		// GtkSourceSearchContext * gtk_source_search_context_new (GtkSourceBuffer *buffer,  GtkSourceSearchSettings *settings);
173 		auto p = gtk_source_search_context_new((buffer is null) ? null : buffer.getSourceBufferStruct(), (settings is null) ? null : settings.getSourceSearchSettingsStruct());
174 		if(p is null)
175 		{
176 			throw new ConstructionException("null returned by gtk_source_search_context_new((buffer is null) ? null : buffer.getSourceBufferStruct(), (settings is null) ? null : settings.getSourceSearchSettingsStruct())");
177 		}
178 		this(cast(GtkSourceSearchContext*) p);
179 	}
180 	
181 	/**
182 	 * Returns: the associated buffer. [transfer none] Since 3.10
183 	 */
184 	public SourceBuffer getBuffer()
185 	{
186 		// GtkSourceBuffer * gtk_source_search_context_get_buffer  (GtkSourceSearchContext *search);
187 		auto p = gtk_source_search_context_get_buffer(gtkSourceSearchContext);
188 		
189 		if(p is null)
190 		{
191 			return null;
192 		}
193 		
194 		return ObjectG.getDObject!(SourceBuffer)(cast(GtkSourceBuffer*) p);
195 	}
196 	
197 	/**
198 	 * Returns: the search settings. [transfer none] Since 3.10
199 	 */
200 	public SourceSearchSettings getSettings()
201 	{
202 		// GtkSourceSearchSettings * gtk_source_search_context_get_settings  (GtkSourceSearchContext *search);
203 		auto p = gtk_source_search_context_get_settings(gtkSourceSearchContext);
204 		
205 		if(p is null)
206 		{
207 			return null;
208 		}
209 		
210 		return ObjectG.getDObject!(SourceSearchSettings)(cast(GtkSourceSearchSettings*) p);
211 	}
212 	
213 	/**
214 	 * Associate a GtkSourceSearchSettings with the search context. If settings is
215 	 * NULL, a new one will be created.
216 	 * The search context holds a reference to settings.
217 	 * Params:
218 	 * settings = the new GtkSourceSearchSettings, or NULL. [allow-none]
219 	 * Since 3.10
220 	 */
221 	public void setSettings(SourceSearchSettings settings)
222 	{
223 		// void gtk_source_search_context_set_settings  (GtkSourceSearchContext *search,  GtkSourceSearchSettings *settings);
224 		gtk_source_search_context_set_settings(gtkSourceSearchContext, (settings is null) ? null : settings.getSourceSearchSettingsStruct());
225 	}
226 	
227 	/**
228 	 * Returns: whether to highlight the search occurrences. Since 3.10
229 	 */
230 	public int getHighlight()
231 	{
232 		// gboolean gtk_source_search_context_get_highlight  (GtkSourceSearchContext *search);
233 		return gtk_source_search_context_get_highlight(gtkSourceSearchContext);
234 	}
235 	
236 	/**
237 	 * Enables or disables the search occurrences highlighting.
238 	 * Params:
239 	 * highlight = the setting.
240 	 * Since 3.10
241 	 */
242 	public void setHighlight(int highlight)
243 	{
244 		// void gtk_source_search_context_set_highlight  (GtkSourceSearchContext *search,  gboolean highlight);
245 		gtk_source_search_context_set_highlight(gtkSourceSearchContext, highlight);
246 	}
247 	
248 	/**
249 	 * Gets the total number of search occurrences. If the buffer is not already
250 	 * fully scanned, the total number of occurrences is unknown, and -1 is
251 	 * returned.
252 	 * Returns: the total number of search occurrences, or -1 if unknown. Since 3.10
253 	 */
254 	public int getOccurrencesCount()
255 	{
256 		// gint gtk_source_search_context_get_occurrences_count  (GtkSourceSearchContext *search);
257 		return gtk_source_search_context_get_occurrences_count(gtkSourceSearchContext);
258 	}
259 	
260 	/**
261 	 * Gets the position of a search occurrence. If the buffer is not already fully
262 	 * scanned, the position may be unknown, and -1 is returned. If 0 is returned,
263 	 * it means that this part of the buffer has already been scanned, and that
264 	 * match_start and match_end don't delimit an occurrence.
265 	 * Params:
266 	 * matchStart = the start of the occurrence.
267 	 * matchEnd = the end of the occurrence.
268 	 * Returns: the position of the search occurrence. The first occurrence has the position 1 (not 0). Returns 0 if match_start and match_end don't delimit an occurrence. Returns -1 if the position is not yet known. Since 3.10
269 	 */
270 	public int getOccurrencePosition(TextIter matchStart, TextIter matchEnd)
271 	{
272 		// gint gtk_source_search_context_get_occurrence_position  (GtkSourceSearchContext *search,  const GtkTextIter *match_start,  const GtkTextIter *match_end);
273 		return gtk_source_search_context_get_occurrence_position(gtkSourceSearchContext, (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct());
274 	}
275 	
276 	/**
277 	 * Synchronous forward search. It is recommended to use the asynchronous
278 	 * functions instead, to not block the user interface. However, if you are sure
279 	 * that the buffer is small, this function is more convenient to use.
280 	 * Params:
281 	 * iter = start of search.
282 	 * matchStart = return location for start of match, or NULL. [out][allow-none]
283 	 * matchEnd = return location for end of match, or NULL. [out][allow-none]
284 	 * Returns: whether a match was found. Since 3.10
285 	 */
286 	public int forward(TextIter iter, TextIter matchStart, TextIter matchEnd)
287 	{
288 		// gboolean gtk_source_search_context_forward (GtkSourceSearchContext *search,  const GtkTextIter *iter,  GtkTextIter *match_start,  GtkTextIter *match_end);
289 		return gtk_source_search_context_forward(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct());
290 	}
291 	
292 	/**
293 	 * Asynchronous forward search. See the GAsyncResult documentation to know
294 	 * how to use this function.
295 	 * If the operation is cancelled, the callback will only be called if
296 	 * cancellable was not NULL. gtk_source_search_context_forward_async() takes
297 	 * ownership of cancellable, so you can unref it after calling this function.
298 	 * Params:
299 	 * iter = start of search.
300 	 * cancellable = a GCancellable, or NULL. [allow-none]
301 	 * callback = a GAsyncReadyCallback to call when the operation is finished.
302 	 * userData = the data to pass to the callback function.
303 	 * Since 3.10
304 	 */
305 	public void forwardAsync(TextIter iter, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
306 	{
307 		// void gtk_source_search_context_forward_async  (GtkSourceSearchContext *search,  const GtkTextIter *iter,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
308 		gtk_source_search_context_forward_async(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
309 	}
310 	
311 	/**
312 	 * Finishes a forward search started with
313 	 * gtk_source_search_context_forward_async().
314 	 * Params:
315 	 * result = a GAsyncResult.
316 	 * matchStart = return location for start of match, or NULL. [out][allow-none]
317 	 * matchEnd = return location for end of match, or NULL. [out][allow-none]
318 	 * Returns: whether a match was found. Since 3.10
319 	 * Throws: GException on failure.
320 	 */
321 	public int forwardFinish(AsyncResultIF result, TextIter matchStart, TextIter matchEnd)
322 	{
323 		// gboolean gtk_source_search_context_forward_finish  (GtkSourceSearchContext *search,  GAsyncResult *result,  GtkTextIter *match_start,  GtkTextIter *match_end,  GError **error);
324 		GError* err = null;
325 		
326 		auto p = gtk_source_search_context_forward_finish(gtkSourceSearchContext, (result is null) ? null : result.getAsyncResultTStruct(), (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct(), &err);
327 		
328 		if (err !is null)
329 		{
330 			throw new GException( new ErrorG(err) );
331 		}
332 		
333 		return p;
334 	}
335 	
336 	/**
337 	 * Synchronous backward search. It is recommended to use the asynchronous
338 	 * functions instead, to not block the user interface. However, if you are sure
339 	 * that the buffer is small, this function is more convenient to use.
340 	 * Params:
341 	 * iter = start of search.
342 	 * matchStart = return location for start of match, or NULL. [out][allow-none]
343 	 * matchEnd = return location for end of match, or NULL. [out][allow-none]
344 	 * Returns: whether a match was found. Since 3.10
345 	 */
346 	public int backward(TextIter iter, TextIter matchStart, TextIter matchEnd)
347 	{
348 		// gboolean gtk_source_search_context_backward (GtkSourceSearchContext *search,  const GtkTextIter *iter,  GtkTextIter *match_start,  GtkTextIter *match_end);
349 		return gtk_source_search_context_backward(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct());
350 	}
351 	
352 	/**
353 	 * Asynchronous backward search. See the GAsyncResult documentation to know
354 	 * how to use this function.
355 	 * If the operation is cancelled, the callback will only be called if
356 	 * cancellable was not NULL. gtk_source_search_context_backward_async() takes
357 	 * ownership of cancellable, so you can unref it after calling this function.
358 	 * Params:
359 	 * iter = start of search.
360 	 * cancellable = a GCancellable, or NULL. [allow-none]
361 	 * callback = a GAsyncReadyCallback to call when the operation is finished.
362 	 * userData = the data to pass to the callback function.
363 	 * Since 3.10
364 	 */
365 	public void backwardAsync(TextIter iter, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
366 	{
367 		// void gtk_source_search_context_backward_async  (GtkSourceSearchContext *search,  const GtkTextIter *iter,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
368 		gtk_source_search_context_backward_async(gtkSourceSearchContext, (iter is null) ? null : iter.getTextIterStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
369 	}
370 	
371 	/**
372 	 * Finishes a backward search started with
373 	 * gtk_source_search_context_backward_async().
374 	 * Params:
375 	 * result = a GAsyncResult.
376 	 * matchStart = return location for start of match, or NULL. [out][allow-none]
377 	 * matchEnd = return location for end of match, or NULL. [out][allow-none]
378 	 * Returns: whether a match was found. Since 3.10
379 	 * Throws: GException on failure.
380 	 */
381 	public int backwardFinish(AsyncResultIF result, TextIter matchStart, TextIter matchEnd)
382 	{
383 		// gboolean gtk_source_search_context_backward_finish  (GtkSourceSearchContext *search,  GAsyncResult *result,  GtkTextIter *match_start,  GtkTextIter *match_end,  GError **error);
384 		GError* err = null;
385 		
386 		auto p = gtk_source_search_context_backward_finish(gtkSourceSearchContext, (result is null) ? null : result.getAsyncResultTStruct(), (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct(), &err);
387 		
388 		if (err !is null)
389 		{
390 			throw new GException( new ErrorG(err) );
391 		}
392 		
393 		return p;
394 	}
395 	
396 	/**
397 	 * Replaces a search match by another text. If match_start and match_end
398 	 * doesn't correspond to a search match, FALSE is returned.
399 	 * For a regular expression replacement, you can check if replace is valid by
400 	 * calling g_regex_check_replacement(). The replace text can contain
401 	 * backreferences; read the g_regex_replace() documentation for more details.
402 	 * Params:
403 	 * matchStart = the start of the match to replace.
404 	 * matchEnd = the end of the match to replace.
405 	 * replace = the replacement text.
406 	 * Returns: whether the match has been replaced. Since 3.10
407 	 * Throws: GException on failure.
408 	 */
409 	public int replace(TextIter matchStart, TextIter matchEnd, string replace)
410 	{
411 		// gboolean gtk_source_search_context_replace (GtkSourceSearchContext *search,  const GtkTextIter *match_start,  const GtkTextIter *match_end,  const gchar *replace,  gint replace_length,  GError **error);
412 		GError* err = null;
413 		
414 		auto p = gtk_source_search_context_replace(gtkSourceSearchContext, (matchStart is null) ? null : matchStart.getTextIterStruct(), (matchEnd is null) ? null : matchEnd.getTextIterStruct(), cast(char*)replace.ptr, cast(int) replace.length, &err);
415 		
416 		if (err !is null)
417 		{
418 			throw new GException( new ErrorG(err) );
419 		}
420 		
421 		return p;
422 	}
423 	
424 	/**
425 	 * Replaces all search matches by another text. It is a synchronous function, so
426 	 * it can block the user interface.
427 	 * For a regular expression replacement, you can check if replace is valid by
428 	 * calling g_regex_check_replacement(). The replace text can contain
429 	 * backreferences; read the g_regex_replace() documentation for more details.
430 	 * Params:
431 	 * replace = the replacement text.
432 	 * Returns: the number of replaced matches. Since 3.10
433 	 * Throws: GException on failure.
434 	 */
435 	public uint replaceAll(string replace)
436 	{
437 		// guint gtk_source_search_context_replace_all  (GtkSourceSearchContext *search,  const gchar *replace,  gint replace_length,  GError **error);
438 		GError* err = null;
439 		
440 		auto p = gtk_source_search_context_replace_all(gtkSourceSearchContext, cast(char*)replace.ptr, cast(int) replace.length, &err);
441 		
442 		if (err !is null)
443 		{
444 			throw new GException( new ErrorG(err) );
445 		}
446 		
447 		return p;
448 	}
449 	
450 	/**
451 	 * Regular expression patterns must follow certain rules. If
452 	 * "search-text" breaks a rule, the error can be retrieved
453 	 * with this function. The error domain is G_REGEX_ERROR.
454 	 * Free the return value with g_error_free().
455 	 * Returns: the GError, or NULL if the pattern is valid. Since 3.10
456 	 */
457 	public ErrorG getRegexError()
458 	{
459 		// GError * gtk_source_search_context_get_regex_error  (GtkSourceSearchContext *search);
460 		auto p = gtk_source_search_context_get_regex_error(gtkSourceSearchContext);
461 		
462 		if(p is null)
463 		{
464 			return null;
465 		}
466 		
467 		return ObjectG.getDObject!(ErrorG)(cast(GError*) p);
468 	}
469 }