]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbhistorytextctrl.cpp
Add version strings
[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  *    Version $Id$
8  */
9 /*
10    Copyright (C) 2004 Kern Sibbald and John Walker
11
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License
14    as published by the Free Software Foundation; either version 2
15    of the License, or (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26  
27 #include "wxbhistorytextctrl.h"
28
29 BEGIN_EVENT_TABLE(wxbHistoryTextCtrl, wxTextCtrl)
30    EVT_KEY_UP(wxbHistoryTextCtrl::OnKeyUp)
31 END_EVENT_TABLE()
32
33 wxbHistoryTextCtrl::wxbHistoryTextCtrl(wxWindow* parent, wxWindowID id, 
34       const wxString& value, const wxPoint& pos, 
35       const wxSize& size , 
36       const wxValidator& validator, 
37       const wxString& name): 
38          wxTextCtrl(parent, id, value, pos, size, 
39             wxTE_PROCESS_ENTER, validator, name) {
40    index = 0;
41    history.Add("");
42 }
43
44 void wxbHistoryTextCtrl::HistoryAdd(wxString cmd) {
45    if (cmd == "") return;
46    index = history.Count();
47    history[index-1] = cmd;
48    history.Add("");
49 }
50
51 void wxbHistoryTextCtrl::OnKeyUp(wxKeyEvent& event) {
52    if (event.m_keyCode == WXK_UP) {
53       if (index > 0) {
54          if (index == ((int)history.Count()-1)) {
55             history[index] = GetValue();
56          }
57          index--;
58          SetValue(history[index]);
59          SetInsertionPointEnd();
60       }
61    }
62    else if (event.m_keyCode == WXK_DOWN) {
63       if (index < ((int)history.Count()-1)) {
64          index++;
65          SetValue(history[index]);
66          SetInsertionPointEnd();
67       }      
68    }
69    else {
70       event.Skip();
71    }
72 }