| Class | Ui::WxWidgets::Widgets::BufferedTextCtrl |
| In: |
ui/wx/widgets/console.rb
|
| Parent: | Wx::TextCtrl |
# File ui/wx/widgets/console.rb, line 47
47: def initialize(parent, name)
48: super(
49: parent,
50: Wx::ID_ANY,
51: '',
52: Wx::DEFAULT_POSITION,
53: Wx::DEFAULT_SIZE,
54: Wx::TE_PROCESS_ENTER,
55: Wx::DEFAULT_VALIDATOR,
56: name)
57:
58: evt_char do | event | on_char(event) end
59:
60: #initialize internal history buffer
61: @history = []
62: @pointer = 0
63: @up = true
64: end
Returns the last command issued by the user. This method should be used when the parent window captures a returnPressed event to examine the las line inputted by the user.
# File ui/wx/widgets/console.rb, line 104
104: def last_command()
105: @history.last
106: end
# File ui/wx/widgets/console.rb, line 66
66: def on_char(event)
67: case (event.key_code)
68: when Wx::K_UP
69: if ((@history.size > 0) && (@pointer >= 0) )
70: if (@pointer == @history.size)
71: @history << self.get_value
72: end
73: @pointer -= 1 if @pointer > 0
74: self.set_value( @history[@pointer] )
75: self.set_insertion_point_end()
76: end
77: when Wx::K_DOWN
78: if ((@history.size > 0) && (@pointer < @history.size) )
79: @pointer += 1 if @pointer < @history.size - 1
80: self.set_value( @history[@pointer] )
81: self.set_insertion_point_end()
82: end
83: when Wx::K_RETURN
84: $logger.debug(@history)
85: #keep an eye on the last entry to avoid empty entries in the list
86: if ((@history.size > 0) && (@history.last.strip.size == 0) )
87: @history.pop
88: end
89:
90: line = self.get_value.strip
91:
92: if line.size > 0
93: @history << line
94: @pointer = @history.size
95: self.clear
96: end
97: $logger.debug(@history)
98: end
99: event.skip
100: end