Skip to content

Commit

Permalink
feat: return list of action menu from specific language
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Oct 22, 2024
1 parent f79960f commit 8f54cf5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/core/rcdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,41 @@ RcCore::ActionList RcDocument::actionsFromMenu(const QString &menuId) const
return actions;
}

/*!
* \qmlmethod array<Action> RcDocument::actionsFromMenuForLanguage(string menuId, string language)
* Returns all actions used in the menu `menuId` for language `language`.
*/
RcCore::ActionList RcDocument::actionsFromMenuForLanguage(const QString &menuId, const QString &language) const
{
LOG(menuId);

if (!isDataValid())
return {};

RcCore::ActionList actions;

if (m_rcFile.isValid && m_rcFile.data.contains(language)) {
const RcCore::Data data = const_cast<RcCore::RcFile *>(&m_rcFile)->data[language];
if (auto menu = data.menu(menuId)) {
const auto actionIds = menu->actionIds();
auto actionsForLanguages = RcCore::convertActions(
data, static_cast<RcCore::Asset::ConversionFlags>(DEFAULT_VALUE(ConversionFlag, RcAssetFlags)));
for (const auto &id : actionIds) {
// We can't use actions() as it uses m_cacheActions
auto result = kdalgorithms::find_if(actionsForLanguages, [id](const auto &data) {
return data.id == id;
});
if (result) {
actions.push_back(*result);
}
}
}
} else {
return {};
}
return actions;
}

/*!
* \qmlmethod array<Action> RcDocument::actionsFromToolbar(string toolBarId)
* Returns all actions used in the toolbar `toolBarId`.
Expand Down
1 change: 1 addition & 0 deletions src/core/rcdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class RcDocument : public Document
QList<RcCore::Action> actions() const;
Q_INVOKABLE RcCore::Action action(const QString &id) const;
Q_INVOKABLE RcCore::ActionList actionsFromMenu(const QString &menuId) const;
Q_INVOKABLE RcCore::ActionList actionsFromMenuForLanguage(const QString &menuId, const QString &language) const;
Q_INVOKABLE RcCore::ActionList actionsFromToolbar(const QString &toolBarId) const;

QList<RcCore::ToolBar> toolBars() const;
Expand Down

0 comments on commit 8f54cf5

Please sign in to comment.