Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to return ribbons for language #199

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/API/knut/rcdocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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)> |**[actionsFromMenuForLanguage](#actionsFromMenuForLanguage)**(string menuId, string language)|
|array<[Action](../knut/action.md)> |**[actionsFromToolbar](#actionsFromToolbar)**(string toolBarId)|
|void |**[convertActions](#convertActions)**(int flags)|
||**[convertAssets](#convertAssets)**(int flags)|
Expand All @@ -41,6 +42,7 @@ import Knut
|bool |**[mergeLanguages](#mergeLanguages)**()|
|bool |**[previewDialog](#previewDialog)**([Widget](../knut/widget.md) dialog)|
|[Menu](../knut/menu.md) |**[ribbon](#ribbon)**(string id)|
|[Menu](../knut/menu.md) |**[ribbonForLanguage](#ribbonForLanguage)**(string id, string language)|
|string |**[string](#string)**(string id)|
|string |**[stringForDialog](#stringForDialog)**(string dialogId, string id)|
|string |**[stringForDialogAndLanguage](#stringForDialogAndLanguage)**(string language, string dialogId, string id)|
Expand Down Expand Up @@ -122,6 +124,10 @@ Returns the action for the given `id`.

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 Expand Up @@ -191,6 +197,10 @@ Previews the result of the conversion RC->UI

Returns the ribbon for the given `id`.

#### <a name="ribbonForLanguage"></a>[Menu](../knut/menu.md) **ribbonForLanguage**(string id, string language)

Returns the ribbon for the given `id` for specific `language`.

#### <a name="string"></a>string **string**(string id)

Returns the string for the given `id`.
Expand Down
18 changes: 18 additions & 0 deletions src/core/rcdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,24 @@ RcCore::Ribbon RcDocument::ribbon(const QString &id) const
return {};
}

/*!
* \qmlmethod Menu RcDocument::ribbonForLanguage(string id, string language)
* Returns the ribbon for the given `id` for specific `language`.
*/
RcCore::Ribbon RcDocument::ribbonForLanguage(const QString &id, const QString &language) const
{
LOG(id);

if (m_rcFile.isValid && m_rcFile.data.contains(language)) {
const RcCore::Data data = const_cast<RcCore::RcFile *>(&m_rcFile)->data[language];
if (auto ribbon = data.ribbon(id)) {
const_cast<RcCore::Ribbon *>(ribbon)->load();
return *ribbon;
}
}
return {};
}

QStringList RcDocument::dialogIds() const
{
LOG();
Expand Down
1 change: 1 addition & 0 deletions src/core/rcdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class RcDocument : public Document
Q_INVOKABLE RcCore::Menu menu(const QString &id) const;

Q_INVOKABLE RcCore::Ribbon ribbon(const QString &id) const;
Q_INVOKABLE RcCore::Ribbon ribbonForLanguage(const QString &id, const QString &language) const;

QStringList dialogIds() const;
QStringList menuIds() const;
Expand Down
29 changes: 29 additions & 0 deletions src/rccore/ribbon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "ribbon.h"
#include "utils/log.h"
#include <kdalgorithms.h>

#include <pugixml.hpp>

Expand Down Expand Up @@ -264,6 +265,34 @@ bool Ribbon::load()
return true;
}

/*!
* \qmlmethod RibbonElement Ribbon::elementFromId(string id)
* This method returns RibbonElement from identifier `id`.
*/
RibbonElement Ribbon::elementFromId(const QString &id) const
Montel marked this conversation as resolved.
Show resolved Hide resolved
{
const auto menuElements = menu.elements;
auto result = kdalgorithms::find_if(menuElements, [&id](const auto &item) {
return item.id == id;
});
if (result) {
return *result;
}

const auto categoriesElements = categories;
for (const auto &cat : categoriesElements) {
for (const auto &panel : cat.panels) {
auto result = kdalgorithms::find_if(panel.elements, [&id](const auto &item) {
return item.id == id;
});
if (result) {
return *result;
}
}
}
return {};
}

bool operator==(const RibbonElement &lhs, const RibbonElement &rhs)
{
return lhs.id == rhs.id;
Expand Down
1 change: 1 addition & 0 deletions src/rccore/ribbon.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct Ribbon
QString fileName;

bool load();
Q_INVOKABLE RcCore::RibbonElement elementFromId(const QString &id) const;
};

} // namespace RcCore
Expand Down
Loading