]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWxGUITextEditor.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.cxx
index b4f10c49ddc768a76a2b50b180e6a5bc91673f0c..56a5a97d56cfea3d7f7dea82c6b76fc879d99c0d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUITextEditor.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/25 10:31:18 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2008/03/25 15:47:54 $
+  Version:   $Revision: 1.4 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #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
 {
@@ -240,25 +248,42 @@ namespace bbtk
     // 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);
-    mwxButtonClose = new wxBitmapButton( btnsCtrlPanel,ID_ButtonClose,bmp_close);//,_T("Open")  );
-    btnsSizer->Add( mwxButtonClose );
     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);
-    mwxButtonSaveAs = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSaveAs,bmp_saveas);//_T("Save")  );
+    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 );
+
+    mwxButtonSaveAs = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSaveAs,bmp_saveas ,wxDefaultPosition, btn_size);//_T("Save")  );
     btnsSizer->Add( mwxButtonSaveAs );
 
-    wxBitmap bmp_run(cc_run_xpm);
-    mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run")  );
+
+    mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run ,wxDefaultPosition, btn_size);//_T("Run")  );
     btnsSizer->Add( mwxButtonRun );
     /*
     wxBitmap bmp_quit(cc_exit_xpm);
@@ -287,6 +312,7 @@ namespace bbtk
   WxGUITextEditor::~WxGUITextEditor()
   {
     m_mgr.UnInit();
+
     //    delete mInterpreter;
   }
   //================================================================
@@ -363,19 +389,28 @@ namespace bbtk
   //================================================================  
   void WxGUITextEditor::OnButtonClose(wxCommandEvent& event) 
   { 
+    CloseCurrentPage();
+  } 
+  //================================================================  
+
+  //================================================================  
+  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 : 
-           return;
+           return false;
            break;
          case wxID_YES : 
            GetCurrentPage()->Save(mFileNameFilter); 
@@ -385,17 +420,33 @@ namespace bbtk
       } 
     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 ---------------"<<std::endl;
     if (mwxNotebook->GetPageCount()==0) return;  
     GetCurrentPage()->Save(mFileNameFilter);
     mwxNotebook->SetPageText(mwxNotebook->GetSelection(),
@@ -408,7 +459,7 @@ namespace bbtk
   { 
     if (mwxNotebook->GetPageCount()==0) return;  
     GetCurrentPage()->SetAskFilename(true);
-    Save();
+    SaveCurrentPage();
   } 
   //================================================================  
 
@@ -416,6 +467,9 @@ namespace bbtk
   void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
   {
     std::cout << "-------------- CLOSE ---------------"<<std::endl;
+    if (!CloseCurrentPage()) evt.Veto();
+
+    /*
     if (mwxNotebook->GetPageCount()==0) return;
     if (GetCurrentPage()->IsModified()) 
       {
@@ -435,7 +489,7 @@ namespace bbtk
          case wxID_NO : ;
          }       
       }
-    
+    */
   }
   //================================================================
 
@@ -559,7 +613,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;