Skip to content

Commit

Permalink
+ fixes #1760: FC fails to load a *.FCStd file if the filename lacks …
Browse files Browse the repository at this point in the history
…the *.FCStd file extension
  • Loading branch information
wwmayer committed Dec 29, 2014
1 parent 72f9474 commit 7aa91ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Gui/CommandDoc.cpp
Expand Up @@ -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());
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/Gui/FileDialog.cpp
Expand Up @@ -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<QLineEdit*>(QString::fromLatin1("fileNameEdit"));
if (fileNameEdit)
fileNameEdit->setText(file);
}
}
}
QFileDialog::accept();
}

Expand Down

0 comments on commit 7aa91ec

Please sign in to comment.