Skip to content

Commit

Permalink
feat: return caption from specific language
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Oct 24, 2024
1 parent 8f54cf5 commit f2c9f26
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/API/knut/rcdocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Knut
|[ToolBar](../knut/toolbar.md) |**[action](#action)**(string id)|
|array<[Action](../knut/action.md)> |**[actionsFromMenu](#actionsFromMenu)**(string menuId)|
|array<[Action](../knut/action.md)> |**[actionsFromToolbar](#actionsFromToolbar)**(string toolBarId)|
|string |**[captionDialogForLanguage](#captionDialogForLanguage)**(string language, string dialogId)|
|void |**[convertActions](#convertActions)**(int flags)|
||**[convertAssets](#convertAssets)**(int flags)|
|string |**[convertLanguageToCode](#convertLanguageToCode)**(string language)|
Expand Down Expand Up @@ -126,6 +127,10 @@ Returns all actions used in the menu `menuId`.

Returns all actions used in the toolbar `toolBarId`.

#### <a name="captionDialogForLanguage"></a>string **captionDialogForLanguage**(string language, string dialogId)

Returns the string with `id` for the given `language`.

#### <a name="convertActions"></a>void **convertActions**(int flags)


Expand Down
18 changes: 18 additions & 0 deletions src/core/rcdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,24 @@ QString RcDocument::stringForDialogAndLanguage(const QString &language, const QS
}
}

/*!
* \qmlmethod string RcDocument::captionDialogForLanguage(string language, string dialogId)
* Returns the string with `id` for the given `language`.
*/
QString RcDocument::captionDialogForLanguage(const QString &language, const QString &dialogId) const
{
LOG(language, dialogId);

if (m_rcFile.isValid && m_rcFile.data.contains(language)) {
const RcCore::Data data = const_cast<RcCore::RcFile *>(&m_rcFile)->data[language];
const auto dialog = data.dialog(dialogId);
return dialog->caption;
} else {
spdlog::warn("{}: language {} does not exist in the rc file.", FUNCTION_NAME, language);
return {};
}
}

/*!
* \qmlmethod string RcDocument::stringForDialog(string dialogId, string id)
* Returns the string with `id` for the given `dialogid`.
Expand Down
2 changes: 2 additions & 0 deletions src/core/rcdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class RcDocument : public Document

const RcCore::RcFile &file() const;

Q_INVOKABLE QString captionDialogForLanguage(const QString &language, const QString &dialogId) const;

public slots:
void convertAssets(int flags = DEFAULT_VALUE(ConversionFlag, RcAssetFlags));
void convertActions(int flags = DEFAULT_VALUE(ConversionFlags, RcAssetFlags));
Expand Down

0 comments on commit f2c9f26

Please sign in to comment.