diff --git a/mainwindow.cc b/mainwindow.cc index 34706c9f..b5980f7c 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -959,7 +959,7 @@ void MainWindow::updateSearchPaneAndBar( bool searchInDock ) updateGroupList(); applyWordsZoomLevel(); - setTranslateBoxTextAndKeepSuffix( text, DisablePopup ); + setTranslateBoxTextAndKeepSuffix( text, WildcardsAreAlreadyEscaped, DisablePopup ); focusTranslateLine(); } @@ -979,7 +979,7 @@ void MainWindow::mousePressEvent( QMouseEvent *event) QString str = QApplication::clipboard()->text(subtype, QClipboard::Selection); - setTranslateBoxTextAndClearSuffix( Folding::escapeWildcardSymbols( str ), NoPopupChange ); + setTranslateBoxTextAndClearSuffix( str, EscapeWildcards, NoPopupChange ); QKeyEvent ev(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); @@ -2350,17 +2350,22 @@ void MainWindow::respondToTranslationRequest( Config::InputPhrase const & phrase } } -void MainWindow::setTranslateBoxTextAndKeepSuffix( QString const & text, TranslateBoxPopup popupAction ) +void MainWindow::setTranslateBoxTextAndKeepSuffix( QString text, WildcardPolicy wildcardPolicy, + TranslateBoxPopup popupAction ) { + if( wildcardPolicy == EscapeWildcards ) + text = Folding::escapeWildcardSymbols( text ); + if( popupAction == NoPopupChange || cfg.preferences.searchInDock ) translateLine->setText( text ); else translateBox->setText( text, popupAction == EnablePopup ); } -void MainWindow::setTranslateBoxTextAndClearSuffix( QString const & text, TranslateBoxPopup popupAction ) +void MainWindow::setTranslateBoxTextAndClearSuffix( QString const & text, WildcardPolicy wildcardPolicy, + TranslateBoxPopup popupAction ) { - setTranslateBoxTextAndKeepSuffix( text, popupAction ); + setTranslateBoxTextAndKeepSuffix( text, wildcardPolicy, popupAction ); translateBoxSuffix = QString(); } @@ -2753,7 +2758,8 @@ void MainWindow::typingEvent( QString const & t ) if( translateLine->isEnabled() ) { translateLine->setFocus(); - setTranslateBoxTextAndClearSuffix( t, EnablePopup ); + // Escaping the typed-in characters is the user's responsibility. + setTranslateBoxTextAndClearSuffix( t, WildcardsAreAlreadyEscaped, EnablePopup ); translateLine->setCursorPosition( t.size() ); } } @@ -2771,7 +2777,7 @@ void MainWindow::showHistoryItem( QString const & word ) history.enableAdd( false ); - setTranslateBoxTextAndClearSuffix( Folding::escapeWildcardSymbols( word ), DisablePopup ); + setTranslateBoxTextAndClearSuffix( word, EscapeWildcards, DisablePopup ); showTranslationFor( word ); history.enableAdd( cfg.preferences.storeHistory ); @@ -3891,7 +3897,7 @@ ArticleView * MainWindow::getCurrentArticleView() void MainWindow::phraseReceived( Config::InputPhrase const & phrase ) { toggleMainWindow( true ); - setTranslateBoxTextAndKeepSuffix( Folding::escapeWildcardSymbols( phrase.phrase ), NoPopupChange ); + setTranslateBoxTextAndKeepSuffix( phrase.phrase, EscapeWildcards, NoPopupChange ); translateBoxSuffix = phrase.punctuationSuffix; respondToTranslationRequest( phrase, false ); } @@ -3904,7 +3910,7 @@ void MainWindow::wordReceived( const QString & word) void MainWindow::headwordReceived( const QString & word, const QString & ID ) { toggleMainWindow( true ); - setTranslateBoxTextAndClearSuffix( Folding::escapeWildcardSymbols( word ), NoPopupChange ); + setTranslateBoxTextAndClearSuffix( word, EscapeWildcards, NoPopupChange ); respondToTranslationRequest( Config::InputPhrase::fromPhrase( word ), false, ArticleView::scrollToFromDictionaryId( ID ) ); } @@ -4544,7 +4550,7 @@ void MainWindow::foundDictsContextMenuRequested( const QPoint &pos ) void MainWindow::sendWordToInputLine( const QString & word ) { - setTranslateBoxTextAndClearSuffix( Folding::escapeWildcardSymbols( word ), NoPopupChange ); + setTranslateBoxTextAndClearSuffix( word, EscapeWildcards, NoPopupChange ); } void MainWindow::storeResourceSavePath( const QString & newPath ) @@ -4847,7 +4853,7 @@ void MainWindow::headwordFromFavorites( QString const & headword, } // Show headword without lost of focus on Favorites tree - setTranslateBoxTextAndClearSuffix( Folding::escapeWildcardSymbols( headword ), DisablePopup ); + setTranslateBoxTextAndClearSuffix( headword, EscapeWildcards, DisablePopup ); showTranslationFor(headword ); } diff --git a/mainwindow.hh b/mainwindow.hh index 2b2806c4..87cd959d 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -265,9 +265,12 @@ private: void updateSuggestionList(); void updateSuggestionList( QString const & text ); + enum WildcardPolicy { EscapeWildcards, WildcardsAreAlreadyEscaped }; enum TranslateBoxPopup { NoPopupChange, EnablePopup, DisablePopup }; - void setTranslateBoxTextAndKeepSuffix( QString const & text, TranslateBoxPopup popupAction ); - void setTranslateBoxTextAndClearSuffix( QString const & text, TranslateBoxPopup popupAction ); + void setTranslateBoxTextAndKeepSuffix( QString text, WildcardPolicy wildcardPolicy, + TranslateBoxPopup popupAction ); + void setTranslateBoxTextAndClearSuffix( QString const & text, WildcardPolicy wildcardPolicy, + TranslateBoxPopup popupAction ); private slots: