Avoid that, if an error dialog pops up during a long operation, it freezes LyX.

This commit is contained in:
Tommaso Cucinotta 2012-07-01 08:27:11 +01:00
parent 4964388408
commit 0f97ae5480
4 changed files with 31 additions and 1 deletions

View File

@ -246,6 +246,8 @@ public:
virtual bool longOperationCancelled() = 0;
/// Stop the long operation mode (i.e., release the GUI)
virtual void stopLongOperation() = 0;
/// A started long operation is still in progress ?
virtual bool longOperationStarted() = 0;
};

View File

@ -92,6 +92,11 @@ int doPrompt(docstring const & title0, docstring const & question,
docstring const title = bformat(_("LyX: %1$s"), title0);
/// Long operation in progress prevents user from Ok-ing the error dialog
bool long_op = theApp()->longOperationStarted();
if (long_op)
theApp()->stopLongOperation();
// For some reason, sometimes Qt uses a hourglass or watch cursor when
// displaying the alert. Hence, we ask for the standard cursor shape.
qApp->setOverrideCursor(Qt::ArrowCursor);
@ -116,6 +121,9 @@ int doPrompt(docstring const & title0, docstring const & question,
qApp->restoreOverrideCursor();
if (long_op)
theApp()->startLongOperation();
// Qt bug: can return -1 on cancel or WM close, despite the docs.
if (res == -1)
res = cancel_button;
@ -197,6 +205,11 @@ void doError(docstring const & title0, docstring const & message)
return;
}
/// Long operation in progress prevents user from Ok-ing the error dialog
bool long_op = theApp()->longOperationStarted();
if (long_op)
theApp()->stopLongOperation();
// Don't use a hourglass cursor while displaying the alert
qApp->setOverrideCursor(Qt::ArrowCursor);
@ -205,6 +218,9 @@ void doError(docstring const & title0, docstring const & message)
toqstr(message));
qApp->restoreOverrideCursor();
if (long_op)
theApp()->startLongOperation();
}
void error(docstring const & title0, docstring const & message)

View File

@ -684,6 +684,7 @@ public:
class KeyChecker : public QObject {
private:
bool pressed_;
bool started_;
public:
KeyChecker() {
pressed_ = false;
@ -691,14 +692,19 @@ public:
void start() {
QCoreApplication::instance()->installEventFilter(this);
pressed_ = false;
started_ = true;
}
void stop() {
QCoreApplication::instance()->removeEventFilter(this);
started_ = false;
}
bool pressed() {
QCoreApplication::processEvents();
return pressed_;
}
bool started() const {
return started_;
}
bool eventFilter(QObject *obj, QEvent *event) {
LYXERR(Debug::ACTION, "Event Type: " << event->type());
switch (event->type()) {
@ -2679,6 +2685,11 @@ void GuiApplication::stopLongOperation() {
}
bool GuiApplication::longOperationStarted() {
return d->key_checker_.started();
}
////////////////////////////////////////////////////////////////////////
//
// X11 specific stuff goes here...

View File

@ -175,7 +175,8 @@ public:
bool longOperationCancelled();
/// Stop the long operation mode (i.e., release the GUI)
void stopLongOperation();
/// A started long operation is still in progress ?
bool longOperationStarted();
private Q_SLOTS:
///
void execBatchCommands();