]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWxGUITextEditor.cxx
Feature #1774
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.cxx
index 7de71068cb5abaf552737309a7d6c7bebbd4d0f3..5f3aea8afe8f077f0ed4ef5a62fda940c58615dd 100644 (file)
@@ -1,20 +1,42 @@
+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ #                        pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ #  This software is governed by the CeCILL-B license under French law and
+ #  abiding by the rules of distribution of free software. You can  use,
+ #  modify and/ or redistribute the software under the terms of the CeCILL-B
+ #  license as circulated by CEA, CNRS and INRIA at the following URL
+ #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ #  or in the file LICENSE.txt.
+ #
+ #  As a counterpart to the access to the source code and  rights to copy,
+ #  modify and redistribute granted by the license, users are provided only
+ #  with a limited warranty  and the software's author,  the holder of the
+ #  economic rights,  and the successive licensors  have only  limited
+ #  liability.
+ #
+ #  The fact that you are presently reading this means that you have had
+ #  knowledge of the CeCILL-B license and that you accept its terms.
+ # ------------------------------------------------------------------------ */
+
+
 /*=========================================================================
-                                                                                
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUITextEditor.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/21 11:46:41 $
-  Version:   $Revision: 1.1 $
-                                                                                
-  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
-  l'Image). All rights reserved. See Doc/License.txt or
-  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
-                                                                                
-     This software is distributed WITHOUT ANY WARRANTY; without even
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-     PURPOSE.  See the above copyright notices for more information.
-                                                                                
-=========================================================================*//**
+  Date:      $Date: 2012/11/16 08:49:01 $
+  Version:   $Revision: 1.22 $
+=========================================================================*/
+
+
+
+
+/**
  * \brief Short description in one line
  * 
  * Long description which 
 #include "bbtkWxGUITextEditor.h"
 #include "bbtkWxBlackBox.h"
 #include "bbtkConfigurationFile.h"
-
-#include "icons/cc_new.xpm"
-#include "icons/cc_open.xpm"
-#include "icons/cc_save.xpm"
-#include "icons/cc_run.xpm"
-#include "icons/cc_exit.xpm"
-
+#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_run.xpm"
+#include "../data/icons/wxart_runbbi.xpm"
+#include "../data/icons/wxart_graphsimple.xpm"
+#include "../data/icons/wxart_graphdetail.xpm"
+#include "../data/icons/wxart_eldel.xpm"
 
 namespace bbtk
 {
@@ -96,43 +133,6 @@ namespace bbtk
   //================================================================
   
   
-  //================================================================
-  class WxGUITextEditorPage : public wxPanel
-  {
-  public:
-    WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
-    ~WxGUITextEditorPage();
-
-    void SetPageName(const std::string& name) { mName = name; }
-    const std::string& GetPageName() const { return mName; }
-
-    bool AskFilename() const { return mAskFilename; }
-
-    WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
-
-    void Load(const std::string& filename);
-    void Save(const std::string& filter);
-
-    bool IsModified() { return mwxInputText->IsModified(); }
-   
-  private:
-    WxGUITextEditor* mEditor;
-    WxTextCtrlGettingKeyEvents* mwxInputText;
-    wxTextAttr* mwxInputTextAttr;
-    std::string mName;
-    bool mAskFilename;
-
-    /*
-    enum
-    {
-      ID_InputText
-    };
-    */
-    //DECLARE_EVENT_TABLE();
-
-  } ;
-  //================================================================
-
   //================================================================  
   /*  BEGIN_EVENT_TABLE(WxGUITextEditorPage, wxPanel)
     EVT_CLOSE(WxGUITextEditorPage::OnClose)
@@ -147,9 +147,13 @@ namespace bbtk
       mName(""),
       mAskFilename(true)
   {  
+
+         //      std::cout << "WxGUITextEditorPage::WxGUITextEditorPage("<<mName<<")"<<std::endl;
+
     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
  
     mwxInputText = 
+               
       new WxTextCtrlGettingKeyEvents(this,
                                     -1, //ID_InputText,
                                     _T(""),
@@ -157,20 +161,30 @@ namespace bbtk
                                     wxDefaultSize,
                                     wxTE_MULTILINE 
                                     //    |wxTE_PROCESS_ENTER
-                                    | wxTE_PROCESS_TAB 
+                                    //| wxTE_PROCESS_TAB 
                                     //             | wxWANTS_CHARS 
-                                    |  wxTAB_TRAVERSAL
+                                   // |  wxTAB_TRAVERSAL
                                     );
     mwxInputText->SetWxGUITextEditor(mEditor);
-    
-    wxFont* FixedFont = new wxFont(10,
+    /*
+       new wxTextCtrl(this,-1,_T(""),
+               wxDefaultPosition,
+                                            wxDefaultSize,
+                                            wxTE_MULTILINE 
+                                            //    |wxTE_PROCESS_ENTER
+                                       //       | wxTE_PROCESS_TAB 
+                               //                  | wxWANTS_CHARS 
+                                //    |  wxTAB_TRAVERSAL
+                                    );
+                                        */
+    mFixedFont = new wxFont(10,
                                    wxFONTFAMILY_MODERN,
                                    wxFONTSTYLE_NORMAL,
                                    wxFONTWEIGHT_NORMAL,
                                    false);
     
     mwxInputTextAttr = new wxTextAttr;
