From a024d3aee686d074c82e45a54e0d8c3a79976b90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Wed, 20 Oct 2010 01:45:51 +0000 Subject: [PATCH] use bind, is this really better? git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35726 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiView.cpp | 41 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 1e499ce139..ac56b7598c 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -370,6 +370,9 @@ public: static docstring compileAndDestroy(Buffer const * orig, Buffer * buffer, string const & format); static docstring saveAndDestroy(Buffer const * orig, Buffer * buffer, FileName const & fname); + template + 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, @@ -2815,45 +2818,37 @@ bool GuiView::goToFileRow(string const & argument) #if (QT_VERSION >= 0x040400) -docstring GuiView::GuiViewPrivate::compileAndDestroy(Buffer const * orig, Buffer * buffer, string const & format) +template +docstring GuiView::GuiViewPrivate::runAndDestroy(const T& func, Buffer const * orig, Buffer * buffer, string const & format, string const & msg) { bool const update_unincluded = buffer->params().maintain_unincluded_children && !buffer->params().getIncludedChildren().empty(); - bool const success = buffer->doExport(format, true, update_unincluded); + bool const success = func(format, update_unincluded); delete buffer; busyBuffers.remove(orig); return success - ? bformat(_("Successful compilation to format: %1$s"), from_utf8(format)) - : bformat(_("Error compiling format: %1$s"), from_utf8(format)); + ? bformat(_("Successful " + msg + " to format: %1$s"), from_utf8(format)) + : bformat(_("Error " + msg + " 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"); +} docstring GuiView::GuiViewPrivate::exportAndDestroy(Buffer const * orig, Buffer * buffer, string const & format) { - 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)); -} + 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"); +} docstring GuiView::GuiViewPrivate::previewAndDestroy(Buffer const * orig, Buffer * buffer, string const & format) { - 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)); + bool(Buffer::* mem_func)(std::string const &, bool) const = &Buffer::preview; + return runAndDestroy(bind(mem_func, buffer, _1, _2), orig, buffer, format, "preview"); } #endif -- 2.39.5