BinEditor: Clean up translation contexts

Change-Id: Ibeb8c93ad1dfa816ccf1160abae8aac6781157d9
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2022-09-29 17:46:03 +02:00
parent 479403e320
commit 191815e974
14 changed files with 86 additions and 330 deletions

View File

@@ -3,13 +3,10 @@
#pragma once
namespace BinEditor {
namespace Constants {
namespace BinEditor::Constants {
const char C_BINEDITOR[] = "BinEditor.BinaryEditor";
const char C_BINEDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("OpenWith::Editors", "Binary Editor");
const char C_BINEDITOR_MIMETYPE[] = "application/octet-stream";
const char C_ENCODING_SETTING[] = "BinEditor/TextEncoding";
} // namespace Constants
} // namespace BinEditor
} // BinEditor::Constants

View File

@@ -2,26 +2,24 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "bineditorplugin.h"
#include "bineditorwidget.h"
#include "bineditorconstants.h"
#include "bineditorservice.h"
#include "bineditortr.h"
#include "bineditorwidget.h"
#include <coreplugin/editormanager/ieditorfactory.h>
#include <coreplugin/icore.h>
#include <texteditor/codecchooser.h>
#include <QCoreApplication>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QTextCodec>
#include <QVariant>
#include <QMenu>
#include <QAction>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QMenu>
#include <QMessageBox>
#include <QRegularExpressionValidator>
#include <QTextCodec>
#include <QToolBar>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -30,6 +28,7 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/find/ifindsupport.h>
#include <coreplugin/idocument.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/reloadpromptutils.h>
@@ -38,13 +37,16 @@
using namespace Utils;
using namespace Core;
namespace BinEditor {
namespace Internal {
namespace BinEditor::Internal {
class BinEditorFactory final : public IEditorFactory
{
public:
BinEditorFactory();
};
class BinEditorFind : public IFindSupport
{
Q_OBJECT
public:
BinEditorFind(BinEditorWidget *widget)
{
@@ -232,31 +234,31 @@ public:
{
const qint64 size = filePath.fileSize();
if (size < 0) {
QString msg = tr("Cannot open %1: %2").arg(filePath.toUserOutput(), tr("File Error"));
QString msg = Tr::tr("Cannot open %1: %2").arg(filePath.toUserOutput(), Tr::tr("File Error"));
// FIXME: Was: file.errorString(), but we don't have a file anymore.
if (errorString)
*errorString = msg;
else
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
return OpenResult::ReadError;
}
if (size == 0) {
QString msg = tr("The Binary Editor cannot open empty files.");
QString msg = Tr::tr("The Binary Editor cannot open empty files.");
if (errorString)
*errorString = msg;
else
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
return OpenResult::CannotHandle;
}
if (size / 16 >= qint64(1) << 31) {
// The limit is 2^31 lines (due to QText* interfaces) * 16 bytes per line.
QString msg = tr("The file is too big for the Binary Editor (max. 32GB).");
QString msg = Tr::tr("The file is too big for the Binary Editor (max. 32GB).");
if (errorString)
*errorString = msg;
else
QMessageBox::critical(ICore::dialogParent(), tr("File Error"), msg);
QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"), msg);
return OpenResult::CannotHandle;
}
@@ -279,8 +281,8 @@ public:
if (dataSize != blockSize)
data += QByteArray(blockSize - dataSize, 0);
m_widget->addData(address, data);
// QMessageBox::critical(ICore::dialogParent(), tr("File Error"),
// tr("Cannot open %1: %2").arg(
// QMessageBox::critical(ICore::dialogParent(), Tr::tr("File Error"),
// Tr::tr("Cannot open %1: %2").arg(
// fn.toUserOutput(), file.errorString()));
}
@@ -415,7 +417,7 @@ BinEditorPluginPrivate::BinEditorPluginPrivate()
ExtensionSystem::PluginManager::addObject(&m_editorFactory);
m_undoAction = new QAction(BinEditorPlugin::tr("&Undo"), this);
m_redoAction = new QAction(BinEditorPlugin::tr("&Redo"), this);
m_redoAction = new QAction(Tr::tr("&Redo"), this);
m_copyAction = new QAction(this);
m_selectAllAction = new QAction(this);
@@ -442,7 +444,7 @@ static BinEditorPluginPrivate *dd = nullptr;
BinEditorFactory::BinEditorFactory()
{
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Constants::C_BINEDITOR_DISPLAY_NAME));
setDisplayName(QCoreApplication::translate("OpenWith::Editors", "Binary Editor"));
addMimeType(Constants::C_BINEDITOR_MIMETYPE);
setEditorCreator([] {
@@ -510,7 +512,6 @@ bool BinEditorPlugin::initialize(const QStringList &arguments, QString *errorMes
return true;
}
} // namespace Internal
} // namespace BinEditor
} // BinEditor::Internal
#include "bineditorplugin.moc"

View File

@@ -6,10 +6,8 @@
#include "bineditorservice.h"
#include <extensionsystem/iplugin.h>
#include <coreplugin/editormanager/ieditorfactory.h>
namespace BinEditor {
namespace Internal {
namespace BinEditor::Internal {
class BinEditorPlugin : public ExtensionSystem::IPlugin
{
@@ -22,12 +20,6 @@ class BinEditorPlugin : public ExtensionSystem::IPlugin
void extensionsInitialized() final {}
};
class BinEditorFactory final : public Core::IEditorFactory
{
public:
BinEditorFactory();
};
class FactoryServiceImpl : public QObject, public FactoryService
{
Q_OBJECT
@@ -37,5 +29,4 @@ public:
EditorService *createEditorService(const QString &title0, bool wantsEditor) final;
};
} // namespace Internal
} // namespace BinEditor
} // BinEditor::Internal

View File

@@ -12,4 +12,4 @@ struct Tr
Q_DECLARE_TR_FUNCTIONS(BinEditor)
};
} // namespace BinEditor
} // BinEditor

