Skip to content

Commit

Permalink
Merge pull request #1501 from ghutchis/script-commands-priority
Browse files Browse the repository at this point in the history
Check script --menupath for {} priority numbers
  • Loading branch information
ghutchis committed Dec 5, 2023
2 parents e00b952 + f230d55 commit 7dce487
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion avogadro/qtplugins/commandscripts/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ QStringList Command::menuPath(QAction* action) const
return path;
}

// look for {number} in the last part of the path
// (this is a priority integer)
QString lastPart = path.takeLast();
int priority = 0;
int braceIndex = lastPart.indexOf('{');
int endBraceIndex = lastPart.indexOf('}');
if (braceIndex >= 0 && endBraceIndex >= 0 && endBraceIndex > braceIndex) {
bool ok = false;
size_t len = endBraceIndex - braceIndex - 1;
priority = lastPart.mid(braceIndex + 1, len).toInt(&ok);
if (ok) {
lastPart = lastPart.left(braceIndex);
}
}
// add it back to the path
path << lastPart;

if (priority != 0) {
action->setProperty("menu priority", priority);
}

// try to translate each part of the path
// not ideal, but menus should already be in the translation file
QStringList translatedPath;
Expand Down Expand Up @@ -306,4 +327,4 @@ void Command::addAction(const QString& label, const QString& scriptFilePath)
m_actions << action;
}

} // namespace Avogadro
} // namespace Avogadro::QtPlugins

0 comments on commit 7dce487

Please sign in to comment.