Author: derek Date: Fri Apr 4 00:15:40 2008 New Revision: 403 Modified: sofaswitch/trunk/callflow/src/callflow.cpp Log: Tidy up handling of the file name, to always default to extension of .src Modified: sofaswitch/trunk/callflow/src/callflow.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/callflow.cpp (original) +++ sofaswitch/trunk/callflow/src/callflow.cpp Fri Apr 4 00:15:40 2008 @@ -257,9 +257,13 @@ wxFileDialog filedlg(this, _T("Select a file to read data from"), _T(""), _T(""), _T("*.src")); if ( filedlg.ShowModal() != wxID_OK ) return; + + wxString name = filedlg.GetPath(); + if (name.Right(4) != wxString(".src")) + name = name + wxString(".src"); - wxTextFile file(filedlg.GetPath()); - + wxTextFile file(name); + if (!file.Exists()) { wxMessageBox(wxString::Format("The file %s must exist to read from", filedlg.GetFilename().c_str())); return; @@ -268,7 +272,7 @@ file.Open(); if (file.IsOpened()) { file.Close(); - currentFileName = filedlg.GetPath(); + currentFileName = name; canvas->ReadShapeInformationFromFile(currentFileName); SetStatusText(wxString::Format("Read source code from %s", currentFileName.c_str())); SetNewWindowName(currentFileName); @@ -313,10 +317,17 @@ if (filedlg.ShowModal() != wxID_OK) return; - wxTextFile file(filedlg.GetPath()); + + wxString name = filedlg.GetPath(); + + if (name.Right(4) != wxString(".src")) + name = name + wxString(".src"); + currentFileName = name; + + wxTextFile file(name); if (file.Exists()) { - wxString msg = wxString::Format("The file \n%s\n exists. Overwrite ? ", (const char *)filedlg.GetPath()); + wxString msg = wxString::Format("The file \n%s\n exists. Overwrite ? ", (const char *)name); wxMessageDialog *dlg= new wxMessageDialog(this, msg, "Overwrite existing file", wxYES_DEFAULT | wxYES_NO); if (wxID_NO == dlg->ShowModal()) return; @@ -327,15 +338,14 @@ file.Open(); if (!file.IsOpened()) { - wxMessageBox(wxString::Format("Unable to open the file %s to write data to", filedlg.GetFilename().c_str())); + wxMessageBox(wxString::Format("Unable to open the file %s to write data to", name.c_str())); return; } - currentFileName = filedlg.GetPath(); file.Close(); - canvas->ShapeInformationToFile(currentFileName); - SetStatusText(wxString::Format("Saved source code to %s", currentFileName.c_str())); - SetNewWindowName(currentFileName); + canvas->ShapeInformationToFile(name); + SetStatusText(wxString::Format("Saved source code to %s", name.c_str())); + SetNewWindowName(name); }
participants (1)
-
SofaSWITCH SVN