class Gtk::TextBuffer

Public Instance Methods

add_mark(mark, where) click to toggle source
# File lib/gtk3/text-buffer.rb, line 33
def add_mark(mark, where)
  @marks ||= {}
  add_mark_raw(mark, where)
  mark_name = mark.name
  @marks[mark_name] = mark if mark_name
end
Also aliased as: add_mark_raw
add_mark_raw(mark, where)
Alias for: add_mark
apply_tag(tag, start, last) click to toggle source
# File lib/gtk3/text-buffer.rb, line 200
def apply_tag(tag, start, last)
  if tag.is_a?(String)
    apply_tag_by_name(tag, start, last)
  else
    apply_tag_raw(tag, start, last)
  end
end
Also aliased as: apply_tag_raw
apply_tag_raw(tag, start, last)
Alias for: apply_tag
create_mark(name, where, options={}) click to toggle source
# File lib/gtk3/text-buffer.rb, line 41
def create_mark(name, where, options={})
  if options == true or options == false
    options = {:left_gravity => options}
  end
  left_gravity = options[:left_gravity]
  left_gravity = true if left_gravity.nil?
  @marks ||= {}
  if name.nil?
    create_mark_raw(name, where, left_gravity)
  else
    @marks[name] = create_mark_raw(name, where, left_gravity)
  end
end
Also aliased as: create_mark_raw
create_mark_raw(name, where, options={})
Alias for: create_mark
create_tag(tag_name=nil, properties={}) click to toggle source
# File lib/gtk3/text-buffer.rb, line 19
def create_tag(tag_name=nil, properties={})
  tag = TextTag.new(tag_name)
  succeeded = tag_table.add(tag)
  return nil unless succeeded

  properties.each do |name, value|
    property_name = name.to_s.gsub(/-/, "_")
    tag.__send__("#{property_name}=", value)
  end

  tag
end
delete_mark(mark) click to toggle source
# File lib/gtk3/text-buffer.rb, line 56
def delete_mark(mark)
  @marks ||= {}
  mark_name = mark.name
  delete_mark_raw(mark)
  @marks.delete(mark_name) if mark_name
end
Also aliased as: delete_mark_raw
delete_mark_raw(mark)
Alias for: delete_mark
get_iter_at(arguments) click to toggle source
# File lib/gtk3/text-buffer.rb, line 70
def get_iter_at(arguments)
  line   = arguments[:line]
  offset = arguments[:offset]
  index  = arguments[:index]
  mark   = arguments[:mark]
  anchor = arguments[:anchor]
  if line
    if offset
      get_iter_at_line_offset_raw(line, offset)
    elsif index
      get_iter_at_line_index_raw(line, index)
    else
      get_iter_at_line_raw(line)
    end
  elsif offset
    get_iter_at_offset_raw(offset)
  elsif mark
    get_iter_at_mark_raw(mark)
  elsif anchor
    get_iter_at_child_anchor_raw(anchor)
  else
    message =
      "Must specify one of :line, :offset, :mark or :anchor: #{arguments.inspect}"
    raise ArgumentError, message
  end
