From: Nicolas Boichat Date: Thu, 15 Jul 2004 17:09:06 +0000 (+0000) Subject: - wxbHistoryTextCtrl : Created a new text control that keep an history X-Git-Tag: Release-1.35.1~68 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=38bdcf6ff540827954e113a59348fda1d1be884c;p=bacula%2Fbacula - wxbHistoryTextCtrl : Created a new text control that keep an history of typed commands. - wxbMainFrame : Fixed config file problem when changing the default configuration file (Linux) git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1466 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/wx-console/CHANGELOG b/bacula/src/wx-console/CHANGELOG index 2d31e0e75c..9a56cfcf4a 100644 --- a/bacula/src/wx-console/CHANGELOG +++ b/bacula/src/wx-console/CHANGELOG @@ -1,3 +1,11 @@ +15-07-2004 : + - wxbHistoryTextCtrl : Created a new text control that keep an history + of typed commands. + +14-07-2004 : + - wxbMainFrame : Fixed config file problem when changing the default + configuration file (Linux) + 03-07-2004 : - wxbConfigPanel : Fixed ?: operator cast problem with gcc 2.95. diff --git a/bacula/src/wx-console/Makefile.in b/bacula/src/wx-console/Makefile.in index 9c3f0163c3..0457717cba 100644 --- a/bacula/src/wx-console/Makefile.in +++ b/bacula/src/wx-console/Makefile.in @@ -22,10 +22,10 @@ dummy: # CONSSRCS = main.cpp console_thread.cpp authenticate.c console_conf.c wxbrestorepanel.cpp \ wxbmainframe.cpp wxbtableparser.cpp wxbtreectrl.cpp wxblistctrl.cpp wxbutils.cpp \ - wxbconfigpanel.cpp wxbconfigfileeditor.cpp + wxbconfigpanel.cpp wxbconfigfileeditor.cpp wxbhistorytextctrl.cpp CONSOBJS = main.o console_thread.o authenticate.o console_conf.o wxbrestorepanel.o \ wxbmainframe.o wxbtableparser.o wxbtreectrl.o wxblistctrl.o wxbutils.o \ - wxbconfigpanel.o wxbconfigfileeditor.o + wxbconfigpanel.o wxbconfigfileeditor.o wxbhistorytextctrl.o win32 = wx-console_private.res diff --git a/bacula/src/wx-console/TODO b/bacula/src/wx-console/TODO index 858787c2f6..3d907a8c7e 100644 --- a/bacula/src/wx-console/TODO +++ b/bacula/src/wx-console/TODO @@ -1,5 +1,9 @@ general : Show nice messages boxes when errors occurs. +wxbRestorePanel : Crashing when there is no backup to show (fresh install) + +GTK2 : The console control is not scrolled correctly + Win32 : Crash when quitting while trying to connect Mac OS X : "You must first get a unique identifier for your application, @@ -22,7 +26,7 @@ wxbUtils : add clients, jobs, filesets, pools... list, merge patch file (wxbnewu general : add a tab containing messages -wxbMainFrame : Implement command history (accessible with up and down keys) +wxbMainFrame : Implement command completion (tab) wxbMainFrame : When an unexpected question is in this format (***? (yes/mod/no):), show a list to choose one of these possibilities. diff --git a/bacula/src/wx-console/wxbhistorytextctrl.cpp b/bacula/src/wx-console/wxbhistorytextctrl.cpp new file mode 100644 index 0000000000..eb5120ef4c --- /dev/null +++ b/bacula/src/wx-console/wxbhistorytextctrl.cpp @@ -0,0 +1,73 @@ +/* + * + * Text control with an history of commands typed + * + * Nicolas Boichat, July 2004 + * + */ +/* + Copyright (C) 2004 Kern Sibbald and John Walker + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "wxbhistorytextctrl.h" + +BEGIN_EVENT_TABLE(wxbHistoryTextCtrl, wxTextCtrl) + EVT_KEY_UP(wxbHistoryTextCtrl::OnKeyUp) +END_EVENT_TABLE() + +wxbHistoryTextCtrl::wxbHistoryTextCtrl(wxWindow* parent, wxWindowID id, + const wxString& value, const wxPoint& pos, + const wxSize& size , + const wxValidator& validator, + const wxString& name): + wxTextCtrl(parent, id, value, pos, size, + wxTE_PROCESS_ENTER, validator, name) { + index = 0; + history.Add(""); +} + +void wxbHistoryTextCtrl::HistoryAdd(wxString cmd) { + if (cmd == "") return; + index = history.Count(); + history[index-1] = cmd; + history.Add(""); +} + +void wxbHistoryTextCtrl::OnKeyUp(wxKeyEvent& event) { + if (event.m_keyCode == WXK_UP) { + if (index > 0) { + if (index == (history.Count()-1)) { + history[index] = GetValue(); + } + index--; + SetValue(history[index]); + SetInsertionPointEnd(); + } + } + else if (event.m_keyCode == WXK_DOWN) { + if (index < (history.Count()-1)) { + index++; + SetValue(history[index]); + SetInsertionPointEnd(); + } + } + else { + event.Skip(); + } +} + + diff --git a/bacula/src/wx-console/wxbhistorytextctrl.h b/bacula/src/wx-console/wxbhistorytextctrl.h new file mode 100644 index 0000000000..a3c0ccf34a --- /dev/null +++ b/bacula/src/wx-console/wxbhistorytextctrl.h @@ -0,0 +1,56 @@ +/* + * + * Text control with an history of commands typed + * + * Nicolas Boichat, July 2004 + * + */ +/* + Copyright (C) 2004 Kern Sibbald and John Walker + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef WXBHISTORYTEXTCTRL +#define WXBHISTORYTEXTCTRL + +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include + +class wxbHistoryTextCtrl: public wxTextCtrl { + public: + wxbHistoryTextCtrl(wxWindow* parent, wxWindowID id, + const wxString& value = "", const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxTextCtrlNameStr); + + void HistoryAdd(wxString cmd); + private: + wxArrayString history; + int index; + + void OnKeyUp(wxKeyEvent& event); + + DECLARE_EVENT_TABLE(); +}; + +#endif //WXBHISTORYTEXTCTRL + diff --git a/bacula/src/wx-console/wxbmainframe.cpp b/bacula/src/wx-console/wxbmainframe.cpp index c61c574216..13a29fb4c3 100644 --- a/bacula/src/wx-console/wxbmainframe.cpp +++ b/bacula/src/wx-console/wxbmainframe.cpp @@ -2,7 +2,7 @@ * * Main frame * - * Nicolas Boichat, April 2004 + * Nicolas Boichat, July 2004 * */ /* @@ -264,7 +264,7 @@ wxbMainFrame::wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSi consoleSizer->AddGrowableCol(0); consoleSizer->AddGrowableRow(0); - typeCtrl = new wxTextCtrl(consolePanel,TypeText,"",wxDefaultPosition,wxSize(200,20), wxTE_PROCESS_ENTER); + typeCtrl = new wxbHistoryTextCtrl(consolePanel,TypeText,"",wxDefaultPosition,wxSize(200,20)); sendButton = new wxButton(consolePanel, SendButton, "Send"); wxFlexGridSizer *typeSizer = new wxFlexGridSizer(1, 3, 0, 0); @@ -479,6 +479,7 @@ void wxbMainFrame::OnChangeConfig(wxCommandEvent& event) { wxYES_NO | wxICON_QUESTION, this); if (answer == wxYES) { wxConfigBase::Get()->Write("/ConfigFile", configfile); + wxConfigBase::Get()->Flush(); StartConsoleThread(""); return; } @@ -512,6 +513,7 @@ void wxbMainFrame::OnEnter(wxCommandEvent& WXUNUSED(event)) { lockedbyconsole = true; DisablePanels(); + typeCtrl->HistoryAdd(typeCtrl->GetValue()); wxString str = typeCtrl->GetValue() + "\n"; Send(str); } @@ -538,6 +540,7 @@ void wxbMainFrame::Print(wxString str, int status) consoleCtrl->AppendText(consoleBuffer); consoleBuffer = ""; SetStatusText("Console thread terminated."); + consoleCtrl->ScrollLines(3); ct = NULL; DisablePanels(); int answer = wxMessageBox("Connection to the director lost. Quit program?", "Connection lost", @@ -569,6 +572,7 @@ void wxbMainFrame::Print(wxString str, int status) if (status == CS_DISCONNECTED) { consoleCtrl->AppendText(consoleBuffer); consoleBuffer = ""; + consoleCtrl->ScrollLines(3); SetStatusText("Disconnected of the director."); DisablePanels(); return; @@ -637,6 +641,7 @@ void wxbMainFrame::Print(wxString str, int status) if (status == CS_DEBUG) { consoleCtrl->AppendText(consoleBuffer); consoleBuffer = ""; + consoleCtrl->ScrollLines(3); consoleCtrl->SetDefaultStyle(wxTextAttr(wxColour(0, 128, 0))); } else { diff --git a/bacula/src/wx-console/wxbmainframe.h b/bacula/src/wx-console/wxbmainframe.h index 3dab968191..9cdcc00005 100644 --- a/bacula/src/wx-console/wxbmainframe.h +++ b/bacula/src/wx-console/wxbmainframe.h @@ -2,7 +2,7 @@ * * Main frame header file * - * Nicolas Boichat, April 2004 + * Nicolas Boichat, July 2004 * */ /* @@ -48,6 +48,8 @@ #include "wxbutils.h" +#include "wxbhistorytextctrl.h" + WX_DEFINE_ARRAY(wxbDataParser*, wxbDataParsers); // ---------------------------------------------------------------------------- @@ -135,11 +137,13 @@ private: wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style); ~wxbMainFrame(); + static wxbMainFrame *frame; /* this */ + wxMenu *menuFile; wxNotebook *notebook; /* main notebook */ wxTextCtrl *consoleCtrl; /* wxTextCtrl containing graphical console */ - wxTextCtrl *typeCtrl; /* wxTextCtrl for console user input */ + wxbHistoryTextCtrl *typeCtrl; /* wxbHistoryTextCtrl for console user input */ wxButton *sendButton; /* wxButton used to send data */ wxbPanel **panels; /* panels array, contained in the notebook */ @@ -147,14 +151,12 @@ private: wxbPromptParser* promptparser; /* prompt parser catching uncatched questions */ - static wxbMainFrame *frame; /* this */ - bool lockedbyconsole; /* true if the panels have been locked by something typed in the console */ wxString configfile; /* configfile used */ wxString consoleBuffer; /* Buffer used to print in the console line by line */ - + // any class wishing to process wxWindows events must use this macro DECLARE_EVENT_TABLE() };