From 7669316bcdec82fce8e85725c05410a239a57df5 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Mon, 8 Jul 2024 17:51:51 +0800 Subject: [PATCH] opt: do not show dictionary menu when set the dictionary count=0 (#1652) * opt: do not show dictionary menu when set the dictionary count=0 * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/ui/articleview.cc | 48 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 8ad840e6..048fcc5a 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -1610,32 +1610,34 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) unsigned refsAdded = 0; bool maxDictionaryRefsReached = false; - for ( QStringList::const_iterator i = ids.constBegin(); i != ids.constEnd(); ++i, ++refsAdded ) { - // Find this dictionary + if ( cfg.preferences.maxDictionaryRefsInContextMenu > 0 ) { + for ( QStringList::const_iterator i = ids.constBegin(); i != ids.constEnd(); ++i, ++refsAdded ) { + // Find this dictionary - auto dictionary = dictionaryGroup->getDictionaryById( i->toUtf8().data() ); - if ( dictionary ) { - QAction * action = nullptr; - if ( refsAdded == cfg.preferences.maxDictionaryRefsInContextMenu ) { - // Enough! Or the menu would become too large. - maxDictionaryRefsAction = new QAction( ".........", &menu ); - action = maxDictionaryRefsAction; - maxDictionaryRefsReached = true; - } - else { - action = new QAction( dictionary->getIcon(), QString::fromUtf8( dictionary->getName().c_str() ), &menu ); - // Force icons in menu on all platforms, - // since without them it will be much harder - // to find things. - action->setIconVisibleInMenu( true ); - } - menu.addAction( action ); + auto dictionary = dictionaryGroup->getDictionaryById( i->toUtf8().data() ); + if ( dictionary ) { + QAction * action = nullptr; + if ( refsAdded == cfg.preferences.maxDictionaryRefsInContextMenu ) { + // Enough! Or the menu would become too large. + maxDictionaryRefsAction = new QAction( ".........", &menu ); + action = maxDictionaryRefsAction; + maxDictionaryRefsReached = true; + } + else { + action = new QAction( dictionary->getIcon(), QString::fromUtf8( dictionary->getName().c_str() ), &menu ); + // Force icons in menu on all platforms, + // since without them it will be much harder + // to find things. + action->setIconVisibleInMenu( true ); + } + menu.addAction( action ); - tableOfContents[ action ] = *i; + tableOfContents[ action ] = *i; + } + + if ( maxDictionaryRefsReached ) + break; } - - if ( maxDictionaryRefsReached ) - break; } menu.addSeparator();