end
insert(iter, target, *args) click to toggle source
# File lib/gtk3/text-buffer.rb, line 100
def insert(iter, target, *args)
  options = nil
  tags = nil
  case args.size
  when 0
    options = {}
  when 1
    case args.first
    when Hash
      options = args.first
    else
      tags = args
    end
  else
    tags = args
  end
  if options.nil?
    signature_prefix = "#{self.class}\##{__method__}(iter, target"
    warn("#{signature_prefix}, *tags) style has been deprecated. " +
         "Use #{signature_prefix}, options={:tags => tags}) style instead.")
    options = {:tags => tags}
  end

  interactive = options[:interactive]
  default_editable = options[:default_editable]
  tags = options[:tags]

  start_offset = iter.offset
  if interactive
    default_editable = true if default_editable.nil?
    insert_interactive(iter, target, default_editable)
  else
    case target
    when GdkPixbuf::Pixbuf
      insert_pixbuf_raw(iter, target)
    when TextChildAnchor
      insert_text_child_anchor_raw(iter, target)
    when GLib::Bytes
      insert_raw(iter, target, target.size)
    else
      insert_raw(iter, target, target.bytesize)
    end
  end

  if tags
    start_iter = get_iter_at(:offset => start_offset)
    tags.each do |tag|
      if tag.is_a?(String)
        resolved_tag = tag_table.lookup(tag)
        if resolved_tag.nil?
          raise ArgumentError "unknown tag: #{tag.inspect}"
        end
        tag = resolved_tag
      end
      apply_tag(tag, start_iter, iter)
    end
  end

  self
end
Also aliased as: insert_raw
insert_at_cursor(text, options={}) click to toggle source
# File lib/gtk3/text-buffer.rb, line 175
def insert_at_cursor(text, options={})
  interactive = options[:interactive]
  default_editable = options[:default_editable]

  if interactive
    default_editable = true if default_editable.nil?
    insert_interactive_at_cursor(text, default_editable)
  else
    insert_at_cursor_raw(text, text.bytesize)
  end
end
Also aliased as: insert_at_cursor_raw
insert_at_cursor_raw(text, options={})
Alias for: insert_at_cursor
insert_markup(iter, markup, n_bytes=nil) click to toggle source
# File lib/gtk3/text-buffer.rb, line 163
def insert_markup(iter, markup, n_bytes=nil)
  case markup
  when GLib::Bytes
    n_bytes ||= markup.size
  else
    n_bytes ||= markup.bytesize
  end
  insert_markup_raw(iter, markup, n_bytes)
end
insert_raw(iter, target, *args)
Alias for: insert
selection_bounds() click to toggle source
# File lib/gtk3/text-buffer.rb, line 214
def selection_bounds
  selected, start_iter, end_iter = selection_bounds_raw
  if selected
    [start_iter, end_iter]
  else
    nil
  end
end
Also aliased as: selection_bounds_raw
selection_bounds_raw()
Alias for: selection_bounds
serialize(*arguments) click to toggle source
# File lib/gtk3/text-buffer.rb, line 209
def serialize(*arguments)
  serialize_raw(*arguments).pack("C*")
end
Also aliased as: serialize_raw
serialize_raw(*arguments)
Alias for: serialize
set_text(text) click to toggle source
# File lib/gtk3/text-buffer.rb, line 188
def set_text(text)
  if text.is_a?(GLib::Bytes)
    text, text_size = text.to_s, text.size
  else
    text_size = text.bytesize
  end
  set_text_raw(text, text_size)
end
Also aliased as: set_text_raw, text=
set_text_raw(text)
Alias for: set_text
text=(text)
Alias for: set_text

Private Instance Methods

insert_interactive(iter, text, default_ediatable) click to toggle source
# File lib/gtk3/text-buffer.rb, line 225
def insert_interactive(iter, text, default_ediatable)
  if text.is_a?(GLib::Bytes)
    text, text_size = text.to_s, text.size
  else
    text_size = text.bytesize
  end
  insert_interactive_raw(iter, text, text_size, default_ediatable)
end
Also aliased as: insert_interactive_raw
insert_interactive_at_cursor(text, default_ediatable) click to toggle source
# File lib/gtk3/text-buffer.rb, line 235
def insert_interactive_at_cursor(text, default_ediatable)
  if text.is_a?(GLib::Bytes)
    text, text_size = text.to_s, text.size
  else
    text_size = text.bytesize
  end
  insert_interactive_at_cursor_raw(text, text_size, default_ediatable)
end
insert_interactive_at_cursor_raw(text, default_ediatable)
insert_interactive_raw(iter, text, default_ediatable)
Alias for: insert_interactive