]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlSendto.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlSendto.C
index 7f53533d2eeeecc19eabb46ca235e9adda36ffad..c58eb7dd45d02df829e640df2a43a4ca0a079e95 100644 (file)
 
 #include <config.h>
 
-
 #include "ControlSendto.h"
-#include "ViewBase.h"
+
 #include "buffer.h"
 #include "converter.h"
 #include "format.h"
-#include "exporter.h"
+#include "funcrequest.h"
 #include "lyxrc.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/systemcall.h"
-
-using lyx::support::AddName;
-using lyx::support::ChangeExtension;
-using lyx::support::contains;
-using lyx::support::subst;
-using lyx::support::Systemcall;
-using lyx::support::trim;
 
 using std::vector;
 using std::string;
 
+namespace lyx {
+
+using support::AddName;
+using support::trim;
 
-ControlSendto::ControlSendto(LyXView & lv, Dialogs & d)
-       : ControlDialogBD(lv, d),
-         format_(0),
-         command_(lyxrc.custom_export_command)
+namespace frontend {
+
+
+ControlSendto::ControlSendto(Dialog & parent)
+       : Dialog::Controller(parent)
 {}
 
 
+bool ControlSendto::initialiseParams(std::string const &)
+{
+       format_ = 0;
+       command_ = lyxrc.custom_export_command;
+       return true;
+}
+
+
+void ControlSendto::dispatchParams()
+{
+       if (command_.empty() || !format_ || format_->name().empty())
+               return;
+
+       string const data = format_->name() + " " + command_;
+       kernel().dispatch(FuncRequest(getLfun(), data));
+}
+
+
 vector<Format const *> const ControlSendto::allFormats() const
 {
        // What formats can we output natively?
@@ -48,15 +62,15 @@ vector<Format const *> const ControlSendto::allFormats() const
        exports.push_back("lyx");
        exports.push_back("text");
 
-#warning Can the doc ever be all/any of these at the same time? (Lgb)
-       // I think some if else if is in order.
-       if (buffer().isLatex())
+       Buffer const & buffer = kernel().buffer();
+
+       if (buffer.isLatex())
                exports.push_back("latex");
-       if (buffer().isLinuxDoc())
+       else if (buffer.isLinuxDoc())
                exports.push_back("linuxdoc");
-       if (buffer().isDocBook())
+       else if (buffer.isDocBook())
                exports.push_back("docbook");
-       if (buffer().isLiterate())
+       else if (buffer.isLiterate())
                exports.push_back("literate");
 
        // Loop over these native formats and ascertain what formats we
@@ -102,40 +116,5 @@ void ControlSendto::setCommand(string const & cmd)
        command_ = trim(cmd);
 }
 
-
-void ControlSendto::apply()
-{
-       if (!bufferIsAvailable())
-               return;
-
-       view().apply();
-
-       if (command_.empty() || !format_)
-               return;
-
-       // The name of the file created by the conversion process
-       string filename;
-
-       // Output to filename
-       if (format_->name() == "lyx") {
-               filename = ChangeExtension(buffer()->getLatexName(false),
-                                          format_->extension());
-               if (!buffer()->temppath().empty())
-                       filename = AddName(buffer()->temppath(), filename);
-
-               buffer()->writeFile(filename);
-
-       } else {
-               Exporter::Export(buffer(), format_->name(), true, filename);
-       }
-
-       // Substitute $$FName for filename
-       string command = command_;
-       if (!contains(command, "$$FName"))
-               command = "( " + command + " ) < $$FName";
-       command = subst(command, "$$FName", filename);
-
-       // Execute the command in the background
-       Systemcall call;
-       call.startscript(Systemcall::DontWait, command);
-}
+} // namespace frontend
+} // namespace lyx