Commit 7b7fef0b authored by Albert Astals Cid's avatar Albert Astals Cid

Move the messagebox about continuing search from core to ui

parent e759c942
......@@ -168,7 +168,7 @@ void DocumentItem::searchText(const QString &text)
m_document->cancelSearch();
m_document->resetSearch(PAGEVIEW_SEARCH_ID);
m_document->searchText(PAGEVIEW_SEARCH_ID, text, 1, Qt::CaseInsensitive,
Okular::Document::AllDocument, true, QColor(100,100,200,40), true);
Okular::Document::AllDocument, true, QColor(100,100,200,40));
if (!m_searchInProgress) {
m_searchInProgress = true;
......
......@@ -124,9 +124,9 @@ struct RunningSearch
Document::SearchType cachedType;
Qt::CaseSensitivity cachedCaseSensitivity;
bool cachedViewportMove : 1;
bool cachedNoDialogs : 1;
bool isCurrentlySearching : 1;
QColor cachedColor;
int pagesDone;
};
#define foreachObserver( cmd ) {\
......@@ -1656,16 +1656,16 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa
if ( !searchStruct->match )
{
const int pageCount = m_pagesVector.count();
if (searchStruct->pagesDone < pageCount)
if (search->pagesDone < pageCount)
{
doContinue = true;
if ( searchStruct->currentPage >= pageCount || searchStruct->currentPage < 0 )
{
const QString question = forward ? i18n("End of document reached.\nContinue from the beginning?") : i18n("Beginning of document reached.\nContinue from the bottom?");
if ( search->cachedNoDialogs || KMessageBox::questionYesNo(m_widget, question, QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::Yes )
searchStruct->currentPage = forward ? 0 : pageCount - 1;
else
doContinue = false;
doContinue = false;
search->isCurrentlySearching = false;
search->continueOnPage = forward ? 0 : pageCount - 1;
search->continueOnMatch = RegularAreaRect();
emit m_parent->searchFinished ( searchStruct->searchID, Document::EndOfDocumentReached );
}
}
}
......@@ -1684,11 +1684,11 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa
{
if (forward) searchStruct->currentPage++;
else searchStruct->currentPage--;
searchStruct->pagesDone++;
search->pagesDone++;
}
else
{
searchStruct->pagesDone = 1;
search->pagesDone = 1;
}
// Both of the previous if branches need to call doContinueDirectionMatchSearch
......@@ -3276,7 +3276,7 @@ void Document::setNextDocumentDestination( const QString &namedDestination )
}
void Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity,
SearchType type, bool moveViewport, const QColor & color, bool noDialogs )
SearchType type, bool moveViewport, const QColor & color )
{
d->m_searchCancelled = false;
......@@ -3303,7 +3303,6 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q
s->cachedType = type;
s->cachedCaseSensitivity = caseSensitivity;
s->cachedViewportMove = moveViewport;
s->cachedNoDialogs = noDialogs;
s->cachedColor = color;
s->isCurrentlySearching = true;
......@@ -3355,12 +3354,13 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q
}
}
s->pagesDone = pagesDone;
DoContinueDirectionMatchSearchStruct *searchStruct = new DoContinueDirectionMatchSearchStruct();
searchStruct->pagesToNotify = pagesToNotify;
searchStruct->match = match;
searchStruct->currentPage = currentPage;
searchStruct->searchID = searchID;
searchStruct->pagesDone = pagesDone;
QMetaObject::invokeMethod(this, "doContinueDirectionMatchSearch", Qt::QueuedConnection, Q_ARG(void *, searchStruct));
}
......@@ -3389,8 +3389,7 @@ void Document::continueSearch( int searchID )
RunningSearch * p = *it;
if ( !p->isCurrentlySearching )
searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity,
p->cachedType, p->cachedViewportMove, p->cachedColor,
p->cachedNoDialogs );
p->cachedType, p->cachedViewportMove, p->cachedColor );
}
void Document::continueSearch( int searchID, SearchType type )
......@@ -3407,8 +3406,7 @@ void Document::continueSearch( int searchID, SearchType type )
RunningSearch * p = *it;
if ( !p->isCurrentlySearching )
searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity,
type, p->cachedViewportMove, p->cachedColor,
p->cachedNoDialogs );
type, p->cachedViewportMove, p->cachedColor );
}
void Document::resetSearch( int searchID )
......
......@@ -487,9 +487,10 @@ class OKULAR_EXPORT Document : public QObject
*/
enum SearchStatus
{
MatchFound, ///< Any match was found
NoMatchFound, ///< No match was found
SearchCancelled ///< The search was cancelled
MatchFound, ///< Any match was found
NoMatchFound, ///< No match was found
SearchCancelled, ///< The search was cancelled
EndOfDocumentReached ///< The end of document was reached without any match @since 0.20 (KDE 4.14)
};
/**
......@@ -501,10 +502,9 @@ class OKULAR_EXPORT Document : public QObject
* @param type The type of the search. @ref SearchType
* @param moveViewport Whether the viewport shall be moved to the position of the matches.
* @param color The highlighting color of the matches.
* @param noDialogs Whether a search dialog shall be shown.
*/
void searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity,
SearchType type, bool moveViewport, const QColor & color, bool noDialogs = false );
SearchType type, bool moveViewport, const QColor & color );
/**
* Continues the search for the given @p searchID.
......
......@@ -71,7 +71,6 @@ struct DoContinueDirectionMatchSearchStruct
RegularAreaRect *match;
int currentPage;
int searchID;
int pagesDone;
};
class DocumentPrivate
......
......@@ -177,7 +177,7 @@ void SearchTest::test311232()
d.openDocument(testFile, KUrl(), mime);
const int searchId = 0;
d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor(), true);
d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor());
QTime t;
t.start();
while (spy.count() != 1 && t.elapsed() < 500)
......
......@@ -20,6 +20,8 @@
#include <kcolorscheme.h>
#include <kpixmapsequence.h>
#include <kpixmapsequencewidget.h>
#include <kmessagebox.h>
#include <klocalizedstring.h>
SearchLineEdit::SearchLineEdit( QWidget * parent, Okular::Document * document )
: KLineEdit( parent ), m_document( document ), m_minLength( 0 ),
......@@ -250,6 +252,15 @@ void SearchLineEdit::searchFinished( int id, Okular::Document::SearchStatus endS
setPalette( pal );
}
if ( endStatus == Okular::Document::EndOfDocumentReached ) {
const bool forward = m_searchType == Okular::Document::NextMatch;
const QString question = forward ? i18n("End of document reached.\nContinue from the beginning?") : i18n("Beginning of document reached.\nContinue from the bottom?");
if ( KMessageBox::questionYesNo(window(), question, QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::Yes ) {
m_document->continueSearch( m_id, m_searchType );
return;
}
}
m_searchRunning = false;
emit searchStopped();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment