diff --git a/src/editortab.cpp b/src/editortab.cpp --- a/src/editortab.cpp +++ b/src/editortab.cpp @@ -296,7 +296,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, @@ -317,12 +318,21 @@ 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; + 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",QString::number(i+1))); + tmactions_remove[i]=tmaction; } #ifndef Q_OS_DARWIN - if (systemLang==QLocale::Czech) ac->setDefaultShortcuts(tmactions[0], QList()<setDefaultShortcuts(tmactions_insert[0], QList()<setDefaultShortcuts(tmactions_remove[0], QList()<addAction( QStringLiteral("showtmqueryview_action"), _tmView->toggleViewAction() ); connect (_tmView,SIGNAL(refreshRequested()),m_view,SLOT(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 @@ -121,6 +121,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 @@ -46,7 +46,7 @@ { Q_OBJECT public: - TMView(QWidget*,Catalog*,const QVector&); + TMView(QWidget*,Catalog*,const QVector&,const QVector&); ~TMView(); void dragEnterEvent(QDragEnterEvent* event); @@ -64,6 +64,7 @@ void slotSuggestionsCame(SelectJob*); void slotUseSuggestion(int); + void slotRemoveSuggestion(int); void slotFileLoaded(const QString& url); void displayFromCache(); @@ -80,6 +81,7 @@ void initLater(); void contextMenu(const QPoint & pos); + void removeEntry(const TMEntry & e); private: bool event(QEvent *event); @@ -91,7 +93,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 @@ -142,12 +142,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) @@ -178,14 +179,24 @@ { 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),SIGNAL(triggered()),signalMapper,SLOT(map())); - signalMapper->setMapping(m_actions.at(i), i); + connect(m_actions_insert.at(i),SIGNAL(triggered()),signalMapper_insert,SLOT(map())); + signalMapper_insert->setMapping(m_actions_insert.at(i), i); } - connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(slotUseSuggestion(int))); + + i=m_actions_remove.size(); + while(--i>=0) + { + connect(m_actions_remove.at(i),SIGNAL(triggered()),signalMapper_remove,SLOT(map())); + signalMapper_remove->setMapping(m_actions_remove.at(i), i); + } + + connect(signalMapper_insert, SIGNAL(mapped(int)), this, SLOT(slotUseSuggestion(int))); + connect(signalMapper_remove, SIGNAL(mapped(int)), this, SLOT(slotRemoveSuggestion(int))); setToolTip(i18nc("@info:tooltip","Double-click any word to insert it into translation")); @@ -515,10 +526,10 @@ //str.replace('&',"&"); TODO check html+=QLatin1String("
"); - if (Q_LIKELY( isetStatusTip(entry.target.string); - html+=QStringLiteral("[%1] ").arg(m_actions.at(i)->shortcut().toString(QKeySequence::NativeText)); + 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("[ - ] "); @@ -581,6 +592,17 @@ 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()); @@ -597,13 +619,9 @@ 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"))) + if (r->data().toInt()==Remove) { - RemoveJob* job=new RemoveJob(e); - connect(job,SIGNAL(done()),this,SLOT(slotNewEntryDisplayed())); - TM::threadPool()->start(job, REMOVE); + removeEntry(e); } else if (r->data().toInt()==Open) emit fileOpenRequested(e.file, e.source.string, e.ctxt); @@ -976,6 +994,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() ))