#include <bbtkWxGUITextEditor.h>
Public Types | |
enum | { ID_ButtonNew, ID_ButtonOpen, ID_ButtonClose, ID_ButtonSave, ID_ButtonSaveAs, ID_ButtonRun, ID_ButtonRunBBI, ID_ButtonGraphSimple, ID_ButtonGraphDetail } |
Public Member Functions | |
WxGUITextEditor (wxWindow *parent, WxGUITextEditorUser *user=0) | |
~WxGUITextEditor () | |
void | OnKeyDown (wxKeyEvent &event) |
void | OnKeyUp (wxKeyEvent &event) |
void | OnToolLeftClick (wxCommandEvent &event) |
void | OnToolRightClick (wxCommandEvent &event) |
void | OnPageClose (wxAuiNotebookEvent &evt) |
void | New () |
void | Open () |
void | Open (const std::string &filename) |
void | SaveCurrentPage () |
bool | CloseCurrentPage () |
bool | CloseAllPages () |
void | HighlightSyntax () |
void | UpdateInfo () |
void | NewPage (const std::string &filename) |
WxGUITextEditorPage * | GetCurrentPage () |
void | FocusOnCurrentPage () |
void | SetFileNameFilter (const std::string &filter) |
Private Attributes | |
WxGUITextEditorUser * | mUser |
wxNotebook * | mwxNotebook |
wxToolBar * | mwxToolBar |
wxStaticText * | mwxPosition |
std::string | mFileNameFilter |
Definition at line 131 of file bbtkWxGUITextEditor.h.
anonymous enum |
ID_ButtonNew | |
ID_ButtonOpen | |
ID_ButtonClose | |
ID_ButtonSave | |
ID_ButtonSaveAs | |
ID_ButtonRun | |
ID_ButtonRunBBI | |
ID_ButtonGraphSimple | |
ID_ButtonGraphDetail |
Definition at line 179 of file bbtkWxGUITextEditor.h.
00180 { 00181 ID_ButtonNew, 00182 ID_ButtonOpen, 00183 ID_ButtonClose, 00184 ID_ButtonSave, 00185 ID_ButtonSaveAs, 00186 ID_ButtonRun, 00187 ID_ButtonRunBBI, 00188 ID_ButtonGraphSimple, 00189 ID_ButtonGraphDetail 00190 // ID_ButtonQuit 00191 };
bbtk::WxGUITextEditor::WxGUITextEditor | ( | wxWindow * | parent, | |
WxGUITextEditorUser * | user = 0 | |||
) |
Definition at line 275 of file bbtkWxGUITextEditor.cxx.
References _T, ID_ButtonClose, ID_ButtonGraphDetail, ID_ButtonGraphSimple, ID_ButtonNew, ID_ButtonOpen, ID_ButtonRun, ID_ButtonRunBBI, ID_ButtonSave, ID_ButtonSaveAs, mwxNotebook, mwxPosition, mwxToolBar, NewPage(), and UpdateInfo().
00277 : wxPanel(parent, -1), 00278 mUser(user), 00279 mFileNameFilter("*.*") 00280 { 00281 // m_mgr.SetManagedWindow(this); 00282 // wxInitAllImageHandlers(); 00283 00284 // std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl; 00285 00286 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); 00287 00288 mwxNotebook = new wxNotebook(this,-1, 00289 wxDefaultPosition, wxDefaultSize, 00290 wxNB_TOP 00291 00292 00293 ); 00294 00295 sizer->Add(mwxNotebook,1,wxGROW); 00296 00297 00298 /* 00299 mwxNotebook = new wxAuiNotebook(this, 00300 -1, 00301 wxPoint(0, 0), 00302 wxSize(500,500), 00303 wxAUI_NB_TAB_SPLIT 00304 | wxAUI_NB_TAB_MOVE 00305 | wxAUI_NB_TAB_EXTERNAL_MOVE 00306 | wxAUI_NB_WINDOWLIST_BUTTON 00307 |wxAUI_NB_SCROLL_BUTTONS 00308 // | wxAUI_NB_CLOSE_BUTTON 00309 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB 00310 //| wxAUI_NB_CLOSE_ON_ALL_TABS 00311 | wxNO_BORDER); 00312 00313 m_mgr.AddPane(mwxNotebook, 00314 wxAuiPaneInfo().Name(wxT("notebook")) 00315 .Caption(wxT("")) 00316 .CaptionVisible(false) 00317 .MinimizeButton(false) 00318 .MaximizeButton(false) 00319 .CloseButton(false) 00320 // .Dockable(false).Float() 00321 .Center() 00322 .MinSize(wxSize(100,50)) 00323 ); 00324 */ 00325 00326 /* 00327 wxBitmap bmp_new(cc_new_xpm); 00328 wxBitmap bmp_open(cc_open_xpm); 00329 wxBitmap bmp_close(cc_stop_xpm); 00330 wxBitmap bmp_save(cc_save_xpm); 00331 wxBitmap bmp_saveas(cc_save_as_xpm); 00332 wxBitmap bmp_run(cc_run_xpm); 00333 */ 00334 wxBitmap bmp_new(new_xpm); 00335 wxBitmap bmp_open(fileopen_xpm); 00336 wxBitmap bmp_close(eldel_xpm); 00337 wxBitmap bmp_save(filesave_xpm); 00338 wxBitmap bmp_saveas(filesaveas_xpm); 00339 wxBitmap bmp_run(wxart_run_xpm); 00340 wxBitmap bmp_runbbi(wxart_runbbi_xpm); 00341 wxBitmap bmp_graphsimple(wxart_graphsimple_xpm); 00342 wxBitmap bmp_graphdetail(wxart_graphdetail_xpm); 00343 00344 mwxToolBar = new wxToolBar(this, wxID_ANY, 00345 wxDefaultPosition, wxDefaultSize, 00346 wxTB_FLAT | wxTB_NODIVIDER); 00347 00348 mwxToolBar->AddTool(ID_ButtonNew, _T("New"), 00349 bmp_new, wxNullBitmap, wxITEM_NORMAL, 00350 _T("New file"), _T("Create a new file")); 00351 mwxToolBar->AddTool(ID_ButtonOpen, _T("Open"), 00352 bmp_open, wxNullBitmap, wxITEM_NORMAL, 00353 _T("Open file"), _T("This is help for new file tool")); 00354 mwxToolBar->AddTool(ID_ButtonClose, _T("Close"), 00355 bmp_close, wxNullBitmap, wxITEM_NORMAL, 00356 _T("Close file"), _T("Close current file")); 00357 mwxToolBar->AddTool(ID_ButtonSave, _T("New"), 00358 bmp_save, wxNullBitmap, wxITEM_NORMAL, 00359 _T("Save file"), _T("Save current file")); 00360 mwxToolBar->AddTool(ID_ButtonSaveAs, _T("New"), 00361 bmp_saveas, wxNullBitmap, wxITEM_NORMAL, 00362 _T("Save file as"), _T("Save current file as")); 00363 mwxToolBar->AddTool(ID_ButtonRun, _T("Run"), 00364 bmp_run, wxNullBitmap, wxITEM_NORMAL, 00365 _T("Run file"), _T("Run current file")); 00366 00367 00368 mwxToolBar->AddTool(ID_ButtonGraphSimple, _T("Graph (simple)"), 00369 bmp_graphsimple, wxNullBitmap, wxITEM_NORMAL, 00370 _T("Graph simple"), _T("Simple graph of actual script")); 00371 00372 mwxToolBar->AddTool(ID_ButtonGraphDetail, _T("Graph (detail)"), 00373 bmp_graphdetail, wxNullBitmap, wxITEM_NORMAL, 00374 _T("Graph (detail)"), _T("Detail graph of actual script")); 00375 00376 mwxToolBar->AddTool(ID_ButtonRunBBI, _T("Run external bbi "), 00377 bmp_runbbi, wxNullBitmap, wxITEM_NORMAL, 00378 _T("Run external bbi"), _T("Run external bbi")); 00379 00380 00381 00382 mwxToolBar->AddSeparator(); 00383 mwxPosition = new wxStaticText ( mwxToolBar, -1, _T("")); 00384 mwxToolBar->AddControl(mwxPosition); 00385 mwxToolBar->Realize(); 00386 00387 sizer->Add(mwxToolBar,0,wxGROW); 00388 00389 /* 00390 m_mgr.AddPane(mwxToolBar, 00391 wxAuiPaneInfo().Name(wxT("toolBar")) 00392 .Caption(wxT("")) 00393 .ToolbarPane() 00394 .Bottom() 00395 .MinSize(wxSize(100,50)) 00396 .LeftDockable(false).RightDockable(false) 00397 ); 00398 */ 00399 SetSizer(sizer); 00400 00401 00402 // m_mgr.Update(); 00403 SetAutoLayout(true); 00404 Layout(); 00405 00406 NewPage(""); 00407 UpdateInfo(); 00408 00409 }
bbtk::WxGUITextEditor::~WxGUITextEditor | ( | ) |
bool bbtk::WxGUITextEditor::CloseAllPages | ( | ) |
Definition at line 588 of file bbtkWxGUITextEditor.cxx.
References CloseCurrentPage(), and mwxNotebook.
00589 { 00590 bool ok = true; 00591 while (mwxNotebook->GetPageCount()!=0) 00592 { 00593 if (!CloseCurrentPage()) 00594 { 00595 ok = false; 00596 break; 00597 } 00598 } 00599 return ok; 00600 }
bool bbtk::WxGUITextEditor::CloseCurrentPage | ( | ) |
Definition at line 557 of file bbtkWxGUITextEditor.cxx.
References _T, FocusOnCurrentPage(), GetCurrentPage(), bbtk::WxGUITextEditorPage::IsModified(), mFileNameFilter, mwxNotebook, bbtk::WxGUITextEditorPage::Save(), and bbtk::std2wx().
Referenced by CloseAllPages(), OnPageClose(), and OnToolLeftClick().
00558 { 00559 if (mwxNotebook->GetPageCount()==0) return true; 00560 00561 if (GetCurrentPage()->IsModified()) 00562 { 00563 wxString mess = std2wx(GetCurrentPage()->GetPageName()); 00564 mess += _T(" modified. Save it ?"); 00565 wxMessageDialog* d = 00566 new wxMessageDialog(this, 00567 mess, 00568 _T("Save buffer"), 00569 wxYES_NO | wxCANCEL | wxICON_QUESTION); 00570 switch (d->ShowModal()) 00571 { 00572 case wxID_CANCEL : 00573 return false; 00574 break; 00575 case wxID_YES : 00576 GetCurrentPage()->Save(mFileNameFilter); 00577 break; 00578 case wxID_NO : ; 00579 } 00580 } 00581 mwxNotebook->DeletePage(mwxNotebook->GetSelection()); 00582 FocusOnCurrentPage(); 00583 return true; 00584 }
void bbtk::WxGUITextEditor::FocusOnCurrentPage | ( | ) |
Definition at line 448 of file bbtkWxGUITextEditor.cxx.
References GetCurrentPage(), and mwxNotebook.
Referenced by CloseCurrentPage(), NewPage(), and OnToolLeftClick().
00449 { 00450 if (mwxNotebook->GetPageCount()==0) return; 00451 GetCurrentPage()->SetFocus(); 00452 }
WxGUITextEditorPage * bbtk::WxGUITextEditor::GetCurrentPage | ( | ) |
Definition at line 440 of file bbtkWxGUITextEditor.cxx.
References mwxNotebook.
Referenced by CloseCurrentPage(), FocusOnCurrentPage(), OnToolLeftClick(), SaveCurrentPage(), UpdateInfo(), bbtk::WxGUIScriptingInterface::WxGUITextEditorRun(), and bbtk::WxGUIScriptingInterface::WxGUITextEditorRunBBI().
00441 { 00442 return (WxGUITextEditorPage*) 00443 mwxNotebook->GetPage(mwxNotebook->GetSelection()); 00444 }
void bbtk::WxGUITextEditor::HighlightSyntax | ( | ) |
void bbtk::WxGUITextEditor::New | ( | ) |
Definition at line 514 of file bbtkWxGUITextEditor.cxx.
References NewPage(), and UpdateInfo().
Referenced by OnKeyDown(), and OnToolLeftClick().
00515 { 00516 NewPage(""); 00517 UpdateInfo(); 00518 }
void bbtk::WxGUITextEditor::NewPage | ( | const std::string & | filename | ) |
Definition at line 422 of file bbtkWxGUITextEditor.cxx.
References FocusOnCurrentPage(), bbtk::Utilities::get_file_name(), bbtk::WxGUITextEditorPage::Load(), mwxNotebook, bbtk::WxGUITextEditorPage::SetPageName(), and bbtk::std2wx().
Referenced by New(), Open(), and WxGUITextEditor().
00423 { 00424 WxGUITextEditorPage* page = 00425 new WxGUITextEditorPage(mwxNotebook,this); 00426 std::string name("untitled"); 00427 if (filename.size()!=0) 00428 { 00429 name = filename; 00430 page->Load(name); 00431 } 00432 page->SetPageName(name); 00433 std::string fname = Utilities::get_file_name(name); 00434 mwxNotebook->AddPage(page,std2wx(fname),true); 00435 FocusOnCurrentPage(); 00436 }
void bbtk::WxGUITextEditor::OnKeyDown | ( | wxKeyEvent & | event | ) |
Definition at line 714 of file bbtkWxGUITextEditor.cxx.
References New(), Open(), and SaveCurrentPage().
Referenced by bbtk::WxTextCtrlGettingKeyEvents::OnKeyDown().
00715 { 00716 // std::cout << "D" << std::endl; 00717 // std::cout << "Key="<<event.GetKeyCode()<<std::endl; 00718 if ( event.ControlDown() ) 00719 { 00720 switch (event.GetKeyCode()) 00721 { 00722 case 'n': case 'N' : New(); break; 00723 case 's': case 'S' : SaveCurrentPage(); break; 00724 case 'o': case 'O' : Open(); break; 00725 // case 'r': case 'R' : Run(); break; 00726 // case 'q': case 'Q' : Quit(); break; 00727 } 00728 } 00729 }
void bbtk::WxGUITextEditor::OnKeyUp | ( | wxKeyEvent & | event | ) |
Definition at line 706 of file bbtkWxGUITextEditor.cxx.
References UpdateInfo().
Referenced by bbtk::WxTextCtrlGettingKeyEvents::OnKeyUp().
00707 { 00708 // std::cout << "U" << std::endl; 00709 UpdateInfo(); 00710 }
void bbtk::WxGUITextEditor::OnPageClose | ( | wxAuiNotebookEvent & | evt | ) |
Definition at line 615 of file bbtkWxGUITextEditor.cxx.
References CloseCurrentPage().
00616 { 00617 if (!CloseCurrentPage()) evt.Veto(); 00618 }
void bbtk::WxGUITextEditor::OnToolLeftClick | ( | wxCommandEvent & | event | ) |
Definition at line 456 of file bbtkWxGUITextEditor.cxx.
References CloseCurrentPage(), FocusOnCurrentPage(), GetCurrentPage(), ID_ButtonClose, ID_ButtonGraphDetail, ID_ButtonGraphSimple, ID_ButtonNew, ID_ButtonOpen, ID_ButtonRun, ID_ButtonRunBBI, ID_ButtonSave, ID_ButtonSaveAs, mUser, mwxNotebook, New(), Open(), SaveCurrentPage(), bbtk::WxGUITextEditorPage::SetAskFilename(), bbtk::WxGUITextEditorUser::WxGUITextEditorGraphDetail(), bbtk::WxGUITextEditorUser::WxGUITextEditorGraphSimple(), bbtk::WxGUITextEditorUser::WxGUITextEditorRun(), and bbtk::WxGUITextEditorUser::WxGUITextEditorRunBBI().
00457 { 00458 switch (event.GetId()) 00459 { 00460 case ID_ButtonNew : 00461 New(); 00462 FocusOnCurrentPage(); 00463 break; 00464 case ID_ButtonOpen : 00465 Open(); 00466 FocusOnCurrentPage(); 00467 break; 00468 case ID_ButtonClose : 00469 CloseCurrentPage(); 00470 break; 00471 case ID_ButtonSave : 00472 SaveCurrentPage(); 00473 break; 00474 case ID_ButtonSaveAs : 00475 if (mwxNotebook->GetPageCount()==0) break; 00476 GetCurrentPage()->SetAskFilename(true); 00477 SaveCurrentPage(); 00478 break; 00479 case ID_ButtonRun : 00480 if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 00481 mUser->WxGUITextEditorRun(); 00482 FocusOnCurrentPage(); 00483 break; 00484 00485 case ID_ButtonGraphSimple : 00486 if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 00487 mUser->WxGUITextEditorGraphSimple(); 00488 FocusOnCurrentPage(); 00489 break; 00490 00491 case ID_ButtonGraphDetail : 00492 if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 00493 mUser->WxGUITextEditorGraphDetail(); 00494 FocusOnCurrentPage(); 00495 break; 00496 00497 case ID_ButtonRunBBI : 00498 if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 00499 mUser->WxGUITextEditorRunBBI(); 00500 FocusOnCurrentPage(); 00501 break; 00502 00503 } 00504 }
void bbtk::WxGUITextEditor::OnToolRightClick | ( | wxCommandEvent & | event | ) |
void bbtk::WxGUITextEditor::Open | ( | const std::string & | filename | ) |
Definition at line 548 of file bbtkWxGUITextEditor.cxx.
References NewPage(), and UpdateInfo().
00549 { 00550 NewPage(filename); 00551 UpdateInfo(); 00552 }
void bbtk::WxGUITextEditor::Open | ( | ) |
Definition at line 522 of file bbtkWxGUITextEditor.cxx.
References _T, mFileNameFilter, bbtk::std2wx(), and bbtk::wx2std().
Referenced by OnKeyDown(), OnToolLeftClick(), bbtk::WxGUIScriptingInterface::Open(), and bbtk::WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked().
00523 { 00524 // std::cout << "-------------- OPEN ---------------"<<std::endl; 00525 00526 wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""), 00527 _T(""),std2wx(mFileNameFilter), 00528 wxOPEN | wxFILE_MUST_EXIST ); 00529 int result_fd = fd->ShowModal(); 00530 00531 // This line is need it by windows //EED 00532 fd->SetReturnCode( result_fd ); 00533 00534 if (fd->GetReturnCode()==wxID_OK) 00535 { 00536 std::string filename = wx2std(fd->GetPath()); 00537 std::cout << "file [" << filename << "]" <<std::endl; 00538 Open(filename); 00539 } 00540 else 00541 { 00542 // std::cout << "-------------- CANCELLED ---------------"<<std::endl; 00543 } 00544 }
void bbtk::WxGUITextEditor::SaveCurrentPage | ( | ) |
Definition at line 604 of file bbtkWxGUITextEditor.cxx.
References GetCurrentPage(), mFileNameFilter, mwxNotebook, bbtk::WxGUITextEditorPage::Save(), and bbtk::std2wx().
Referenced by OnKeyDown(), and OnToolLeftClick().
00605 { 00606 if (mwxNotebook->GetPageCount()==0) return; 00607 GetCurrentPage()->Save(mFileNameFilter); 00608 mwxNotebook->SetPageText(mwxNotebook->GetSelection(), 00609 std2wx(GetCurrentPage()->GetPageName())); 00610 }
void bbtk::WxGUITextEditor::SetFileNameFilter | ( | const std::string & | filter | ) | [inline] |
Definition at line 161 of file bbtkWxGUITextEditor.h.
Referenced by bbtk::WxGUIScriptingInterface::WxGUIScriptingInterface().
00162 { mFileNameFilter = filter; }
void bbtk::WxGUITextEditor::UpdateInfo | ( | ) |
Definition at line 672 of file bbtkWxGUITextEditor.cxx.
References GetCurrentPage(), bbtk::WxGUITextEditorPage::GetPageName(), bbtk::WxGUITextEditorPage::GetTextCtrl(), mwxNotebook, mwxPosition, and bbtk::std2wx().
Referenced by New(), OnKeyUp(), Open(), and WxGUITextEditor().
00673 { 00674 if (mwxNotebook->GetPageCount()==0) return; 00675 WxTextCtrlGettingKeyEvents* text = GetCurrentPage()->GetTextCtrl(); 00676 00677 long line, column, pos; 00678 pos = text->GetInsertionPoint(); 00679 text->PositionToXY(pos, &column, &line); 00680 00681 00682 // wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"), 00683 00684 00685 char mess[200]; 00686 sprintf(mess,"%ld:%ld/%ld:%ld", 00687 line+1,column+1, 00688 (long)text->GetNumberOfLines(), 00689 (long)text->GetLineLength(line)+1); 00690 // pos+1, 00691 // (long)mwxInputText->GetValue().length())+1; 00692 00693 // mwxPosition->SetLabel(wxString(mess)); 00694 mwxPosition->SetLabel(std2wx(mess)); 00695 mwxPosition->Show(); 00696 00697 if (text->IsModified()) 00698 { 00699 std::string title("*"); 00700 title += GetCurrentPage()->GetPageName(); 00701 mwxNotebook->SetPageText(mwxNotebook->GetSelection(),std2wx(title)); 00702 } 00703 }
std::string bbtk::WxGUITextEditor::mFileNameFilter [private] |
Definition at line 175 of file bbtkWxGUITextEditor.h.
Referenced by CloseCurrentPage(), Open(), and SaveCurrentPage().
WxGUITextEditorUser* bbtk::WxGUITextEditor::mUser [private] |
wxNotebook* bbtk::WxGUITextEditor::mwxNotebook [private] |
Definition at line 169 of file bbtkWxGUITextEditor.h.
Referenced by CloseAllPages(), CloseCurrentPage(), FocusOnCurrentPage(), GetCurrentPage(), NewPage(), OnToolLeftClick(), SaveCurrentPage(), UpdateInfo(), and WxGUITextEditor().
wxStaticText* bbtk::WxGUITextEditor::mwxPosition [private] |
Definition at line 173 of file bbtkWxGUITextEditor.h.
Referenced by UpdateInfo(), and WxGUITextEditor().
wxToolBar* bbtk::WxGUITextEditor::mwxToolBar [private] |