Skip to content

Commit

Permalink
feat: return actions from languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Oct 24, 2024
1 parent 448d048 commit 4d37048
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/API/knut/rcdocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import Knut
| | Name |
|-|-|
|[ToolBar](../knut/toolbar.md) |**[action](#action)**(string id)|
|array<[Action](../knut/action.md)> |**[actionsForLanguage](#actionsForLanguage)**(string language)|
|array<[Action](../knut/action.md)> |**[actionsFromMenu](#actionsFromMenu)**(string menuId)|
|array<[Action](../knut/action.md)> |**[actionsFromMenuForLanguage](#actionsFromMenuForLanguage)**(string menuId, string language)|
|array<[Action](../knut/action.md)> |**[actionsFromToolbar](#actionsFromToolbar)**(string toolBarId)|
|string |**[captionDialogForLanguage](#captionDialogForLanguage)**(string language, string dialogId)|
|void |**[convertActions](#convertActions)**(int flags)|
Expand Down Expand Up @@ -119,10 +121,18 @@ Note that the RC file may be valid, and our parser needs to be updated.

Returns the action for the given `id`.

#### <a name="actionsForLanguage"></a>array&lt;[Action](../knut/action.md)> **actionsForLanguage**(string language)

Returns all actions used for language `language`.

#### <a name="actionsFromMenu"></a>array&lt;[Action](../knut/action.md)> **actionsFromMenu**(string menuId)

Returns all actions used in the menu `menuId`.

#### <a name="actionsFromMenuForLanguage"></a>array&lt;[Action](../knut/action.md)> **actionsFromMenuForLanguage**(string menuId, string language)

Returns all actions used in the menu `menuId` for language `language`.

#### <a name="actionsFromToolbar"></a>array&lt;[Action](../knut/action.md)> **actionsFromToolbar**(string toolBarId)

Returns all actions used in the toolbar `toolBarId`.
Expand Down
23 changes: 23 additions & 0 deletions src/core/rcdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,29 @@ RcCore::ActionList RcDocument::actionsFromMenuForLanguage(const QString &menuId,
return actions;
}

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

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];
actions = RcCore::convertActions(
data, static_cast<RcCore::Asset::ConversionFlags>(DEFAULT_VALUE(ConversionFlag, RcAssetFlags)));

} 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 @@ -65,6 +65,7 @@ class RcDocument : public Document
QList<RcCore::Asset> assets() const;
QList<RcCore::Action> actions() const;
Q_INVOKABLE RcCore::Action action(const QString &id) const;
Q_INVOKABLE RcCore::ActionList actionsForLanguage(const QString &language) 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;
Expand Down

0 comments on commit 4d37048

Please sign in to comment.