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.SourceBuffer; 26 27 private import glib.ConstructionException; 28 private import glib.ListSG; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gsv.SourceLanguage; 33 private import gsv.SourceMark; 34 private import gsv.SourceStyleScheme; 35 private import gsv.SourceUndoManager; 36 private import gsv.SourceUndoManagerIF; 37 private import gsvc.gsv; 38 public import gsvc.gsvtypes; 39 private import gtk.TextBuffer; 40 private import gtk.TextIter; 41 private import gtk.TextMark; 42 private import gtk.TextTag; 43 private import gtk.TextTagTable; 44 private import std.algorithm; 45 46 47 /** */ 48 public class SourceBuffer : TextBuffer 49 { 50 /** the main Gtk struct */ 51 protected GtkSourceBuffer* gtkSourceBuffer; 52 53 /** Get the main Gtk struct */ 54 public GtkSourceBuffer* getSourceBufferStruct() 55 { 56 return gtkSourceBuffer; 57 } 58 59 /** the main Gtk struct as a void* */ 60 protected override void* getStruct() 61 { 62 return cast(void*)gtkSourceBuffer; 63 } 64 65 protected override void setStruct(GObject* obj) 66 { 67 gtkSourceBuffer = cast(GtkSourceBuffer*)obj; 68 super.setStruct(obj); 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GtkSourceBuffer* gtkSourceBuffer, bool ownedRef = false) 75 { 76 this.gtkSourceBuffer = gtkSourceBuffer; 77 super(cast(GtkTextBuffer*)gtkSourceBuffer, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return gtk_source_buffer_get_type(); 85 } 86 87 /** 88 * Creates a new source buffer. 89 * 90 * Params: 91 * table = a #GtkTextTagTable, or %NULL to create a new one. 92 * 93 * Returns: a new source buffer. 94 * 95 * Throws: ConstructionException GTK+ fails to create the object. 96 */ 97 public this(TextTagTable table) 98 { 99 auto p = gtk_source_buffer_new((table is null) ? null : table.getTextTagTableStruct()); 100 101 if(p is null) 102 { 103 throw new ConstructionException("null returned by new"); 104 } 105 106 this(cast(GtkSourceBuffer*) p, true); 107 } 108 109 /** 110 * Creates a new source buffer using the highlighting patterns in 111 * @language. This is equivalent to creating a new source buffer with 112 * a new tag table and then calling gtk_source_buffer_set_language(). 113 * 114 * Params: 115 * language = a #GtkSourceLanguage. 116 * 117 * Returns: a new source buffer which will highlight text 118 * according to the highlighting patterns in @language. 119 * 120 * Throws: ConstructionException GTK+ fails to create the object. 121 */ 122 public this(SourceLanguage language) 123 { 124 auto p = gtk_source_buffer_new_with_language((language is null) ? null : language.getSourceLanguageStruct()); 125 126 if(p is null) 127 { 128 throw new ConstructionException("null returned by new_with_language"); 129 } 130 131 this(cast(GtkSourceBuffer*) p, true); 132 } 133 134 /** 135 * Moves @iter to the position of the previous #GtkSourceMark of the given 136 * category. Returns %TRUE if @iter was moved. If @category is NULL, the 137 * previous source mark can be of any category. 138 * 139 * Params: 140 * iter = an iterator. 141 * category = category to search for, or %NULL 142 * 143 * Returns: whether @iter was moved. 144 * 145 * Since: 2.2 146 */ 147 public bool backwardIterToSourceMark(TextIter iter, string category) 148 { 149 return gtk_source_buffer_backward_iter_to_source_mark(gtkSourceBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(category)) != 0; 150 } 151 152 /** 153 * Marks the beginning of a not undoable action on the buffer, 154 * disabling the undo manager. Typically you would call this function 155 * before initially setting the contents of the buffer (e.g. when 156 * loading a file in a text editor). 157 * 158 * You may nest gtk_source_buffer_begin_not_undoable_action() / 159 * gtk_source_buffer_end_not_undoable_action() blocks. 160 */ 161 public void beginNotUndoableAction() 162 { 163 gtk_source_buffer_begin_not_undoable_action(gtkSourceBuffer); 164 } 165 166 /** 167 * Determines whether a source buffer can redo the last action 168 * (i.e. if the last operation was an undo). 169 * 170 * Returns: %TRUE if a redo is possible. 171 */ 172 public bool canRedo() 173 { 174 return gtk_source_buffer_can_redo(gtkSourceBuffer) != 0; 175 } 176 177 /** 178 * Determines whether a source buffer can undo the last action. 179 * 180 * Returns: %TRUE if it's possible to undo the last action. 181 */ 182 public bool canUndo() 183 { 184 return gtk_source_buffer_can_undo(gtkSourceBuffer) != 0; 185 } 186 187 /** 188 * Changes the case of the text between the specified iterators. 189 * 190 * Params: 191 * caseType = how to change the case. 192 * start = a #GtkTextIter. 193 * end = a #GtkTextIter. 194 * 195 * Since: 3.12 196 */ 197 public void changeCase(GtkSourceChangeCaseType caseType, TextIter start, TextIter end) 198 { 199 gtk_source_buffer_change_case(gtkSourceBuffer, caseType, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 200 } 201 202 /** 203 * Creates a source mark in the @buffer of category @category. A source mark is 204 * a #GtkTextMark but organised into categories. Depending on the category 205 * a pixbuf can be specified that will be displayed along the line of the mark. 206 * 207 * Like a #GtkTextMark, a #GtkSourceMark can be anonymous if the 208 * passed @name is %NULL. Also, the buffer owns the marks so you 209 * shouldn't unreference it. 210 * 211 * Marks always have left gravity and are moved to the beginning of 212 * the line when the user deletes the line they were in. 213 * 214 * Typical uses for a source mark are bookmarks, breakpoints, current 215 * executing instruction indication in a source file, etc.. 216 * 217 * Params: 218 * name = the name of the mark, or %NULL. 219 * category = a string defining the mark category. 220 * where = location to place the mark. 221 * 222 * Returns: a new #GtkSourceMark, owned by the buffer. 223 * 224 * Since: 2.2 225 */ 226 public SourceMark createSourceMark(string name, string category, TextIter where) 227 { 228 auto p = gtk_source_buffer_create_source_mark(gtkSourceBuffer, Str.toStringz(name), Str.toStringz(category), (where is null) ? null : where.getTextIterStruct()); 229 230 if(p is null) 231 { 232 return null; 233 } 234 235 return ObjectG.getDObject!(SourceMark)(cast(GtkSourceMark*) p); 236 } 237 238 /** 239 * Marks the end of a not undoable action on the buffer. When the 240 * last not undoable block is closed through the call to this 241 * function, the list of undo actions is cleared and the undo manager 242 * is re-enabled. 243 */ 244 public void endNotUndoableAction() 245 { 246 gtk_source_buffer_end_not_undoable_action(gtkSourceBuffer); 247 } 248 249 /** 250 * Forces buffer to analyze and highlight the given area synchronously. 251 * 252 * <note> 253 * <para> 254 * This is a potentially slow operation and should be used only 255 * when you need to make sure that some text not currently 256 * visible is highlighted, for instance before printing. 257 * </para> 258 * </note> 259 * 260 * Params: 261 * start = start of the area to highlight. 262 * end = end of the area to highlight. 263 */ 264 public void ensureHighlight(TextIter start, TextIter end) 265 { 266 gtk_source_buffer_ensure_highlight(gtkSourceBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 267 } 268 269 /** 270 * Moves @iter to the position of the next #GtkSourceMark of the given 271 * @category. Returns %TRUE if @iter was moved. If @category is NULL, the 272 * next source mark can be of any category. 273 * 274 * Params: 275 * iter = an iterator. 276 * category = category to search for, or %NULL 277 * 278 * Returns: whether @iter was moved. 279 * 280 * Since: 2.2 281 */ 282 public bool forwardIterToSourceMark(TextIter iter, string category) 283 { 284 return gtk_source_buffer_forward_iter_to_source_mark(gtkSourceBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(category)) != 0; 285 } 286 287 /** 288 * Get all defined context classes at @iter. 289 * 290 * See the #GtkSourceBuffer description for the list of default context classes. 291 * 292 * Params: 293 * iter = a #GtkTextIter. 294 * 295 * Returns: a new %NULL 296 * terminated array of context class names. 297 * Use g_strfreev() to free the array if it is no longer needed. 298 * 299 * Since: 2.10 300 */ 301 public string[] getContextClassesAtIter(TextIter iter) 302 { 303 auto retStr = gtk_source_buffer_get_context_classes_at_iter(gtkSourceBuffer, (iter is null) ? null : iter.getTextIterStruct()); 304 305 scope(exit) Str.freeStringArray(retStr); 306 return Str.toStringArray(retStr); 307 } 308 309 /** 310 * Determines whether bracket match highlighting is activated for the 311 * source buffer. 312 * 313 * Returns: %TRUE if the source buffer will highlight matching 314 * brackets. 315 */ 316 public bool getHighlightMatchingBrackets() 317 { 318 return gtk_source_buffer_get_highlight_matching_brackets(gtkSourceBuffer) != 0; 319 } 320 321 /** 322 * Determines whether syntax highlighting is activated in the source 323 * buffer. 324 * 325 * Returns: %TRUE if syntax highlighting is enabled, %FALSE otherwise. 326 */ 327 public bool getHighlightSyntax() 328 { 329 return gtk_source_buffer_get_highlight_syntax(gtkSourceBuffer) != 0; 330 } 331 332 /** 333 * Returns: whether the @buffer has an implicit trailing newline. 334 * 335 * Since: 3.14 336 */ 337 public bool getImplicitTrailingNewline() 338 { 339 return gtk_source_buffer_get_implicit_trailing_newline(gtkSourceBuffer) != 0; 340 } 341 342 /** 343 * Returns the #GtkSourceLanguage associated with the buffer, 344 * see gtk_source_buffer_set_language(). The returned object should not be 345 * unreferenced by the user. 346 * 347 * Returns: the #GtkSourceLanguage associated 348 * with the buffer, or %NULL. 349 */ 350 public SourceLanguage getLanguage() 351 { 352 auto p = gtk_source_buffer_get_language(gtkSourceBuffer); 353 354 if(p is null) 355 { 356 return null; 357 } 358 359 return ObjectG.getDObject!(SourceLanguage)(cast(GtkSourceLanguage*) p); 360 } 361 362 /** 363 * Determines the number of undo levels the buffer will track for buffer edits. 364 * 365 * Returns: the maximum number of possible undo levels or -1 if no limit is set. 366 */ 367 public int getMaxUndoLevels() 368 { 369 return gtk_source_buffer_get_max_undo_levels(gtkSourceBuffer); 370 } 371 372 /** 373 * Returns the list of marks of the given category at @iter. If @category 374 * is %NULL it returns all marks at @iter. 375 * 376 * Params: 377 * iter = an iterator. 378 * category = category to search for, or %NULL 379 * 380 * Returns: a newly allocated #GSList. 381 * 382 * Since: 2.2 383 */ 384 public ListSG getSourceMarksAtIter(TextIter iter, string category) 385 { 386 auto p = gtk_source_buffer_get_source_marks_at_iter(gtkSourceBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(category)); 387 388 if(p is null) 389 { 390 return null; 391 } 392 393 return new ListSG(cast(GSList*) p); 394 } 395 396 /** 397 * Returns the list of marks of the given category at @line. 398 * If @category is %NULL, all marks at @line are returned. 399 * 400 * Params: 401 * line = a line number. 402 * category = category to search for, or %NULL 403 * 404 * Returns: a newly allocated #GSList. 405 * 406 * Since: 2.2 407 */ 408 public ListSG getSourceMarksAtLine(int line, string category) 409 { 410 auto p = gtk_source_buffer_get_source_marks_at_line(gtkSourceBuffer, line, Str.toStringz(category)); 411 412 if(p is null) 413 { 414 return null; 415 } 416 417 return new ListSG(cast(GSList*) p); 418 } 419 420 /** 421 * Returns the #GtkSourceStyleScheme associated with the buffer, 422 * see gtk_source_buffer_set_style_scheme(). 423 * The returned object should not be unreferenced by the user. 424 * 425 * Returns: the #GtkSourceStyleScheme 426 * associated with the buffer, or %NULL. 427 */ 428 public SourceStyleScheme getStyleScheme() 429 { 430 auto p = gtk_source_buffer_get_style_scheme(gtkSourceBuffer); 431 432 if(p is null) 433 { 434 return null; 435 } 436 437 return ObjectG.getDObject!(SourceStyleScheme)(cast(GtkSourceStyleScheme*) p); 438 } 439 440 /** 441 * Returns the #GtkSourceUndoManager associated with the buffer, 442 * see gtk_source_buffer_set_undo_manager(). The returned object should not be 443 * unreferenced by the user. 444 * 445 * Returns: the #GtkSourceUndoManager associated 446 * with the buffer, or %NULL. 447 */ 448 public SourceUndoManagerIF getUndoManager() 449 { 450 auto p = gtk_source_buffer_get_undo_manager(gtkSourceBuffer); 451 452 if(p is null) 453 { 454 return null; 455 } 456 457 return ObjectG.getDObject!(SourceUndoManager, SourceUndoManagerIF)(cast(GtkSourceUndoManager*) p); 458 } 459 460 /** 461 * Moves backward to the next toggle (on or off) of the context class. If no 462 * matching context class toggles are found, returns %FALSE, otherwise %TRUE. 463 * Does not return toggles located at @iter, only toggles after @iter. Sets 464 * @iter to the location of the toggle, or to the end of the buffer if no 465 * toggle is found. 466 * 467 * See the #GtkSourceBuffer description for the list of default context classes. 468 * 469 * Params: 470 * iter = a #GtkTextIter. 471 * contextClass = the context class. 472 * 473 * Returns: whether we found a context class toggle before @iter 474 * 475 * Since: 2.10 476 */ 477 public bool iterBackwardToContextClassToggle(TextIter iter, string contextClass) 478 { 479 return gtk_source_buffer_iter_backward_to_context_class_toggle(gtkSourceBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(contextClass)) != 0; 480 } 481 482 /** 483 * Moves forward to the next toggle (on or off) of the context class. If no 484 * matching context class toggles are found, returns %FALSE, otherwise %TRUE. 485 * Does not return toggles located at @iter, only toggles after @iter. Sets 486 * @iter to the location of the toggle, or to the end of the buffer if no 487 * toggle is found. 488 * 489 * See the #GtkSourceBuffer description for the list of default context classes. 490 * 491 * Params: 492 * iter = a #GtkTextIter. 493 * contextClass = the context class. 494 * 495 * Returns: whether we found a context class toggle after @iter 496 * 497 * Since: 2.10 498 */ 499 public bool iterForwardToContextClassToggle(TextIter iter, string contextClass) 500 { 501 return gtk_source_buffer_iter_forward_to_context_class_toggle(gtkSourceBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(contextClass)) != 0; 502 } 503 504 /** 505 * Check if the class @context_class is set on @iter. 506 * 507 * See the #GtkSourceBuffer description for the list of default context classes. 508 * 509 * Params: 510 * iter = a #GtkTextIter. 511 * contextClass = class to search for. 512 * 513 * Returns: whether @iter has the context class. 514 * 515 * Since: 2.10 516 */ 517 public bool iterHasContextClass(TextIter iter, string contextClass) 518 { 519 return gtk_source_buffer_iter_has_context_class(gtkSourceBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(contextClass)) != 0; 520 } 521 522 /** 523 * Joins the lines of text between the specified iterators. 524 * 525 * Params: 526 * start = a #GtkTextIter. 527 * end = a #GtkTextIter. 528 * 529 * Since: 3.16 530 */ 531 public void joinLines(TextIter start, TextIter end) 532 { 533 gtk_source_buffer_join_lines(gtkSourceBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 534 } 535 536 /** 537 * Redoes the last undo operation. Use gtk_source_buffer_can_redo() 538 * to check whether a call to this function will have any effect. 539 * 540 * This function emits the #GtkSourceBuffer::redo signal. 541 */ 542 public void redo() 543 { 544 gtk_source_buffer_redo(gtkSourceBuffer); 545 } 546 547 /** 548 * Remove all marks of @category between @start and @end from the buffer. 549 * If @category is NULL, all marks in the range will be removed. 550 * 551 * Params: 552 * start = a #GtkTextIter. 553 * end = a #GtkTextIter. 554 * category = category to search for, or %NULL. 555 * 556 * Since: 2.2 557 */ 558 public void removeSourceMarks(TextIter start, TextIter end, string category) 559 { 560 gtk_source_buffer_remove_source_marks(gtkSourceBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), Str.toStringz(category)); 561 } 562 563 /** 564 * Controls the bracket match highlighting function in the buffer. If 565 * activated, when you position your cursor over a bracket character 566 * (a parenthesis, a square bracket, etc.) the matching opening or 567 * closing bracket character will be highlighted. 568 * 569 * Params: 570 * highlight = %TRUE if you want matching brackets highlighted. 571 */ 572 public void setHighlightMatchingBrackets(bool highlight) 573 { 574 gtk_source_buffer_set_highlight_matching_brackets(gtkSourceBuffer, highlight); 575 } 576 577 /** 578 * Controls whether syntax is highlighted in the buffer. 579 * 580 * If @highlight is %TRUE, the text will be highlighted according to the syntax 581 * patterns specified in the #GtkSourceLanguage set with 582 * gtk_source_buffer_set_language(). 583 * 584 * If @highlight is %FALSE, syntax highlighting is disabled and all the 585 * #GtkTextTag objects that have been added by the syntax highlighting engine 586 * are removed from the buffer. 587 * 588 * Params: 589 * highlight = %TRUE to enable syntax highlighting, %FALSE to disable it. 590 */ 591 public void setHighlightSyntax(bool highlight) 592 { 593 gtk_source_buffer_set_highlight_syntax(gtkSourceBuffer, highlight); 594 } 595 596 /** 597 * Sets whether the @buffer has an implicit trailing newline. 598 * 599 * If an explicit trailing newline is present in a #GtkTextBuffer, #GtkTextView 600 * shows it as an empty line. This is generally not what the user expects. 601 * 602 * If @implicit_trailing_newline is %TRUE (the default value): 603 * - when a #GtkSourceFileLoader loads the content of a file into the @buffer, 604 * the trailing newline (if present in the file) is not inserted into the 605 * @buffer. 606 * - when a #GtkSourceFileSaver saves the content of the @buffer into a file, a 607 * trailing newline is added to the file. 608 * 609 * On the other hand, if @implicit_trailing_newline is %FALSE, the file's 610 * content is not modified when loaded into the @buffer, and the @buffer's 611 * content is not modified when saved into a file. 612 * 613 * Params: 614 * implicitTrailingNewline = the new value. 615 * 616 * Since: 3.14 617 */ 618 public void setImplicitTrailingNewline(bool implicitTrailingNewline) 619 { 620 gtk_source_buffer_set_implicit_trailing_newline(gtkSourceBuffer, implicitTrailingNewline); 621 } 622 623 /** 624 * Associates a #GtkSourceLanguage with the buffer. 625 * 626 * Note that a #GtkSourceLanguage affects not only the syntax highlighting, but 627 * also the [context classes][context-classes]. If you want to disable just the 628 * syntax highlighting, see gtk_source_buffer_set_highlight_syntax(). 629 * 630 * The buffer holds a reference to @language. 631 * 632 * Params: 633 * language = a #GtkSourceLanguage to set, or %NULL. 634 */ 635 public void setLanguage(SourceLanguage language) 636 { 637 gtk_source_buffer_set_language(gtkSourceBuffer, (language is null) ? null : language.getSourceLanguageStruct()); 638 } 639 640 /** 641 * Sets the number of undo levels for user actions the buffer will 642 * track. If the number of user actions exceeds the limit set by this 643 * function, older actions will be discarded. 644 * 645 * If @max_undo_levels is -1, the undo/redo is unlimited. 646 * 647 * If @max_undo_levels is 0, the undo/redo is disabled. 648 * 649 * Params: 650 * maxUndoLevels = the desired maximum number of undo levels. 651 */ 652 public void setMaxUndoLevels(int maxUndoLevels) 653 { 654 gtk_source_buffer_set_max_undo_levels(gtkSourceBuffer, maxUndoLevels); 655 } 656 657 /** 658 * Sets a #GtkSourceStyleScheme to be used by the buffer and the view. 659 * 660 * Note that a #GtkSourceStyleScheme affects not only the syntax highlighting, 661 * but also other #GtkSourceView features such as highlighting the current line, 662 * matching brackets, the line numbers, etc. 663 * 664 * Instead of setting a %NULL @scheme, it is better to disable syntax 665 * highlighting with gtk_source_buffer_set_highlight_syntax(), and setting the 666 * #GtkSourceStyleScheme with the "classic" or "tango" ID, because those two 667 * style schemes follow more closely the GTK+ theme (for example for the 668 * background color). 669 * 670 * The buffer holds a reference to @scheme. 671 * 672 * Params: 673 * scheme = a #GtkSourceStyleScheme or %NULL. 674 */ 675 public void setStyleScheme(SourceStyleScheme scheme) 676 { 677 gtk_source_buffer_set_style_scheme(gtkSourceBuffer, (scheme is null) ? null : scheme.getSourceStyleSchemeStruct()); 678 } 679 680 /** 681 * Set the buffer undo manager. If @manager is %NULL the default undo manager 682 * will be set. 683 * 684 * Params: 685 * manager = A #GtkSourceUndoManager or %NULL. 686 */ 687 public void setUndoManager(SourceUndoManagerIF manager) 688 { 689 gtk_source_buffer_set_undo_manager(gtkSourceBuffer, (manager is null) ? null : manager.getSourceUndoManagerStruct()); 690 } 691 692 /** 693 * Sort the lines of text between the specified iterators. 694 * 695 * Params: 696 * start = a #GtkTextIter. 697 * end = a #GtkTextIter. 698 * flags = #GtkSourceSortFlags specifying how the sort should behave 699 * column = sort considering the text starting at the given column 700 * 701 * Since: 3.18 702 */ 703 public void sortLines(TextIter start, TextIter end, GtkSourceSortFlags flags, int column) 704 { 705 gtk_source_buffer_sort_lines(gtkSourceBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), flags, column); 706 } 707 708 /** 709 * Undoes the last user action which modified the buffer. Use 710 * gtk_source_buffer_can_undo() to check whether a call to this 711 * function will have any effect. 712 * 713 * This function emits the #GtkSourceBuffer::undo signal. 714 */ 715 public void undo() 716 { 717 gtk_source_buffer_undo(gtkSourceBuffer); 718 } 719 720 protected class OnBracketMatchedDelegateWrapper 721 { 722 static OnBracketMatchedDelegateWrapper[] listeners; 723 void delegate(TextIter, GtkSourceBracketMatchType, SourceBuffer) dlg; 724 gulong handlerId; 725 726 this(void delegate(TextIter, GtkSourceBracketMatchType, SourceBuffer) dlg) 727 { 728 this.dlg = dlg; 729 this.listeners ~= this; 730 } 731 732 void remove(OnBracketMatchedDelegateWrapper source) 733 { 734 foreach(index, wrapper; listeners) 735 { 736 if (wrapper.handlerId == source.handlerId) 737 { 738 listeners[index] = null; 739 listeners = std.algorithm.remove(listeners, index); 740 break; 741 } 742 } 743 } 744 } 745 746 /** 747 * @iter is set to a valid iterator pointing to the matching bracket 748 * if @state is %GTK_SOURCE_BRACKET_MATCH_FOUND. Otherwise @iter is 749 * meaningless. 750 * 751 * The signal is emitted only when the @state changes, typically when 752 * the cursor moves. 753 * 754 * A use-case for this signal is to show messages in a #GtkStatusbar. 755 * 756 * Params: 757 * iter = if found, the location of the matching bracket. 758 * state = state of bracket matching. 759 * 760 * Since: 2.12 761 */ 762 gulong addOnBracketMatched(void delegate(TextIter, GtkSourceBracketMatchType, SourceBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 763 { 764 auto wrapper = new OnBracketMatchedDelegateWrapper(dlg); 765 wrapper.handlerId = Signals.connectData( 766 this, 767 "bracket-matched", 768 cast(GCallback)&callBackBracketMatched, 769 cast(void*)wrapper, 770 cast(GClosureNotify)&callBackBracketMatchedDestroy, 771 connectFlags); 772 return wrapper.handlerId; 773 } 774 775 extern(C) static void callBackBracketMatched(GtkSourceBuffer* sourcebufferStruct, GtkTextIter* iter, GtkSourceBracketMatchType state, OnBracketMatchedDelegateWrapper wrapper) 776 { 777 wrapper.dlg(ObjectG.getDObject!(TextIter)(iter), state, wrapper.outer); 778 } 779 780 extern(C) static void callBackBracketMatchedDestroy(OnBracketMatchedDelegateWrapper wrapper, GClosure* closure) 781 { 782 wrapper.remove(wrapper); 783 } 784 785 protected class OnHighlightUpdatedDelegateWrapper 786 { 787 static OnHighlightUpdatedDelegateWrapper[] listeners; 788 void delegate(TextIter, TextIter, SourceBuffer) dlg; 789 gulong handlerId; 790 791 this(void delegate(TextIter, TextIter, SourceBuffer) dlg) 792 { 793 this.dlg = dlg; 794 this.listeners ~= this; 795 } 796 797 void remove(OnHighlightUpdatedDelegateWrapper source) 798 { 799 foreach(index, wrapper; listeners) 800 { 801 if (wrapper.handlerId == source.handlerId) 802 { 803 listeners[index] = null; 804 listeners = std.algorithm.remove(listeners, index); 805 break; 806 } 807 } 808 } 809 } 810 811 /** 812 * The ::highlight-updated signal is emitted when the syntax 813 * highlighting and [context classes][context-classes] are updated in a 814 * certain region of the @buffer. 815 * 816 * Params: 817 * start = the start of the updated region 818 * end = the end of the updated region 819 */ 820 gulong addOnHighlightUpdated(void delegate(TextIter, TextIter, SourceBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 821 { 822 auto wrapper = new OnHighlightUpdatedDelegateWrapper(dlg); 823 wrapper.handlerId = Signals.connectData( 824 this, 825 "highlight-updated", 826 cast(GCallback)&callBackHighlightUpdated, 827 cast(void*)wrapper, 828 cast(GClosureNotify)&callBackHighlightUpdatedDestroy, 829 connectFlags); 830 return wrapper.handlerId; 831 } 832 833 extern(C) static void callBackHighlightUpdated(GtkSourceBuffer* sourcebufferStruct, GtkTextIter* start, GtkTextIter* end, OnHighlightUpdatedDelegateWrapper wrapper) 834 { 835 wrapper.dlg(ObjectG.getDObject!(TextIter)(start), ObjectG.getDObject!(TextIter)(end), wrapper.outer); 836 } 837 838 extern(C) static void callBackHighlightUpdatedDestroy(OnHighlightUpdatedDelegateWrapper wrapper, GClosure* closure) 839 { 840 wrapper.remove(wrapper); 841 } 842 843 protected class OnRedoDelegateWrapper 844 { 845 static OnRedoDelegateWrapper[] listeners; 846 void delegate(SourceBuffer) dlg; 847 gulong handlerId; 848 849 this(void delegate(SourceBuffer) dlg) 850 { 851 this.dlg = dlg; 852 this.listeners ~= this; 853 } 854 855 void remove(OnRedoDelegateWrapper source) 856 { 857 foreach(index, wrapper; listeners) 858 { 859 if (wrapper.handlerId == source.handlerId) 860 { 861 listeners[index] = null; 862 listeners = std.algorithm.remove(listeners, index); 863 break; 864 } 865 } 866 } 867 } 868 869 /** 870 * The ::redo signal is emitted to redo the last undo operation. 871 */ 872 gulong addOnRedo(void delegate(SourceBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 873 { 874 auto wrapper = new OnRedoDelegateWrapper(dlg); 875 wrapper.handlerId = Signals.connectData( 876 this, 877 "redo", 878 cast(GCallback)&callBackRedo, 879 cast(void*)wrapper, 880 cast(GClosureNotify)&callBackRedoDestroy, 881 connectFlags); 882 return wrapper.handlerId; 883 } 884 885 extern(C) static void callBackRedo(GtkSourceBuffer* sourcebufferStruct, OnRedoDelegateWrapper wrapper) 886 { 887 wrapper.dlg(wrapper.outer); 888 } 889 890 extern(C) static void callBackRedoDestroy(OnRedoDelegateWrapper wrapper, GClosure* closure) 891 { 892 wrapper.remove(wrapper); 893 } 894 895 protected class OnSourceMarkUpdatedDelegateWrapper 896 { 897 static OnSourceMarkUpdatedDelegateWrapper[] listeners; 898 void delegate(TextMark, SourceBuffer) dlg; 899 gulong handlerId; 900 901 this(void delegate(TextMark, SourceBuffer) dlg) 902 { 903 this.dlg = dlg; 904 this.listeners ~= this; 905 } 906 907 void remove(OnSourceMarkUpdatedDelegateWrapper source) 908 { 909 foreach(index, wrapper; listeners) 910 { 911 if (wrapper.handlerId == source.handlerId) 912 { 913 listeners[index] = null; 914 listeners = std.algorithm.remove(listeners, index); 915 break; 916 } 917 } 918 } 919 } 920 921 /** 922 * The ::source-mark-updated signal is emitted each time 923 * a mark is added to, moved or removed from the @buffer. 924 * 925 * Params: 926 * mark = the #GtkSourceMark 927 */ 928 gulong addOnSourceMarkUpdated(void delegate(TextMark, SourceBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 929 { 930 auto wrapper = new OnSourceMarkUpdatedDelegateWrapper(dlg); 931 wrapper.handlerId = Signals.connectData( 932 this, 933 "source-mark-updated", 934 cast(GCallback)&callBackSourceMarkUpdated, 935 cast(void*)wrapper, 936 cast(GClosureNotify)&callBackSourceMarkUpdatedDestroy, 937 connectFlags); 938 return wrapper.handlerId; 939 } 940 941 extern(C) static void callBackSourceMarkUpdated(GtkSourceBuffer* sourcebufferStruct, GtkTextMark* mark, OnSourceMarkUpdatedDelegateWrapper wrapper) 942 { 943 wrapper.dlg(ObjectG.getDObject!(TextMark)(mark), wrapper.outer); 944 } 945 946 extern(C) static void callBackSourceMarkUpdatedDestroy(OnSourceMarkUpdatedDelegateWrapper wrapper, GClosure* closure) 947 { 948 wrapper.remove(wrapper); 949 } 950 951 protected class OnUndoDelegateWrapper 952 { 953 static OnUndoDelegateWrapper[] listeners; 954 void delegate(SourceBuffer) dlg; 955 gulong handlerId; 956 957 this(void delegate(SourceBuffer) dlg) 958 { 959 this.dlg = dlg; 960 this.listeners ~= this; 961 } 962 963 void remove(OnUndoDelegateWrapper source) 964 { 965 foreach(index, wrapper; listeners) 966 { 967 if (wrapper.handlerId == source.handlerId) 968 { 969 listeners[index] = null; 970 listeners = std.algorithm.remove(listeners, index); 971 break; 972 } 973 } 974 } 975 } 976 977 /** 978 * The ::undo signal is emitted to undo the last user action which 979 * modified the buffer. 980 */ 981 gulong addOnUndo(void delegate(SourceBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 982 { 983 auto wrapper = new OnUndoDelegateWrapper(dlg); 984 wrapper.handlerId = Signals.connectData( 985 this, 986 "undo", 987 cast(GCallback)&callBackUndo, 988 cast(void*)wrapper, 989 cast(GClosureNotify)&callBackUndoDestroy, 990 connectFlags); 991 return wrapper.handlerId; 992 } 993 994 extern(C) static void callBackUndo(GtkSourceBuffer* sourcebufferStruct, OnUndoDelegateWrapper wrapper) 995 { 996 wrapper.dlg(wrapper.outer); 997 } 998 999 extern(C) static void callBackUndoDestroy(OnUndoDelegateWrapper wrapper, GClosure* closure) 1000 { 1001 wrapper.remove(wrapper); 1002 } 1003 }