[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [lokalize] src: Add a shortcut to delete TM entries (Ctrl+Alt+Number)
From: Simon Depiets <null () kde ! org>
Date: 2018-08-16 6:30:04
Message-ID: E1fqBnI-0003L8-NW () code ! kde ! org
[Download RAW message or body]
Git commit d05eaee2566b4b8c692ac6ecac434ae8659d06f6 by Simon Depiets.
Committed on 16/08/2018 at 06:29.
Pushed by sdepiets into branch 'master'.
Add a shortcut to delete TM entries (Ctrl+Alt+Number)
Summary:
Add a shortcut to delete TM entries (Ctrl+Alt+Number)
FEATURE: 233144
Reviewers: aacid, ltoscano, shaforostoff, mlaurent, #localization
Reviewed By: aacid, #localization
Tags: #localization
Differential Revision: https://phabricator.kde.org/D14573
M +14 -5 src/editortab.cpp
M +15 -1 src/editorui.rc
M +42 -17 src/tm/tmview.cpp
M +5 -2 src/tm/tmview.h
https://commits.kde.org/lokalize/d05eaee2566b4b8c692ac6ecac434ae8659d06f6
diff --git a/src/editortab.cpp b/src/editortab.cpp
index 1602468..496a92a 100644
--- a/src/editortab.cpp
+++ b/src/editortab.cpp
@@ -294,7 +294,8 @@ void EditorTab::setupActions()
//action->setShortcut(Qt::CTRL+glist[i]);
action->setText(i18nc("@action:inmenu", "Add a note"));
- QVector<QAction*> tmactions(TM_SHORTCUTS);
+ QVector<QAction*> tmactions_insert(TM_SHORTCUTS);
+ QVector<QAction*> tmactions_remove(TM_SHORTCUTS);
Qt::Key tmlist[TM_SHORTCUTS] = {
Qt::Key_1,
Qt::Key_2,
@@ -312,13 +313,21 @@ void EditorTab::setupActions()
// action->setVisible(false);
tmaction = tm->addAction(QStringLiteral("tmquery_insert_%1").arg(i));
ac->setDefaultShortcut(tmaction, QKeySequence(Qt::CTRL + tmlist[i]));
- tmaction->setText(i18nc("@action:inmenu", "Insert TM suggestion #%1", \
QString::number(i + 1)));
- tmactions[i] = tmaction;
+ tmaction->setText(i18nc("@action:inmenu", "Insert TM suggestion #%1", i + \
1)); + tmactions_insert[i] = tmaction;
+
+ tmaction = tm->addAction(QStringLiteral("tmquery_remove_%1").arg(i));
+ ac->setDefaultShortcut(tmaction, QKeySequence(Qt::CTRL + Qt::ALT + \
tmlist[i])); + tmaction->setText(i18nc("@action:inmenu", "Remove TM suggestion \
#%1", i + 1)); + tmactions_remove[i] = tmaction;
}
#ifndef Q_OS_DARWIN
- if (systemLang == QLocale::Czech) ac->setDefaultShortcuts(tmactions[0], \
QList<QKeySequence>() << QKeySequence(Qt::CTRL + tmlist[0]) << QKeySequence(Qt::CTRL \
+ Qt::Key_Plus)); + if (systemLang == QLocale::Czech) {
+ ac->setDefaultShortcuts(tmactions_insert[0], QList<QKeySequence>() << \
QKeySequence(Qt::CTRL + tmlist[0]) << QKeySequence(Qt::CTRL + Qt::Key_Plus)); + \
ac->setDefaultShortcuts(tmactions_remove[0], QList<QKeySequence>() << \
QKeySequence(Qt::CTRL + Qt::ALT + tmlist[0]) << QKeySequence(Qt::CTRL + Qt::ALT + \
Qt::Key_Plus)); + }
#endif
- TM::TMView* _tmView = new TM::TMView(this, m_catalog, tmactions);
+ TM::TMView* _tmView = new TM::TMView(this, m_catalog, tmactions_insert, \
tmactions_remove); addDockWidget(Qt::BottomDockWidgetArea, _tmView);
tm->addAction(QStringLiteral("showtmqueryview_action"), \
_tmView->toggleViewAction());
connect(_tmView, &TM::TMView::refreshRequested, m_view, \
QOverload<>::of(&EditorView::gotoEntry), Qt::QueuedConnection);
diff --git a/src/editorui.rc b/src/editorui.rc
index 3ae2049..f7e4f68 100644
--- a/src/editorui.rc
+++ b/src/editorui.rc
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="Editor" version="12">
+<kpartgui name="Editor" version="13">
<MenuBar>
<Menu name="file"><text>&File</text>
<Action name="file_new"/>
@@ -122,6 +122,20 @@
<Action name="tmquery_insert_10"/>
<Action name="tmquery_insert_11"/>
<Action name="tmquery_insert_12"/>
+ <Separator/>
+ <Action name="tmquery_remove_0"/>
+ <Action name="tmquery_remove_1"/>
+ <Action name="tmquery_remove_2"/>
+ <Action name="tmquery_remove_3"/>
+ <Action name="tmquery_remove_4"/>
+ <Action name="tmquery_remove_5"/>
+ <Action name="tmquery_remove_6"/>
+ <Action name="tmquery_remove_7"/>
+ <Action name="tmquery_remove_8"/>
+ <Action name="tmquery_remove_9"/>
+ <Action name="tmquery_remove_10"/>
+ <Action name="tmquery_remove_11"/>
+ <Action name="tmquery_remove_12"/>
</Menu>
<Menu name="alttrans"><text>Alternative Translations</text>
<Action name="alttrans_attach"/>
diff --git a/src/tm/tmview.cpp b/src/tm/tmview.cpp
index 1e79057..4878d62 100644
--- a/src/tm/tmview.cpp
+++ b/src/tm/tmview.cpp
@@ -131,12 +131,13 @@ void TextBrowser::mouseDoubleClickEvent(QMouseEvent* event)
}
-TMView::TMView(QWidget* parent, Catalog* catalog, const QVector<QAction*>& actions)
+TMView::TMView(QWidget* parent, Catalog* catalog, const QVector<QAction*>& \
actions_insert, const QVector<QAction*>& actions_remove) : \
QDockWidget(i18nc("@title:window", "Translation Memory"), parent) , m_browser(new \
TextBrowser(this)) , m_catalog(catalog)
, m_currentSelectJob(0)
- , m_actions(actions)
+ , m_actions_insert(actions_insert)
+ , m_actions_remove(actions_remove)
, m_normTitle(i18nc("@title:window", "Translation Memory"))
, m_hasInfoTitle(m_normTitle + QStringLiteral(" [*]"))
, m_hasInfo(false)
@@ -166,13 +167,21 @@ void TMView::initLater()
{
setAcceptDrops(true);
- QSignalMapper* signalMapper = new QSignalMapper(this);
- int i = m_actions.size();
+ QSignalMapper* signalMapper_insert = new QSignalMapper(this);
+ QSignalMapper* signalMapper_remove = new QSignalMapper(this);
+ int i = m_actions_insert.size();
while (--i >= 0) {
- connect(m_actions.at(i), &QAction::triggered, signalMapper, \
QOverload<>::of(&QSignalMapper::map));
- signalMapper->setMapping(m_actions.at(i), i);
+ connect(m_actions_insert.at(i), &QAction::triggered, signalMapper_insert, \
QOverload<>::of(&QSignalMapper::map)); + \
signalMapper_insert->setMapping(m_actions_insert.at(i), i); }
- connect(signalMapper, QOverload<int>::of(&QSignalMapper::mapped), this, \
&TMView::slotUseSuggestion); +
+ i = m_actions_remove.size();
+ while (--i >= 0) {
+ connect(m_actions_remove.at(i), &QAction::triggered, signalMapper_remove, \
QOverload<>::of(&QSignalMapper::map)); + \
signalMapper_remove->setMapping(m_actions_remove.at(i), i); + }
+ connect(signalMapper_insert, QOverload<int>::of(&QSignalMapper::mapped), this, \
&TMView::slotUseSuggestion); + connect(signalMapper_remove, \
QOverload<int>::of(&QSignalMapper::mapped), this, &TMView::slotRemoveSuggestion);
setToolTip(i18nc("@info:tooltip", "Double-click any word to insert it into \
translation"));
@@ -490,9 +499,9 @@ void TMView::slotSuggestionsCame(SelectJob* j)
//str.replace('&',"&"); TODO check
html += QLatin1String("<br>");
- if (Q_LIKELY(i < m_actions.size())) {
- m_actions.at(i)->setStatusTip(entry.target.string);
- html += QStringLiteral("[%1] \
").arg(m_actions.at(i)->shortcut().toString(QKeySequence::NativeText)); + if \
(Q_LIKELY(i < m_actions_insert.size())) { + \
m_actions_insert.at(i)->setStatusTip(entry.target.string); + html += \
QStringLiteral("[%1] \
").arg(m_actions_insert.at(i)->shortcut().toString(QKeySequence::NativeText)); } \
else html += QLatin1String("[ - ] ");
/*
@@ -552,6 +561,16 @@ bool TMView::event(QEvent *event)
return QWidget::event(event);
}
+void TMView::removeEntry(const TMEntry& e)
+{
+ if (KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("<html>Do you \
really want to remove this entry:<br/><i>%1</i><br/>from translation memory \
%2?</html>", e.target.string.toHtmlEscaped(), e.dbName), + \
i18nc("@title:window", "Translation Memory Entry Removal"))) { + RemoveJob* \
job = new RemoveJob(e); + connect(job, SIGNAL(done()), this, \
SLOT(slotNewEntryDisplayed())); + TM::threadPool()->start(job, REMOVE);
+ }
+}
+
void TMView::contextMenu(const QPoint& pos)
{
int block = *m_entryPositions.lowerBound(m_browser->cursorForPosition(pos).anchor());
@@ -568,14 +587,11 @@ void TMView::contextMenu(const QPoint& pos)
QAction* r = popup.exec(m_browser->mapToGlobal(pos));
if (!r)
return;
- if ((r->data().toInt() == Remove) &&
- KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("<html>Do you \
really want to remove this entry:<br/><i>%1</i><br/>from translation memory \
%2?</html>", e.target.string.toHtmlEscaped(), e.dbName),
- i18nc("@title:window", "Translation Memory Entry Removal"))) {
- RemoveJob* job = new RemoveJob(e);
- connect(job, &RemoveJob::done, this, \
QOverload<>::of(&TMView::slotNewEntryDisplayed));
- TM::threadPool()->start(job, REMOVE);
- } else if (r->data().toInt() == Open)
+ if (r->data().toInt() == Remove) {
+ removeEntry(e);
+ } else if (r->data().toInt() == Open) {
emit fileOpenRequested(e.file, e.source.string, e.ctxt);
+ }
}
/**
@@ -922,6 +938,15 @@ CatalogString TM::targetAdapted(const TMEntry& entry, const \
CatalogString& ref) return target;
}
+void TMView::slotRemoveSuggestion(int i)
+{
+ if (Q_UNLIKELY(i >= m_entries.size()))
+ return;
+
+ const TMEntry& e = m_entries.at(i);
+ removeEntry(e);
+}
+
void TMView::slotUseSuggestion(int i)
{
if (Q_UNLIKELY(i >= m_entries.size()))
diff --git a/src/tm/tmview.h b/src/tm/tmview.h
index 5598a06..b57497e 100644
--- a/src/tm/tmview.h
+++ b/src/tm/tmview.h
@@ -47,7 +47,7 @@ class TMView: public QDockWidget
{
Q_OBJECT
public:
- TMView(QWidget*, Catalog*, const QVector<QAction*>&);
+ TMView(QWidget*, Catalog*, const QVector<QAction*>&, const QVector<QAction*>&);
~TMView();
void dragEnterEvent(QDragEnterEvent* event);
@@ -69,6 +69,7 @@ public slots:
void slotSuggestionsCame(SelectJob*);
void slotUseSuggestion(int);
+ void slotRemoveSuggestion(int);
void slotFileLoaded(const QString& url);
void displayFromCache();
@@ -85,6 +86,7 @@ private slots:
void initLater();
void contextMenu(const QPoint & pos);
+ void removeEntry(const TMEntry & e);
private:
bool event(QEvent *event);
@@ -96,7 +98,8 @@ private:
DocPosition m_pos;
SelectJob* m_currentSelectJob;
- QVector<QAction*> m_actions;//need them to get shortcuts
+ QVector<QAction*> m_actions_insert;//need them to get insertion shortcuts
+ QVector<QAction*> m_actions_remove;//need them to get deletion shortcuts
QList<TMEntry> m_entries;
QMap<int, int> m_entryPositions;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic