preview: dont search for anchors if we have none

This commit is contained in:
dockes 2007-07-20 14:43:21 +00:00
parent 3892cb1517
commit 7f5a9a720d
2 changed files with 14 additions and 6 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.25 2007-07-20 11:38:18 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.26 2007-07-20 14:43:21 dockes Exp $ (C) 2005 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -99,6 +99,7 @@ void Preview::init()
m_loading = false; m_loading = false;
currentChanged(pvTab->currentPage()); currentChanged(pvTab->currentPage());
m_justCreated = true; m_justCreated = true;
m_haveAnchors = false;
} }
void Preview::closeEvent(QCloseEvent *e) void Preview::closeEvent(QCloseEvent *e)
@ -233,6 +234,8 @@ void Preview::doSearch(const QString &_text, bool next, bool reverse,
} }
if (text.isEmpty()) { if (text.isEmpty()) {
if (m_haveAnchors == false)
return;
#ifdef QT_SCROLL_TO_ANCHOR_BUG #ifdef QT_SCROLL_TO_ANCHOR_BUG
text = QString::fromUtf8(firstTermBeacon); text = QString::fromUtf8(firstTermBeacon);
matchCase = false; matchCase = false;
@ -630,6 +633,8 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
LoadGuard guard(&m_loading); LoadGuard guard(&m_loading);
CancelCheck::instance().setCancel(false); CancelCheck::instance().setCancel(false);
m_haveAnchors = false;
Rcl::Doc doc = idoc; Rcl::Doc doc = idoc;
if (doc.meta["title"].empty()) if (doc.meta["title"].empty())
@ -740,9 +745,11 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
} }
int pos = richTxt.find(QString::fromUtf8(firstTermBeacon)); int pos = richTxt.find(QString::fromUtf8(firstTermBeacon));
bool hasAnchors = (pos != -1); m_haveAnchors = (pos != -1);
LOGDEB(("LoadFileInCurrentTab: rich: cancel %d txtln %d, hasAnchors %d (pos %d)\n", LOGDEB(("LoadFileInCurrentTab: rich: cancel %d txtln %d, hasAnchors %d "
CancelCheck::instance().cancelState(), richTxt.length(), hasAnchors, pos)); "(pos %d)\n",
CancelCheck::instance().cancelState(), richTxt.length(),
m_haveAnchors, pos));
// Load into editor // Load into editor
// Do it in several chunks // Do it in several chunks
@ -792,7 +799,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
m_canBeep = true; m_canBeep = true;
doSearch(searchTextLine->text(), true, false); doSearch(searchTextLine->text(), true, false);
} else { } else {
if (hasAnchors) { if (m_haveAnchors) {
QString aname = QString::fromUtf8(termAnchorName(1).c_str()); QString aname = QString::fromUtf8(termAnchorName(1).c_str());
LOGDEB2(("Call scrolltoanchor(%s)\n", (const char *)aname.utf8())); LOGDEB2(("Call scrolltoanchor(%s)\n", (const char *)aname.utf8()));
editor->scrollToAnchor(aname); editor->scrollToAnchor(aname);

View File

@ -1,6 +1,6 @@
#ifndef _PREVIEW_W_H_INCLUDED_ #ifndef _PREVIEW_W_H_INCLUDED_
#define _PREVIEW_W_H_INCLUDED_ #define _PREVIEW_W_H_INCLUDED_
/* @(#$Id: preview_w.h,v 1.14 2007-07-20 11:38:18 dockes Exp $ (C) 2006 J.F.Dockes */ /* @(#$Id: preview_w.h,v 1.15 2007-07-20 14:43:21 dockes Exp $ (C) 2006 J.F.Dockes */
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -113,6 +113,7 @@ private:
QWidget *m_currentW; QWidget *m_currentW;
HiliteData m_hData; HiliteData m_hData;
bool m_justCreated; // First tab create is different bool m_justCreated; // First tab create is different
bool m_haveAnchors; // Search terms are marked in text
void init(); void init();
virtual void setCurTabProps(const string& fn, const Rcl::Doc& doc, virtual void setCurTabProps(const string& fn, const Rcl::Doc& doc,