-    mwxInputTextAttr->SetFont(*FixedFont);
+    mwxInputTextAttr->SetFont(*mFixedFont);
    
     sizer->Add(mwxInputText,1,wxGROW);
     SetSizer(sizer);
@@ -182,15 +196,24 @@ namespace bbtk
   //================================================================
   WxGUITextEditorPage::~WxGUITextEditorPage()
   {
+         delete mwxInputTextAttr;
+         delete mFixedFont;
   }
   //================================================================
 
+  bool WxGUITextEditorPage::IsModified()
+   { return mwxInputText->IsModified(); }
+
+  std::string WxGUITextEditorPage::GetText()
+  {
+    return wx2std(GetTextCtrl()->GetValue());
+  }
 
   //================================================================
   void WxGUITextEditorPage::Load(const std::string& filename)
   {
-    std::cout << "-------------- LOAD ---------------"<<std::endl;
-    std::cout << "'" << filename << "'"<<std::endl;
+    //    std::cout << "-------------- LOAD ---------------"<<std::endl;
+    //    std::cout << "'" << filename << "'"<<std::endl;
     //std::string oldFilename = mFilename;
     mName = filename;
     mAskFilename = false;
@@ -201,14 +224,17 @@ namespace bbtk
   //================================================================
   void WxGUITextEditorPage::Save(const std::string& filter)
   {
-    std::cout << "-------------- SAVE ---------------"<<std::endl;
+    //    std::cout << "-------------- SAVE ---------------"<<std::endl;
     if (mAskFilename)
       {
        wxFileDialog* fd = new wxFileDialog(this,_T("Save file"),_T(""),
                                            _T(""),std2wx(filter),
                                            wxSAVE | wxOVERWRITE_PROMPT );
-       fd->ShowModal();
+       int result_fd = fd->ShowModal();
     
+       // This line is need it by windows // EED
+       fd->SetReturnCode( result_fd );
+
        if (fd->GetReturnCode()==wxID_OK)
          {
            mName = wx2std(fd->GetPath());
@@ -216,37 +242,68 @@ namespace bbtk
          }
        else 
          {
-           std::cout << "-------------- CANCELLED ---------------"
-                     <<std::endl;
+           //      std::cout << "-------------- CANCELLED ---------------"
+           //                <<std::endl;
            return;
          } 
       }
-    std::cout << "file [" << mName << "]" <<std::endl;
-    mwxInputText->SaveFile(mName);
+    //    std::cout << "file [" << mName << "]" <<std::endl;
+//    mwxInputText->SaveFile(std2wx(mName));
+       SaveFile(mName);
     mwxInputText->SetModified(false);
   }
   //================================================================
   
+
+       //================================================================
+       void WxGUITextEditorPage::SaveFile(const std::string& filename)
+       {
+               mwxInputText->SaveFile( std2wx(filename) );
+       }
+       //================================================================
+       
+       
+
+
+
+
+
+
+
+
+
+
   //================================================================
-  WxGUITextEditor::WxGUITextEditor( wxWindow *parent )
+  // WxGUITextEditor
+  //================================================================
+
+
+  //================================================================
+  WxGUITextEditor::WxGUITextEditor( wxWindow *parent,
+                                   WxGUITextEditorUser* user )
     : wxPanel(parent, -1),
+      mUser(user),
       mFileNameFilter("*.*")
   {
-    std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
-    //    mInterpreter = new bbtk::Interpreter();
-    //mInterpreter->SetWxGUITextEditor(this);
-    //  mInterpreter->SetCommandLine(true);
-    m_mgr.SetManagedWindow(this);
-    
-    //==============
-    // Menu
-    wxInitAllImageHandlers();
-    
-    
-    //    wxFlexGridSizer *sizer= new wxFlexGridSizer(2);
-    wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
-    
-    mwxNotebook = new wxAuiNotebook(this,  
+  //  m_mgr.SetManagedWindow(this);
+                   //    wxInitAllImageHandlers();
+     
+       //  std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
+
+      wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+    mwxNotebook = new wxNotebook(this,-1,
+               wxDefaultPosition, wxDefaultSize, 
+               wxNB_TOP 
+
+               
+               );
+               
+   sizer->Add(mwxNotebook,1,wxGROW);
+
+               
+               /*
+   mwxNotebook =               new wxAuiNotebook(this,  
                                    -1,
                                    wxPoint(0, 0),
                                    wxSize(500,500),
@@ -260,52 +317,110 @@ namespace bbtk
                                    //| wxAUI_NB_CLOSE_ON_ALL_TABS
                                    | wxNO_BORDER);
     
-    sizer->Add(mwxNotebook,1,wxGROW);
-    
-    // BUTTONS
-    wxPanel *btnsCtrlPanel = new wxPanel(this,-1);
-    wxBoxSizer *btnsSizer  = new wxBoxSizer(wxHORIZONTAL);
-    
+    m_mgr.AddPane(mwxNotebook,
+                 wxAuiPaneInfo().Name(wxT("notebook"))
+                 .Caption(wxT(""))
+                 .CaptionVisible(false)
+                 .MinimizeButton(false)
+                 .MaximizeButton(false)
+                 .CloseButton(false)
+                 //              .Dockable(false).Float()
+                 .Center()
+                 .MinSize(wxSize(100,50))
+                 );   
+*/
+    /*   
     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")  );
-    btnsSizer->Add( mwxButtonSave );
-
-    /*
+    wxBitmap bmp_saveas(cc_save_as_xpm);
     wxBitmap bmp_run(cc_run_xpm);
-    mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run")  );
-    btnsSizer->Add( mwxButtonRun );
-    wxBitmap bmp_quit(cc_exit_xpm);
-    mwxButtonQuit = new wxBitmapButton( btnsCtrlPanel,ID_ButtonQuit,bmp_quit);//_T("Quit")  );
-    btnsSizer->Add( mwxButtonQuit );
-    */    
-    
-    mwxPosition = new wxStaticText ( btnsCtrlPanel, -1, _T(""));
-    btnsSizer->Add( mwxPosition );
+    */
+    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(wxart_run_xpm);
+    wxBitmap bmp_runbbi(wxart_runbbi_xpm);
+    wxBitmap bmp_graphsimple(wxart_graphsimple_xpm);
+       wxBitmap bmp_graphdetail(wxart_graphdetail_xpm);
+
+    mwxToolBar = new wxToolBar(this, wxID_ANY, 
+                              wxDefaultPosition, wxDefaultSize,
+                              wxTB_FLAT | wxTB_NODIVIDER);
+    
+    mwxToolBar->AddTool(ID_ButtonNew, _T("New"),
+                     bmp_new, wxNullBitmap, wxITEM_NORMAL,
+                     _T("New file"), _T("Create a new file"));
+    mwxToolBar->AddTool(ID_ButtonOpen, _T("Open"),
+                     bmp_open, wxNullBitmap, wxITEM_NORMAL,
+                     _T("Open file"), _T("This is help for new file tool"));
+    mwxToolBar->AddTool(ID_ButtonClose, _T("Close"),
+                     bmp_close, wxNullBitmap, wxITEM_NORMAL,
+                     _T("Close file"), _T("Close current file"));
+    mwxToolBar->AddTool(ID_ButtonSave, _T("New"),
+                     bmp_save, wxNullBitmap, wxITEM_NORMAL,
+                     _T("Save file"), _T("Save current file"));
+    mwxToolBar->AddTool(ID_ButtonSaveAs, _T("New"),
+                     bmp_saveas, wxNullBitmap, wxITEM_NORMAL,
+                     _T("Save file as"), _T("Save current file as"));
+    mwxToolBar->AddTool(ID_ButtonRun, _T("Run"),
+                     bmp_run, wxNullBitmap, wxITEM_NORMAL,
+                     _T("Run file"), _T("Run current file"));
+
+         
+       mwxToolBar->AddTool(ID_ButtonGraphSimple, _T("Graph (simple)"),
+                                                 bmp_graphsimple, wxNullBitmap, wxITEM_NORMAL,
+                                                 _T("Graph simple"), _T("Simple graph of actual script"));
+
+       mwxToolBar->AddTool(ID_ButtonGraphDetail, _T("Graph (detail)"),
+                                                 bmp_graphdetail, wxNullBitmap, wxITEM_NORMAL,
+                                                 _T("Graph (detail)"), _T("Detail graph of actual script"));
+         
+       mwxToolBar->AddTool(ID_ButtonRunBBI, _T("Run external bbi "),
+                                                 bmp_runbbi, wxNullBitmap, wxITEM_NORMAL,
+                                                 _T("Run external bbi"), _T("Run external bbi"));
+         
+         
+         
+    mwxToolBar->AddSeparator();
+    mwxPosition = new wxStaticText ( mwxToolBar, -1, _T(""));
+    mwxToolBar->AddControl(mwxPosition);
+    mwxToolBar->Realize();
+
+         sizer->Add(mwxToolBar,0,wxGROW);
+
+       /*
+    m_mgr.AddPane(mwxToolBar, 
+                 wxAuiPaneInfo().Name(wxT("toolBar"))
+                 .Caption(wxT(""))
+                 .ToolbarPane()
+                 .Bottom()
+                 .MinSize(wxSize(100,50))
+                 .LeftDockable(false).RightDockable(false)
+                 );   
+*/
+  SetSizer(sizer);
+  
     
-    btnsCtrlPanel->SetSizer(btnsSizer);
-    sizer->Add ( btnsCtrlPanel, 0, wxLEFT | wxRIGHT | wxBOTTOM  //| wxGROW
-                , 10 );
-       
+//    m_mgr.Update();
+    SetAutoLayout(true);
+    Layout();
 
     NewPage("");
     UpdateInfo();
-    
-    SetSizer(sizer);
-    SetAutoLayout(true);
-    Layout();
+
   }
   //================================================================
   
   //================================================================
   WxGUITextEditor::~WxGUITextEditor()
   {
-    m_mgr.UnInit();
+  //  m_mgr.UnInit();
+
     //    delete mInterpreter;
   }
   //================================================================
@@ -322,7 +437,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();
   }
   //================================================================
@@ -344,20 +460,84 @@ namespace bbtk
   //================================================================
 
   //================================================================  
-  void WxGUITextEditor::OnButtonOpen(wxCommandEvent& event) 
-  { 
-    Open(); 
-    FocusOnCurrentPage();
-  } 
+  void WxGUITextEditor::OnToolLeftClick(wxCommandEvent& event)
+  {
+    switch (event.GetId())
+      {
+      case ID_ButtonNew :
+       New(); 
+       FocusOnCurrentPage();
+       break;
+      case ID_ButtonOpen :
+       Open(); 
+       FocusOnCurrentPage();
+       break;
+      case ID_ButtonClose :
+       CloseCurrentPage();
+       break;
+      case ID_ButtonSave :
+       SaveCurrentPage();
+       break;
+      case ID_ButtonSaveAs :
+       if (mwxNotebook->GetPageCount()==0) break;  
+       GetCurrentPage()->SetAskFilename(true);
+       SaveCurrentPage();
+       break;
+      case ID_ButtonRun :
+       if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
+         mUser->WxGUITextEditorRun();
+       FocusOnCurrentPage();
+       break;
+                         
+                 case ID_ButtonGraphSimple :
+                         if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
+                                 mUser->WxGUITextEditorGraphSimple();
+                         FocusOnCurrentPage();
+                         break;
+
+                 case ID_ButtonGraphDetail :
+                         if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
+                                 mUser->WxGUITextEditorGraphDetail();
+                         FocusOnCurrentPage();
+                         break;
+                         
+                 case ID_ButtonRunBBI :
+                         if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
+                                 mUser->WxGUITextEditorRunBBI();
+                         FocusOnCurrentPage();
+                         break;
+                         
+      }
+  }
+  //================================================================  
+
+  //================================================================  
+  void WxGUITextEditor::OnToolRightClick(wxCommandEvent& event)
+  {
+  }
+  //================================================================  
+
+  //================================================================  
+  void WxGUITextEditor::New()
+  {
+    NewPage("");
+    UpdateInfo();
+  }
+  //================================================================
+
+  //================================================================  
   void WxGUITextEditor::Open()
   {
-    std::cout << "-------------- OPEN ---------------"<<std::endl;
+    //    std::cout << "-------------- OPEN ---------------"<<std::endl;
 
     wxFileDialog* fd = new wxFileDialog(this,_T("Open file"),_T(""),
                                        _T(""),std2wx(mFileNameFilter),
                                        wxOPEN | wxFILE_MUST_EXIST );
-    fd->ShowModal();
-    
+    int result_fd = fd->ShowModal();
+
+       // This line is need it by windows //EED
+       fd->SetReturnCode( result_fd );
+
     if (fd->GetReturnCode()==wxID_OK)
       {
        std::string filename = wx2std(fd->GetPath());
@@ -366,7 +546,7 @@ namespace bbtk
       }
     else 
       {
-       std::cout << "-------------- CANCELLED ---------------"<<std::endl;
+       //      std::cout << "-------------- CANCELLED ---------------"<<std::endl;
       }
   }
   //================================================================  
@@ -379,49 +559,74 @@ namespace bbtk
   }
   //================================================================  
 
