Commit e295307d authored by Michael Abrahams's avatar Michael Abrahams

Port away from `new QAction` retaining i18n strings

Summary:
This replaces most calls to `new QAction` with `KisActionRegistry::makeQAction()`, getting rid of static data in the code.

Now, instead of i18n() calls in the code right next to each action, krita.action  (and the other .action files) become the primary source of strings.

To handle this, we make a small modification to the script extractrc, which I've called action_i18n.pl.  This is intended for testing, the ultimate goal being to merge the changes to upstream extractrc.

Messages.sh is modified to include action_i18n.pl for the generation of translation strings.

Depends on D478

Tasks: T947

Reviewers: kossebau, rempt

Differential Revision: https://phabricator.kde.org/D479
parent 06d0ebfe
......@@ -9,7 +9,17 @@ RCFILES=`find . -name \*.rc \
| grep -v gemini/KritaGeminiWin.rc
`
$EXTRACTRC $RCFILES >> rc.cpp
ACTIONFILES=`find . -name \*.action`
./action_i18n.pl --context=action $ACTIONFILES >> rc.cpp
# extracti18n.pl extracts additional data from brushes, palettes etc.
perl extracti18n.pl > i18ndata
# ignore sdk/templates since it contains templates for use a future plugins, none of the strings there will ever be seen by any user
calligra_xgettext krita.pot i18ndata rc.cpp `find . -name \*.cc -o -name \*.h -o -name \*.cpp | grep -v '/tests/' | grep -v './sdk/templates'`
# Ignore sdk/templates which contains templates for writing future plugins.
# None of the placeholder strings inside will be seen by users.
calligra_xgettext krita.pot i18ndata rc.cpp \
`find . -name \*.cc -o -name \*.h -o -name \*.cpp | grep -v '/tests/' | grep -v './sdk/templates'`
# Clean up
rm -f i18ndata rc.cpp
This diff is collapsed.
......@@ -127,7 +127,7 @@ void KisPart::Private::loadActions()
foreach (const QString &name, actionNames) {
KisAction *a = new KisAction();
actionRegistry->propertizeAction(a, name);
actionRegistry->propertizeAction(name, a);
if (!actionCollection->action(name)) {
actionCollection->addAction(name, a);
......
......@@ -65,7 +65,7 @@
#include <kis_selection_mask.h>
#include "kis_resources_snapshot.h"
#include <KisView.h>
#include "kis_action_registry.h"
struct KisTool::Private {
......@@ -104,15 +104,13 @@ KisTool::KisTool(KoCanvasBase * canvas, const QCursor & cursor)
KActionCollection *collection = this->canvas()->canvasController()->actionCollection();
if (!collection->action("toggle_fg_bg")) {
QAction *toggleFgBg = new QAction(i18n("Swap Foreground and Background Color"), collection);
toggleFgBg->setShortcut(QKeySequence(Qt::Key_X));
QAction *toggleFgBg = KisActionRegistry::instance()->makeQAction("toggle_fg_bg", collection, "Canvas");
collection->addAction("toggle_fg_bg", toggleFgBg);
}
if (!collection->action("reset_fg_bg")) {
QAction *resetFgBg = new QAction(i18n("Reset Foreground and Background Color"), collection);
resetFgBg->setShortcut(QKeySequence(Qt::Key_D));
collection->addAction("reset_fg_bg", resetFgBg);
QAction *toggleFgBg = KisActionRegistry::instance()->makeQAction("reset_fg_bg", collection, "Canvas");
collection->addAction("reset_fg_bg", toggleFgBg);
}
addAction("toggle_fg_bg", dynamic_cast<QAction *>(collection->action("toggle_fg_bg")));
......@@ -696,5 +694,3 @@ bool KisTool::listeningToModifiers()
{
return false;
}
......@@ -145,7 +145,7 @@ void KisActionRegistry::addAction(QString name, QAction *a, QString category)
ac = d->actionCollections.value(category);
} else {
ac = new KActionCollection(this, category);
d->actionCollections.insert("Krita", ac);
d->actionCollections.insert(category, ac);
dbgAction << "Adding a new KActionCollection - " << category;
}
......@@ -183,8 +183,8 @@ void KisActionRegistry::configureShortcuts(KActionCollection *ac)
KisShortcutsDialog dlg;
dlg.addCollection(ac);
foreach (auto collection, d->actionCollections) {
dlg.addCollection(collection);
for (auto i = d->actionCollections.constBegin(); i != d->actionCollections.constEnd(); i++ ) {
dlg.addCollection(i.value(), i.key());
}
dlg.configure(); // Show the dialog.
......
......@@ -44,8 +44,6 @@
// dialogs/KisShortcutsDialog_p.h <- kshortcutsdialog_p.h, kshortcutseditor_p.h
// forms/KisShortcutsDialog.ui <- kshortcutsdialog.ui
//
// These files were forked from KF5 WidgetViews
//
//
// Changes that have been done to the files:
// * Adapt of includes
......
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