The idea here is to force commands to be run syncrhonously when
they are launched via "command-sequence" or "repeat". We do this
by using a new flag in FuncRequest.

(cherry picked from commit 2477493cf5)
This commit is contained in:
Richard Heck 2018-04-18 23:03:24 -04:00
parent 7d0b7e0840
commit 00522ecd3f
4 changed files with 65 additions and 45 deletions

View File

@ -31,38 +31,38 @@ FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
FuncRequest::FuncRequest(Origin o) FuncRequest::FuncRequest(Origin o)
: action_(LFUN_NOACTION), origin_(o), x_(0), y_(0), : action_(LFUN_NOACTION), origin_(o), x_(0), y_(0),
button_(mouse_button::none), modifier_(NoModifier) button_(mouse_button::none), modifier_(NoModifier), allow_async_(true)
{} {}
FuncRequest::FuncRequest(FuncCode act, Origin o) FuncRequest::FuncRequest(FuncCode act, Origin o)
: action_(act), origin_(o), x_(0), y_(0), : action_(act), origin_(o), x_(0), y_(0),
button_(mouse_button::none), modifier_(NoModifier) button_(mouse_button::none), modifier_(NoModifier), allow_async_(true)
{} {}
FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o) FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
: action_(act), argument_(arg), origin_(o), x_(0), y_(0), : action_(act), argument_(arg), origin_(o), x_(0), y_(0),
button_(mouse_button::none), modifier_(NoModifier) button_(mouse_button::none), modifier_(NoModifier), allow_async_(true)
{} {}
FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o) FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
: action_(act), argument_(from_utf8(arg)), origin_(o), x_(0), y_(0), : action_(act), argument_(from_utf8(arg)), origin_(o), x_(0), y_(0),
button_(mouse_button::none), modifier_(NoModifier) button_(mouse_button::none), modifier_(NoModifier), allow_async_(true)
{} {}
FuncRequest::FuncRequest(FuncCode act, int ax, int ay, FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
mouse_button::state but, KeyModifier modifier, Origin o) mouse_button::state but, KeyModifier modifier, Origin o)
: action_(act), origin_(o), x_(ax), y_(ay), button_(but), : action_(act), origin_(o), x_(ax), y_(ay), button_(but),
modifier_(modifier) modifier_(modifier), allow_async_(true)
{} {}
FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o) FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
: action_(cmd.action()), argument_(arg), origin_(o), : action_(cmd.action()), argument_(arg), origin_(o), x_(cmd.x_), y_(cmd.y_),
x_(cmd.x_), y_(cmd.y_), button_(cmd.button_), modifier_(NoModifier) button_(cmd.button_), modifier_(NoModifier), allow_async_(true)
{} {}

View File

@ -90,6 +90,11 @@ public:
static FuncRequest const unknown; static FuncRequest const unknown;
/// ///
static FuncRequest const noaction; static FuncRequest const noaction;
///
bool allowAsync() const { return allow_async_; }
///
void allowAsync(bool allow_async) { allow_async_ = allow_async; }
private: private:
/// the action /// the action
FuncCode action_; FuncCode action_;
@ -105,6 +110,8 @@ private:
mouse_button::state button_; mouse_button::state button_;
/// ///
KeyModifier modifier_; KeyModifier modifier_;
///
bool allow_async_;
}; };

View File

@ -1850,8 +1850,11 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
dr.setMessage(bformat(_("Cannot iterate more than %1$d times"), max_iter)); dr.setMessage(bformat(_("Cannot iterate more than %1$d times"), max_iter));
dr.setError(true); dr.setError(true);
} else { } else {
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i) {
dispatch(lyxaction.lookupFunc(rest)); FuncRequest lfun = lyxaction.lookupFunc(rest);
lfun.allowAsync(false);
dispatch(lfun);
}
} }
break; break;
} }
@ -1868,6 +1871,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
string first; string first;
arg = split(arg, first, ';'); arg = split(arg, first, ';');
FuncRequest func(lyxaction.lookupFunc(first)); FuncRequest func(lyxaction.lookupFunc(first));
func.allowAsync(false);
func.setOrigin(cmd.origin()); func.setOrigin(cmd.origin());
dispatch(func); dispatch(func);
} }

View File