View File

@@ -2,8 +2,10 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "bineditorwidget.h"
#include "bineditorconstants.h"
#include "bineditorservice.h"
#include "bineditortr.h"
#include "markup.h"
#include <coreplugin/coreconstants.h>
@@ -42,8 +44,7 @@
using namespace Core;
using namespace Utils;
namespace BinEditor {
namespace Internal {
namespace BinEditor::Internal {
const QChar MidpointChar(u'\u00B7');
@@ -1218,7 +1219,7 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
QString msg;
QTextStream str(&msg);
str << "<html><head/><body><p align=\"center\"><b>"
<< tr("Memory at 0x%1").arg(address, 0, 16) << "</b></p>";
<< Tr::tr("Memory at 0x%1").arg(address, 0, 16) << "</b></p>";
for (const Markup &m : qAsConst(m_markup)) {
if (m.covers(address) && !m.toolTip.isEmpty()) {
@@ -1226,16 +1227,16 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
break;
}
}
const QString msgDecimalUnsigned = tr("Decimal&nbsp;unsigned&nbsp;value:");
const QString msgDecimalSigned = tr("Decimal&nbsp;signed&nbsp;value:");
const QString msgOldDecimalUnsigned = tr("Previous&nbsp;decimal&nbsp;unsigned&nbsp;value:");
const QString msgOldDecimalSigned = tr("Previous&nbsp;decimal&nbsp;signed&nbsp;value:");
const QString msgDecimalUnsigned = Tr::tr("Decimal&nbsp;unsigned&nbsp;value:");
const QString msgDecimalSigned = Tr::tr("Decimal&nbsp;signed&nbsp;value:");
const QString msgOldDecimalUnsigned = Tr::tr("Previous&nbsp;decimal&nbsp;unsigned&nbsp;value:");
const QString msgOldDecimalSigned = Tr::tr("Previous&nbsp;decimal&nbsp;signed&nbsp;value:");
// Table showing little vs. big endian integers for multi-byte
if (intSize > 1) {
str << "<table><tr><th>"
<< tr("%1-bit&nbsp;Integer&nbsp;Type").arg(8 * intSize) << "</th><th>"
<< tr("Little Endian") << "</th><th>" << tr("Big Endian") << "</th></tr>";
<< Tr::tr("%1-bit&nbsp;Integer&nbsp;Type").arg(8 * intSize) << "</th><th>"
<< Tr::tr("Little Endian") << "</th><th>" << Tr::tr("Big Endian") << "</th></tr>";
str << tableRowStartC << msgDecimalUnsigned
<< numericTableRowSepC << littleEndianValue << numericTableRowSepC
<< bigEndianValue << tableRowEndC << tableRowStartC << msgDecimalSigned
@@ -1261,14 +1262,14 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
str << tableRowStartC << msgDecimalSigned << numericTableRowSepC
<< littleEndianSigned << tableRowEndC;
}
str << tableRowStartC << tr("Binary&nbsp;value:") << numericTableRowSepC;
str << tableRowStartC << Tr::tr("Binary&nbsp;value:") << numericTableRowSepC;
str.setIntegerBase(2);
str.setFieldWidth(8);
str.setPadChar(QLatin1Char('0'));
str << littleEndianValue;
str.setFieldWidth(0);
str << tableRowEndC << tableRowStartC
<< tr("Octal&nbsp;value:") << numericTableRowSepC;
<< Tr::tr("Octal&nbsp;value:") << numericTableRowSepC;
str.setIntegerBase(8);
str.setFieldWidth(3);
str << littleEndianValue << tableRowEndC;
@@ -1281,13 +1282,13 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
str << tableRowStartC << msgOldDecimalSigned << numericTableRowSepC
<< littleEndianSignedOld << tableRowEndC;
}
str << tableRowStartC << tr("Previous&nbsp;binary&nbsp;value:")
str << tableRowStartC << Tr::tr("Previous&nbsp;binary&nbsp;value:")
<< numericTableRowSepC;
str.setIntegerBase(2);
str.setFieldWidth(8);
str << littleEndianValueOld;
str.setFieldWidth(0);
str << tableRowEndC << tableRowStartC << tr("Previous&nbsp;octal&nbsp;value:")
str << tableRowEndC << tableRowStartC << Tr::tr("Previous&nbsp;octal&nbsp;value:")
<< numericTableRowSepC;
str.setIntegerBase(8);
str.setFieldWidth(3);
@@ -1303,10 +1304,10 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
double doubleValue, doubleValueOld;
asDouble(selStart, doubleValue, false);
asDouble(selStart, doubleValueOld, true);
str << tableRowStartC << tr("<i>double</i>&nbsp;value:") << numericTableRowSepC
str << tableRowStartC << Tr::tr("<i>double</i>&nbsp;value:") << numericTableRowSepC
<< doubleValue << tableRowEndC;
if (doubleValue != doubleValueOld)
str << tableRowStartC << tr("Previous <i>double</i>&nbsp;value:") << numericTableRowSepC
str << tableRowStartC << Tr::tr("Previous <i>double</i>&nbsp;value:") << numericTableRowSepC
<< doubleValueOld << tableRowEndC;
str << "</table>";
}
@@ -1317,10 +1318,10 @@ QString BinEditorWidget::toolTip(const QHelpEvent *helpEvent) const
float floatValue, floatValueOld;
asFloat(selStart, floatValue, false);
asFloat(selStart, floatValueOld, true);
str << tableRowStartC << tr("<i>float</i>&nbsp;value:") << numericTableRowSepC
str << tableRowStartC << Tr::tr("<i>float</i>&nbsp;value:") << numericTableRowSepC
<< floatValue << tableRowEndC;
if (floatValue != floatValueOld)
str << tableRowStartC << tr("Previous <i>float</i>&nbsp;value:") << numericTableRowSepC
str << tableRowStartC << Tr::tr("Previous <i>float</i>&nbsp;value:") << numericTableRowSepC
<< floatValueOld << tableRowEndC;
str << "</table>";
@@ -1441,8 +1442,7 @@ void BinEditorWidget::keyPressEvent(QKeyEvent *e)
static void showZoomIndicator(QWidget *editor, const int newZoom)
{
Utils::FadingIndicator::showText(editor,
QCoreApplication::translate("BinEditorWidget::TextEditorWidget",
"Zoom: %1%").arg(newZoom),
Tr::tr("Zoom: %1%").arg(newZoom),
Utils::FadingIndicator::SmallText);
}
@@ -1465,8 +1465,8 @@ void BinEditorWidget::copy(bool raw)
int selEnd = selectionEnd();
const int selectionLength = selEnd - selStart + 1;
if (selectionLength >> 22) {
QMessageBox::warning(this, tr("Copying Failed"),
tr("You cannot copy more than 4 MB of binary data."));
QMessageBox::warning(this, Tr::tr("Copying Failed"),
Tr::tr("You cannot copy more than 4 MB of binary data."));
return;
}
QByteArray data = dataMid(selStart, selectionLength);
@@ -1577,15 +1577,15 @@ void BinEditorWidget::contextMenuEvent(QContextMenuEvent *event)
QPointer<QMenu> contextMenu(new QMenu(this));
auto copyAsciiAction = new QAction(tr("Copy Selection as ASCII Characters"), contextMenu);
auto copyHexAction = new QAction(tr("Copy Selection as Hex Values"), contextMenu);
auto copyAsciiAction = new QAction(Tr::tr("Copy Selection as ASCII Characters"), contextMenu);
auto copyHexAction = new QAction(Tr::tr("Copy Selection as Hex Values"), contextMenu);
auto copyBeValue = new QAction(contextMenu);
auto copyLeValue = new QAction(contextMenu);
auto jumpToBeAddressHereAction = new QAction(contextMenu);
auto jumpToBeAddressNewWindowAction = new QAction(contextMenu);
auto jumpToLeAddressHereAction = new QAction(contextMenu);
auto jumpToLeAddressNewWindowAction = new QAction(contextMenu);
auto addWatchpointAction = new QAction(tr("Set Data Breakpoint on Selection"), contextMenu);
auto addWatchpointAction = new QAction(Tr::tr("Set Data Breakpoint on Selection"), contextMenu);
contextMenu->addAction(copyAsciiAction);
contextMenu->addAction(copyHexAction);
contextMenu->addAction(addWatchpointAction);
@@ -1596,11 +1596,11 @@ void BinEditorWidget::contextMenuEvent(QContextMenuEvent *event)
quint64 leAddress = 0;
if (byteCount <= 8) {
asIntegers(selStart, byteCount, beAddress, leAddress);
copyBeValue->setText(tr("Copy 0x%1").arg(QString::number(beAddress, 16)));
copyBeValue->setText(Tr::tr("Copy 0x%1").arg(QString::number(beAddress, 16)));
contextMenu->addAction(copyBeValue);
// If the menu entries would be identical, show only one of them.
if (beAddress != leAddress) {
copyLeValue->setText(tr("Copy 0x%1").arg(QString::number(leAddress, 16)));
copyLeValue->setText(Tr::tr("Copy 0x%1").arg(QString::number(leAddress, 16)));
contextMenu->addAction(copyLeValue);
}
setupJumpToMenuAction(contextMenu, jumpToBeAddressHereAction,
@@ -1611,9 +1611,9 @@ void BinEditorWidget::contextMenuEvent(QContextMenuEvent *event)
jumpToLeAddressNewWindowAction, leAddress);
}
} else {
jumpToBeAddressHereAction->setText(tr("Jump to Address in This Window"));
jumpToBeAddressNewWindowAction->setText(tr("Jump to Address in New Window"));
copyBeValue->setText(tr("Copy Value"));
jumpToBeAddressHereAction->setText(Tr::tr("Jump to Address in This Window"));
jumpToBeAddressNewWindowAction->setText(Tr::tr("Jump to Address in New Window"));
copyBeValue->setText(Tr::tr("Copy Value"));
jumpToBeAddressHereAction->setEnabled(false);
jumpToBeAddressNewWindowAction->setEnabled(false);
copyBeValue->setEnabled(false);
@@ -1650,9 +1650,9 @@ void BinEditorWidget::contextMenuEvent(QContextMenuEvent *event)
void BinEditorWidget::setupJumpToMenuAction(QMenu *menu, QAction *actionHere,
QAction *actionNew, quint64 addr)
{
actionHere->setText(tr("Jump to Address 0x%1 in This Window")
actionHere->setText(Tr::tr("Jump to Address 0x%1 in This Window")
.arg(QString::number(addr, 16)));
actionNew->setText(tr("Jump to Address 0x%1 in New Window")
actionNew->setText(Tr::tr("Jump to Address 0x%1 in New Window")
.arg(QString::number(addr, 16)));
menu->addAction(actionHere);
menu->addAction(actionNew);
@@ -1735,5 +1735,4 @@ void BinEditorWidget::setMarkup(const QList<Markup> &markup)
viewport()->update();
}
} // namespace Internal
} // namespace BinEditor
} // BinEditor::Internal

View File

@@ -31,8 +31,7 @@ namespace Core { class IEditor; }
namespace TextEditor { class FontSettings; }
namespace BinEditor {
namespace Internal {
namespace BinEditor::Internal {
class BinEditorWidgetPrivate;
@@ -228,5 +227,4 @@ private:
QList<Markup> m_markup;
};
} // namespace Internal
} // namespace BinEditor
} // BinEditor::Internal

View File

@@ -23,6 +23,6 @@ public:
QString toolTip;
};
} // namespace BinEditor
} // BinEditor
Q_DECLARE_METATYPE(BinEditor::Markup)