in preview window if search line empty look for search terms
This commit is contained in:
parent
ad1e16bce0
commit
2174327a7e
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.20 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.21 2007-05-23 09:19:48 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
|
||||||
@ -301,12 +301,32 @@ bool myTextSplitCB::matchGroups()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *firstTermAnchorName = "FIRSTTERM";
|
// Setting searchable beacons in the text to walk the term list.
|
||||||
|
static const char *termAnchorNameBase = "FIRSTTERM";
|
||||||
|
string termAnchorName(int i)
|
||||||
|
{
|
||||||
|
char acname[sizeof(termAnchorNameBase) + 20];
|
||||||
|
sprintf(acname, "%s%d", termAnchorNameBase, i);
|
||||||
|
return string(acname);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
||||||
const char *firstTermBeacon = "\xe2\xa0\x91\xe2\x96\x9f\x20\x01\x9a";
|
// 0xcd8f is utf8 for unicode 034F COMBINING GRAPHEME JOINER
|
||||||
|
// Qt doesn't display it, but accepts to search for it.
|
||||||
|
const char *firstTermBeacon = "\xcd\x8f\xcd\x8f\xcd\x8f\xcd\x8f";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static string termBeacon(int i)
|
||||||
|
{
|
||||||
|
return string("<a name=\"") + termAnchorName(i) + "\">"
|
||||||
|
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
||||||
|
+ "<font color=\"white\">" + firstTermBeacon + "</font>"
|
||||||
|
#endif
|
||||||
|
+ "</a>";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Fix result text for display inside the gui text window.
|
// Fix result text for display inside the gui text window.
|
||||||
//
|
//
|
||||||
// To compute the term character positions in the output text, we used
|
// To compute the term character positions in the output text, we used
|
||||||
@ -318,7 +338,7 @@ const char *firstTermBeacon = "\xe2\xa0\x91\xe2\x96\x9f\x20\x01\x9a";
|
|||||||
// editor's find() function to position on it
|
// editor's find() function to position on it
|
||||||
bool plaintorich(const string& in, string& out,
|
bool plaintorich(const string& in, string& out,
|
||||||
const HiliteData& hdata,
|
const HiliteData& hdata,
|
||||||
bool noHeader, bool fft)
|
bool noHeader, bool)
|
||||||
{
|
{
|
||||||
Chrono chron;
|
Chrono chron;
|
||||||
out.erase();
|
out.erase();
|
||||||
@ -375,26 +395,21 @@ bool plaintorich(const string& in, string& out,
|
|||||||
Utf8Iter chariter(in);
|
Utf8Iter chariter(in);
|
||||||
// State variable used to limitate the number of consecutive empty lines
|
// State variable used to limitate the number of consecutive empty lines
|
||||||
int ateol = 0;
|
int ateol = 0;
|
||||||
// State variable to update the char pos only for the first of
|
|
||||||
// consecutive blank chars
|
// Stuff for numbered anchors at each term match
|
||||||
int atblank = 0;
|
int anchoridx = 1;
|
||||||
|
|
||||||
for (string::size_type pos = 0; pos != string::npos; pos = chariter++) {
|
for (string::size_type pos = 0; pos != string::npos; pos = chariter++) {
|
||||||
if ((pos & 0xfff) == 0) {
|
if ((pos & 0xfff) == 0) {
|
||||||
CancelCheck::instance().checkCancel();
|
CancelCheck::instance().checkCancel();
|
||||||
}
|
}
|
||||||
// If we still have terms positions, check (byte) position
|
|
||||||
|
// If we still have terms positions, check (byte) position. If
|
||||||
|
// we are at or after a term match, mark.
|
||||||
if (tPosIt != tboffsend) {
|
if (tPosIt != tboffsend) {
|
||||||
int ibyteidx = chariter.getBpos();
|
int ibyteidx = chariter.getBpos();
|
||||||
|
|
||||||
if (fft && ibyteidx == cb.m_firstTermBPos) {
|
|
||||||
out += string("<a name=\"") + firstTermAnchorName + "\"> "
|
|
||||||
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
|
||||||
+ "<font color=\"white\"> " + firstTermBeacon + " </font> "
|
|
||||||
#endif
|
|
||||||
+ "</a>";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ibyteidx == tPosIt->first) {
|
if (ibyteidx == tPosIt->first) {
|
||||||
|
out += termBeacon(anchoridx++);
|
||||||
out += "<termtag>";
|
out += "<termtag>";
|
||||||
} else if (ibyteidx == tPosIt->second) {
|
} else if (ibyteidx == tPosIt->second) {
|
||||||
// Output end tag, then skip all highlight areas that
|
// Output end tag, then skip all highlight areas that
|
||||||
@ -405,6 +420,7 @@ bool plaintorich(const string& in, string& out,
|
|||||||
tPosIt++;
|
tPosIt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(*chariter) {
|
switch(*chariter) {
|
||||||
case '\n':
|
case '\n':
|
||||||
if (ateol < 2) {
|
if (ateol < 2) {
|
||||||
@ -424,11 +440,8 @@ bool plaintorich(const string& in, string& out,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// We don't change the eol status for whitespace, want a real line
|
// We don't change the eol status for whitespace, want a real line
|
||||||
if (*chariter == ' ' || *chariter == '\t') {
|
if (!(*chariter == ' ' || *chariter == '\t')) {
|
||||||
atblank = 1;
|
|
||||||
} else {
|
|
||||||
ateol = 0;
|
ateol = 0;
|
||||||
atblank = 0;
|
|
||||||
}
|
}
|
||||||
chariter.appendchartostring(out);
|
chariter.appendchartostring(out);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _PLAINTORICH_H_INCLUDED_
|
#ifndef _PLAINTORICH_H_INCLUDED_
|
||||||
#define _PLAINTORICH_H_INCLUDED_
|
#define _PLAINTORICH_H_INCLUDED_
|
||||||
/* @(#$Id: plaintorich.h,v 1.12 2007-01-19 15:22:50 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: plaintorich.h,v 1.13 2007-05-23 09:19:48 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ extern bool plaintorich(const string &in, string &out,
|
|||||||
bool noHeader = false,
|
bool noHeader = false,
|
||||||
bool fft = false);
|
bool fft = false);
|
||||||
|
|
||||||
extern const char *firstTermAnchorName;
|
extern string termAnchorName(int i);
|
||||||
|
|
||||||
#define QT_SCROLL_TO_ANCHOR_BUG
|
#define QT_SCROLL_TO_ANCHOR_BUG
|
||||||
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
||||||
|
|||||||
@ -102,7 +102,7 @@
|
|||||||
<cstring>nextButton</cstring>
|
<cstring>nextButton</cstring>
|
||||||
</property>
|
</property>
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Next</string>
|
<string>&Next</string>
|
||||||
@ -116,7 +116,7 @@
|
|||||||
<cstring>prevButton</cstring>
|
<cstring>prevButton</cstring>
|
||||||
</property>
|
</property>
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Previous</string>
|
<string>&Previous</string>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.17 2007-02-19 18:15:14 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.18 2007-05-23 09:19:48 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
|
||||||
@ -159,7 +159,7 @@ bool Preview::eventFilter(QObject *target, QEvent *event)
|
|||||||
if (tw)
|
if (tw)
|
||||||
e = (QWidget *)tw->child("pvEdit");
|
e = (QWidget *)tw->child("pvEdit");
|
||||||
LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
|
LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
|
||||||
if (e && target == tw && keyEvent->key() == Qt::Key_Slash) {
|
if (e && target == e && keyEvent->key() == Qt::Key_Slash) {
|
||||||
searchTextLine->setFocus();
|
searchTextLine->setFocus();
|
||||||
dynSearchActive = true;
|
dynSearchActive = true;
|
||||||
return true;
|
return true;
|
||||||
@ -174,13 +174,13 @@ void Preview::searchTextLine_textChanged(const QString & text)
|
|||||||
LOGDEB1(("search line text changed. text: '%s'\n", text.ascii()));
|
LOGDEB1(("search line text changed. text: '%s'\n", text.ascii()));
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
dynSearchActive = false;
|
dynSearchActive = false;
|
||||||
nextButton->setEnabled(false);
|
// nextButton->setEnabled(false);
|
||||||
prevButton->setEnabled(false);
|
// prevButton->setEnabled(false);
|
||||||
clearPB->setEnabled(false);
|
clearPB->setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
dynSearchActive = true;
|
dynSearchActive = true;
|
||||||
nextButton->setEnabled(true);
|
// nextButton->setEnabled(true);
|
||||||
prevButton->setEnabled(true);
|
// prevButton->setEnabled(true);
|
||||||
clearPB->setEnabled(true);
|
clearPB->setEnabled(true);
|
||||||
doSearch(text, false, false);
|
doSearch(text, false, false);
|
||||||
}
|
}
|
||||||
@ -206,54 +206,55 @@ QTextEdit *Preview::getCurrentEditor()
|
|||||||
// current search, trying to advance and possibly wrapping around. If next is
|
// current search, trying to advance and possibly wrapping around. If next is
|
||||||
// false, the search string has been modified, we search for the new string,
|
// false, the search string has been modified, we search for the new string,
|
||||||
// starting from the current position
|
// starting from the current position
|
||||||
void Preview::doSearch(const QString &text, bool next, bool reverse,
|
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
||||||
bool wordOnly)
|
bool wordOnly)
|
||||||
{
|
{
|
||||||
LOGDEB1(("Preview::doSearch: [%s] next %d rev %d\n",
|
LOGDEB(("Preview::doSearch: [%s] next %d rev %d\n",
|
||||||
(const char *)text.utf8(), int(next), int(reverse)));
|
(const char *)_text.utf8(), int(next), int(reverse)));
|
||||||
if (text.isEmpty())
|
QString text = _text;
|
||||||
return;
|
if (text.isEmpty()) {
|
||||||
|
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
||||||
|
text = QString::fromUtf8(firstTermBeacon);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
QTextEdit *edit = getCurrentEditor();
|
QTextEdit *edit = getCurrentEditor();
|
||||||
if (edit == 0) {
|
if (edit == 0) {
|
||||||
// ??
|
// ??
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool matchCase = matchCheck->isChecked();
|
|
||||||
int mspara, msindex, mepara, meindex;
|
|
||||||
edit->getSelection(&mspara, &msindex, &mepara, &meindex);
|
|
||||||
if (mspara == -1)
|
|
||||||
mspara = msindex = mepara = meindex = 0;
|
|
||||||
|
|
||||||
if (next) {
|
bool matchCase = matchCheck->isChecked();
|
||||||
// We search again, starting from the current match
|
|
||||||
if (reverse) {
|
LOGDEB(("Preview::doSearch: find: case %d word %d fw %d\n",
|
||||||
// when searching backwards, have to move back one char
|
matchCase, wordOnly, !reverse));
|
||||||
if (msindex > 0)
|
|
||||||
msindex --;
|
// If the search text changed we need to reset the cursor position
|
||||||
else if (mspara > 0) {
|
// to the start of the previous match, else incremental search is
|
||||||
mspara --;
|
// going to look for the next occurrence instead of trying to
|
||||||
msindex = edit->paragraphLength(mspara);
|
// lenghten the current match
|
||||||
}
|
if (!next) {
|
||||||
} else {
|
int ps, is, pe, ie;
|
||||||
// Forward search: start from end of selection
|
edit->getSelection(&ps, &is, &pe, &ie);
|
||||||
mspara = mepara;
|
if (is > 0)
|
||||||
msindex = meindex;
|
is--;
|
||||||
LOGDEB1(("New para: %d index %d\n", mspara, msindex));
|
else if (ps > 0)
|
||||||
}
|
ps--;
|
||||||
|
LOGDEB(("Setting cursor to %d %d\n", ps, is));
|
||||||
|
edit->setCursorPosition(ps, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool found = edit->find(text, matchCase, wordOnly,
|
bool found = edit->find(text, matchCase, wordOnly, !reverse, 0, 0);
|
||||||
!reverse, &mspara, &msindex);
|
// If not found, try to wrap around.
|
||||||
LOGDEB(("Found at para: %d index %d\n", mspara, msindex));
|
if (!found && next) {
|
||||||
|
LOGDEB(("Preview::doSearch: wrapping around\n"));
|
||||||
if (!found && next && true) { // need a 'canwrap' test here
|
int mspara, msindex;
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
mspara = edit->paragraphs();
|
mspara = edit->paragraphs();
|
||||||
msindex = edit->paragraphLength(mspara);
|
msindex = edit->paragraphLength(mspara);
|
||||||
} else {
|
} else {
|
||||||
mspara = msindex = 0;
|
mspara = msindex = 0;
|
||||||
}
|
}
|
||||||
found = edit->find(text, matchCase, false, !reverse, &mspara, &msindex);
|
found = edit->find(text,matchCase, false, !reverse, &mspara, &msindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
@ -622,7 +623,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
|
|
||||||
// Create preview text: highlight search terms (if not too big):
|
// Create preview text: highlight search terms (if not too big):
|
||||||
QString richTxt;
|
QString richTxt;
|
||||||
bool highlightTerms = fdoc.text.length() < 1000 *1024;
|
bool highlightTerms = fdoc.text.length() < 2000 * 1024;
|
||||||
if (highlightTerms) {
|
if (highlightTerms) {
|
||||||
progress.setLabelText(tr("Creating preview text"));
|
progress.setLabelText(tr("Creating preview text"));
|
||||||
ToRichThread rthr(fdoc.text, m_hData, richTxt);
|
ToRichThread rthr(fdoc.text, m_hData, richTxt);
|
||||||
@ -657,7 +658,7 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
richTxt = fdoc.text.c_str();
|
richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load into editor
|
// Load into editor
|
||||||
@ -708,20 +709,18 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
canBeep = true;
|
canBeep = true;
|
||||||
doSearch(searchTextLine->text(), true, false);
|
doSearch(searchTextLine->text(), true, false);
|
||||||
} else {
|
} else {
|
||||||
QString aname = QString::fromUtf8(firstTermAnchorName);
|
QString aname = QString::fromUtf8(termAnchorName(1).c_str());
|
||||||
LOGDEB2(("Calling scrolltoanchor [%s]\n", (const char *)aname.utf8()));
|
LOGDEB2(("Calling scrolltoanchor [%s]\n", (const char *)aname.utf8()));
|
||||||
editor->scrollToAnchor(aname);
|
editor->scrollToAnchor(aname);
|
||||||
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
||||||
bool wasC = matchCheck->isChecked();
|
|
||||||
matchCheck->setChecked(false);
|
|
||||||
bool ocanbeep = canBeep;
|
bool ocanbeep = canBeep;
|
||||||
canBeep = false;
|
canBeep = false;
|
||||||
doSearch(QString::fromUtf8(firstTermBeacon), 0, false, false);
|
QString empty;
|
||||||
|
doSearch(empty, 0, false, false);
|
||||||
canBeep = ocanbeep;
|
canBeep = ocanbeep;
|
||||||
editor->del();
|
|
||||||
matchCheck->setChecked(wasC);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
editor->setFocus();
|
||||||
emit(previewExposed(m_searchId, docnum));
|
emit(previewExposed(m_searchId, docnum));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.9 2007-02-19 18:15:14 dockes Exp $ (C) 2006 J.F.Dockes */
|
/* @(#$Id: preview_w.h,v 1.10 2007-05-23 09:19:48 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
|
||||||
@ -39,8 +39,9 @@ class TabData {
|
|||||||
QWidget *w; // widget for setCurrent
|
QWidget *w; // widget for setCurrent
|
||||||
int docnum; // Index of doc in db search results.
|
int docnum; // Index of doc in db search results.
|
||||||
|
|
||||||
|
TabData(QWidget *wi)
|
||||||
TabData(QWidget *wi) : w(wi) {}
|
: w(wi), docnum(-1)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user