Class: Gtk::TextBuffer

Inherits:
Object
  • Object
show all
Extended by:
GLib::Deprecatable
Defined in:
lib/gtk4/deprecated.rb,
lib/gtk4/text-buffer.rb

Instance Method Summary collapse

Instance Method Details

#add_mark(mark, where) ⇒ Object



33
34
35
36
37
38
# File 'lib/gtk4/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

#add_mark_rawObject



32
# File 'lib/gtk4/text-buffer.rb', line 32

alias_method :add_mark_raw, :add_mark

#apply_tag(tag, start, last) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/gtk4/text-buffer.rb', line 202

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

#apply_tag_rawObject



201
# File 'lib/gtk4/text-buffer.rb', line 201

alias_method :apply_tag_raw, :apply_tag

#create_mark(name, where, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gtk4/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

#create_mark_rawObject



40
# File 'lib/gtk4/text-buffer.rb', line 40

alias_method :create_mark_raw, :create_mark

#create_tag(tag_name = nil, properties = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gtk4/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) ⇒ Object



56
57
58
59
60
61
# File 'lib/gtk4/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

#delete_mark_rawObject



55
# File 'lib/gtk4/text-buffer.rb', line 55

alias_method :delete_mark_raw, :delete_mark

#get_iter_at(arguments) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gtk4/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) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/gtk4/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 Gdk::Paintable
      insert_paintable_raw(iter, target)
    when GdkPixbuf::Pixbuf
      insert_paintable_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

#insert_at_cursor(text, options = {}) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/gtk4/text-buffer.rb', line 177

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

#insert_at_cursor_rawObject



176
# File 'lib/gtk4/text-buffer.rb', line 176

alias_method :insert_at_cursor_raw, :insert_at_cursor

#insert_markup(iter, markup, n_bytes = nil) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/gtk4/text-buffer.rb', line 165

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_markup_rawObject



164
# File 'lib/gtk4/text-buffer.rb', line 164

alias_method :insert_markup_raw, :insert_markup

#insert_rawObject



97
# File 'lib/gtk4/text-buffer.rb', line 97

alias_method :insert_raw,              :insert

#selection_boundsObject



211
212
213
214
215
216
217
218
# File 'lib/gtk4/text-buffer.rb', line 211

def selection_bounds
  selected, start_iter, end_iter = selection_bounds_raw
  if selected
    [start_iter, end_iter]
  else
    nil
  end
end

#selection_bounds_rawObject



210
# File 'lib/gtk4/text-buffer.rb', line 210

alias_method :selection_bounds_raw, :selection_bounds

#set_text(text) ⇒ Object Also known as: text=



190
191
192
193
194
195
196
197
# File 'lib/gtk4/text-buffer.rb', line 190

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

#set_text_rawObject



189
# File 'lib/gtk4/text-buffer.rb', line 189

alias_method :set_text_raw, :set_text