Skip to content

Commit

Permalink
Cache command menu paths
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 30, 2024
1 parent c9c992a commit c18cf3a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion avogadro/qtplugins/commandscripts/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ QStringList Command::menuPath(QAction* action) const
return path;
}

// cache the menu paths
QSettings settings;
QFileInfo info(scriptFileName); // check if the script matches the hash
QString hash =
settings.value("scripts/" + scriptFileName + "/hash").toString();
if (hash == QString::number(info.size()) + info.lastModified().toString()) {
path = settings.value("scripts/" + scriptFileName + "/menu").toStringList();
if (!path.isEmpty())
return path;
}

// otherwise, we have a script name, so ask it
InterfaceScript gen(scriptFileName);
path = gen.menuPath().split('|');
Expand Down Expand Up @@ -93,12 +104,15 @@ QStringList Command::menuPath(QAction* action) const
// add it back to the path
path << lastPart;

// cache the path
settings.setValue("scripts/" + scriptFileName + "/menu", path);

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
// not ideal, but most menus should already be in the translation file
QStringList translatedPath;
foreach (QString part, path)
translatedPath << tr(part.toUtf8());
Expand Down

0 comments on commit c18cf3a

Please sign in to comment.