00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00047 #ifdef _USE_WXWIDGETS_
00048
00049 #include "bbtkWxGUICommand.h"
00050 #include "bbtkMessageManager.h"
00051 #include "bbtkConfigurationFile.h"
00052 #include "bbtkWxGUIPackageBrowser2.h"
00053
00054 namespace bbtk
00055 {
00056
00057 BEGIN_EVENT_TABLE(WxGUICommand, wxPanel)
00058 EVT_TEXT_ENTER(WxGUICommand::ID_Text_Command, WxGUICommand::OnCommandEnter)
00059 EVT_BUTTON(WxGUICommand::ID_Btn_Go, WxGUICommand::OnBtnGo)
00060 EVT_BUTTON(WxGUICommand::ID_Btn_Include, WxGUICommand::OnBtnInclude)
00061 EVT_BUTTON(WxGUICommand::ID_Btn_Reset, WxGUICommand::OnBtnReset)
00062 EVT_BUTTON(WxGUICommand::ID_Btn_Config, WxGUICommand::OnBtnConfig)
00063 EVT_BUTTON(WxGUICommand::ID_Btn_GraphS, WxGUICommand::OnBtnGraphS)
00064 EVT_BUTTON(WxGUICommand::ID_Btn_GraphD, WxGUICommand::OnBtnGraphD)
00065 EVT_BUTTON(WxGUICommand::ID_Btn_Help, WxGUICommand::OnBtnHelp)
00066 EVT_BUTTON(WxGUICommand::ID_Btn_PackageBrowser, WxGUICommand::OnBtnPackageBrowser)
00067 END_EVENT_TABLE()
00068
00069
00070
00071 WxGUICommand::WxGUICommand(wxWindow *parent, WxGUICommandUser* user)
00072 : wxPanel(parent,-1),
00073 mUser(user)
00074 {
00075 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00076
00077 mwxTextCommand =
00078 new wxComboBox(this,
00079 ID_Text_Command,
00080 _T(""),
00081 wxDefaultPosition,
00082 wxDefaultSize,
00083 0, NULL,
00084 wxTE_PROCESS_ENTER
00085
00086
00087
00088 );
00089
00090 wxButton *btnGo = new wxButton(this,ID_Btn_Go,_T("Go"));
00091
00092 wxFlexGridSizer *sizerCommand= new wxFlexGridSizer(2);
00093 sizerCommand->AddGrowableCol(0);
00094 sizerCommand->Add(mwxTextCommand,1,wxGROW);
00095 sizerCommand->Add(btnGo);
00096
00097 sizer->Add(sizerCommand,0,wxGROW);
00098
00099 wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL);
00100
00101 wxButton *btnInclude = new wxButton(this,ID_Btn_Include ,_T("include") );
00102 wxButton *btnReset = new wxButton(this,ID_Btn_Reset ,_T("reset") );
00103 wxButton *btnConfig = new wxButton(this,ID_Btn_Config ,_T("config") );
00104 wxButton *btnGraphS = new wxButton(this,ID_Btn_GraphS ,_T("graph (simple)") );
00105 wxButton *btnGraphD = new wxButton(this,ID_Btn_GraphD ,_T("graph (detailed)") );
00106 wxButton *btnHelp = new wxButton(this,ID_Btn_Help ,_T("help") );
00107 wxButton *btnPackageBrowser = new wxButton(this,ID_Btn_PackageBrowser ,_T("Start Package Browser") );
00108
00109 btnsSizer->Add( btnInclude );
00110 btnsSizer->Add( btnReset );
00111 btnsSizer->Add( btnConfig );
00112 btnsSizer->Add( btnGraphS );
00113 btnsSizer->Add( btnGraphD );
00114 btnsSizer->Add( btnHelp );
00115 btnsSizer->Add( btnPackageBrowser );
00116
00117 sizer->Add(btnsSizer,0,wxTOP|wxGROW, 10 );
00118
00119 SetSizer(sizer);
00120
00121 SetAutoLayout(true);
00122 Layout();
00123 }
00124
00125 WxGUICommand::~WxGUICommand()
00126 {
00127 }
00128
00129 void WxGUICommand::OnBtnGo(wxCommandEvent& event)
00130 {
00131 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGo"<<std::endl);
00132 SendCommand(wx2std(mwxTextCommand->GetValue()));
00133 }
00134
00135 void WxGUICommand::OnCommandEnter(wxCommandEvent& event)
00136 {
00137 bbtkDebugMessage("gui",2,"WxGUICommand::OnCommandEnter"<<std::endl);
00138 SendCommand(wx2std(mwxTextCommand->GetValue()));
00139 }
00140
00141 void WxGUICommand::SendCommand(const std::string& command)
00142 {
00143 if (command.length()==0) return;
00144
00145 mwxTextCommand->SetValue(_T(""));
00146 mwxTextCommand->Append(std2wx(command));
00147 if (mUser) mUser->WxGUICommandEnter(command);
00148 }
00149
00150
00151 void WxGUICommand::OnBtnInclude(wxCommandEvent& event)
00152 {
00153 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnInclude"<<std::endl);
00154
00155 std::string default_doc_dir =
00156 ConfigurationFile::GetInstance().Get_default_temp_dir();
00157 std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
00158 wxString defaultDir(stdDir.c_str(), wxConvUTF8);
00159
00160 wxFileDialog dialog(this, _T("Include file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
00161 if (dialog.ShowModal() == wxID_OK)
00162 {
00163
00164
00165 std::string command("include ");
00166 command = command + "\"" + wx2std(dialog.GetPath()) + "\"";
00167 SendCommand(command);
00168 }
00169 }
00170
00171 void WxGUICommand::OnBtnReset(wxCommandEvent& event)
00172 {
00173 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnReset"<<std::endl);
00174 SendCommand("reset");
00175 }
00176
00177 void WxGUICommand::OnBtnConfig(wxCommandEvent& event)
00178 {
00179 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnConfig"<<std::endl);
00180 SendCommand("config");
00181 }
00182
00183 void WxGUICommand::OnBtnGraphS(wxCommandEvent& event)
00184 {
00185 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphS"<<std::endl);
00186 SendCommand("graph");
00187 }
00188
00189 void WxGUICommand::OnBtnGraphD(wxCommandEvent& event)
00190 {
00191 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphD"<<std::endl);
00192 SendCommand("graph . 1");
00193 }
00194
00195 void WxGUICommand::OnBtnHelp(wxCommandEvent& event)
00196 {
00197 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnHelp"<<std::endl);
00198 SendCommand("help");
00199 }
00200
00201 void WxGUICommand::OnBtnPackageBrowser(wxCommandEvent& event)
00202 {
00203 wxBusyCursor wait;
00204 WxGUIPackageBrowser2Window *helpbrowser = new
00205 WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
00206 helpbrowser->Show();
00207 }
00208
00209 }
00210
00211 #endif // _USE_WXWIDGETS_