#include <bbtkWxGUITextEditor.h>
Public Types | |
enum | { ID_ButtonNew, ID_ButtonOpen, ID_ButtonClose, ID_ButtonSave, ID_ButtonSaveAs, ID_ButtonRun } |
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 124 of file bbtkWxGUITextEditor.h.
anonymous enum |
Definition at line 172 of file bbtkWxGUITextEditor.h.
00173 { 00174 ID_ButtonNew, 00175 ID_ButtonOpen, 00176 ID_ButtonClose, 00177 ID_ButtonSave, 00178 ID_ButtonSaveAs, 00179 ID_ButtonRun 00180 // ID_ButtonQuit 00181 };
bbtk::WxGUITextEditor::WxGUITextEditor | ( | wxWindow * | parent, | |
WxGUITextEditorUser * | user = 0 | |||
) |
Definition at line 270 of file bbtkWxGUITextEditor.cxx.
References _T, ID_ButtonClose, ID_ButtonNew, ID_ButtonOpen, ID_ButtonRun, ID_ButtonSave, ID_ButtonSaveAs, mwxNotebook, mwxPosition, mwxToolBar, NewPage(), and UpdateInfo().
00272 : wxPanel(parent, -1), 00273 mUser(user), 00274 mFileNameFilter("*.*") 00275 { 00276 // m_mgr.SetManagedWindow(this); 00277 // wxInitAllImageHandlers(); 00278 00279 // std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl; 00280 00281 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); 00282 00283 mwxNotebook = new wxNotebook(this,-1, 00284 wxDefaultPosition, wxDefaultSize, 00285 wxNB_TOP 00286 00287 00288 ); 00289 00290 sizer->Add(mwxNotebook,1,wxGROW); 00291 00292 00293 /* 00294 mwxNotebook = new wxAuiNotebook(this, 00295 -1, 00296 wxPoint(0, 0), 00297 wxSize(500,500), 00298 wxAUI_NB_TAB_SPLIT 00299 | wxAUI_NB_TAB_MOVE 00300 | wxAUI_NB_TAB_EXTERNAL_MOVE 00301 | wxAUI_NB_WINDOWLIST_BUTTON 00302 |wxAUI_NB_SCROLL_BUTTONS 00303 // | wxAUI_NB_CLOSE_BUTTON 00304 | wxAUI_NB_CLOSE_ON_ACTIVE_TAB 00305 //| wxAUI_NB_CLOSE_ON_ALL_TABS 00306 | wxNO_BORDER); 00307 00308 m_mgr.AddPane(mwxNotebook, 00309 wxAuiPaneInfo().Name(wxT("notebook")) 00310 .Caption(wxT("")) 00311 .CaptionVisible(false) 00312 .MinimizeButton(false) 00313 .MaximizeButton(false) 00314 .CloseButton(false) 00315 // .Dockable(false).Float() 00316 .Center() 00317 .MinSize(wxSize(100,50)) 00318 ); 00319 */ 00320 00321 /* 00322 wxBitmap bmp_new(cc_new_xpm); 00323 wxBitmap bmp_open(cc_open_xpm); 00324 wxBitmap bmp_close(cc_stop_xpm); 00325 wxBitmap bmp_save(cc_save_xpm); 00326 wxBitmap bmp_saveas(cc_save_as_xpm); 00327 wxBitmap bmp_run(cc_run_xpm); 00328 */ 00329 wxBitmap bmp_new(new_xpm); 00330 wxBitmap bmp_open(fileopen_xpm); 00331 wxBitmap bmp_close(eldel_xpm); 00332 wxBitmap bmp_save(filesave_xpm); 00333 wxBitmap bmp_saveas(filesaveas_xpm); 00334 wxBitmap bmp_run(down_xpm); 00335 00336 mwxToolBar = new wxToolBar(this, wxID_ANY, 00337 wxDefaultPosition, wxDefaultSize, 00338 wxTB_FLAT | wxTB_NODIVIDER); 00339 00340 mwxToolBar->AddTool(ID_ButtonNew, _T("New"), 00341 bmp_new, wxNullBitmap, wxITEM_NORMAL, 00342 _T("New file"), _T("Create a new file")); 00343 mwxToolBar->AddTool(ID_ButtonOpen, _T("Open"), 00344 bmp_open, wxNullBitmap, wxITEM_NORMAL, 00345 _T("Open file"), _T("This is help for new file tool")); 00346 mwxToolBar->AddTool(ID_ButtonClose, _T("Close"), 00347 bmp_close, wxNullBitmap, wxITEM_NORMAL, 00348 _T("Close file"), _T("Close current file")); 00349 mwxToolBar->AddTool(ID_ButtonSave, _T("New"), 00350 bmp_save, wxNullBitmap, wxITEM_NORMAL, 00351 _T("Save file"), _T("Save current file")); 00352 mwxToolBar->AddTool(ID_ButtonSaveAs, _T("New"), 00353 bmp_saveas, wxNullBitmap, wxITEM_NORMAL, 00354 _T("Save file as"), _T("Save current file as")); 00355 mwxToolBar->AddTool(ID_ButtonRun, _T("Run"), 00356 bmp_run, wxNullBitmap, wxITEM_NORMAL, 00357 _T("Run file"), _T("Run current file")); 00358 00359 mwxToolBar->AddSeparator(); 00360 mwxPosition = new wxStaticText ( mwxToolBar, -1, _T("")); 00361 mwxToolBar->AddControl(mwxPosition); 00362 mwxToolBar->Realize(); 00363 00364 sizer->Add(mwxToolBar,0,wxGROW); 00365 00366 /* 00367 m_mgr.AddPane(mwxToolBar, 00368 wxAuiPaneInfo().Name(wxT("toolBar")) 00369 .Caption(wxT("")) 00370 .ToolbarPane() 00371 .Bottom() 00372 .MinSize(wxSize(100,50)) 00373 .LeftDockable(false).RightDockable(false) 00374 ); 00375 */ 00376 SetSizer(sizer); 00377 00378 00379 // m_mgr.Update(); 00380 SetAutoLayout(true); 00381 Layout(); 00382 00383 NewPage(""); 00384 UpdateInfo(); 00385 00386 }
bbtk::WxGUITextEditor::~WxGUITextEditor | ( | ) |
void bbtk::WxGUITextEditor::OnKeyDown | ( | wxKeyEvent & | event | ) |
Definition at line 672 of file bbtkWxGUITextEditor.cxx.
References New(), Open(), and SaveCurrentPage().
Referenced by bbtk::WxTextCtrlGettingKeyEvents::OnKeyDown().
00673 { 00674 // std::cout << "D" << std::endl; 00675 // std::cout << "Key="<<event.GetKeyCode()<<std::endl; 00676 if ( event.ControlDown() ) 00677 { 00678 switch (event.GetKeyCode()) 00679 { 00680 case 'n': case 'N' : New(); break; 00681 case 's': case 'S' : SaveCurrentPage(); break; 00682 case 'o': case 'O' : Open(); break; 00683 // case 'r': case 'R' : Run(); break; 00684 // case 'q': case 'Q' : Quit(); break; 00685 } 00686 } 00687 }
void bbtk::WxGUITextEditor::OnKeyUp | ( | wxKeyEvent & | event | ) |
Definition at line 664 of file bbtkWxGUITextEditor.cxx.
References UpdateInfo().
Referenced by bbtk::WxTextCtrlGettingKeyEvents::OnKeyUp().
00665 { 00666 // std::cout << "U" << std::endl; 00667 UpdateInfo(); 00668 }
void bbtk::WxGUITextEditor::OnToolLeftClick | ( | wxCommandEvent & | event | ) |
Definition at line 433 of file bbtkWxGUITextEditor.cxx.
References CloseCurrentPage(), FocusOnCurrentPage(), GetCurrentPage(), ID_ButtonClose, ID_ButtonNew, ID_ButtonOpen, ID_ButtonRun, ID_ButtonSave, ID_ButtonSaveAs, mUser, mwxNotebook, New(), Open(), SaveCurrentPage(), bbtk::WxGUITextEditorPage::SetAskFilename(), and bbtk::WxGUITextEditorUser::WxGUITextEditorRun().
00434 { 00435 switch (event.GetId()) 00436 { 00437 case ID_ButtonNew : 00438 New(); 00439 FocusOnCurrentPage(); 00440 break; 00441 case ID_ButtonOpen : 00442 Open(); 00443 FocusOnCurrentPage(); 00444 break; 00445 case ID_ButtonClose : 00446 CloseCurrentPage(); 00447 break; 00448 case ID_ButtonSave : 00449 SaveCurrentPage(); 00450 break; 00451 case ID_ButtonSaveAs : 00452 if (mwxNotebook->GetPageCount()==0) break; 00453 GetCurrentPage()->SetAskFilename(true); 00454 SaveCurrentPage(); 00455 break; 00456 case ID_ButtonRun : 00457 if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 00458 mUser->WxGUITextEditorRun(); 00459 FocusOnCurrentPage(); 00460 break; 00461 } 00462 }
void bbtk::WxGUITextEditor::OnToolRightClick | ( | wxCommandEvent & | event | ) |
void bbtk::WxGUITextEditor::OnPageClose | ( | wxAuiNotebookEvent & | evt | ) |
Definition at line 573 of file bbtkWxGUITextEditor.cxx.
References CloseCurrentPage().
00574 { 00575 if (!CloseCurrentPage()) evt.Veto(); 00576 }
void bbtk::WxGUITextEditor::New | ( | ) |
Definition at line 472 of file bbtkWxGUITextEditor.cxx.
References NewPage(), and UpdateInfo().
Referenced by OnKeyDown(), and OnToolLeftClick().
00473 { 00474 NewPage(""); 00475 UpdateInfo(); 00476 }
void bbtk::WxGUITextEditor::Open | ( | ) |
Definition at line 480 of file bbtkWxGUITextEditor.cxx.
References _T, mFileNameFilter, Open(), bbtk::std2wx(), and bbtk::wx2std().
Referenced by OnKeyDown(), OnToolLeftClick(), Open(), bbtk::WxGUIScriptingInterface::Open(), and bbtk::WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked().
00481 { 00482 // std::cout << "-------------- OPEN ---------------"<<std::endl; 00483 00484 wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""), 00485 _T(""),std2wx(mFileNameFilter), 00486 wxOPEN | wxFILE_MUST_EXIST ); 00487 int result_fd = fd->ShowModal(); 00488 00489 // This line is need it by windows //EED 00490 fd->SetReturnCode( result_fd ); 00491 00492 if (fd->GetReturnCode()==wxID_OK) 00493 { 00494 std::string filename = wx2std(fd->GetPath()); 00495 std::cout << "file [" << filename << "]" <<std::endl; 00496 Open(filename); 00497 } 00498 else 00499 { 00500 // std::cout << "-------------- CANCELLED ---------------"<<std::endl; 00501 } 00502 }
void bbtk::WxGUITextEditor::Open | ( | const std::string & | filename | ) |
Definition at line 506 of file bbtkWxGUITextEditor.cxx.
References NewPage(), and UpdateInfo().
00507 { 00508 NewPage(filename); 00509 UpdateInfo(); 00510 }
void bbtk::WxGUITextEditor::SaveCurrentPage | ( | ) |
Definition at line 562 of file bbtkWxGUITextEditor.cxx.
References GetCurrentPage(), mFileNameFilter, mwxNotebook, bbtk::WxGUITextEditorPage::Save(), and bbtk::std2wx().
Referenced by OnKeyDown(), and OnToolLeftClick().
00563 { 00564 if (mwxNotebook->GetPageCount()==0) return; 00565 GetCurrentPage()->Save(mFileNameFilter); 00566 mwxNotebook->SetPageText(mwxNotebook->GetSelection(), 00567 std2wx(GetCurrentPage()->GetPageName())); 00568 }
bool bbtk::WxGUITextEditor::CloseCurrentPage | ( | ) |
Definition at line 515 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().
00516 { 00517 if (mwxNotebook->GetPageCount()==0) return true; 00518 00519 if (GetCurrentPage()->IsModified()) 00520 { 00521 wxString mess = std2wx(GetCurrentPage()->GetPageName()); 00522 mess += _T(" modified. Save it ?"); 00523 wxMessageDialog* d = 00524 new wxMessageDialog(this, 00525 mess, 00526 _T("Save buffer"), 00527 wxYES_NO | wxCANCEL | wxICON_QUESTION); 00528 switch (d->ShowModal()) 00529 { 00530 case wxID_CANCEL : 00531 return false; 00532 break; 00533 case wxID_YES : 00534 GetCurrentPage()->Save(mFileNameFilter); 00535 break; 00536 case wxID_NO : ; 00537 } 00538 } 00539 mwxNotebook->DeletePage(mwxNotebook->GetSelection()); 00540 FocusOnCurrentPage(); 00541 return true; 00542 }
bool bbtk::WxGUITextEditor::CloseAllPages | ( | ) |
Definition at line 546 of file bbtkWxGUITextEditor.cxx.
References CloseCurrentPage(), and mwxNotebook.
00547 { 00548 bool ok = true; 00549 while (mwxNotebook->GetPageCount()!=0) 00550 { 00551 if (!CloseCurrentPage()) 00552 { 00553 ok = false; 00554 break; 00555 } 00556 } 00557 return ok; 00558 }
void bbtk::WxGUITextEditor::HighlightSyntax | ( | ) |
void bbtk::WxGUITextEditor::UpdateInfo | ( | ) |
Definition at line 630 of file bbtkWxGUITextEditor.cxx.
References GetCurrentPage(), bbtk::WxGUITextEditorPage::GetPageName(), bbtk::WxGUITextEditorPage::GetTextCtrl(), mwxNotebook, mwxPosition, and bbtk::std2wx().
Referenced by New(), OnKeyUp(), Open(), and WxGUITextEditor().
00631 { 00632 if (mwxNotebook->GetPageCount()==0) return; 00633 WxTextCtrlGettingKeyEvents* text = GetCurrentPage()->GetTextCtrl(); 00634 00635 long line, column, pos; 00636 pos = text->GetInsertionPoint(); 00637 text->PositionToXY(pos, &column, &line); 00638 00639 00640 // wxLogMessage(_T("Current position: %ld\nCurrent line, column: (%ld, %ld)\nNumber of lines: %ld\nCurrent line length: %ld\nTotal text length: %u (%ld)"), 00641 00642 00643 char mess[200]; 00644 sprintf(mess,"%ld:%ld/%ld:%ld", 00645 line+1,column+1, 00646 (long)text->GetNumberOfLines(), 00647 (long)text->GetLineLength(line)+1); 00648 // pos+1, 00649 // (long)mwxInputText->GetValue().length())+1; 00650 00651 // mwxPosition->SetLabel(wxString(mess)); 00652 mwxPosition->SetLabel(std2wx(mess)); 00653 mwxPosition->Show(); 00654 00655 if (text->IsModified()) 00656 { 00657 std::string title("*"); 00658 title += GetCurrentPage()->GetPageName(); 00659 mwxNotebook->SetPageText(mwxNotebook->GetSelection(),std2wx(title)); 00660 } 00661 }
void bbtk::WxGUITextEditor::NewPage | ( | const std::string & | filename | ) |
Definition at line 399 of file bbtkWxGUITextEditor.cxx.
References FocusOnCurrentPage(), bbtk::WxGUITextEditorPage::Load(), mwxNotebook, bbtk::WxGUITextEditorPage::SetPageName(), and bbtk::std2wx().
Referenced by New(), Open(), and WxGUITextEditor().
00400 { 00401 WxGUITextEditorPage* page = 00402 new WxGUITextEditorPage(mwxNotebook,this); 00403 std::string name("untitled"); 00404 if (filename.size()!=0) 00405 { 00406 name = filename; 00407 page->Load(name); 00408 } 00409 page->SetPageName(name); 00410 std::string fname = Utilities::get_file_name(name); 00411 mwxNotebook->AddPage(page,std2wx(fname),true); 00412 FocusOnCurrentPage(); 00413 }
WxGUITextEditorPage * bbtk::WxGUITextEditor::GetCurrentPage | ( | ) |
Definition at line 417 of file bbtkWxGUITextEditor.cxx.
References mwxNotebook.
Referenced by CloseCurrentPage(), FocusOnCurrentPage(), OnToolLeftClick(), SaveCurrentPage(), UpdateInfo(), and bbtk::WxGUIScriptingInterface::WxGUITextEditorRun().
00418 { 00419 return (WxGUITextEditorPage*) 00420 mwxNotebook->GetPage(mwxNotebook->GetSelection()); 00421 }
void bbtk::WxGUITextEditor::FocusOnCurrentPage | ( | ) |
Definition at line 425 of file bbtkWxGUITextEditor.cxx.
References GetCurrentPage(), and mwxNotebook.
Referenced by CloseCurrentPage(), NewPage(), and OnToolLeftClick().
00426 { 00427 if (mwxNotebook->GetPageCount()==0) return; 00428 GetCurrentPage()->SetFocus(); 00429 }
void bbtk::WxGUITextEditor::SetFileNameFilter | ( | const std::string & | filter | ) | [inline] |
Definition at line 154 of file bbtkWxGUITextEditor.h.
Referenced by bbtk::WxGUIScriptingInterface::WxGUIScriptingInterface().
00155 { mFileNameFilter = filter; }
WxGUITextEditorUser* bbtk::WxGUITextEditor::mUser [private] |
wxNotebook* bbtk::WxGUITextEditor::mwxNotebook [private] |
Definition at line 162 of file bbtkWxGUITextEditor.h.
Referenced by CloseAllPages(), CloseCurrentPage(), FocusOnCurrentPage(), GetCurrentPage(), NewPage(), OnToolLeftClick(), SaveCurrentPage(), UpdateInfo(), and WxGUITextEditor().
wxToolBar* bbtk::WxGUITextEditor::mwxToolBar [private] |
wxStaticText* bbtk::WxGUITextEditor::mwxPosition [private] |
Definition at line 166 of file bbtkWxGUITextEditor.h.
Referenced by UpdateInfo(), and WxGUITextEditor().
std::string bbtk::WxGUITextEditor::mFileNameFilter [private] |
Definition at line 168 of file bbtkWxGUITextEditor.h.
Referenced by CloseCurrentPage(), Open(), and SaveCurrentPage().