summaryrefslogtreecommitdiff
authorpaule <paule>2007-01-13 07:03:58 (UTC)
committer paule <paule>2007-01-13 07:03:58 (UTC)
commit75c65c1dc728929f0430b8faf956195657b73311 (patch) (side-by-side diff)
tree52fce1ccec59285e4e887d908b0da3a0431c13d9
parente9768d9a498037195b8ca3bb5155db7419f30e1a (diff)
downloadopie-75c65c1dc728929f0430b8faf956195657b73311.zip
opie-75c65c1dc728929f0430b8faf956195657b73311.tar.gz
opie-75c65c1dc728929f0430b8faf956195657b73311.tar.bz2
Call qApp->processEvents() before deleting dialog objects to avoid crashes (Qt bug?)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/view/kateview.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp
index 423634b..c5673a5 100644
--- a/noncore/apps/tinykate/libkate/view/kateview.cpp
+++ b/noncore/apps/tinykate/libkate/view/kateview.cpp
@@ -1704,443 +1704,446 @@ void KateView::toggleVertical()
setConfig(configFlags ^ KateView::cfVerticalSelect);
}
int KateView::numLines() {
return myDoc->numLines();
}
QString KateView::text() {
return myDoc->text();
}
QString KateView::currentTextLine() {
TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y);
return QString(textLine->getText(), textLine->length());
}
QString KateView::textLine(int num) {
TextLine::Ptr textLine = myDoc->getTextLine(num);
return QString(textLine->getText(), textLine->length());
}
QString KateView::currentWord() {
return myDoc->getWord(myViewInternal->cursor);
}
QString KateView::word(int x, int y) {
PointStruc cursor;
cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight;
if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString();
cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x);
return myDoc->getWord(cursor);
}
void KateView::setText(const QString &s) {
myDoc->setText(s);
myDoc->updateViews();
}
void KateView::insertText(const QString &s, bool /*mark*/) {
VConfig c;
myViewInternal->getVConfig(c);
myDoc->insert(c, s);
myDoc->updateViews();
}
bool KateView::hasMarkedText() {
return myDoc->hasMarkedText();
}
QString KateView::markedText() {
return myDoc->markedText(configFlags);
}
bool KateView::canDiscard() {
int query;
if (isModified()) {
query = KMessageBox::warningYesNoCancel(this,
i18n("The current Document has been modified.\nWould you like to save it?"));
switch (query) {
case KMessageBox::Yes: //yes
if (save() == CANCEL) return false;
if (isModified()) {
query = KMessageBox::warningContinueCancel(this,
i18n("Could not save the document.\nDiscard it and continue?"),
QString::null, i18n("&Discard"));
if (query == KMessageBox::Cancel) return false;
}
break;
case KMessageBox::Cancel: //cancel
return false;
}
}
return true;
}
void KateView::flush()
{
if (canDiscard()) myDoc->flush();
}
KateView::fileResult KateView::save() {
int query = KMessageBox::Yes;
if (isModified()) {
return saveAs();
}
return OK;
}
KateView::fileResult KateView::saveAs() {
return OK;
}
void KateView::doCursorCommand(int cmdNum) {
VConfig c;
myViewInternal->getVConfig(c);
if (cmdNum & selectFlag) c.flags |= KateView::cfMark;
if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection;
cmdNum &= ~(selectFlag | multiSelectFlag);
myViewInternal->doCursorCommand(c, cmdNum);
myDoc->updateViews();
}
void KateView::doEditCommand(int cmdNum) {
VConfig c;
myViewInternal->getVConfig(c);
myViewInternal->doEditCommand(c, cmdNum);
myDoc->updateViews();
}
void KateView::undoMultiple(int count) {
if (isReadOnly())
return;
VConfig c;
myViewInternal->getVConfig(c);
myDoc->undo(c, count);
myDoc->updateViews();
}
void KateView::redoMultiple(int count) {
if (isReadOnly())
return;
VConfig c;
myViewInternal->getVConfig(c);
myDoc->redo(c, count);
myDoc->updateViews();
}
void KateView::undoHistory()
{
UndoHistory *undoH;
undoH = new UndoHistory(this, this, "UndoHistory", true);
undoH->setCaption(i18n("Undo/Redo History"));
connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo()));
connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int)));
connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int)));
undoH->exec();
delete undoH;
}
static void kwview_addToStrList(QStringList &list, const QString &str) {
if (list.count() > 0) {
if (list.first() == str) return;
QStringList::Iterator it;
it = list.find(str);
if (*it != 0L) list.remove(it);
if (list.count() >= 16) list.remove(list.fromLast());
}
list.prepend(str);
}
void KateView::find() {
SearchDialog *searchDialog;
if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
searchFlags & ~KateView::sfReplace);
// If the user has marked some text we use that otherwise
// use the word under the cursor.
QString str;
if (myDoc->hasMarkedText())
str = markedText();
if (str.isEmpty())
str = currentWord();
if (!str.isEmpty())
{
str.replace(QRegExp("^\n"), "");
int pos=str.find("\n");
if (pos>-1)
str=str.left(pos);
searchDialog->setSearchText( str );
}
myViewInternal->focusOutEvent(0L);// QT bug ?
if (searchDialog->exec() == QDialog::Accepted) {
kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt);
initSearch(s, searchFlags);
findAgain(s);
}
+ qApp->processEvents();
delete searchDialog;
}
void KateView::replace() {
SearchDialog *searchDialog;
if (isReadOnly()) return;
if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected;
searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList,
searchFlags | KateView::sfReplace);
// If the user has marked some text we use that otherwise
// use the word under the cursor.
QString str;
if (myDoc->hasMarkedText())
str = markedText();
if (str.isEmpty())
str = currentWord();
if (!str.isEmpty())
{
str.replace(QRegExp("^\n"), "");
int pos=str.find("\n");
if (pos>-1)
str=str.left(pos);
searchDialog->setSearchText( str );
}
myViewInternal->focusOutEvent(0L);// QT bug ?
if (searchDialog->exec() == QDialog::Accepted) {
// myDoc->recordReset();
kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor());
kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith());
searchFlags = searchDialog->getFlags();
initSearch(s, searchFlags);
replaceAgain();
}
+ qApp->processEvents();
delete searchDialog;
}
void KateView::gotoLine() {
GotoLineDialog *dlg;
PointStruc cursor;
dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines());
// dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this);
if (dlg->exec() == QDialog::Accepted) {
// myDoc->recordReset();
cursor.x = 0;
cursor.y = dlg->getLine() - 1;
myDoc->needPreHighlight(cursor.y);
myViewInternal->updateCursor(cursor);
myViewInternal->center();
myViewInternal->updateView(KateView::ufUpdateOnScroll);
myDoc->updateViews(this); //uptade all other views except this one
}
+ qApp->processEvents();
delete dlg;
}
void KateView::initSearch(SConfig &s, int flags) {
s.flags = flags;
s.setPattern(myDoc->searchForList.first());
if (!(s.flags & KateView::sfFromBeginning)) {
// If we are continuing a backward search, make sure we do not get stuck
// at an existing match.
s.cursor = myViewInternal->cursor;
TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y);
QString const txt(textLine->getText(),textLine->length());
const QString searchFor= myDoc->searchForList.first();
int pos = s.cursor.x-searchFor.length()-1;
if ( pos < 0 ) pos = 0;
pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive);
if ( s.flags & KateView::sfBackward )
{
if ( pos <= s.cursor.x ) s.cursor.x= pos-1;
}
else
if ( pos == s.cursor.x ) s.cursor.x++;
} else {
if (!(s.flags & KateView::sfBackward)) {
s.cursor.x = 0;
s.cursor.y = 0;
} else {
s.cursor.x = -1;
s.cursor.y = myDoc->lastLine();
}
s.flags |= KateView::sfFinished;
}
if (!(s.flags & KateView::sfBackward)) {
if (!(s.cursor.x || s.cursor.y))
s.flags |= KateView::sfFinished;
}
s.startCursor = s.cursor;
}
void KateView::continueSearch(SConfig &s) {
if (!(s.flags & KateView::sfBackward)) {
s.cursor.x = 0;
s.cursor.y = 0;
} else {
s.cursor.x = -1;
s.cursor.y = myDoc->lastLine();
}
s.flags |= KateView::sfFinished;
s.flags &= ~KateView::sfAgain;
}
void KateView::findAgain(SConfig &s) {
int query;
PointStruc cursor;
QString str;
QString searchFor = myDoc->searchForList.first();
if( searchFor.isEmpty() ) {
find();
return;
}
do {
query = KMessageBox::Cancel;
if (myDoc->doSearch(s,searchFor)) {
cursor = s.cursor;
if (!(s.flags & KateView::sfBackward))
s.cursor.x += s.matchedLength;
myViewInternal->updateCursor(s.cursor); //does deselectAll()
exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false);
} else {
if (!(s.flags & KateView::sfFinished)) {
// ask for continue
if (!(s.flags & KateView::sfBackward)) {
// forward search
str = i18n("End of document reached.\n"
"Continue from the beginning?");
query = KMessageBox::warningContinueCancel(this,
str, i18n("Find"), i18n("Continue"));
} else {
// backward search
str = i18n("Beginning of document reached.\n"
"Continue from the end?");
query = KMessageBox::warningContinueCancel(this,
str, i18n("Find"), i18n("Continue"));
}
continueSearch(s);
} else {
// wrapped
KMessageBox::sorry(this,
i18n("Search string '%1' not found!").arg(searchFor),
i18n("Find"));
}
}
} while (query == KMessageBox::Continue);
}
void KateView::replaceAgain() {
if (isReadOnly())
return;
replaces = 0;
if (s.flags & KateView::sfPrompt) {
doReplaceAction(-1);
} else {
doReplaceAction(KateView::srAll);
}
}
void KateView::doReplaceAction(int result, bool found) {
int rlen;
PointStruc cursor;
bool started;
QString searchFor = myDoc->searchForList.first();
QString replaceWith = myDoc->replaceWithList.first();
rlen = replaceWith.length();
switch (result) {
case KateView::srYes: //yes
myDoc->recordStart(this, s.cursor, configFlags,
KateActionGroup::ugReplace, true);
myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
replaces++;
if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
s.startCursor.x += rlen - s.matchedLength;
if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent);
break;
case KateView::srNo: //no
if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength;
break;
case KateView::srAll: //replace all
deleteReplacePrompt();
do {
started = false;
while (found || myDoc->doSearch(s,searchFor)) {
if (!started) {
found = false;
myDoc->recordStart(this, s.cursor, configFlags,
KateActionGroup::ugReplace);
started = true;
}
myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith);
replaces++;
if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x)
s.startCursor.x += rlen - s.matchedLength;
if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen;
}
if (started) myDoc->recordEnd(this, s.cursor,
configFlags | KateView::cfPersistent);
} while (!askReplaceEnd());
return;
case KateView::srCancel: //cancel
deleteReplacePrompt();
return;
default:
replacePrompt = 0L;
}
do {
if (myDoc->doSearch(s,searchFor)) {
//text found: highlight it, show replace prompt if needed and exit
cursor = s.cursor;
if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength;
myViewInternal->updateCursor(cursor); //does deselectAll()
exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true);
if (replacePrompt == 0L) {
replacePrompt = new ReplacePrompt(this);
myDoc->setPseudoModal(replacePrompt);//disable();
connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot()));
replacePrompt->show(); //this is not modal
}
return; //exit if text found
}
//nothing found: repeat until user cancels "repeat from beginning" dialog
} while (!askReplaceEnd());
deleteReplacePrompt();
}
void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) {
int x1, x2, y1, y2, xPos, yPos;
VConfig c;
myViewInternal->getVConfig(c);
myDoc->selectLength(cursor,slen,c.flags);