diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 60bb1033ecaf..c5fc734ecc22 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -133,10 +133,20 @@ void StdCmdOpen::activated(int iMsg) QString selectedFilter; QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(), QObject::tr("Open document"), QString(), formatList, &selectedFilter); + if (fileList.isEmpty()) + return; + // load the files with the associated modules SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter); - for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) { - getGuiApplication()->open(it.key().toUtf8(), it.value().toAscii()); + if (dict.isEmpty()) { + QMessageBox::critical(getMainWindow(), + qApp->translate("StdCmdOpen", "Cannot open file"), + qApp->translate("StdCmdOpen", "Loading the file %1 is not supported").arg(fileList.front())); + } + else { + for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) { + getGuiApplication()->open(it.key().toUtf8(), it.value().toAscii()); + } } } diff --git a/src/Gui/FileDialog.cpp b/src/Gui/FileDialog.cpp index 90fc87af9ef4..9a6877ff6374 100644 --- a/src/Gui/FileDialog.cpp +++ b/src/Gui/FileDialog.cpp @@ -71,6 +71,22 @@ void FileDialog::onSelectedFilter(const QString& filter) void FileDialog::accept() { + // When saving to a file make sure that the entered filename ends with the selected + // file filter + if (acceptMode() == QFileDialog::AcceptSave) { + QStringList files = selectedFiles(); + if (!files.isEmpty()) { + QString ext = this->defaultSuffix(); + QString file = files.front(); + if (!ext.isEmpty() && !file.endsWith(ext, Qt::CaseInsensitive)) { + file = QString::fromLatin1("%1.%2").arg(file).arg(ext); + // That's the built-in line edit + QLineEdit* fileNameEdit = this->findChild(QString::fromLatin1("fileNameEdit")); + if (fileNameEdit) + fileNameEdit->setText(file); + } + } + } QFileDialog::accept(); }