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