Class: Canis::TextActionEvent

Inherits:
ActionEvent show all
Defined in:
lib/canis/core/include/ractionevent.rb

Overview

a derivative of Action Event for textviews We allow a user to press ENTER on a row and use that for processing. We are basically using TextView as a list in which user can scroll around and move cursor at will.

Instance Attribute Summary collapse

Attributes inherited from ActionEvent

#action_command, #event, #source

Instance Method Summary collapse

Methods inherited from ActionEvent

#getvalue

Constructor Details

#initialize(source, event, action_command, current_index, curpos) ⇒ TextActionEvent

Returns a new instance of TextActionEvent.



46
47
48
49
50
# File 'lib/canis/core/include/ractionevent.rb', line 46

def initialize source, event, action_command, current_index, curpos
  super source, event, action_command
  @current_index = current_index
  @curpos = curpos
end

Instance Attribute Details

#curposObject

cursor position on the line



45
46
47
# File 'lib/canis/core/include/ractionevent.rb', line 45

def curpos
  @curpos
end

#current_indexObject

current_index or line number starting 0



43
44
45
# File 'lib/canis/core/include/ractionevent.rb', line 43

def current_index
  @current_index
end

Instance Method Details

#textObject

the text of the line on which the user is



52
53
54
# File 'lib/canis/core/include/ractionevent.rb', line 52

def text
  source.current_value.to_s
end

#word_under_cursor(line = text(), pos = @curpos, delim = " ") ⇒ Object

the word under the cursor TODO if its a text with pipe delim, then ??



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/canis/core/include/ractionevent.rb', line 57

def word_under_cursor line=text(), pos=@curpos, delim=" "
  line ||= text()
  pos ||= @curpos
  # if pressed on a space, try to go to next word to make easier 2013-03-24
  if line[pos,1] == delim
    while line[pos,1] == delim
      pos += 1
    end
  end
  finish = line.index(delim, pos)
  start = line.rindex(delim,pos)
  finish = -1 if finish.nil?
  start = 0 if start.nil?
  return line[start..finish]
end