diff --git a/src/editortab.cpp b/src/editortab.cpp --- a/src/editortab.cpp +++ b/src/editortab.cpp @@ -294,7 +294,8 @@ //action->setShortcut(Qt::CTRL+glist[i]); action->setText(i18nc("@action:inmenu", "Add a note")); - QVector tmactions(TM_SHORTCUTS); + QVector tmactions_insert(TM_SHORTCUTS); + QVector tmactions_remove(TM_SHORTCUTS); Qt::Key tmlist[TM_SHORTCUTS] = { Qt::Key_1, Qt::Key_2, @@ -312,13 +313,21 @@ // 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(Qt::CTRL + tmlist[0]) << QKeySequence(Qt::CTRL + Qt::Key_Plus)); + if (systemLang == QLocale::Czech) { + ac->setDefaultShortcuts(tmactions_insert[0], QList() << QKeySequence(Qt::CTRL + tmlist[0]) << QKeySequence(Qt::CTRL + Qt::Key_Plus)); + ac->setDefaultShortcuts(tmactions_remove[0], QList() << 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 --- a/src/editorui.rc +++ b/src/editorui.rc @@ -1,5 +1,5 @@ - + &File @@ -122,6 +122,20 @@ + + + + + + + + + + + + + + Alternative Translations diff --git a/src/tm/tmview.h b/src/tm/tmview.h --- a/src/tm/tmview.h +++ b/src/tm/tmview.h @@ -47,7 +47,7 @@ { Q_OBJECT public: - TMView(QWidget*, Catalog*, const QVector&); + TMView(QWidget*, Catalog*, const QVector&, const QVector&); ~TMView(); void dragEnterEvent(QDragEnterEvent* event); @@ -69,6 +69,7 @@ void slotSuggestionsCame(SelectJob*); void slotUseSuggestion(int); + void slotRemoveSuggestion(int); void slotFileLoaded(const QString& url); void displayFromCache(); @@ -85,6 +86,7 @@ void initLater(); void contextMenu(const QPoint & pos); + void removeEntry(const TMEntry & e); private: bool event(QEvent *event); @@ -96,7 +98,8 @@ DocPosition m_pos; SelectJob* m_currentSelectJob; - QVector m_actions;//need them to get shortcuts + QVector m_actions_insert;//need them to get insertion shortcuts + QVector m_actions_remove;//need them to get deletion shortcuts QList m_entries; QMap m_entryPositions; diff --git a/src/tm/tmview.cpp b/src/tm/tmview.cpp --- a/src/tm/tmview.cpp +++ b/src/tm/tmview.cpp @@ -131,12 +131,13 @@ } -TMView::TMView(QWidget* parent, Catalog* catalog, const QVector& actions) +TMView::TMView(QWidget* parent, Catalog* catalog, const QVector& actions_insert, const QVector& 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 @@ { 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::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::of(&QSignalMapper::mapped), this, &TMView::slotUseSuggestion); + connect(signalMapper_remove, QOverload::of(&QSignalMapper::mapped), this, &TMView::slotRemoveSuggestion); setToolTip(i18nc("@info:tooltip", "Double-click any word to insert it into translation")); @@ -490,9 +499,9 @@ //str.replace('&',"&"); TODO check html += QLatin1String("
"); - 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 @@ return QWidget::event(event); } +void TMView::removeEntry(const TMEntry& e) +{ + if (KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("Do you really want to remove this entry:
%1
from translation memory %2?", 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 @@ QAction* r = popup.exec(m_browser->mapToGlobal(pos)); if (!r) return; - if ((r->data().toInt() == Remove) && - KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("Do you really want to remove this entry:
%1
from translation memory %2?", 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 @@ 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()))