Skip to content

Commit

Permalink
Make sure to cancel "Insert SMILES"
Browse files Browse the repository at this point in the history
Also save the last SMILES for re-use

Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Feb 14, 2025
1 parent 3ae0eec commit 53e5fc9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 5 additions & 4 deletions avogadro/qtplugins/lineformatinput/lineformatinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ using Avogadro::QtGui::FileFormatDialog;
namespace Avogadro::QtPlugins {

LineFormatInput::LineFormatInput(QObject* parent_)
: Avogadro::QtGui::ExtensionPlugin(parent_),
m_molecule(nullptr), m_reader(nullptr)
: Avogadro::QtGui::ExtensionPlugin(parent_), m_molecule(nullptr),
m_reader(nullptr)
{
auto* action = new QAction(tr("SMILES…"), this);
action->setProperty("menu priority", 800);
Expand Down Expand Up @@ -98,7 +98,8 @@ void LineFormatInput::showDialog()
dlg.exec();

// check if the reply is empty
if (dlg.descriptor().isEmpty())
if (dlg.result() != LineFormatInputDialog::Accepted ||
dlg.descriptor().isEmpty())
return; // nothing to do

// Resolve any format conflicts:
Expand Down Expand Up @@ -137,4 +138,4 @@ void LineFormatInput::showDialog()
m_reader = nullptr;
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins
14 changes: 13 additions & 1 deletion avogadro/qtplugins/lineformatinput/lineformatinputdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ LineFormatInputDialog::LineFormatInputDialog(QWidget* aParent)
: QDialog(aParent), m_ui(new Ui::LineFormatInputDialog)
{
m_ui->setupUi(this);

QSettings settings;
// set the last used descriptor
QString lastDescriptor =
settings.value("lineformatinput/lastDescriptor").toString();
setDescriptor(lastDescriptor);
}

LineFormatInputDialog::~LineFormatInputDialog()
Expand Down Expand Up @@ -45,6 +51,11 @@ void LineFormatInputDialog::setCurrentFormat(const QString& format)
m_ui->formats->setCurrentIndex(index);
}

void LineFormatInputDialog::setDescriptor(const QString& descriptor)
{
m_ui->descriptor->setText(descriptor);
}

QString LineFormatInputDialog::descriptor() const
{
return m_ui->descriptor->text();
Expand All @@ -54,7 +65,8 @@ void LineFormatInputDialog::accept()
{
QSettings settings;
settings.setValue("lineformatinput/lastUsed", format());
settings.setValue("lineformatinput/lastDescriptor", descriptor());
QDialog::accept();
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins
2 changes: 2 additions & 0 deletions avogadro/qtplugins/lineformatinput/lineformatinputdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class LineFormatInputDialog : public QDialog

void setCurrentFormat(const QString& format);

void setDescriptor(const QString& descriptor);

QString descriptor() const;

protected slots:
Expand Down

0 comments on commit 53e5fc9

Please sign in to comment.