mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Add word to history through context menu
This commit is contained in:
parent
5ceab47fb3
commit
ea442909ae
|
@ -950,6 +950,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
|
|||
QAction * lookupSelectionNewTab = 0;
|
||||
QAction * lookupSelectionNewTabGr = 0;
|
||||
QAction * maxDictionaryRefsAction = 0;
|
||||
QAction * addWordToHistoryAction = 0;
|
||||
|
||||
QUrl targetUrl( r.linkUrl() );
|
||||
Contexts contexts;
|
||||
|
@ -998,6 +999,11 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
|
|||
arg( ui.definition->selectedText() ),
|
||||
&menu );
|
||||
menu.addAction( lookupSelectionNewTab );
|
||||
|
||||
addWordToHistoryAction = new QAction( tr( "&Add \"%1\" to history" ).
|
||||
arg( ui.definition->selectedText() ),
|
||||
&menu );
|
||||
menu.addAction( addWordToHistoryAction );
|
||||
}
|
||||
|
||||
Instances::Group const * altGroup =
|
||||
|
@ -1097,6 +1103,9 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
|
|||
if ( result == lookupSelectionGr && groupComboBox )
|
||||
showDefinition( selectedText, groupComboBox->getCurrentGroup(), QString() );
|
||||
else
|
||||
if ( result == addWordToHistoryAction )
|
||||
emit forceAddWordToHistory( selectedText );
|
||||
else
|
||||
if ( !popupView && result == followLinkNewTab )
|
||||
emit openLinkInNewTab( targetUrl, ui.definition->url(), getCurrentArticle(), contexts );
|
||||
else
|
||||
|
|
|
@ -189,6 +189,9 @@ signals:
|
|||
/// id - the dictionary id of the active article.
|
||||
void activeArticleChanged ( QString const & id );
|
||||
|
||||
/// Signal to add word to history even if history is disabled
|
||||
void forceAddWordToHistory( const QString & word);
|
||||
|
||||
public slots:
|
||||
|
||||
void on_searchPrevious_clicked();
|
||||
|
|
|
@ -979,6 +979,9 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
|
|||
|
||||
connect( view, SIGNAL( showDictsPane( ) ), this, SLOT( showDictsPane( ) ) );
|
||||
|
||||
connect( view, SIGNAL( forceAddWordToHistory( const QString & ) ),
|
||||
this, SLOT( forceAddWordToHistory( const QString & ) ) );
|
||||
|
||||
int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
|
||||
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
|
||||
|
||||
|
@ -2863,3 +2866,35 @@ void MainWindow::focusWordList()
|
|||
if( ui.wordList->count() > 0 )
|
||||
ui.wordList->setFocus();
|
||||
}
|
||||
|
||||
void MainWindow::forceAddWordToHistory( const QString & word )
|
||||
{
|
||||
history.enableAdd( true );
|
||||
history.addItem( History::Item( 1, word.trimmed() ) );
|
||||
|
||||
if( showHistory )
|
||||
{
|
||||
int index = ui.wordList->currentRow();
|
||||
QListWidgetItem *item = ui.wordList->item( index );
|
||||
QString currentWord;
|
||||
if( item )
|
||||
currentWord = item->text();
|
||||
if( index < (int) history.getMaxSize() - 1 )
|
||||
index += 1;
|
||||
|
||||
fillWordListFromHistory();
|
||||
|
||||
if( index < 0 || index >= ui.wordList->count() || currentWord.compare( ui.wordList->item( index )->text() ) != 0 )
|
||||
index = 0;
|
||||
|
||||
if( index )
|
||||
disconnect( ui.wordList, SIGNAL( itemSelectionChanged() ),
|
||||
this, SLOT( wordListSelectionChanged() ) );
|
||||
ui.wordList->setCurrentRow( index, QItemSelectionModel::Select );
|
||||
if( index )
|
||||
connect( ui.wordList, SIGNAL( itemSelectionChanged() ),
|
||||
this, SLOT( wordListSelectionChanged() ) );
|
||||
}
|
||||
|
||||
history.enableAdd( cfg.preferences.storeHistory );
|
||||
}
|
||||
|
|
|
@ -330,6 +330,9 @@ private slots:
|
|||
void on_exportHistory_activated();
|
||||
void on_importHistory_activated();
|
||||
void focusWordList();
|
||||
|
||||
/// Add word to history even if history is disabled in options
|
||||
void forceAddWordToHistory( const QString & word);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue