Class: Smartdict::Gui::WordList
- Inherits:
-
Gtk::TreeView
- Object
- Gtk::TreeView
- Smartdict::Gui::WordList
- Defined in:
- lib/smartdict/gui/word_list.rb
Defined Under Namespace
Classes: ListColumn
Instance Method Summary collapse
- #first_item_matches?(word, from_lang, to_lang) ⇒ Boolean
-
#initialize(controller) ⇒ WordList
constructor
A new instance of WordList.
- #prepend_word(translation) ⇒ Object
- #scroll_up ⇒ Object
Constructor Details
#initialize(controller) ⇒ WordList
Returns a new instance of WordList.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/smartdict/gui/word_list.rb', line 24 def initialize(controller) @controller = controller @list_model = Gtk::ListStore.new(String, String, String) super(@list_model) self.append_column(ListColumn.new("History")) self.selection.signal_connect("changed"){ item = self.selection.selected word, from_lang, to_lang = item[0], item[1], item[2] @controller.translate_selected_word(word, from_lang, to_lang) } end |
Instance Method Details
#first_item_matches?(word, from_lang, to_lang) ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/smartdict/gui/word_list.rb', line 47 def first_item_matches?(word, from_lang, to_lang) iter = @list_model.iter_first return false unless iter word == @list_model.get_value(iter, 0) && from_lang == @list_model.get_value(iter, 1) && to_lang == @list_model.get_value(iter, 2) end |
#prepend_word(translation) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/smartdict/gui/word_list.rb', line 39 def prepend_word(translation) item = @list_model.prepend item[0] = translation.word item[1] = translation.from_lang item[2] = translation.to_lang selection.select_iter(item) end |
#scroll_up ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/smartdict/gui/word_list.rb', line 55 def scroll_up # TODO: It's a dirty hack! # We need just resize WordList and set vadjustment.value = 0. # But WordList is resized after, so I do this hack to make sure # that it's already resized. Thread.new do # Expected to parent be Gtk::ScrolledWindow vad = self.parent.vadjustment vad.value = vad.lower vad.value_changed end end |