+ fixes #0001760: FC fails to load a *.FCStd file if the filename lacks the *.FCStd file extension

This commit is contained in:
wmayer 2014-12-30 00:31:39 +01:00
parent 72f947433c
commit 7aa91ecee3
2 changed files with 28 additions and 2 deletions

View File

@ -133,12 +133,22 @@ void StdCmdOpen::activated(int iMsg)
QString selectedFilter; QString selectedFilter;
QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(), QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(),
QObject::tr("Open document"), QString(), formatList, &selectedFilter); QObject::tr("Open document"), QString(), formatList, &selectedFilter);
if (fileList.isEmpty())
return;
// load the files with the associated modules // load the files with the associated modules
SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter); SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter);
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) { for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
getGuiApplication()->open(it.key().toUtf8(), it.value().toAscii()); getGuiApplication()->open(it.key().toUtf8(), it.value().toAscii());
} }
} }
}
//=========================================================================== //===========================================================================
// Std_Import // Std_Import

View File

@ -71,6 +71,22 @@ void FileDialog::onSelectedFilter(const QString& filter)
void FileDialog::accept() 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<QLineEdit*>(QString::fromLatin1("fileNameEdit"));
if (fileNameEdit)
fileNameEdit->setText(file);
}
}
}
QFileDialog::accept(); QFileDialog::accept();
} }