better handle preview close during load
This commit is contained in:
parent
68bc385137
commit
e527642485
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.22 2007-06-20 13:15:57 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.23 2007-07-13 06:31:30 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
|
||||||
@ -100,12 +100,14 @@ void Preview::init()
|
|||||||
currentChanged(pvTab->currentPage());
|
currentChanged(pvTab->currentPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preview::destroy()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Preview::closeEvent(QCloseEvent *e)
|
void Preview::closeEvent(QCloseEvent *e)
|
||||||
{
|
{
|
||||||
|
LOGDEB(("Preview::closeEvent. m_loading %d\n", m_loading));
|
||||||
|
if (m_loading) {
|
||||||
|
CancelCheck::instance().setCancel();
|
||||||
|
e->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
prefs.pvwidth = width();
|
prefs.pvwidth = width();
|
||||||
prefs.pvheight = height();
|
prefs.pvheight = height();
|
||||||
emit previewExposed(m_searchId, -1);
|
emit previewExposed(m_searchId, -1);
|
||||||
@ -217,29 +219,32 @@ QTextEdit *Preview::getCurrentEditor()
|
|||||||
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
||||||
bool wordOnly)
|
bool wordOnly)
|
||||||
{
|
{
|
||||||
LOGDEB(("Preview::doSearch: [%s] next %d rev %d\n",
|
LOGDEB(("Preview::doSearch: text [%s] txtlen %d next %d rev %d word %d\n",
|
||||||
(const char *)_text.utf8(), int(next), int(reverse)));
|
(const char *)_text.utf8(), _text.length(), int(next),
|
||||||
|
int(reverse), int(wordOnly)));
|
||||||
QString text = _text;
|
QString text = _text;
|
||||||
if (text.isEmpty()) {
|
|
||||||
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
bool matchCase = matchCheck->isChecked();
|
||||||
text = QString::fromUtf8(firstTermBeacon);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
QTextEdit *edit = getCurrentEditor();
|
QTextEdit *edit = getCurrentEditor();
|
||||||
if (edit == 0) {
|
if (edit == 0) {
|
||||||
// ??
|
// ??
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matchCase = matchCheck->isChecked();
|
if (text.isEmpty()) {
|
||||||
|
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
||||||
|
text = QString::fromUtf8(firstTermBeacon);
|
||||||
|
matchCase = false;
|
||||||
|
#else
|
||||||
|
#error "Cycling without beacons needs coding"
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
LOGDEB(("Preview::doSearch: find: case %d word %d fw %d\n",
|
// If next is false, the user added characters to the current
|
||||||
matchCase, wordOnly, !reverse));
|
// search string. We need to reset the cursor position to the
|
||||||
|
// start of the previous match, else incremental search is going
|
||||||
// If the search text changed we need to reset the cursor position
|
// to look for the next occurrence instead of trying to lenghten
|
||||||
// to the start of the previous match, else incremental search is
|
// the current match
|
||||||
// going to look for the next occurrence instead of trying to
|
|
||||||
// lenghten the current match
|
|
||||||
if (!next) {
|
if (!next) {
|
||||||
int ps, is, pe, ie;
|
int ps, is, pe, ie;
|
||||||
edit->getSelection(&ps, &is, &pe, &ie);
|
edit->getSelection(&ps, &is, &pe, &ie);
|
||||||
@ -247,11 +252,13 @@ void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
|||||||
is--;
|
is--;
|
||||||
else if (ps > 0)
|
else if (ps > 0)
|
||||||
ps--;
|
ps--;
|
||||||
LOGDEB(("Setting cursor to %d %d\n", ps, is));
|
LOGDEB(("Preview::doSearch: setting cursor to %d %d\n", ps, is));
|
||||||
edit->setCursorPosition(ps, is);
|
edit->setCursorPosition(ps, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOGDEB(("Preview::doSearch: first find call\n"));
|
||||||
bool found = edit->find(text, matchCase, wordOnly, !reverse, 0, 0);
|
bool found = edit->find(text, matchCase, wordOnly, !reverse, 0, 0);
|
||||||
|
LOGDEB(("Preview::doSearch: first find call return\n"));
|
||||||
// If not found, try to wrap around.
|
// If not found, try to wrap around.
|
||||||
if (!found && next) {
|
if (!found && next) {
|
||||||
LOGDEB(("Preview::doSearch: wrapping around\n"));
|
LOGDEB(("Preview::doSearch: wrapping around\n"));
|
||||||
@ -262,7 +269,9 @@ void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
|||||||
} else {
|
} else {
|
||||||
mspara = msindex = 0;
|
mspara = msindex = 0;
|
||||||
}
|
}
|
||||||
|
LOGDEB(("Preview::doSearch: 2nd find call\n"));
|
||||||
found = edit->find(text,matchCase, false, !reverse, &mspara, &msindex);
|
found = edit->find(text,matchCase, false, !reverse, &mspara, &msindex);
|
||||||
|
LOGDEB(("Preview::doSearch: 2nd find call return\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
@ -272,15 +281,14 @@ void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
|||||||
QApplication::beep();
|
QApplication::beep();
|
||||||
canBeep = false;
|
canBeep = false;
|
||||||
}
|
}
|
||||||
|
LOGDEB(("Preview::doSearch: return\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Preview::nextPressed()
|
void Preview::nextPressed()
|
||||||
{
|
{
|
||||||
doSearch(searchTextLine->text(), true, false);
|
doSearch(searchTextLine->text(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Preview::prevPressed()
|
void Preview::prevPressed()
|
||||||
{
|
{
|
||||||
doSearch(searchTextLine->text(), true, true);
|
doSearch(searchTextLine->text(), true, true);
|
||||||
@ -362,8 +370,11 @@ void Preview::textDoubleClicked(int, int)
|
|||||||
|
|
||||||
void Preview::closeCurrentTab()
|
void Preview::closeCurrentTab()
|
||||||
{
|
{
|
||||||
if (m_loading)
|
LOGDEB(("Preview::closeCurrentTab: m_loading %d\n", m_loading));
|
||||||
|
if (m_loading) {
|
||||||
|
CancelCheck::instance().setCancel();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (pvTab->count() > 1) {
|
if (pvTab->count() > 1) {
|
||||||
QWidget *tw = pvTab->currentPage();
|
QWidget *tw = pvTab->currentPage();
|
||||||
if (!tw)
|
if (!tw)
|
||||||
@ -595,7 +606,7 @@ class LoadGuard {
|
|||||||
bool *m_bp;
|
bool *m_bp;
|
||||||
public:
|
public:
|
||||||
LoadGuard(bool *bp) {m_bp = bp ; *m_bp = true;}
|
LoadGuard(bool *bp) {m_bp = bp ; *m_bp = true;}
|
||||||
~LoadGuard() {*m_bp = false;}
|
~LoadGuard() {*m_bp = false; CancelCheck::instance().setCancel(false);}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
||||||
@ -607,9 +618,9 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
LoadGuard guard(&m_loading);
|
LoadGuard guard(&m_loading);
|
||||||
|
CancelCheck::instance().setCancel(false);
|
||||||
|
|
||||||
Rcl::Doc doc = idoc;
|
Rcl::Doc doc = idoc;
|
||||||
bool cancel = false;
|
|
||||||
|
|
||||||
if (doc.meta["title"].empty())
|
if (doc.meta["title"].empty())
|
||||||
doc.meta["title"] = path_getsimple(doc.url);
|
doc.meta["title"] = path_getsimple(doc.url);
|
||||||
@ -650,12 +661,16 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
if (progress.wasCanceled()) {
|
if (progress.wasCanceled()) {
|
||||||
CancelCheck::instance().setCancel();
|
CancelCheck::instance().setCancel();
|
||||||
cancel = true;
|
|
||||||
}
|
}
|
||||||
if (prog >= 5)
|
if (prog >= 5)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
if (cancel)
|
|
||||||
|
LOGDEB(("LoadFileInCurrentTab: after file load: cancel %d status %d"
|
||||||
|
" text length %d\n",
|
||||||
|
CancelCheck::instance().cancelState(), status, fdoc.text.length()));
|
||||||
|
|
||||||
|
if (CancelCheck::instance().cancelState())
|
||||||
return false;
|
return false;
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
QString explain;
|
QString explain;
|
||||||
@ -694,12 +709,13 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
if (progress.wasCanceled()) {
|
if (progress.wasCanceled()) {
|
||||||
CancelCheck::instance().setCancel();
|
CancelCheck::instance().setCancel();
|
||||||
cancel = true;
|
|
||||||
}
|
}
|
||||||
if (prog >= 5)
|
if (prog >= 5)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
if (cancel) {
|
|
||||||
|
// Conversion to rich text done
|
||||||
|
if (CancelCheck::instance().cancelState()) {
|
||||||
if (richTxt.length() == 0) {
|
if (richTxt.length() == 0) {
|
||||||
// We cant call closeCurrentTab here as it might delete
|
// We cant call closeCurrentTab here as it might delete
|
||||||
// the object which would be a nasty surprise to our
|
// the object which would be a nasty surprise to our
|
||||||
@ -713,6 +729,11 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
|
richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pos = richTxt.find(QString::fromUtf8(firstTermBeacon));
|
||||||
|
bool hasAnchors = (pos != -1);
|
||||||
|
LOGDEB(("LoadFileInCurrentTab: rich: cancel %d txtln %d, hasAnchors %d (pos %d)\n",
|
||||||
|
CancelCheck::instance().cancelState(), richTxt.length(), hasAnchors, pos));
|
||||||
|
|
||||||
// Load into editor
|
// Load into editor
|
||||||
// Do it in several chunks
|
// Do it in several chunks
|
||||||
QTextEdit *editor = getCurrentEditor();
|
QTextEdit *editor = getCurrentEditor();
|
||||||
@ -750,32 +771,40 @@ bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (progress.wasCanceled()) {
|
if (progress.wasCanceled()) {
|
||||||
cancel = true;
|
|
||||||
editor->append("<b>Cancelled !</b>");
|
editor->append("<b>Cancelled !</b>");
|
||||||
LOGDEB(("Cancelled\n"));
|
LOGDEB(("LoadFileInCurrentTab: cancelled in editor load\n"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
progress.close();
|
||||||
|
|
||||||
if (searchTextLine->text().length() != 0) {
|
if (searchTextLine->text().length() != 0) {
|
||||||
canBeep = true;
|
canBeep = true;
|
||||||
doSearch(searchTextLine->text(), true, false);
|
doSearch(searchTextLine->text(), true, false);
|
||||||
} else {
|
} else {
|
||||||
QString aname = QString::fromUtf8(termAnchorName(1).c_str());
|
if (hasAnchors) {
|
||||||
LOGDEB2(("Calling scrolltoanchor [%s]\n", (const char *)aname.utf8()));
|
QString aname = QString::fromUtf8(termAnchorName(1).c_str());
|
||||||
editor->scrollToAnchor(aname);
|
LOGDEB2(("Call scrolltoanchor(%s)\n", (const char *)aname.utf8()));
|
||||||
|
editor->scrollToAnchor(aname);
|
||||||
|
// The q3textedit version of find is slow to the point of being
|
||||||
|
// unusable (plus it does not always work)
|
||||||
|
#if (QT_VERSION < 0x040000)
|
||||||
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
||||||
bool ocanbeep = canBeep;
|
bool ocanbeep = canBeep;
|
||||||
canBeep = false;
|
canBeep = false;
|
||||||
QString empty;
|
QString empty;
|
||||||
doSearch(empty, 0, false, false);
|
// doSearch(_text, next, reverse, wordOnly)
|
||||||
canBeep = ocanbeep;
|
doSearch(empty, true, false, false);
|
||||||
|
canBeep = ocanbeep;
|
||||||
#endif
|
#endif
|
||||||
|
#endif // (QT_VERSION < 0x040000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Enter document in document history
|
// Enter document in document history
|
||||||
g_dynconf->enterDoc(fn, doc.ipath);
|
g_dynconf->enterDoc(fn, doc.ipath);
|
||||||
|
|
||||||
editor->setFocus();
|
editor->setFocus();
|
||||||
emit(previewExposed(m_searchId, docnum));
|
emit(previewExposed(m_searchId, docnum));
|
||||||
|
LOGDEB(("LoadFileInCurrentTab: returning true\n"));
|
||||||
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.11 2007-06-12 13:31:38 dockes Exp $ (C) 2006 J.F.Dockes */
|
/* @(#$Id: preview_w.h,v 1.12 2007-07-13 06:31:30 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
|
||||||
@ -118,7 +118,6 @@ private:
|
|||||||
QWidget *currentW;
|
QWidget *currentW;
|
||||||
HiliteData m_hData;
|
HiliteData m_hData;
|
||||||
void init();
|
void init();
|
||||||
virtual void destroy();
|
|
||||||
TabData *tabDataForCurrent(); // Return auxiliary data pointer for cur tab
|
TabData *tabDataForCurrent(); // Return auxiliary data pointer for cur tab
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.31 2007-06-20 13:15:58 dockes Exp $ (C) 2005 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.32 2007-07-13 06:31:30 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
|
||||||
@ -418,6 +418,7 @@ void RclMain::showExtIdxDialog()
|
|||||||
// where the current one is closed
|
// where the current one is closed
|
||||||
void RclMain::previewClosed(QWidget *w)
|
void RclMain::previewClosed(QWidget *w)
|
||||||
{
|
{
|
||||||
|
LOGDEB(("RclMain::previewClosed(%p)\n", w));
|
||||||
if (w == (QWidget *)curPreview) {
|
if (w == (QWidget *)curPreview) {
|
||||||
LOGDEB(("Active preview closed\n"));
|
LOGDEB(("Active preview closed\n"));
|
||||||
curPreview = 0;
|
curPreview = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user