]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx
Bug #1688 RaC 2012 Bug to avoid opening twice the same diagram. Corrected and tested.
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / wxTabPanelsManager.cxx
index faa28b6ba9a89b5d65a8589477f574cd95faf8ae..fe453d791a001df2bc4b3f8fa63364a276387727 100644 (file)
@@ -36,7 +36,6 @@ Version:   $Revision$
 
 #include "wxTabPanelsManager.h"
 
-
 namespace bbtk
 {
 
@@ -49,6 +48,8 @@ namespace bbtk
                _notebook       = _parent->getAuiNotebook();
                addNewTab();
                _notebook->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED,wxAuiNotebookEventHandler(wxTabPanelsManager::OnTabChanged),0,this);
+               _notebook->Connect(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE,wxAuiNotebookEventHandler(wxTabPanelsManager::OnTabClose),0,this);
+
        }
 
        //=========================================================================
@@ -59,17 +60,21 @@ namespace bbtk
        //=========================================================================
        void wxTabPanelsManager::addNewTab(wxString tabName)
        {
-printf("EED wxTabPanelsManager::addNewTab 0\n");
-
                _lastId++;
-               wxGEditorTabPanel *newPanel         = new wxGEditorTabPanel(_notebook,_lastId);
+
+               //EED 13/10/2012                wxGEditorTabPanel *newPanel         = new wxGEditorTabPanel( _notebook,_lastId );
+               wxGEditorTabPanel *newPanel         = new wxGEditorTabPanel( _notebook,_lastId, _parent->GetBBTKFactory() );
+
                newPanel->setPanelsManager(this);
                _panels[_lastId]                    = newPanel;
                _actual                             = newPanel;
                _notebook->AddPage(newPanel, tabName  ,true);
-printf("EED wxTabPanelsManager::addNewTab 1\n");
        }
 
+
+
+
+
        //=========================================================================
        wxAuiNotebook* wxTabPanelsManager::getAuiNotebook()
        {
@@ -133,18 +138,44 @@ printf("EED wxTabPanelsManager::addNewTab 1\n");
 
        //=========================================================================
 
-       void wxTabPanelsManager::saveActualDiagram(std::string &content)
+       void wxTabPanelsManager::saveActualDiagram(std::string &content, const std::string &path) //DFCH
        {
-               _actual->saveDiagram(content);
+               _actual->saveDiagram(content, path);
        }
 
        //=========================================================================
 
-       void wxTabPanelsManager::loadDiagram(ifstream &inputStream)
+       void wxTabPanelsManager::loadDiagram(ifstream &inputStream, const std::string &path) //DFCH
+       {
+               _actual->loadDiagram(inputStream, path);
+       }
+
+       //=========================================================================
+       void wxTabPanelsManager::saveTempandUpdate(const std::string &action) //FCY
+       {
+               _parent->SaveTempActualDiagram(action);
+       }
+       //=========================================================================
+       void wxTabPanelsManager::saveTempActualDiagram(const std::string &action) //FCY
+       {
+               _actual->saveTempDiagram(action);
+       }
+       //=========================================================================
+       void wxTabPanelsManager::loadTempDiagram(unsigned short un) //FCY
        {
-               _actual->loadDiagram(inputStream);
+                _actual->loadTempDiagram(un);
        }
 
+       //=========================================================================
+       unsigned short wxTabPanelsManager::getUndoState( std::string &stun) //FCY
+       {
+                return _actual->getUndoState(stun);
+       }
+               //=========================================================================
+       unsigned short wxTabPanelsManager::getRedoState(std::string &stre) //FCY
+       {
+                return _actual->getRedoState(stre);
+       }
        //=========================================================================
 
        bool wxTabPanelsManager::isActualDiagramComplexBox()
@@ -211,6 +242,38 @@ printf("wxTabPanelsManager::VerifyActualTabPanel  %d \n", this->_notebook->GetPa
                int id                      = tab->getPanelId();
                _actual                     = _panels[id];
                _parent->refreshGUIControls();
+
+       }
+
+       //=========================================================================
+
+       void wxTabPanelsManager::OnTabClose(wxAuiNotebookEvent& event)
+       {
+
+               std::cout<<"RaC wxTabPanelsManager::OnTabClose Start... "<<_panels.size()<<std::endl;
+               int index = event.GetSelection();
+
+               if(_panels.size()>0)
+               {
+                       wxGEditorTabPanel* tab      = (wxGEditorTabPanel*)_notebook->GetPage(index);
+                       int id                      = tab->getPanelId();
+                       tab->deleteAllBoxes();
+                       _panels.erase(id);
+
+                       _notebook->RemovePage(index);
+
+                       std::cout<<"RaC wxTabPanelsManager::OnTabClose  IMPORTANT. The complete tab is not erased from memory... "<<std::endl;
+                       //////////////////////////////
+                       // TO FIX . RaC May 2012 - IMPORTANT. The complete tab is not erased from memory.
+                       // Only the objects are deleted and the tab is hidden
+                       // Execution problems when a tab is deleted using delete or DeletePage
+                       // delete tab;
+
+                       map<int, wxGEditorTabPanel*>::iterator it = _panels.begin() ;
+                       _actual=(*it).second;
+
+                       std::cout<<"RaC wxTabPanelsManager::OnTabClose End..."<< std::endl;
+               }
        }
 
        //=========================================================================
@@ -218,14 +281,44 @@ printf("wxTabPanelsManager::VerifyActualTabPanel  %d \n", this->_notebook->GetPa
        {
            return _actual->GetCbName();
        }
-
+       
+       //=========================================================================
        void wxTabPanelsManager::SetNameTabPanel(wxString tabpanelname)
        {
            int id          = _notebook->GetSelection();
            _notebook->SetPageText( id , tabpanelname );
        }
 
+       std::string wxTabPanelsManager::GetNameTabPanel() 
+       {
+                int id = _notebook->GetSelection();
+               return crea::wx2std(_notebook->GetPageText(id));
+       }
+
+       //=========================================================================
+       //DFCH
+       std::string wxTabPanelsManager::GetCurrentTabPanelPath( )
+       {
+               int id          = _notebook->GetSelection();
+               wxGEditorTabPanel* auxPanel = (wxGEditorTabPanel*) _notebook->GetPage(id);
+               return( auxPanel->GetFullPath( ) );
+           //return ( (wxGEditorTabPanel) _notebook->GetPage(id)->GetFullPath( ) );
+       }
+
+       //=========================================================================
 
+       int  wxTabPanelsManager::FindTab(std::string filename)
+       {
+               std::map<int, wxGEditorTabPanel*>::iterator it;
+               for (it = _panels.begin(); it != _panels.end(); ++it)
+               {
+                       wxGEditorTabPanel *obj = it->second;
+                       int id = it->first;
+                       if(obj->GetFullPath()==filename)
+                               return id;
+               }
+               return -1;
+       }
 
        //=========================================================================
     std::string wxTabPanelsManager::GetCbPackageName()