]> Creatis software - bbtkGEditor.git/blobdiff - lib/EditorGraphicBBS/bbsWxGUIEditorGraphic/bbtkwxGUIEditorGraphicBBS.cxx
Bug #1365,
[bbtkGEditor.git] / lib / EditorGraphicBBS / bbsWxGUIEditorGraphic / bbtkwxGUIEditorGraphicBBS.cxx
index fd7fa6528d6bae23f661004c5f2a6ff8a7a02716..af24586bf94ea1e451900fdbf7e6a69b38b866c4 100644 (file)
@@ -69,8 +69,8 @@ wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
        initToolbar();
        initTabPanelsManager();
        initPackageBrowser();
-       initHelpHTMLBrowser();
-
+        // JGGR & CM  initHelpHTMLBrowser();
+        _helpHtmlBrowser = NULL;
        CreateStatusBar();
        _frameAUIMgr->Update();
        _actualPkgBrowserBoxName = "";
@@ -80,6 +80,7 @@ wxGUIEditorGraphicBBS::wxGUIEditorGraphicBBS(wxFrame *parent) :
 
 //=========================================================================
 wxGUIEditorGraphicBBS::~wxGUIEditorGraphicBBS() {
+
        printf("EED %p ~wxGUIEditorGraphicBBS()\n", this);
 
        //EED02JUIN2010         delete _tabsMgr;
@@ -146,14 +147,15 @@ void wxGUIEditorGraphicBBS::initToolbar() {
        toolbar->AddSeparator();
        toolbar->AddTool(ID_UNDO, _T("Undo"),bmp_undo, wxNullBitmap, wxITEM_NORMAL,     _T("Undo"), _T("Undo"));
        toolbar->AddTool(ID_REDO, _T("Redo"),bmp_redo, wxNullBitmap, wxITEM_NORMAL,     _T("Redo"), _T("Redo"));
-       //toolbar->EnableTool(ID_UNDO, false);
-       //toolbar->EnableTool(ID_REDO, false);
+       toolbar->EnableTool(ID_UNDO, false);
+       toolbar->EnableTool(ID_REDO, false);
        toolbar->SetMargins(2, 2);
        toolbar->Realize();
        SetToolBar(toolbar);
 
        
        // connect command event handlers
+
        Connect(ID_NEW, wxEVT_COMMAND_TOOL_CLICKED,
                        wxCommandEventHandler(wxGUIEditorGraphicBBS::OnCreateNewTab));
        Connect(ID_OPEN, wxEVT_COMMAND_TOOL_CLICKED,
@@ -188,15 +190,15 @@ void wxGUIEditorGraphicBBS::initToolbar() {
                        wxCommandEventHandler(wxGUIEditorGraphicBBS::OnAddComplexBoxOutput));
        Connect(ID_UNDO,wxEVT_COMMAND_TOOL_CLICKED,     wxCommandEventHandler(wxGUIEditorGraphicBBS::OnUndo));
        Connect(ID_REDO,wxEVT_COMMAND_TOOL_CLICKED,     wxCommandEventHandler(wxGUIEditorGraphicBBS::OnRedo));
-
+       Connect(ID_CHANGENAME, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(wxGUIEditorGraphicBBS::OnChangeName));
 }
 //=========================================================================
 void wxGUIEditorGraphicBBS::initHelpHTMLBrowser() {
-       //TO FIX THE PATH OF BBTK BIN  IN ORDER TO USE REGENERATE EXECUTABLES
-       //RegenerateAll();
+       // JGRR & CM 
        _helpHtmlBrowser = new WxGUIHtmlBrowser(this, wxSize(200, 0));
-       _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(
-                       200, 200));
+   
+       // EO JGRR & CM 
+       
 }
 
 //=========================================================================
@@ -459,6 +461,17 @@ void wxGUIEditorGraphicBBS::executeScript(std::string script) {
        system(command.c_str());
 }
 
+//=========================================================================
+std::string wxGUIEditorGraphicBBS::CheckExtension(std::string filename, std::string extension) {
+        if(filename.size() > extension.size() ){
+                if( (filename.compare(filename.size()-extension.size(), extension.size(),extension)) !=0 ){
+                        filename.append(extension);
+                }
+        }else{
+                filename.append(extension);
+        }
+       return filename;
+}
 //=========================================================================
 // EVENT HANDLERS
 //=========================================================================
@@ -470,19 +483,33 @@ void wxGUIEditorGraphicBBS::OnCreateNewTab(wxCommandEvent& event) {
 
 void wxGUIEditorGraphicBBS::OnUndo(wxCommandEvent& event) {
        unsigned short disable;
-       GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->loadTempDiagram(0));
-       if (GetToolBar()->GetToolEnabled(ID_REDO) == false)
-                       GetToolBar()->EnableTool(ID_REDO,true);
+       _tabsMgr->loadTempDiagram(0);
+       disable = _tabsMgr->getUndoState();
+       if(disable == 0)
+       {
+               std::string name = _tabsMgr->GetNameTabPanel();
+               if(name[name.length() - 1] == '*')
+               {
+                       name =name.substr(0,name.length()-1);
+               }
+               _tabsMgr->SetNameTabPanel(name);
+       }
+
+       GetToolBar()->EnableTool(ID_UNDO,disable);
+       GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
        refreshGUIControls();
 }
 
 void wxGUIEditorGraphicBBS::OnRedo(wxCommandEvent& event) {
        unsigned short disable;
-       GetToolBar()->EnableTool(ID_REDO, _tabsMgr->loadTempDiagram(1));
-       if (GetToolBar()->GetToolEnabled(ID_UNDO) == false)
-                       GetToolBar()->EnableTool(ID_UNDO,true);
+       _tabsMgr->loadTempDiagram(1);
+       GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
+       GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
        refreshGUIControls();
 }
+
+void wxGUIEditorGraphicBBS::OnChangeName(wxCommandEvent& event){
+}
 //=========================================================================
 
 void wxGUIEditorGraphicBBS::OnExecuteActualDiagram(wxCommandEvent& event) {
@@ -543,7 +570,9 @@ void wxGUIEditorGraphicBBS::OnSaveActualBBS(wxCommandEvent& event) {
                        wxT("*.bbs"), wxSAVE | wxOVERWRITE_PROMPT);
        if (saveFileDialog->ShowModal() == wxID_OK) {
                wxString fileName = saveFileDialog->GetPath();
-               SaveActualBBS((const char*) (fileName.mb_str()));
+               std::string filename = (const char*) (fileName.mb_str());
+               filename=CheckExtension (filename, ".bbs");
+               SaveActualBBS(filename);
        }
 
 }
@@ -604,7 +633,9 @@ void wxGUIEditorGraphicBBS::OnSaveActualComplexBox(wxCommandEvent& event) {
                                        | wxOVERWRITE_PROMPT);
        if (saveFileDialog->ShowModal() == wxID_OK) {
                wxString fileName = saveFileDialog->GetPath();
-               SaveActualComplexBox((const char*) (fileName.mb_str()));
+               std::string filename = (const char*) (fileName.mb_str());
+               filename=CheckExtension (filename, ".bbs");
+               SaveActualComplexBox(filename);
        }
 }
 
