Class: JLDrill::Gtk::VocabPopupFactory
- Inherits:
-
PopupFactory
- Object
- PopupFactory
- JLDrill::Gtk::VocabPopupFactory
- Defined in:
- lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb
Instance Method Summary collapse
- #createPopup(searchString, x, y) ⇒ Object
- #dictionaryLoaded? ⇒ Boolean
- #getCandidates(string) ⇒ Object
- #getStringAt(widget, window, x, y) ⇒ Object
-
#initialize(view) ⇒ VocabPopupFactory
constructor
A new instance of VocabPopupFactory.
- #notify(event) ⇒ Object
- #sameString?(string, x, y) ⇒ Boolean
Methods inherited from PopupFactory
#belowRect, #block, #closePopup, #getPopupString, #showBusy, #toAbsPos, #unblock
Constructor Details
#initialize(view) ⇒ VocabPopupFactory
Returns a new instance of VocabPopupFactory.
8 9 10 |
# File 'lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb', line 8 def initialize(view) super(view) end |
Instance Method Details
#createPopup(searchString, x, y) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb', line 44 def createPopup(searchString, x, y) closePopup candidates = getCandidates(searchString) if !candidates.nil? && !candidates.empty? if !candidates[0].kanji.nil? string = candidates[0].kanji else string = candidates[0].reading end @currentPopup = VocabPopup.new(string, candidates, @view.mainWindow, x, y) end end |
#dictionaryLoaded? ⇒ Boolean
12 13 14 |
# File 'lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb', line 12 def dictionaryLoaded? @context.dictionaryLoaded? end |
#getCandidates(string) ⇒ Object
21 22 23 |
# File 'lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb', line 21 def getCandidates(string) return @context.search(string) end |
#getStringAt(widget, window, x, y) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb', line 25 def getStringAt(, window, x, y) type = .get_window_type(window) coords = .window_to_buffer_coords(type, x, y) iter, tr = .get_iter_at_position(coords[0], coords[1]) sentenceEnd = iter.buffer.get_iter_at_offset(iter.offset) sentenceEnd.forward_sentence_end string = iter.get_visible_text(sentenceEnd) pos = .get_iter_location(iter) if (coords[0] > pos.x) && (coords[0] < pos.x + pos.width) && string != "" rect = .buffer_to_window_coords(type, pos.x, pos.y) charPos = belowRect([rect[0], rect[1], pos.width, pos.height]) screenPos = toAbsPos(, charPos[0], charPos[1]) [string, screenPos] else [nil, nil] end end |
#notify(event) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb', line 58 def notify(event) if @blocked || !dictionaryLoaded? return end string, screenPos = getStringAt(event., event.motion.window, event.motion.x, event.motion.y) if string.nil? || screenPos.nil? closePopup return elsif sameString?(string, screenPos[0], screenPos[1]) return end createPopup(string, screenPos[0], screenPos[1]) end |
#sameString?(string, x, y) ⇒ Boolean
16 17 18 19 |
# File 'lib/jldrill/views/gtk/widgets/VocabPopupFactory.rb', line 16 def sameString?(string, x, y) !@currentPopup.nil? && # @currentPopup.character == string && @currentPopup.x == x && @currentPopup.y == y end |