]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWxGUITextEditor.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUITextEditor.cxx
index e2f7fe46eada0f9f3346205ff88feac0f3089e44..b4f10c49ddc768a76a2b50b180e6a5bc91673f0c 100644 (file)
@@ -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/03/25 10:31:18 $
+  Version:   $Revision: 1.3 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -39,7 +39,9 @@
 
 #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"
 
@@ -245,9 +247,15 @@ namespace bbtk
     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")  );
+    btnsSizer->Add( mwxButtonSaveAs );
 
     wxBitmap bmp_run(cc_run_xpm);
     mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run")  );
@@ -352,6 +360,34 @@ namespace bbtk
   }
   //================================================================  
 
+  //================================================================  
+  void WxGUITextEditor::OnButtonClose(wxCommandEvent& event) 
+  { 
+    std::cout << "-------------- CLOSE ---------------"<<std::endl;
+    if (mwxNotebook->GetPageCount()==0) return;
+    if (GetCurrentPage()->IsModified()) 
+      {
+       wxMessageDialog* d = 
+         new wxMessageDialog(this,
+                             _T("Buffer modified. Save it ?"), 
+                             _T("Save buffer"), 
+                             wxYES_NO | wxCANCEL | wxICON_QUESTION);
+       switch (d->ShowModal())
+         {
+         case wxID_CANCEL : 
+           return;
+           break;
+         case wxID_YES : 
+           GetCurrentPage()->Save(mFileNameFilter); 
+           break;
+         case wxID_NO : ;
+         }       
+      } 
+    mwxNotebook->DeletePage(mwxNotebook->GetSelection());
+    FocusOnCurrentPage();
+  } 
+  //================================================================  
+
   //================================================================  
   void WxGUITextEditor::OnButtonSave(wxCommandEvent& event) 
   { 
@@ -367,6 +403,15 @@ namespace bbtk
   }
   //================================================================  
 
+  //================================================================  
+  void WxGUITextEditor::OnButtonSaveAs(wxCommandEvent& event) 
+  { 
+    if (mwxNotebook->GetPageCount()==0) return;  
+    GetCurrentPage()->SetAskFilename(true);
+    Save();
+  } 
+  //================================================================  
+
   //================================================================  
   void WxGUITextEditor::OnPageClose(wxAuiNotebookEvent& evt)
   {
@@ -395,6 +440,7 @@ namespace bbtk
   //================================================================
 
 
+
   /*
   //================================================================  
   void WxGUITextEditor::OnButtonQuit(wxCommandEvent& event) 
@@ -413,7 +459,8 @@ namespace bbtk
   //================================================================  
   void WxGUITextEditor::OnButtonRun(wxCommandEvent& event) 
   { 
-    if (mUser!=0) mUser->WxGUITextEditorRun();
+    if ((mUser!=0) && (mwxNotebook->GetPageCount()>0)) 
+      mUser->WxGUITextEditorRun();
     FocusOnCurrentPage();
   }
 
@@ -526,7 +573,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)