On 10/20/2010 05:44 AM, Pavel Sanda wrote:
Peter Kümmel wrote:
I agree. But this would mean that all dialog related code must be
removed from the export functions... which would be a good thing in
itself but is a bit more involved than what was originally thought.
The "box" is open again ;)
ouch. is there easy way to switch back or would it mean revert the whole
serie of patches?

Some of the early ones were just cleanup, and export code itself is in an #if 0 block, so it shouldn't be that bad. Maybe it would be worth reverting r35726. To answer Peter's question, in the log, I'm not sure that is better. If we go back to before that,
then it's fairly easy.

The attached patch should do it.

Richard

Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp       (revision 35728)
+++ src/frontends/qt4/GuiView.cpp       (working copy)
@@ -370,9 +370,6 @@
        static docstring compileAndDestroy(Buffer const * orig, Buffer * 
buffer, string const & format);
        static docstring saveAndDestroy(Buffer const * orig, Buffer * buffer, 
FileName const & fname);
 
-       template<class T>
-       static docstring runAndDestroy(const T& func, Buffer const * orig, 
Buffer * buffer, string const & format, string const & msg);
-       
        // TODO syncFunc/previewFunc: use bind
        bool asyncBufferProcessing(string const & argument,
                                   Buffer const * used_buffer,
@@ -2818,37 +2815,48 @@
 
 
 #if (QT_VERSION >= 0x040400)
-template<class T>
-docstring GuiView::GuiViewPrivate::runAndDestroy(const T& func, Buffer const * 
orig, Buffer * buffer, string const & format, string const & msg)
+docstring GuiView::GuiViewPrivate::compileAndDestroy(Buffer const * orig, 
Buffer * buffer, string const & format)
 {
        bool const update_unincluded =
                                buffer->params().maintain_unincluded_children
                                && 
!buffer->params().getIncludedChildren().empty();
-       bool const success = func(format, update_unincluded);
+       bool const success = buffer->doExport(format, true, update_unincluded);
        delete buffer;
        busyBuffers.remove(orig);
        return success
-               ? bformat(_("Successful " + msg + " to format: %1$s"), 
from_utf8(format))
-               : bformat(_("Error " + msg + " format: %1$s"), 
from_utf8(format));
+               ? bformat(_("Successful compilation to format: %1$s"), 
from_utf8(format))
+               : bformat(_("Error compiling format: %1$s"), from_utf8(format));
 }
 
-docstring GuiView::GuiViewPrivate::compileAndDestroy(Buffer const * orig, 
Buffer * buffer, string const & format)
-{
-       bool (Buffer::* mem_func)(std::string const &, bool, bool) const = 
&Buffer::doExport;
-       return runAndDestroy(bind(mem_func, buffer, _1, true, _2), orig, 
buffer, format, "export");
-}
-
+#if 0
+/// Asynchronous export runs into problems with the  creation of
+/// dialogs from the export thread:
+/// http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg162502.html
 docstring GuiView::GuiViewPrivate::exportAndDestroy(Buffer const * orig, 
Buffer * buffer, string const & format)
 {
-       bool (Buffer::* mem_func)(std::string const &, bool, bool) const = 
&Buffer::doExport;
-       return runAndDestroy(bind(mem_func, buffer, _1, false, _2), orig, 
buffer, format, "export");
-
+       bool const update_unincluded =
+                               buffer->params().maintain_unincluded_children
+                               && 
!buffer->params().getIncludedChildren().empty();
+       bool const success = buffer->doExport(format, false, update_unincluded);
+       delete buffer;
+       busyBuffers.remove(orig);
+       return success
+               ? bformat(_("Successful export to format: %1$s"), 
from_utf8(format))
+               : bformat(_("Error exporting to format: %1$s"), 
from_utf8(format));
 }
+#endif
 
 docstring GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, 
Buffer * buffer, string const & format)
 {
-       bool(Buffer::* mem_func)(std::string const &, bool) const = 
&Buffer::preview;
-       return runAndDestroy(bind(mem_func, buffer, _1, _2), orig, buffer, 
format, "preview");
+       bool const update_unincluded =
+                               buffer->params().maintain_unincluded_children
+                               && 
!buffer->params().getIncludedChildren().empty();
+       bool const success = buffer->preview(format, update_unincluded);
+       delete buffer;
+       busyBuffers.remove(orig);
+       return success
+               ? bformat(_("Successful preview of format: %1$s"), 
from_utf8(format))
+               : bformat(_("Error previewing format: %1$s"), 
from_utf8(format));
 }
 #endif
 
@@ -2936,14 +2944,7 @@
                                dispatch(FuncRequest(LFUN_DIALOG_SHOW, 
"sendto"), dr);
                                break;
                        }
-#if 0
-                       // TODO Remove if we could export asynchronous
-                       if (!doc_buffer->doExport(argument, false)) {
-                               dr.setError(true);
-                               dr.setMessage(bformat(_("Error exporting to 
format: %1$s."),
-                                       cmd.argument()));
-                       }
-#else
+#if 0 && EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
                        /* TODO/Review: Is it a problem to also export the 
children?
                                        See the update_unincluded flag */
                        d.asyncBufferProcessing(argument,
@@ -2953,6 +2954,13 @@
                                                &Buffer::doExport,
                                                0);
                        // TODO Inform user about success
+#else
+                       // TODO Remove if we could export asynchronous
+                       if (!doc_buffer->doExport(argument, false)) {
+                               dr.setError(true);
+                               dr.setMessage(bformat(_("Error exporting to 
format: %1$s."),
+                                       cmd.argument()));
+                       }
 #endif
                        break;
                }

Reply via email to