@ -498,7 +498,8 @@ public:
docstring const & msg, docstring const & msg,
Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &), Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const, Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const); Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const,
bool allow_async);
QVector<GuiWorkArea*> guiWorkAreas(); QVector<GuiWorkArea*> guiWorkAreas();
}; };
@ -3579,7 +3580,8 @@ bool GuiView::GuiViewPrivate::asyncBufferProcessing(
docstring const & msg, docstring const & msg,
Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &), Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string const &),
Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const, Buffer::ExportStatus (Buffer::*syncFunc)(string const &, bool) const,
Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const) Buffer::ExportStatus (Buffer::*previewFunc)(string const &) const,
bool allow_async)
{ {
if (!used_buffer) if (!used_buffer)
return false; return false;
@ -3593,36 +3595,43 @@ bool GuiView::GuiViewPrivate::asyncBufferProcessing(
gv_->message(msg); gv_->message(msg);
} }
#if EXPORT_in_THREAD #if EXPORT_in_THREAD
GuiViewPrivate::busyBuffers.insert(used_buffer); if (allow_async) {
Buffer * cloned_buffer = used_buffer->cloneFromMaster(); GuiViewPrivate::busyBuffers.insert(used_buffer);
if (!cloned_buffer) { Buffer * cloned_buffer = used_buffer->cloneFromMaster();
Alert::error(_("Export Error"), if (!cloned_buffer) {
_("Error cloning the Buffer.")); Alert::error(_("Export Error"),
return false; _("Error cloning the Buffer."));
return false;
}
QFuture<Buffer::ExportStatus> f = QtConcurrent::run(
asyncFunc,
used_buffer,
cloned_buffer,
format);
setPreviewFuture(f);
last_export_format = used_buffer->params().bufferFormat();
(void) syncFunc;
(void) previewFunc;
// We are asynchronous, so we don't know here anything about the success
return true;
} else {
#endif
// this will be run unconditionally in case EXPORT_in_THREAD
// is not defined.
Buffer::ExportStatus status;
if (syncFunc) {
status = (used_buffer->*syncFunc)(format, true);
} else if (previewFunc) {
status = (used_buffer->*previewFunc)(format);
} else
return false;
handleExportStatus(gv_, status, format);
(void) asyncFunc;
return (status == Buffer::ExportSuccess
|| status == Buffer::PreviewSuccess);
#if EXPORT_in_THREAD
// the end of the else clause in that case.
} }
QFuture<Buffer::ExportStatus> f = QtConcurrent::run(
asyncFunc,
used_buffer,
cloned_buffer,
format);
setPreviewFuture(f);
last_export_format = used_buffer->params().bufferFormat();
(void) syncFunc;
(void) previewFunc;
// We are asynchronous, so we don't know here anything about the success
return true;
#else
Buffer::ExportStatus status;
if (syncFunc) {
status = (used_buffer->*syncFunc)(format, true);
} else if (previewFunc) {
status = (used_buffer->*previewFunc)(format);
} else
return false;
handleExportStatus(gv_, status, format);
(void) asyncFunc;
return (status == Buffer::ExportSuccess
|| status == Buffer::PreviewSuccess);
#endif #endif
} }
@ -3732,7 +3741,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
_("Exporting ..."), _("Exporting ..."),
&GuiViewPrivate::exportAndDestroy, &GuiViewPrivate::exportAndDestroy,
&Buffer::doExport, &Buffer::doExport,
0); 0, cmd.allowAsync());
// TODO Inform user about success // TODO Inform user about success
break; break;
} }
@ -3752,7 +3761,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
_("Exporting ..."), _("Exporting ..."),
&GuiViewPrivate::compileAndDestroy, &GuiViewPrivate::compileAndDestroy,
&Buffer::doExport, &Buffer::doExport,
0); 0, cmd.allowAsync());
break; break;
} }
case LFUN_BUFFER_VIEW: { case LFUN_BUFFER_VIEW: {
@ -3761,7 +3770,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
_("Previewing ..."), _("Previewing ..."),
&GuiViewPrivate::previewAndDestroy, &GuiViewPrivate::previewAndDestroy,
0, 0,
&Buffer::preview); &Buffer::preview, cmd.allowAsync());
break; break;
} }
case LFUN_MASTER_BUFFER_UPDATE: { case LFUN_MASTER_BUFFER_UPDATE: {
@ -3770,7 +3779,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
docstring(), docstring(),
&GuiViewPrivate::compileAndDestroy, &GuiViewPrivate::compileAndDestroy,
&Buffer::doExport, &Buffer::doExport,
0); 0, cmd.allowAsync());
break; break;
} }
case LFUN_MASTER_BUFFER_VIEW: { case LFUN_MASTER_BUFFER_VIEW: {
@ -3778,7 +3787,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
(doc_buffer ? doc_buffer->masterBuffer() : 0), (doc_buffer ? doc_buffer->masterBuffer() : 0),
docstring(), docstring(),
&GuiViewPrivate::previewAndDestroy, &GuiViewPrivate::previewAndDestroy,
0, &Buffer::preview); 0, &Buffer::preview, cmd.allowAsync());
break; break;
} }
case LFUN_BUFFER_SWITCH: { case LFUN_BUFFER_SWITCH: {