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