+ //save current file before close if modified
+ boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+ if(aDoc->isModified()) {
+ //TODO(sbh): re-launch the app?
+ int anAnswer = QMessageBox::question(
+ myMainWindow, tr("Save current file"),
+ tr("The document is modified, save before opening another?"),
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
+ if(anAnswer == QMessageBox::Save) {
+ onSave();
+ } else if (anAnswer == QMessageBox::Cancel) {
+ return;
+ }
+ aDoc->close();
+ myCurrentFile = "";
+ }
+
+ //show file dialog, check if readable and open
+ myCurrentFile = QFileDialog::getOpenFileName(mainWindow());
+ if(myCurrentFile.isEmpty())
+ return;
+ QFileInfo aFileInfo(myCurrentFile);
+ if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
+ QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
+ myCurrentFile = "";
+ return;
+ }
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ aDoc->load(myCurrentFile.toLatin1().constData());
+ QApplication::restoreOverrideCursor();