#include <console.h>
Public Member Functions | |
Console (wxWindow *parentWin) | |
Class constructor. | |
virtual | ~Console () |
Class destructor. | |
Protected Member Functions | |
void | onKeyDown (wxKeyEvent &evt) |
Process key down event. | |
void | onCommand (wxCommandEvent &WXUNUSED(evt)) |
Process command event. | |
Protected Attributes | |
std::vector< wxString > | cmdHistory |
Commands history. | |
size_t | cmdHistoryIndex |
Current history index. | |
wxStaticText * | helperWin |
Helper window. |
Definition at line 23 of file console.h.
Console::Console | ( | wxWindow * | parentWin | ) |
Class constructor.
Definition at line 27 of file console.cpp.
00028 : wxTextCtrl(parentWin, 00029 wxID_ANY, 00030 wxEmptyString, 00031 wxDefaultPosition, 00032 wxDefaultSize, 00033 wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxTE_NOHIDESEL | wxTE_LEFT | wxTE_BESTWRAP) 00034 { 00035 helperWin = new wxStaticText(parentWin, wxID_ANY, wxEmptyString); 00036 00037 cmdHistoryIndex = 0; 00038 cmdHistory.push_back(wxEmptyString); 00039 Connect(wxID_ANY, 00040 wxEVT_KEY_DOWN, 00041 wxKeyEventHandler(Console::onKeyDown), 00042 (wxObject *)NULL, 00043 this); 00044 Connect(wxID_ANY, 00045 wxEVT_COMMAND_TEXT_ENTER, 00046 wxCommandEventHandler(Console::onCommand), 00047 (wxObject *)NULL, 00048 this); 00049 }
Console::~Console | ( | ) | [virtual] |
void Console::onKeyDown | ( | wxKeyEvent & | evt | ) | [protected] |
Process key down event.
Helper text
Definition at line 57 of file console.cpp.
00058 { 00059 #ifdef EVENT_DEBUG 00060 LOG(wxT("<Console>key event")); 00061 #endif 00062 00063 wxString cmd = GetValue(); 00064 if (evt.GetKeyCode() == WXK_TAB) 00065 { 00066 std::vector<wxString> candidates; 00067 if (!cmd.IsEmpty() && KERNEL->interpreter.GetCommandsStarting(cmd, &candidates)) 00068 { 00069 cmd = candidates.front().BeforeFirst(' ') + wxT(" "); 00070 SetValue(cmd); 00071 SetInsertionPointEnd(); 00072 cmdHistory.back() = cmd; 00073 } 00074 } 00075 else if (evt.GetKeyCode() == WXK_UP) 00076 { 00077 if (cmdHistory.size()) 00078 { 00079 cmdHistoryIndex = __max(int(cmdHistoryIndex) - 1, 0); 00080 cmd = cmdHistory[cmdHistoryIndex]; 00081 SetValue(cmd); 00082 SetInsertionPointEnd(); 00083 } 00084 } 00085 else if (evt.GetKeyCode() == WXK_DOWN) 00086 { 00087 if (cmdHistory.size()) 00088 { 00089 cmdHistoryIndex = __min(cmdHistoryIndex + 1, cmdHistory.size() - 1); 00090 cmd = cmdHistory[cmdHistoryIndex]; 00091 SetValue(cmd); 00092 SetInsertionPointEnd(); 00093 } 00094 } 00095 else if (evt.GetKeyCode() == WXK_ESCAPE) 00096 { 00097 Clear(); 00098 cmdHistoryIndex = cmdHistory.size(); 00099 cmd.Empty(); 00100 } 00101 else if (evt.GetKeyCode() == WXK_BACK) 00102 { 00103 evt.Skip(); 00104 cmd.RemoveLast(); 00105 cmdHistory.back() = cmd; 00106 } 00107 else if (evt.GetModifiers() == wxMOD_CONTROL && (evt.GetKeyCode() == 'V')) 00108 { 00109 if (wxTheClipboard->Open()) 00110 { 00111 if (wxTheClipboard->IsSupported( wxDF_TEXT )) 00112 { 00113 wxTextDataObject data; 00114 wxTheClipboard->GetData( data ); 00115 wxString text(GetValue()+data.GetText()); 00116 int posr=text.Find('\r'), posn=text.Find('\n'); 00117 while ((posr!=wxNOT_FOUND) || (posn!=wxNOT_FOUND)) 00118 { 00119 int pos=(posr!=wxNOT_FOUND)?posr:posn; 00120 if (posn!=wxNOT_FOUND) 00121 pos=(posn<pos)?posn:pos; 00122 SetValue(text.substr(0, pos)); 00123 wxCommandEvent evt; 00124 onCommand(evt); 00125 text.erase(0, pos+1); 00126 while ((text.size()>0) && ((text.at(0)==wxT('\r')) || (text.at(0)==wxT('\n')))) 00127 text.erase(0, 1); 00128 posr=text.Find('\r'); 00129 posn=text.Find('\n'); 00130 } 00131 SetValue(text); 00132 SetInsertionPointEnd(); 00133 } 00134 if (wxTheClipboard->IsSupported( wxDF_FILENAME )) 00135 { 00136 wxFileDataObject data; 00137 wxTheClipboard->GetData( data ); 00138 wxArrayString fileNames=data.GetFilenames(); 00139 wxString origValue(GetValue()); 00140 for (size_t i=0; i<fileNames.size(); i++) 00141 { 00142 SetValue(wxT("importscene ")+fileNames[i]); 00143 wxCommandEvent evt; 00144 onCommand(evt); 00145 } 00146 SetValue(origValue); 00147 SetInsertionPointEnd(); 00148 } 00149 wxTheClipboard->Close(); 00150 } 00151 } 00152 else 00153 { 00154 evt.Skip(); 00155 cmdHistory.back() = cmd; 00156 if (wxIsalpha(wxChar(evt.GetKeyCode()))) 00157 cmd.Append(wxChar(evt.GetKeyCode())); 00158 } 00159 00161 std::vector<wxString> candidates; 00162 if (!cmd.IsEmpty() && KERNEL->interpreter.GetCommandsStarting(cmd, &candidates)) 00163 { 00164 helperWin->SetLabel(candidates.front()); 00165 helperWin->SetPosition(GetPosition() + wxPoint(GetSize().x - helperWin->GetSize().x - 35, -GetSize().y)); 00166 helperWin->Show(); 00167 } 00168 else 00169 helperWin->Hide(); 00170 }
void Console::onCommand | ( | wxCommandEvent & | WXUNUSEDevt | ) | [protected] |
Process command event.
Definition at line 173 of file console.cpp.
00174 { 00175 const wxString cmd = GetValue(); 00176 if (!wxString(cmd).Trim().IsEmpty()) 00177 { 00178 cmdHistory.back() = cmd; 00179 cmdHistoryIndex = cmdHistory.size(); 00180 KERNEL->interpreter.ProcessCommand(cmd); 00181 cmdHistory.push_back(wxEmptyString); 00182 } 00183 Clear(); 00184 helperWin->Hide(); 00185 SetFocus(); 00186 }
std::vector<wxString> VRUT::Console::cmdHistory [protected] |
size_t VRUT::Console::cmdHistoryIndex [protected] |
wxStaticText* VRUT::Console::helperWin [protected] |