@@ -635,6 +666,10 @@ void wxGUIEditorGraphicBBS::SaveActualDiagram(std::string filename) {
 //=========================================================================
 void wxGUIEditorGraphicBBS::SaveTempActualDiagram() 
 {
+       std::string name = _tabsMgr->GetNameTabPanel();
+       if(name[name.length() - 1] != '*')
+               name +="*";
+       _tabsMgr->SetNameTabPanel(name);
        _tabsMgr->saveTempActualDiagram();
 }
 
@@ -647,9 +682,17 @@ void wxGUIEditorGraphicBBS::SaveCurrentDiagramAs() {
                        wxT("Save current diagram"), wxEmptyString, wxT("NewDiagram"),
                        wxT("*.bbg"), wxSAVE | wxOVERWRITE_PROMPT);
        if (saveFileDialog->ShowModal() == wxID_OK) {
-               _tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
+               //_tabsMgr->SetNameTabPanel(saveFileDialog->GetFilename());
                wxString pathfileName = saveFileDialog->GetPath();
                std::string pathfilename = (const char*) (pathfileName.mb_str());
+               pathfilename=CheckExtension (pathfilename, ".bbg");
+
+               //modify the tab name accordingly
+               wxString fileName = saveFileDialog->GetFilename();
+               std::string filename = (const char*) (fileName.mb_str());
+               filename=CheckExtension (filename, ".bbg");
+               _tabsMgr->SetNameTabPanel( wxString (filename.c_str(), wxConvUTF8) );
+
                std::string pathfilenamebbs = pathfilename;
                pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
                if (_tabsMgr->isActualDiagramComplexBox() == false) {
@@ -671,7 +714,7 @@ void wxGUIEditorGraphicBBS::OnSaveActualDiagram(wxCommandEvent& event) {
        } else {
                std::string pathfilenamebbs = pathfilename;
                pathfilenamebbs[pathfilenamebbs.length() - 1] = 's';
-
+               
                if (_tabsMgr->isActualDiagramComplexBox() == false) {
                        SaveActualDiagram(pathfilename);
                        SaveActualBBS(pathfilenamebbs);
@@ -707,6 +750,9 @@ void wxGUIEditorGraphicBBS::refreshGUIControls() {
                GetMenuBar()->GetMenu(0)->Enable(ID_SAVE_AS_BBS, true);
        }
 
+       GetToolBar()->EnableTool(ID_UNDO,_tabsMgr->getUndoState());
+       GetToolBar()->EnableTool(ID_REDO,_tabsMgr->getRedoState());
+
        if (_tabsMgr->getNumActualSelectedObjects() > 0) {
                GetMenuBar()->GetMenu(1)->Enable(ID_COPY_TO_COMPLEXDIAGRAM, true);
        } else {
@@ -743,9 +789,10 @@ void wxGUIEditorGraphicBBS::OnOpenDiagram(wxCommandEvent& event) {
                wxString fileName = openFileDialog->GetPath();
                ifstream inputStream;
                std::string fName = (const char*) (fileName.mb_str());
+
                inputStream.open(fName.c_str());
+               assert(inputStream.good()); // fails
                _tabsMgr->addNewTab(openFileDialog->GetFilename());
-
                _tabsMgr->loadDiagram(inputStream, fName);
 
                inputStream.close();
@@ -868,10 +915,21 @@ void wxGUIEditorGraphicBBS::OnPlugPackage(wxCommandEvent& event) {
 //=========================================================================
 void wxGUIEditorGraphicBBS::OnEditConfig(wxCommandEvent& event) {
        printf("EED wxGUIEditorGraphicBBS::OnEditConfig ... not implemented ..\n");
-}
-//=========================================================================
-void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
-       printf("EED wxGUIEditorGraphicBBS::OnShowHTMLDoc ... not implemented ..\n");
+    }
+    //=========================================================================
+
+    void wxGUIEditorGraphicBBS::OnShowHTMLDoc(wxCommandEvent& event) {
+        // JGRR & CM WH
+        if (_helpHtmlBrowser != NULL){
+             _frameAUIMgr->DetachPane(_helpHtmlBrowser);
+            _helpHtmlBrowser->Destroy();   
+        }
+        initHelpHTMLBrowser();
+        _frameAUIMgr->AddPane(_helpHtmlBrowser, wxAuiPaneInfo().Right().MinSize(200, 200));
+        _frameAUIMgr->Update();
+        refreshGUIControls();
+        
+        // EO JGRR    & CM WH       
 }
 //=========================================================================
 void wxGUIEditorGraphicBBS::OnCreateIndex(wxCommandEvent& event) {
@@ -884,6 +942,8 @@ void wxGUIEditorGraphicBBS::OnExit(wxCommandEvent& event) {
        Close(true);
 }
 
+
+
 //=========================================================================
 
 } // EO namespace bbtk