]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbhistorytextctrl.cpp
- wxbHistoryTextCtrl : Created a new text control that keep an history
[bacula/bacula] / bacula / src / wx-console / wxbhistorytextctrl.cpp
1 /*
2  *
3  *   Text control with an history of commands typed
4  *
5  *    Nicolas Boichat, July 2004
6  *
7  */
8 /*
9    Copyright (C) 2004 Kern Sibbald and John Walker
10
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.
15
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.
20
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.
24  */
25  
26 #include "wxbhistorytextctrl.h"
27
28 BEGIN_EVENT_TABLE(wxbHistoryTextCtrl, wxTextCtrl)
29    EVT_KEY_UP(wxbHistoryTextCtrl::OnKeyUp)
30 END_EVENT_TABLE()
31
32 wxbHistoryTextCtrl::wxbHistoryTextCtrl(wxWindow* parent, wxWindowID id, 
33       const wxString& value, const wxPoint& pos, 
34       const wxSize& size , 
35       const wxValidator& validator, 
36       const wxString& name): 
37          wxTextCtrl(parent, id, value, pos, size, 
38             wxTE_PROCESS_ENTER, validator, name) {
39    index = 0;
40    history.Add("");
41 }
42
43 void wxbHistoryTextCtrl::HistoryAdd(wxString cmd) {
44    if (cmd == "") return;
45    index = history.Count();
46    history[index-1] = cmd;
47    history.Add("");
48 }
49
50 void wxbHistoryTextCtrl::OnKeyUp(wxKeyEvent& event) {
51    if (event.m_keyCode == WXK_UP) {
52       if (index > 0) {
53          if (index == (history.Count()-1)) {
54             history[index] = GetValue();
55          }
56          index--;
57          SetValue(history[index]);
58          SetInsertionPointEnd();
59       }
60    }
61    else if (event.m_keyCode == WXK_DOWN) {
62       if (index < (history.Count()-1)) {
63          index++;
64          SetValue(history[index]);
65          SetInsertionPointEnd();
66       }      
67    }
68    else {
69       event.Skip();
70    }
71 }
72
73