-  //================================================================  
-  void WxGUITextEditor::OnButtonSave(wxCommandEvent& event) 
-  { 
-    Save();
-  } 
-  void WxGUITextEditor::Save()
-  {
-    std::cout << "-------------- SAVE ---------------"<<std::endl;
-    if (mwxNotebook->GetPageCount()==0) return;  
-    GetCurrentPage()->Save(mFileNameFilter);
-    mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
-                            GetCurrentPage()->GetPageName());
-  }
-  //================================================================  
 
   //================================================================  
-  void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
+  bool WxGUITextEditor::CloseCurrentPage()
   {
-    std::cout << "-------------- CLOSE ---------------"<<std::endl;
-    if (mwxNotebook->GetPageCount()==0) return;
+    if (mwxNotebook->GetPageCount()==0) return true;
+
     if (GetCurrentPage()->IsModified()) 
       {
+       wxString mess = std2wx(GetCurrentPage()->GetPageName());
+       mess += _T(" modified. Save it ?");
        wxMessageDialog* d = 
          new wxMessageDialog(this,
-                             _T("Buffer modified. Save it ?")
+                             mess
                              _T("Save buffer"), 
                              wxYES_NO | wxCANCEL | wxICON_QUESTION);
        switch (d->ShowModal())
          {
          case wxID_CANCEL : 
-           evt.Veto(); 
+           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::SaveCurrentPage()
+  {
+    if (mwxNotebook->GetPageCount()==0) return;  
+    GetCurrentPage()->Save(mFileNameFilter);
+    mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
+                            std2wx(GetCurrentPage()->GetPageName()));
+  }
+  //================================================================  
+
+
+  //================================================================  
+  void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
+  {
+    if (!CloseCurrentPage()) evt.Veto();
   }
   //================================================================
 
 
+
   /*
   //================================================================  
   void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event) 
@@ -435,14 +640,11 @@ namespace bbtk
     if (AskSave()) GetParent()->Close();
   }
   //================================================================  
-
+  */
 
   //================================================================  
-  void WxGUITextEditor::OnButtonRun(wxCommandEvent& event) 
-  { 
-    Run(); 
-    FocusOnCurrentPage();
-  }
+
+  /*
   void WxGUITextEditor::Run()
   {
     std::cout << "-------------- RUN ---------------"<<std::endl;
@@ -472,19 +674,6 @@ namespace bbtk
   
   //================================================================
   
-  //================================================================  
-  void WxGUITextEditor::OnButtonNew(wxCommandEvent& event) 
-  { 
-    New(); 
-    FocusOnCurrentPage();
-  }
-  void WxGUITextEditor::New()
-  {
-    std::cout << "-------------- NEW ---------------" << std::endl;
-    NewPage("");
-    UpdateInfo();
-  }
-  //================================================================
 
   //================================================================
   void WxGUITextEditor::UpdateInfo()
@@ -508,21 +697,22 @@ 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));
       }
   }
   //================================================================
   //================================================================
   void WxGUITextEditor::OnKeyUp(wxKeyEvent& event)
   {
-    //  std::cout << "U" << std::endl;
+  //    std::cout << "U" << std::endl;
     UpdateInfo();
   }
   //================================================================
@@ -530,14 +720,14 @@ namespace bbtk
   //================================================================
   void WxGUITextEditor::OnKeyDown(wxKeyEvent& event)
   {
-    //    std::cout << "D" << std::endl;
+     //   std::cout << "D" << std::endl;
     // std::cout << "Key="<<event.GetKeyCode()<<std::endl;
     if ( event.ControlDown() )
       {
        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;
@@ -548,12 +738,8 @@ namespace bbtk
   
   //================================================================  
   BEGIN_EVENT_TABLE(WxGUITextEditor, wxPanel)
-  //    EVT_CHAR(WxGUITextEditor::OnKeyPress)
-    EVT_BUTTON(WxGUITextEditor::ID_ButtonNew, WxGUITextEditor::OnButtonNew)
-    EVT_BUTTON(WxGUITextEditor::ID_ButtonOpen, WxGUITextEditor::OnButtonOpen)
-    EVT_BUTTON(WxGUITextEditor::ID_ButtonSave, WxGUITextEditor::OnButtonSave)
-  //    EVT_BUTTON(WxGUITextEditor::ID_ButtonRun, WxGUITextEditor::OnButtonRun)
-  //    EVT_BUTTON(WxGUITextEditor::ID_ButtonQuit, WxGUITextEditor::OnButtonQuit)
+    EVT_MENU(wxID_ANY,  WxGUITextEditor::OnToolLeftClick)
+    EVT_TOOL_RCLICKED(wxID_ANY,  WxGUITextEditor::OnToolRightClick)
     EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose)
     END_EVENT_TABLE()
   //================================================================
@@ -580,11 +766,12 @@ namespace bbtk
     
     SetSizer(sizer);
 
-    // Creates and sets the parent window of all bbtk windows
-    wxWindow* top = new wxPanel(this,-1);
-    top->Hide();
+    // parent window of all bbtk windows will be a child of this
+    //    Wx::SetTopWindowParent(this);
+    Wx::SetTopWindow(this);
+    // Add the method OnWxSignal as a Wx::Signal observer 
+    //bbtkAddWxSignalObserver(WxGUITextEditorWindow::OnWxSignal);
     
-    Wx::SetTopWindow(top);
    
     SetAutoLayout(true);
     Layout();