Class: Gtk::TextView

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk_app/ext/text_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(buffer = nil) ⇒ TextView

Returns a new instance of TextView.



7
8
9
10
# File 'lib/gtk_app/ext/text_view.rb', line 7

def initialize(buffer = nil)
  self.buffer = buffer
  self.gtk2_initialize(nil)
end

Instance Method Details

#__button_press_event(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
24
25
# File 'lib/gtk_app/ext/text_view.rb', line 18

def __button_press_event(event)
  if event.button == 3
    x, y = window_to_buffer_coords(Gtk::TextView::WINDOW_TEXT, *event.coords)
    iter, _ = get_iter_at_position(x, y)
    buffer.move_mark('click', iter)
  end
  false
end

#__populate_popup(menu) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gtk_app/ext/text_view.rb', line 28

def __populate_popup(menu)
  iter = buffer.get_iter_at_mark(buffer.text_marks[:click])
  s_iter, e_iter = iter.clone, iter.clone
  
  s_iter.backward_word_start unless s_iter.starts_word?
  e_iter.forward_word_end if e_iter.inside_word?

  word = buffer.get_text(s_iter, e_iter)

  menu_item = Gtk::MenuItem.new("Spelling Suggestions")
  submenu   = Gtk::Menu.new
  buffer.spell_check.send(:suggestions, word).each_with_index do |wurd, ndx|
    _menu_item = Gtk::MenuItem.new(wurd)
    _menu_item.signal_connect('activate') do |mi|
      buffer.begin_user_action
      buffer.delete(s_iter, e_iter)
      buffer.insert(s_iter, mi.label)
      buffer.end_user_action
    end
    submenu.append(_menu_item)
  end 
  menu_item.submenu = submenu
  menu.prepend(menu_item)
  menu.show_all
end

#buffer=(buffer) ⇒ Object



12
13
14
15
# File 'lib/gtk_app/ext/text_view.rb', line 12

def buffer=(buffer)
  buffer.view = self if buffer.is_a?(GtkApp::TextBuffer)
  self.gtk2_buffer = buffer
end

#gtk2_buffer=Object



5
# File 'lib/gtk_app/ext/text_view.rb', line 5

alias_method :gtk2_buffer=, :buffer=

#gtk2_initializeObject



4
# File 'lib/gtk_app/ext/text_view.rb', line 4

alias_method :gtk2_initialize, :initialize