]> git.sur5r.net Git - bacula/bacula/commitdiff
- general : implemented command completion and interactive help.
authorNicolas Boichat <nicolas@boichat.ch>
Thu, 12 Aug 2004 23:15:40 +0000 (23:15 +0000)
committerNicolas Boichat <nicolas@boichat.ch>
Thu, 12 Aug 2004 23:15:40 +0000 (23:15 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1518 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/wx-console/CHANGELOG
bacula/src/wx-console/TODO
bacula/src/wx-console/wxbhistorytextctrl.cpp
bacula/src/wx-console/wxbhistorytextctrl.h
bacula/src/wx-console/wxbmainframe.cpp
bacula/src/wx-console/wxbmainframe.h

index 4b8ce8731728cbbc7d6a6ee1f8a6690f5e46e8ac..ef9a750d3eeb5965798b1af35e2ed566c68a6756 100644 (file)
@@ -1,3 +1,6 @@
+13-08-2004 :
+ - general : implemented command completion and interactive help.
+
 06-08-2004 :
  - wxbRestorePanel : now parsing '+' sent by the director when building
      tree.
index 726adbf6ec614bbde50cccc52e8b0faf8e123d64..cce06f422a3e57d51385a24cfa1e8db8e75e6d79 100644 (file)
@@ -26,9 +26,9 @@ wxbMainFrame : When exiting using menu, a messagebox is shown to ask the
 
 wxbUtils : add clients, jobs, filesets, pools... list, merge patch file (wxbnewutils.patch)
 
-general : add a tab containing messages
+general : do not show some commands results (for example .help)
 
-wxbMainFrame : Implement command completion (tab)
+general : add a tab containing messages
 
 wxbConfigFileEditor : create a more precise editor, with something like
    a tree structure
index 25e05a6e707eb29c7a7fac3cdf976fc568a61c69..10122cfc646f95f22adc827ead9e47e55f960bea 100644 (file)
 #include "wxbhistorytextctrl.h"
 
 BEGIN_EVENT_TABLE(wxbHistoryTextCtrl, wxTextCtrl)
+   EVT_KEY_DOWN(wxbHistoryTextCtrl::OnKeyDown)
    EVT_KEY_UP(wxbHistoryTextCtrl::OnKeyUp)
 END_EVENT_TABLE()
 
-wxbHistoryTextCtrl::wxbHistoryTextCtrl(wxWindow* parent, wxWindowID id, 
+wxbHistoryTextCtrl::wxbHistoryTextCtrl(wxStaticText* help, 
+      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) {
+   this->help = help;
    index = 0;
    history.Add("");
 }
 
+void wxbHistoryTextCtrl::AddCommand(wxString cmd, wxString description) {
+   commands[cmd] = description;
+}
+
+void wxbHistoryTextCtrl::ClearCommandList() {
+   commands.clear();
+}
+
 void wxbHistoryTextCtrl::HistoryAdd(wxString cmd) {
    if (cmd == "") return;
    index = history.Count();
@@ -48,6 +59,22 @@ void wxbHistoryTextCtrl::HistoryAdd(wxString cmd) {
    history.Add("");
 }
 
+void wxbHistoryTextCtrl::SetValue(const wxString& value) {
+   if (value == "") {
+      help->SetLabel("Type your command below:");
+   }
+   wxTextCtrl::SetValue(value);
+}
+
+void wxbHistoryTextCtrl::OnKeyDown(wxKeyEvent& event) {
+   if (event.m_keyCode == WXK_TAB) {
+
+   }
+   else {
+      event.Skip();
+   }
+}
+
 void wxbHistoryTextCtrl::OnKeyUp(wxKeyEvent& event) {
    if (event.m_keyCode == WXK_UP) {
       if (index > 0) {
@@ -66,7 +93,46 @@ void wxbHistoryTextCtrl::OnKeyUp(wxKeyEvent& event) {
          SetInsertionPointEnd();
       }      
    }
+   else if (GetValue() != "") {
+      wxbCommands::iterator it;
+      wxString key;
+      wxString helptext = "Unknown command.";
+      int found = 0;      
+      for( it = commands.begin(); it != commands.end(); ++it ) {         
+         if (it->first.Find(GetValue()) == 0) {
+            found++;
+            if (found > 2) {
+               helptext += " " + it->first;
+            }
+            else if (found > 1) {
+               helptext = "Possible completions: " + key + " " + it->first;
+            }
+            else { // (found == 1)
+               helptext = it->first + ": " + it->second;
+               key = it->first;
+            }
+         }
+         else if (GetValue().Find(it->first) == 0) {
+            helptext = it->first + ": " + it->second;
+            found = 0;
+            break;
+         }
+      }
+      
+      help->SetLabel(helptext);
+            
+      if (event.m_keyCode == WXK_TAB) {
+         if (found == 1) {
+            SetValue(key);
+            SetInsertionPointEnd();
+         }
+      }
+      else {
+         event.Skip();
+      }
+   }
    else {
+      help->SetLabel("Type your command below:");
       event.Skip();
    }
 }
index 79fe0225eb529bed7a28f3e3b3f2f4dbd0501b94..220a5e91468bccd7452063a1597e8d08c3109879 100644 (file)
 
 #include <wx/treectrl.h>
 
+WX_DECLARE_STRING_HASH_MAP( wxString, wxbCommands );
+
 class wxbHistoryTextCtrl: public wxTextCtrl {
    public:
-      wxbHistoryTextCtrl(wxWindow* parent, wxWindowID id, 
+      wxbHistoryTextCtrl(wxStaticText* help, 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);
+      
+      void AddCommand(wxString cmd, wxString description);
+      void ClearCommandList();
+      
+      virtual void SetValue(const wxString& value);
    private:
       wxArrayString history;
+      wxbCommands commands;
       int index;
+      wxStaticText* help;
       
       void OnKeyUp(wxKeyEvent& event);
+      void OnKeyDown(wxKeyEvent& event);
       
       DECLARE_EVENT_TABLE();
 };
index f37c9e714c180c4c62ed8a372ba58be0740185b6..f9633378b5ace80a58aec9c2f933419fa930d073 100644 (file)
@@ -37,7 +37,7 @@
 #include <wx/arrimpl.cpp>
 
 #include <wx/stattext.h>
-
+#include <wx/statline.h>
 #include <wx/config.h>
 
 #include <wx/filename.h>
@@ -261,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 );
@@ -561,6 +565,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 < 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");
index d66e856eff256f3aa16c6cf81a5688d83e81248b..45143b2333d77430771a39abf8377162e0335819 100644 (file)
@@ -144,6 +144,7 @@ private:
 
    wxNotebook *notebook; /* main notebook */
    wxTextCtrl *consoleCtrl; /* wxTextCtrl containing graphical console */
+   wxStaticText *helpCtrl; /* wxStaticText showing help messages */
    wxbHistoryTextCtrl *typeCtrl; /* wxbHistoryTextCtrl for console user input */
    wxButton *sendButton; /* wxButton used to send data */