Skip to content

Commit

Permalink
Merge pull request #1338 from ghutchis/fix-register-script-commands
Browse files Browse the repository at this point in the history
Fixup mechanism to register script commands - now called by the app
  • Loading branch information
ghutchis authored Sep 12, 2023
2 parents 891a387 + af8af39 commit 6dc948e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions avogadro/qtgui/extensionplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class AVOGADROQTGUI_EXPORT ExtensionPlugin : public QObject
*/
virtual QList<Io::FileFormat*> fileFormats() const;

/**
* If the extension plugin has script commands, this method
* should be implemented to emit the registerCommand signals.
*/
virtual void registerCommands() {}

public slots:
/**
* Called when the current molecule changes.
Expand Down
6 changes: 6 additions & 0 deletions avogadro/qtgui/toolplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class AVOGADROQTGUI_EXPORT ToolPlugin : public QObject
virtual bool handleCommand(const QString& command,
const QVariantMap& options);

/**
* Called by the app to tell the tool to register commands.
* If the tool has commands, it should emit the registerCommand signals.
*/
virtual void registerCommands() {}

signals:
/**
* Emitted when draw() needs to be called again due to updates.
Expand Down
23 changes: 13 additions & 10 deletions avogadro/qtplugins/spectra/spectra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ Spectra::Spectra(QObject* p)
action->setText(tr("Vibrational Modes…"));
connect(action, SIGNAL(triggered()), SLOT(openDialog()));
m_actions.push_back(action);

emit registerCommand("showVibrations",
tr("Show the vibrational modes dialog."));
emit registerCommand("setVibrationalMode", tr("Set the vibrational mode."));
emit registerCommand("setVibrationalAmplitude",
tr("Set the vibrational amplitude."));
emit registerCommand("startVibrationAnimation",
tr("Start the vibrational animation."));
emit registerCommand("stopVibrationAnimation",
tr("Stop the vibrational animation."));
}

Spectra::~Spectra() {}
Expand Down Expand Up @@ -68,6 +58,19 @@ void Spectra::setMolecule(QtGui::Molecule* mol)
openDialog();
}

void Spectra::registerCommands()
{
emit registerCommand("showVibrations",
tr("Show the vibrational modes dialog."));
emit registerCommand("setVibrationalMode", tr("Set the vibrational mode."));
emit registerCommand("setVibrationalAmplitude",
tr("Set the vibrational amplitude."));
emit registerCommand("startVibrationAnimation",
tr("Start the vibrational animation."));
emit registerCommand("stopVibrationAnimation",
tr("Stop the vibrational animation."));
}

bool Spectra::handleCommand(const QString& command, const QVariantMap& options)
{
if (m_molecule == nullptr)
Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtplugins/spectra/spectra.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Spectra : public QtGui::ExtensionPlugin
bool handleCommand(const QString& command,
const QVariantMap& options) override;

void registerCommands() override;

public slots:
void setMode(int mode);
void setAmplitude(int amplitude);
Expand Down

0 comments on commit 6dc948e

Please sign in to comment.