mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix #8338.
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:
parent
7d0b7e0840
commit
00522ecd3f
@ -31,38 +31,38 @@ FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
|
||||
|
||||
FuncRequest::FuncRequest(Origin o)
|
||||
: 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)
|
||||
: 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)
|
||||
: 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)
|
||||
: 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,
|
||||
mouse_button::state but, KeyModifier modifier, Origin o)
|
||||
: 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)
|
||||
: action_(cmd.action()), argument_(arg), origin_(o),
|
||||
x_(cmd.x_), y_(cmd.y_), button_(cmd.button_), modifier_(NoModifier)
|
||||
: action_(cmd.action()), argument_(arg), origin_(o), x_(cmd.x_), y_(cmd.y_),
|
||||
button_(cmd.button_), modifier_(NoModifier), allow_async_(true)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -90,6 +90,11 @@ public:
|
||||
static FuncRequest const unknown;
|
||||
///
|
||||
static FuncRequest const noaction;
|
||||
///
|
||||
bool allowAsync() const { return allow_async_; }
|
||||
///
|
||||
void allowAsync(bool allow_async) { allow_async_ = allow_async; }
|
||||
|
||||
private:
|
||||
/// the action
|
||||
FuncCode action_;
|
||||
@ -105,6 +110,8 @@ private:
|
||||
mouse_button::state button_;
|
||||
///
|
||||
KeyModifier modifier_;
|
||||
///
|
||||
bool allow_async_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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.setError(true);
|
||||
} else {
|
||||
for (int i = 0; i < count; ++i)
|
||||
dispatch(lyxaction.lookupFunc(rest));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
FuncRequest lfun = lyxaction.lookupFunc(rest);
|
||||
lfun.allowAsync(false);
|
||||
dispatch(lfun);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1868,6 +1871,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
string first;
|
||||
arg = split(arg, first, ';');
|
||||
FuncRequest func(lyxaction.lookupFunc(first));
|
||||
func.allowAsync(false);
|
||||
func.setOrigin(cmd.origin());
|
||||
dispatch(func);
|
||||
}
|
||||
|
@ -498,7 +498,8 @@ public:
|
||||
docstring const & msg,
|
||||
Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string 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();
|
||||
};
|
||||
@ -3579,7 +3580,8 @@ bool GuiView::GuiViewPrivate::asyncBufferProcessing(
|
||||
docstring const & msg,
|
||||
Buffer::ExportStatus (*asyncFunc)(Buffer const *, Buffer *, string 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)
|
||||
return false;
|
||||
@ -3593,36 +3595,43 @@ bool GuiView::GuiViewPrivate::asyncBufferProcessing(
|
||||
gv_->message(msg);
|
||||
}
|
||||
#if EXPORT_in_THREAD
|
||||
GuiViewPrivate::busyBuffers.insert(used_buffer);
|
||||
Buffer * cloned_buffer = used_buffer->cloneFromMaster();
|
||||
if (!cloned_buffer) {
|
||||
Alert::error(_("Export Error"),
|
||||
_("Error cloning the Buffer."));
|
||||
return false;
|
||||
if (allow_async) {
|
||||
GuiViewPrivate::busyBuffers.insert(used_buffer);
|
||||
Buffer * cloned_buffer = used_buffer->cloneFromMaster();
|
||||
if (!cloned_buffer) {
|
||||
Alert::error(_("Export Error"),
|
||||
_("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
|
||||
}
|
||||
|
||||
@ -3732,7 +3741,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
_("Exporting ..."),
|
||||
&GuiViewPrivate::exportAndDestroy,
|
||||
&Buffer::doExport,
|
||||
0);
|
||||
0, cmd.allowAsync());
|
||||
// TODO Inform user about success
|
||||
break;
|
||||
}
|
||||
@ -3752,7 +3761,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
_("Exporting ..."),
|
||||
&GuiViewPrivate::compileAndDestroy,
|
||||
&Buffer::doExport,
|
||||
0);
|
||||
0, cmd.allowAsync());
|
||||
break;
|
||||
}
|
||||
case LFUN_BUFFER_VIEW: {
|
||||
@ -3761,7 +3770,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
_("Previewing ..."),
|
||||
&GuiViewPrivate::previewAndDestroy,
|
||||
0,
|
||||
&Buffer::preview);
|
||||
&Buffer::preview, cmd.allowAsync());
|
||||
break;
|
||||
}
|
||||
case LFUN_MASTER_BUFFER_UPDATE: {
|
||||
@ -3770,7 +3779,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
docstring(),
|
||||
&GuiViewPrivate::compileAndDestroy,
|
||||
&Buffer::doExport,
|
||||
0);
|
||||
0, cmd.allowAsync());
|
||||
break;
|
||||
}
|
||||
case LFUN_MASTER_BUFFER_VIEW: {
|
||||
@ -3778,7 +3787,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
(doc_buffer ? doc_buffer->masterBuffer() : 0),
|
||||
docstring(),
|
||||
&GuiViewPrivate::previewAndDestroy,
|
||||
0, &Buffer::preview);
|
||||
0, &Buffer::preview, cmd.allowAsync());
|
||||
break;
|
||||
}
|
||||
case LFUN_BUFFER_SWITCH: {
|
||||
|
Loading…
Reference in New Issue
Block a user