X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkWxGUITextEditor.cxx;h=a61de17e9a919d1610bd391a42414687c87ca537;hb=7a26044dd46cb80ab90ee1f63d3b4d8ce52b2d39;hp=e2f7fe46eada0f9f3346205ff88feac0f3089e44;hpb=fc399c5aab38ad24ea5d57552701411b4d805181;p=bbtk.git diff --git a/kernel/src/bbtkWxGUITextEditor.cxx b/kernel/src/bbtkWxGUITextEditor.cxx index e2f7fe4..a61de17 100644 --- a/kernel/src/bbtkWxGUITextEditor.cxx +++ b/kernel/src/bbtkWxGUITextEditor.cxx @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkWxGUITextEditor.cxx,v $ Language: C++ - Date: $Date: 2008/03/21 14:59:39 $ - Version: $Revision: 1.2 $ + Date: $Date: 2008/04/24 12:56:40 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -36,13 +36,24 @@ #include "bbtkWxGUITextEditor.h" #include "bbtkWxBlackBox.h" #include "bbtkConfigurationFile.h" +#include "bbtkUtilities.h" #include "icons/cc_new.xpm" #include "icons/cc_open.xpm" +#include "icons/cc_stop.xpm" #include "icons/cc_save.xpm" +#include "icons/cc_save_as.xpm" #include "icons/cc_run.xpm" #include "icons/cc_exit.xpm" +#include "../data/icons/wxart_new.xpm" +#include "../data/icons/wxart_fileopen.xpm" +#include "../data/icons/wxart_filesave.xpm" +#include "../data/icons/wxart_filesaveas.xpm" +#include "../data/icons/wxart_exefile.xpm" +#include "../data/icons/wxart_delete.xpm" +#include "../data/icons/wxart_down.xpm" +#include "../data/icons/wxart_eldel.xpm" namespace bbtk { @@ -160,8 +171,8 @@ namespace bbtk //================================================================ void WxGUITextEditorPage::Load(const std::string& filename) { - std::cout << "-------------- LOAD ---------------"<SaveFile(mName); + // std::cout << "file [" << mName << "]" <SaveFile(std2wx(mName)); mwxInputText->SetModified(false); } //================================================================ @@ -205,7 +216,7 @@ namespace bbtk mUser(user), mFileNameFilter("*.*") { - std::cout << "WxGUITextEditor::WxGUITextEditor"<SetWxGUITextEditor(this); // mInterpreter->SetCommandLine(true); @@ -234,23 +245,47 @@ namespace bbtk | wxNO_BORDER); sizer->Add(mwxNotebook,1,wxGROW); - + + // BUTTONS wxPanel *btnsCtrlPanel = new wxPanel(this,-1); wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL); - + + /* wxBitmap bmp_new(cc_new_xpm); - mwxButtonNew = new wxBitmapButton( btnsCtrlPanel,ID_ButtonNew,bmp_new);//_T("New") ); - btnsSizer->Add( mwxButtonNew ); wxBitmap bmp_open(cc_open_xpm); - mwxButtonOpen = new wxBitmapButton( btnsCtrlPanel,ID_ButtonOpen,bmp_open);//,_T("Open") ); - btnsSizer->Add( mwxButtonOpen ); + wxBitmap bmp_close(cc_stop_xpm); wxBitmap bmp_save(cc_save_xpm); - mwxButtonSave = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSave,bmp_save);//_T("Save") ); + wxBitmap bmp_saveas(cc_save_as_xpm); + wxBitmap bmp_run(cc_run_xpm); + */ + wxBitmap bmp_new(new_xpm); + wxBitmap bmp_open(fileopen_xpm); + wxBitmap bmp_close(eldel_xpm); + wxBitmap bmp_save(filesave_xpm); + wxBitmap bmp_saveas(filesaveas_xpm); + wxBitmap bmp_run(down_xpm); + + + wxSize btn_size(32,32); + mwxButtonNew = new wxBitmapButton( btnsCtrlPanel,ID_ButtonNew,bmp_new + ,wxDefaultPosition, btn_size); + btnsSizer->Add( mwxButtonNew ); + + mwxButtonOpen = new wxBitmapButton( btnsCtrlPanel,ID_ButtonOpen,bmp_open ,wxDefaultPosition, btn_size);//,_T("Open") ); + btnsSizer->Add( mwxButtonOpen ); + + mwxButtonClose = new wxBitmapButton( btnsCtrlPanel,ID_ButtonClose,bmp_close ,wxDefaultPosition, btn_size);//,_T("Open") ); + btnsSizer->Add( mwxButtonClose ); + + mwxButtonSave = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSave,bmp_save ,wxDefaultPosition, btn_size);//_T("Save") ); btnsSizer->Add( mwxButtonSave ); - wxBitmap bmp_run(cc_run_xpm); - mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run") ); + mwxButtonSaveAs = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSaveAs,bmp_saveas ,wxDefaultPosition, btn_size);//_T("Save") ); + btnsSizer->Add( mwxButtonSaveAs ); + + + mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run ,wxDefaultPosition, btn_size);//_T("Run") ); btnsSizer->Add( mwxButtonRun ); /* wxBitmap bmp_quit(cc_exit_xpm); @@ -262,6 +297,9 @@ namespace bbtk btnsSizer->Add( mwxPosition ); btnsCtrlPanel->SetSizer(btnsSizer); + btnsCtrlPanel->SetAutoLayout(true); + btnsCtrlPanel->Layout(); + sizer->Add ( btnsCtrlPanel, 0, wxLEFT | wxRIGHT | wxBOTTOM //| wxGROW , 10 ); @@ -279,6 +317,7 @@ namespace bbtk WxGUITextEditor::~WxGUITextEditor() { m_mgr.UnInit(); + // delete mInterpreter; } //================================================================ @@ -295,7 +334,8 @@ namespace bbtk page->Load(name); } page->SetPageName(name); - mwxNotebook->AddPage(page,name,true); + std::string fname = Utilities::get_file_name(name); + mwxNotebook->AddPage(page,std2wx(fname),true); FocusOnCurrentPage(); } //================================================================ @@ -324,7 +364,7 @@ namespace bbtk } void WxGUITextEditor::Open() { - std::cout << "-------------- OPEN ---------------"<GetPageCount()==0) return true; + if (GetCurrentPage()->IsModified()) + { + wxString mess = std2wx(GetCurrentPage()->GetPageName()); + mess += _T(" modified. Save it ?"); + wxMessageDialog* d = + new wxMessageDialog(this, + mess, + _T("Save buffer"), + wxYES_NO | wxCANCEL | wxICON_QUESTION); + switch (d->ShowModal()) + { + case wxID_CANCEL : + return false; + break; + case wxID_YES : + GetCurrentPage()->Save(mFileNameFilter); + break; + case wxID_NO : ; + } + } + mwxNotebook->DeletePage(mwxNotebook->GetSelection()); + FocusOnCurrentPage(); + return true; + } + //================================================================ + + //================================================================ + bool WxGUITextEditor::CloseAllPages() + { + bool ok = true; + while (mwxNotebook->GetPageCount()!=0) + { + if (!CloseCurrentPage()) + { + ok = false; + break; + } + } + return ok; + } + //================================================================ + //================================================================ void WxGUITextEditor::OnButtonSave(wxCommandEvent& event) { - Save(); + SaveCurrentPage(); } - void WxGUITextEditor::Save() + void WxGUITextEditor::SaveCurrentPage() { - std::cout << "-------------- SAVE ---------------"<GetPageCount()==0) return; GetCurrentPage()->Save(mFileNameFilter); mwxNotebook->SetPageText(mwxNotebook->GetSelection(), - GetCurrentPage()->GetPageName()); + std2wx(GetCurrentPage()->GetPageName())); } //================================================================ + //================================================================ + void WxGUITextEditor::OnButtonSaveAs(wxCommandEvent& event) + { + if (mwxNotebook->GetPageCount()==0) return; + GetCurrentPage()->SetAskFilename(true); + SaveCurrentPage(); + } + //================================================================ + //================================================================ void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt) { - std::cout << "-------------- CLOSE ---------------"<GetPageCount()==0) return; if (GetCurrentPage()->IsModified()) { @@ -390,11 +495,12 @@ namespace bbtk case wxID_NO : ; } } - + */ } //================================================================ + /* //================================================================ void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event) @@ -413,7 +519,8 @@ namespace bbtk //================================================================ void WxGUITextEditor::OnButtonRun(wxCommandEvent& event) { - if (mUser!=0) mUser->WxGUITextEditorRun(); + if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) + mUser->WxGUITextEditorRun(); FocusOnCurrentPage(); } @@ -455,7 +562,7 @@ namespace bbtk } void WxGUITextEditor::New() { - std::cout << "-------------- NEW ---------------" << std::endl; + /// std::cout << "-------------- NEW ---------------" << std::endl; NewPage(""); UpdateInfo(); } @@ -483,14 +590,15 @@ namespace bbtk // pos+1, // (long)mwxInputText->GetValue().length())+1; - mwxPosition->SetLabel(wxString(mess)); + // mwxPosition->SetLabel(wxString(mess)); + mwxPosition->SetLabel(std2wx(mess)); mwxPosition->Show(); if (text->IsModified()) { std::string title("*"); title += GetCurrentPage()->GetPageName(); - mwxNotebook->SetPageText(mwxNotebook->GetSelection(),title); + mwxNotebook->SetPageText(mwxNotebook->GetSelection(),std2wx(title)); } } //================================================================ @@ -512,7 +620,7 @@ namespace bbtk switch (event.GetKeyCode()) { case 'n': case 'N' : New(); break; - case 's': case 'S' : Save(); break; + case 's': case 'S' : SaveCurrentPage(); break; case 'o': case 'O' : Open(); break; // case 'r': case 'R' : Run(); break; // case 'q': case 'Q' : Quit(); break; @@ -526,7 +634,9 @@ namespace bbtk // EVT_CHAR(WxGUITextEditor::OnKeyPress) EVT_BUTTON(WxGUITextEditor::ID_ButtonNew, WxGUITextEditor::OnButtonNew) EVT_BUTTON(WxGUITextEditor::ID_ButtonOpen, WxGUITextEditor::OnButtonOpen) + EVT_BUTTON(WxGUITextEditor::ID_ButtonClose, WxGUITextEditor::OnButtonClose) EVT_BUTTON(WxGUITextEditor::ID_ButtonSave, WxGUITextEditor::OnButtonSave) + EVT_BUTTON(WxGUITextEditor::ID_ButtonSaveAs, WxGUITextEditor::OnButtonSaveAs) EVT_BUTTON(WxGUITextEditor::ID_ButtonRun, WxGUITextEditor::OnButtonRun) // EVT_BUTTON(WxGUITextEditor::ID_ButtonQuit, WxGUITextEditor::OnButtonQuit) EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose) @@ -555,11 +665,11 @@ namespace bbtk SetSizer(sizer); - // Creates and sets the parent window of all bbtk windows - wxWindow* top = new wxPanel(this,-1); - top->Hide(); + // Creates the parent window of all bbtk windows as a child of this + Wx::CreateTopWindow(this); + // Add the method OnWxSignal as a Wx::Signal observer + //bbtkAddWxSignalObserver(WxGUITextEditorWindow::OnWxSignal); - Wx::SetTopWindow(top); SetAutoLayout(true); Layout();