From: corredor <> Date: Tue, 16 Oct 2012 08:40:18 +0000 (+0000) Subject: Bug #1688 RaC 2012 Bug to avoid opening twice the same diagram. Corrected and tested. X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=bbtkGEditor.git;a=commitdiff_plain;h=0209f53d6a0dbefceb3610b8d074e8fc4dcaba33 Bug #1688 RaC 2012 Bug to avoid opening twice the same diagram. Corrected and tested. --- diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx index a26f9dd..e7a9362 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx @@ -980,13 +980,21 @@ void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) { wxEmptyString, wxT(""), wxT("*.bbg"), wxOPEN | wxFILE_MUST_EXIST); printf("SCP: wxGUIEditorGraphicBBS::OnOpenDiagram \n"); if (openFileDialog->ShowModal() == wxID_OK) { - wxString fileName = openFileDialog->GetPath(); + wxString filePath = openFileDialog->GetPath(); ifstream inputStream; - std::string fName = (const char*) (fileName.mb_str()); + std::string fName = (const char*) (filePath.mb_str()); inputStream.open(fName.c_str()); assert(inputStream.good()); // fails - _tabsMgr->addNewTab(openFileDialog->GetFilename()); + + if(_tabsMgr->FindTab(crea::wx2std(filePath))!=-1) //RaC2012 avoid opening same diagram twice + { + inputStream.close(); + printf("RaC: Diagram already opened\n"); + return; + } + wxString fileName = openFileDialog->GetFilename(); + _tabsMgr->addNewTab(fileName); _tabsMgr->loadDiagram(inputStream, fName); _tabsMgr->saveTempActualDiagram("load diagram"); GetToolBar()->EnableTool(ID_UNDO, false); diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx index 7c29eae..fe453d7 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.cxx @@ -305,6 +305,20 @@ printf("wxTabPanelsManager::VerifyActualTabPanel %d \n", this->_notebook->GetPa //return ( (wxGEditorTabPanel) _notebook->GetPage(id)->GetFullPath( ) ); } + //========================================================================= + + int wxTabPanelsManager::FindTab(std::string filename) + { + std::map::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() diff --git a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h index c60e684..432e215 100644 --- a/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h +++ b/lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/wxTabPanelsManager.h @@ -123,6 +123,7 @@ namespace bbtk void SetNameTabPanel(wxString tabpanelname); std::string GetNameTabPanel(); std::string GetCurrentTabPanelPath( ); //DFCH + int FindTab(std::string filename);