3 * Text control with an history of commands typed
5 * Nicolas Boichat, July 2004
9 Copyright (C) 2004 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "wxbhistorytextctrl.h"
28 BEGIN_EVENT_TABLE(wxbHistoryTextCtrl, wxTextCtrl)
29 EVT_KEY_UP(wxbHistoryTextCtrl::OnKeyUp)
32 wxbHistoryTextCtrl::wxbHistoryTextCtrl(wxWindow* parent, wxWindowID id,
33 const wxString& value, const wxPoint& pos,
35 const wxValidator& validator,
36 const wxString& name):
37 wxTextCtrl(parent, id, value, pos, size,
38 wxTE_PROCESS_ENTER, validator, name) {
43 void wxbHistoryTextCtrl::HistoryAdd(wxString cmd) {
44 if (cmd == "") return;
45 index = history.Count();
46 history[index-1] = cmd;
50 void wxbHistoryTextCtrl::OnKeyUp(wxKeyEvent& event) {
51 if (event.m_keyCode == WXK_UP) {
53 if (index == ((int)history.Count()-1)) {
54 history[index] = GetValue();
57 SetValue(history[index]);
58 SetInsertionPointEnd();
61 else if (event.m_keyCode == WXK_DOWN) {
62 if (index < ((int)history.Count()-1)) {
64 SetValue(history[index]);
65 SetInsertionPointEnd();