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