ruby-****@sourc*****
ruby-****@sourc*****
2012年 9月 6日 (木) 09:53:40 JST
------------------------- REMOTE_ADDR = 70.49.49.99 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-txtw-itrsmrks ------------------------- @@ -187,7 +187,7 @@ === Revised and more complete example dealing with marks and iterators -Now that we have learned the basics, let us look at the revised "iterators.rb" example, which in addition to simple insertions at a single selected location, also deals correctly with some arbitrarily selected text. That is, you can highlight a block of consecutive characters and replace them with the text from entry field when clicking "Insert" button. The solution with buttons is not the proper way to implement this feature (more appropriate would be the use of some kind of context menu), however, the mechanics of replacing selected text using of text buffer marks and iters would be identical. +Now that we have learned the basics, let us look at the revised "iterators.rb" example which, in addition to simple insertions at a single selected location, also deals correctly with some arbitrarily selected text. That is, you can highlight a block of consecutive characters and replace them with the text from entry field when clicking "Insert" button. The solution with buttons is not the proper way to implement this feature (more appropriate would be the use of some kind of context menu), however, the mechanics of replacing selected text using of text buffer marks and iters would be identical. I have also included two simple debugging code segments, to additionally expose the use of Gtk::TextIter and Gtk::TextMark objects. You may have noticed that it is very easy to obtain or convert a mark to an iter with Gtk::TextBuffer#get_iter_at_mark(mark), and that there is no equivalent feature to convert an iter to mark, though you can always create a a new mark from an existing iter with Gtk::TextBuffer#create_mark(mark_name, iter, left_gravity). The debug sections also show you how the values of iterators change when you delete or insert text by printing byte offset boundaries for the selection in the text buffer, i.e. selection we are replacing with the text entered in the entry widget.