3 * Text control with an history of commands typed
5 * Nicolas Boichat, July 2004
10 Bacula® - The Network Backup Solution
12 Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
14 The main author of Bacula is Kern Sibbald, with contributions from
15 many others, a complete list can be found in the file AUTHORS.
16 This program is Free Software; you can redistribute it and/or
17 modify it under the terms of version two of the GNU General Public
18 License as published by the Free Software Foundation and included
21 This program is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 Bacula® is a registered trademark of Kern Sibbald.
32 The licensor of Bacula is the Free Software Foundation Europe
33 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34 Switzerland, email:ftf@fsfeurope.org.
37 /* Windows debug builds set _DEBUG which is used by wxWidgets to select their
38 * debug memory allocator. Unfortunately it conflicts with Bacula's SmartAlloc.
39 * So we turn _DEBUG off since we aren't interested in things it enables.
45 #include "wxbhistorytextctrl.h"
47 BEGIN_EVENT_TABLE(wxbHistoryTextCtrl, wxTextCtrl)
48 EVT_KEY_DOWN(wxbHistoryTextCtrl::OnKeyDown)
49 EVT_KEY_UP(wxbHistoryTextCtrl::OnKeyUp)
52 wxbHistoryTextCtrl::wxbHistoryTextCtrl(wxStaticText* help,
53 wxWindow* parent, wxWindowID id,
54 const wxString& value, const wxPoint& pos,
56 const wxValidator& validator,
57 const wxString& name):
58 wxTextCtrl(parent, id, value, pos, size,
59 wxTE_PROCESS_ENTER, validator, name) {
65 void wxbHistoryTextCtrl::AddCommand(wxString cmd, wxString description) {
66 commands[cmd] = description;
69 void wxbHistoryTextCtrl::ClearCommandList() {
73 void wxbHistoryTextCtrl::HistoryAdd(wxString cmd) {
74 if (cmd == wxT("")) return;
75 index = history.Count();
76 history[index-1] = cmd;
80 void wxbHistoryTextCtrl::SetValue(const wxString& value) {
81 if (value == wxT("")) {
82 help->SetLabel(_("Type your command below:"));
84 wxTextCtrl::SetValue(value);
87 void wxbHistoryTextCtrl::OnKeyDown(wxKeyEvent& event) {
88 if (event.m_keyCode == WXK_TAB) {
96 void wxbHistoryTextCtrl::OnKeyUp(wxKeyEvent& event) {
97 if (event.m_keyCode == WXK_UP) {
99 if (index == ((int)history.Count()-1)) {
100 history[index] = GetValue();
103 SetValue(history[index]);
104 SetInsertionPointEnd();
107 else if (event.m_keyCode == WXK_DOWN) {
108 if (index < ((int)history.Count()-1)) {
110 SetValue(history[index]);
111 SetInsertionPointEnd();
114 else if (GetValue() != wxT("")) {
115 wxbCommands::iterator it;
117 wxString helptext = _("Unknown command.");
119 for( it = commands.begin(); it != commands.end(); ++it ) {
120 if (it->first.Find(GetValue()) == 0) {
123 helptext += wxT(" ") + it->first;
125 else if (found > 1) {
126 helptext = _("Possible completions: ") + key + wxT(" ") + it->first;
128 else { // (found == 1)
129 helptext = it->first + wxT(": ") + it->second;
133 else if (GetValue().Find(it->first) == 0) {
134 helptext = it->first + wxT(": ") + it->second;
140 help->SetLabel(helptext);
142 if (event.m_keyCode == WXK_TAB) {
145 SetInsertionPointEnd();
153 help->SetLabel(_("Type your command below:"));