]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/wx-console/wxbmainframe.cpp
- Fix ANSI labels to put EOF1 and EOF2 after each file mark.
[bacula/bacula] / bacula / src / wx-console / wxbmainframe.cpp
index 13a29fb4c3bd29061fa95124bb0b47efb1fd6f1b..5f03634826dd03801857d8d19287d9ea43297ed5 100644 (file)
@@ -4,6 +4,7 @@
  *
  *    Nicolas Boichat, July 2004
  *
+ *    Version $Id$
  */
 /*
    Copyright (C) 2004 Kern Sibbald and John Walker
@@ -36,7 +37,7 @@
 #include <wx/arrimpl.cpp>
 
 #include <wx/stattext.h>
-
+#include <wx/statline.h>
 #include <wx/config.h>
 
 #include <wx/filename.h>
@@ -260,23 +261,27 @@ wxbMainFrame::wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSi
    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 wxbHistoryTextCtrl(consolePanel,TypeText,"",wxDefaultPosition,wxSize(200,20));
+   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 );
@@ -334,11 +339,30 @@ void wxbMainFrame::StartConsoleThread(const wxString& config) {
       promptparser = new wxbPromptParser();      
    }
    
-   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
@@ -357,10 +381,6 @@ void wxbMainFrame::StartConsoleThread(const wxString& config) {
 #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") <<
@@ -560,6 +580,17 @@ void wxbMainFrame::Print(wxString str, int status)
    
    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");
@@ -616,11 +647,16 @@ void wxbMainFrame::Print(wxString str, int status)
             
             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 {
@@ -765,4 +801,3 @@ void csprint(const char* str, int status)
       firePrintEvent("", status);
    }
 }
-