Commit d10af909 authored by Dominik Haumann's avatar Dominik Haumann

External Tools: Fix translation of empty name/category

parent 8c3a777a
......@@ -20,6 +20,7 @@
#include "kateexternaltool.h"
#include <KConfigGroup>
#include <KLocalizedString>>
#include <QStandardPaths>
namespace
......@@ -141,6 +142,16 @@ void KateExternalTool::save(KConfigGroup &cg) const
cg.writeEntry("output", toString(outputMode));
}
QString KateExternalTool::translatedName() const
{
return name.isEmpty() ? QString() : i18n(name.toUtf8().data());
}
QString KateExternalTool::translatedCategory() const
{
return category.isEmpty() ? QString() : i18n(category.toUtf8().data());
}
bool operator==(const KateExternalTool &lhs, const KateExternalTool &rhs)
{
return lhs.category == rhs.category && lhs.name == rhs.name && lhs.icon == rhs.icon && lhs.executable == rhs.executable && lhs.arguments == rhs.arguments && lhs.input == rhs.input && lhs.workingDir == rhs.workingDir &&
......
......@@ -103,6 +103,16 @@ public:
* Save tool data to the config group @p cg.
*/
void save(KConfigGroup &cg) const;
/**
* Returns the translated name if possible.
*/
QString translatedName() const;
/**
* Returns the translated category if possible.
*/
QString translatedCategory() const;
};
/**
......
......@@ -54,7 +54,7 @@ constexpr int ToolRole = Qt::UserRole + 1;
*/
QStandardItem *newToolItem(const QIcon &icon, KateExternalTool *tool)
{
auto item = new QStandardItem(icon, i18n(tool->name.toUtf8().data()));
auto item = new QStandardItem(icon, tool->translatedName());
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled);
item->setData(QVariant::fromValue(reinterpret_cast<quintptr>(tool)), ToolRole);
return item;
......@@ -146,7 +146,7 @@ KateExternalToolServiceEditor::KateExternalToolServiceEditor(KateExternalTool *t
connect(ui->btnMimeType, &QToolButton::clicked, this, &KateExternalToolServiceEditor::showMTDlg);
Q_ASSERT(m_tool != nullptr);
ui->edtName->setText(i18n(m_tool->name.toUtf8().data()));
ui->edtName->setText(m_tool->translatedName());
if (!m_tool->icon.isEmpty())
ui->btnIcon->setIcon(m_tool->icon);
......@@ -168,7 +168,7 @@ KateExternalToolServiceEditor::KateExternalToolServiceEditor(KateExternalTool *t
ui->buttonBox->setToolTip(i18n("Revert tool to default settings"));
connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, [this, tool]() {
const auto t = defaultTool(tool->actionName, m_plugin->defaultTools());
ui->edtName->setText(i18n(t.name.toUtf8().data()));
ui->edtName->setText(t.translatedName());
ui->btnIcon->setIcon(t.icon);
ui->edtExecutable->setText(t.executable);
ui->edtArgs->setText(t.arguments);
......@@ -409,7 +409,7 @@ void KateExternalToolsConfigWidget::lazyInitDefaultsMenu(QMenu *defaultsMenu)
// first add categorized actions, such that the submenus appear at the top
int defaultToolsIndex = 0;
for (const auto &tool : m_plugin->defaultTools()) {
const QString category = tool.category.isEmpty() ? i18n("Uncategorized") : i18n(tool.category.toUtf8().data());
const QString category = tool.category.isEmpty() ? i18n("Uncategorized") : tool.translatedCategory();
auto categoryMenu = categories[category];
if (!categoryMenu) {
categoryMenu = new QMenu(category, this);
......@@ -417,7 +417,7 @@ void KateExternalToolsConfigWidget::lazyInitDefaultsMenu(QMenu *defaultsMenu)
defaultsMenu->addMenu(categoryMenu);
}
auto a = categoryMenu->addAction(QIcon::fromTheme(tool.icon), i18n(tool.name.toUtf8().data()));
auto a = categoryMenu->addAction(QIcon::fromTheme(tool.icon), tool.translatedName());
a->setData(defaultToolsIndex);
connect(a, &QAction::triggered, [this, a]() { slotAddDefaultTool(a->data().toInt()); });
......@@ -442,7 +442,7 @@ void KateExternalToolsConfigWidget::addNewTool(KateExternalTool *tool)
makeEditorCommandUnique(tool, tools);
auto item = newToolItem(tool->icon.isEmpty() ? blankIcon() : QIcon::fromTheme(tool->icon), tool);
auto category = addCategory(i18n(tool->category.toUtf8().data()));
auto category = addCategory(tool->translatedCategory());
category->appendRow(item);
lbTools->setCurrentIndex(item->index());
......@@ -452,7 +452,7 @@ void KateExternalToolsConfigWidget::addNewTool(KateExternalTool *tool)
QStandardItem *KateExternalToolsConfigWidget::addCategory(const QString &translatedCategory)
{
if (translatedCategory.isEmpty()) {
if (translatedCategory.isEmpty() || (m_noCategory && translatedCategory == i18n("Uncategorized"))) {
return m_noCategory;
}
......
......@@ -75,7 +75,7 @@ void KateExternalToolsMenuAction::reload()
// first add categorized actions, such that the submenus appear at the top
for (auto tool : m_plugin->tools()) {
if (tool->hasexec) {
auto a = new QAction(tool->name, this);
auto a = new QAction(tool->translatedName(), this);
a->setIcon(QIcon::fromTheme(tool->icon));
a->setData(QVariant::fromValue(tool));
......@@ -85,7 +85,7 @@ void KateExternalToolsMenuAction::reload()
if (!tool->category.isEmpty()) {
auto categoryMenu = categories[tool->category];
if (!categoryMenu) {
categoryMenu = new KActionMenu(i18n(tool->category.toUtf8().data()), this);
categoryMenu = new KActionMenu(tool->translatedCategory(), this);
categories[tool->category] = categoryMenu;
addAction(categoryMenu);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment