diff --git a/avogadro/qtgui/fileformatdialog.cpp b/avogadro/qtgui/fileformatdialog.cpp index c5ca455097..ee2dc34442 100644 --- a/avogadro/qtgui/fileformatdialog.cpp +++ b/avogadro/qtgui/fileformatdialog.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -222,7 +223,7 @@ QString FileFormatDialog::generateFilterString( for (auto ff : ffs) { QString name(QString::fromStdString(ff->name())); std::vector exts = ff->fileExtensions(); - for (auto & eit : exts) { + for (auto& eit : exts) { QString ext(QString::fromStdString(eit)); if (!formatMap.values(name).contains(ext)) { formatMap.insertMulti(name, ext); @@ -309,12 +310,34 @@ const Io::FileFormat* FileFormatDialog::selectFileFormat( if (preferred.size() == 1) return ffs[idents.indexOf(preferred.first())]; + // We will only show the dialog if the user is pressing + // the shift, control or meta keys. + if (!(QApplication::keyboardModifiers() & + (Qt::ShiftModifier | Qt::ControlModifier | Qt::MetaModifier))) { + // use a script format if set (i.e., these override internal) + // otherwise use internal over Open Babel + for (int i = 0; i < static_cast(ffs.size()); ++i) { + if (idents[i].startsWith("User")) { + return ffs[i]; + } else if (idents[i].startsWith("Avogadro")) { + return ffs[i]; + } else if (idents[i].startsWith("OpenBabel")) { + return ffs[i]; + } + } + // if we get here, we should show the user the dialog + // .. but it should never happen + } + // See if they used one before: QString lastIdent = settingsKey.isNull() ? QString() : QSettings().value(settingsKey).toString(); int lastIdentIndex = idents.indexOf(lastIdent); + + // we're going to show the dialog - if there wasn't a choice + // the default should be the first one if (lastIdentIndex < 0) lastIdentIndex = 0; @@ -334,4 +357,4 @@ const Io::FileFormat* FileFormatDialog::selectFileFormat( return ffs[index]; } -} // namespace Avogadro +} // namespace Avogadro::QtGui