*
* Main frame
*
- * Nicolas Boichat, April 2004
+ * Nicolas Boichat, July 2004
*
+ * Version $Id$
*/
/*
Copyright (C) 2004 Kern Sibbald and John Walker
#include <wx/arrimpl.cpp>
#include <wx/stattext.h>
-
+#include <wx/statline.h>
#include <wx/config.h>
#include <wx/filename.h>
+#undef Yield /* MinGW defines Yield */
+
// ----------------------------------------------------------------------------
// event tables and other macros for wxWindows
// ----------------------------------------------------------------------------
consoleCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
#endif
- wxFlexGridSizer *consoleSizer = new wxFlexGridSizer(2, 1, 0, 0);
+ helpCtrl = new wxStaticText(consolePanel, -1, "Type your command below:");
+
+ wxFlexGridSizer *consoleSizer = new wxFlexGridSizer(4, 1, 0, 0);
consoleSizer->AddGrowableCol(0);
consoleSizer->AddGrowableRow(0);
- typeCtrl = new wxTextCtrl(consolePanel,TypeText,"",wxDefaultPosition,wxSize(200,20), wxTE_PROCESS_ENTER);
+ typeCtrl = new wxbHistoryTextCtrl(helpCtrl, consolePanel,TypeText,"",wxDefaultPosition,wxSize(200,20));
sendButton = new wxButton(consolePanel, SendButton, "Send");
- wxFlexGridSizer *typeSizer = new wxFlexGridSizer(1, 3, 0, 0);
- typeSizer->AddGrowableCol(1);
+ wxFlexGridSizer *typeSizer = new wxFlexGridSizer(1, 2, 0, 0);
+ typeSizer->AddGrowableCol(0);
typeSizer->AddGrowableRow(0);
- typeSizer->Add(new wxStaticText(consolePanel, -1, "Command: "), 0, wxALIGN_CENTER | wxALL, 0);
+ //typeSizer->Add(new wxStaticText(consolePanel, -1, "Command: "), 0, wxALIGN_CENTER | wxALL, 0);
typeSizer->Add(typeCtrl, 1, wxEXPAND | wxALL, 0);
typeSizer->Add(sendButton, 1, wxEXPAND | wxLEFT, 5);
consoleSizer->Add(consoleCtrl, 1, wxEXPAND | wxALL, 0);
- consoleSizer->Add(typeSizer, 0, wxEXPAND | wxALL, 0);
+ consoleSizer->Add(new wxStaticLine(consolePanel, -1), 0, wxEXPAND | wxALL, 0);
+ consoleSizer->Add(helpCtrl, 1, wxEXPAND | wxALL, 2);
+ consoleSizer->Add(typeSizer, 0, wxEXPAND | wxALL, 2);
consolePanel->SetAutoLayout( TRUE );
consolePanel->SetSizer( consoleSizer );
lockedbyconsole = false;
consoleBuffer = "";
+
+ configfile = "";
}
/*
if (ct != NULL) {
ct->Delete();
ct = NULL;
+ wxTheApp->Yield();
}
if (promptparser == NULL) {
promptparser = new wxbPromptParser();
}
- wxString configfile;
-
- if (config == "") {
- if ((wxTheApp->argc == 3) && (wxString(wxTheApp->argv[1]) == "-c")) {
- configfile = wxTheApp->argv[2];
+ if (config == "") {
+ configfile = "";
+
+ if (((wxTheApp->argc % 2) != 1)) {
+ Print("Error while parsing command line arguments, using defaults.\n", CS_DEBUG);
+ Print("Usage: wx-console [-c configfile] [-w tmp]\n", CS_DEBUG);
}
else {
+ for (int c = 1; c < wxTheApp->argc; c += 2) {
+ if ((wxTheApp->argc >= c+2) && (wxString(wxTheApp->argv[c]) == "-c")) {
+ configfile = wxTheApp->argv[c+1];
+ }
+ if ((wxTheApp->argc >= c+2) && (wxString(wxTheApp->argv[c]) == "-w")) {
+ console_thread::SetWorkingDirectory(wxTheApp->argv[c+1]);
+ }
+ if (wxTheApp->argv[c][0] != '-') {
+ Print("Error while parsing command line arguments, using defaults.\n", CS_DEBUG);
+ Print("Usage: wx-console [-c configfile] [-w tmp]\n", CS_DEBUG);
+ break;
+ }
+ }
+ }
+
+ if (configfile == "") {
wxConfig::Set(new wxConfig("wx-console", "bacula"));
if (!wxConfig::Get()->Read("/ConfigFile", &configfile)) {
#ifdef HAVE_MACOSX
#endif //HAVE_WIN32
#endif //HAVE_MACOSX
wxConfig::Get()->Write("/ConfigFile", configfile);
- if (wxTheApp->argc > 1) {
- Print("Error while parsing command line arguments, using defaults.\n", CS_DEBUG);
- Print("Usage: wx-console [-c configfile]\n", CS_DEBUG);
- }
int answer = wxMessageBox(
wxString("It seems that it is the first time you run wx-console.\n") <<
if (ct != NULL) {
ct->Delete();
ct = NULL;
+ wxTheApp->Yield();
}
console_thread::FreeLib();
frame = NULL;
+ wxTheApp->Yield();
Close(TRUE);
}
wxYES_NO | wxICON_QUESTION, this);
if (answer == wxYES) {
wxConfigBase::Get()->Write("/ConfigFile", configfile);
+ wxConfigBase::Get()->Flush();
StartConsoleThread("");
return;
}
}
void wxbMainFrame::OnConnect(wxCommandEvent& event) {
- menuFile->Enable(MenuConnect, false);
- menuFile->Enable(MenuDisconnect, false);
- menuFile->Enable(ChangeConfigFile, false);
- menuFile->Enable(EditConfigFile, false);
-
- if (ct != NULL) {
- ct->Delete();
- ct = NULL;
- }
- if (promptparser == NULL) {
- promptparser = new wxbPromptParser();
- }
-
- ct = new console_thread();
- ct->Create();
- ct->Run();
- SetStatusText("Connecting to the director...");
+ StartConsoleThread(configfile);
}
void wxbMainFrame::OnDisconnect(wxCommandEvent& event) {
{
lockedbyconsole = true;
DisablePanels();
+ typeCtrl->HistoryAdd(typeCtrl->GetValue());
wxString str = typeCtrl->GetValue() + "\n";
Send(str);
}
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",
if (status == CS_CONNECTED) {
SetStatusText("Connected to the director.");
+ typeCtrl->ClearCommandList();
+ wxbDataTokenizer* dt = wxbUtils::WaitForEnd(".help", true);
+ int i, j;
+ wxString str;
+ for (i = 0; i < (int)dt->GetCount(); i++) {
+ str = (*dt)[i];
+ str.RemoveLast();
+ if ((j = str.Find(' ')) > -1) {
+ typeCtrl->AddCommand(str.Mid(0, j), str.Mid(j+1));
+ }
+ }
EnablePanels();
menuFile->Enable(MenuConnect, true);
menuFile->SetLabel(MenuConnect, "Reconnect");
menuFile->SetHelpString(MenuConnect, "Reconnect to the director");
- menuFile->Enable(MenuDisconnect, false);
+ menuFile->Enable(MenuDisconnect, true);
menuFile->Enable(ChangeConfigFile, true);
menuFile->Enable(EditConfigFile, true);
return;
if (status == CS_DISCONNECTED) {
consoleCtrl->AppendText(consoleBuffer);
consoleBuffer = "";
+ consoleCtrl->ScrollLines(3);
SetStatusText("Disconnected of the director.");
DisablePanels();
return;
int res = ::wxGetSingleChoiceIndex(message,
"wx-console: unexpected director's question.", n, choices, this);
- if (res == -1) {
- Send("\n");
+ if (res == -1) { //Cancel pressed
+ Send(".\n");
}
else {
- Send(wxString() << numbers[res] << "\n");
+ if (promptparser->isNumericalChoice()) {
+ Send(wxString() << numbers[res] << "\n");
+ }
+ else {
+ Send(wxString() << choices[res] << "\n");
+ }
}
}
else {
if (status == CS_DEBUG) {
consoleCtrl->AppendText(consoleBuffer);
consoleBuffer = "";
+ consoleCtrl->ScrollLines(3);
consoleCtrl->SetDefaultStyle(wxTextAttr(wxColour(0, 128, 0)));
}
else {
if (lockedbyconsole) {
EnableConsole(true);
}
- consoleBuffer << "<P>";
+ //consoleBuffer << "<P>";
}
if ((status == CS_END) || (status == CS_PROMPT) || (str.Find("\n") > -1)) {
firePrintEvent("", status);
}
}
-