]> 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 8b36d6f66464debb1e44a4d5544ef85914bb0dd9..c58eb7dd45d02df829e640df2a43a4ca0a079e95 100644 (file)
@@ -1,41 +1,60 @@
 /**
  * \file ControlSendto.C
- * Copyright 2002 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Angus Leeming, a.leeming@.ac.uk
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "ControlSendto.h"
-#include "ViewBase.h"
-#include "frontends/LyXView.h"
-#include "BufferView.h"
+
 #include "buffer.h"
 #include "converter.h"
-#include "exporter.h"
-#include "gettext.h"
+#include "format.h"
+#include "funcrequest.h"
 #include "lyxrc.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/systemcall.h"
 
 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?
@@ -43,13 +62,15 @@ vector<Format const *> const ControlSendto::allFormats() const
        exports.push_back("lyx");
        exports.push_back("text");
 
-       if (lv_.buffer()->isLatex())
+       Buffer const & buffer = kernel().buffer();
+
+       if (buffer.isLatex())
                exports.push_back("latex");
-       if (lv_.buffer()->isLinuxDoc())
+       else if (buffer.isLinuxDoc())
                exports.push_back("linuxdoc");
-       if (lv_.buffer()->isDocBook())
+       else if (buffer.isDocBook())
                exports.push_back("docbook");
-       if (lv_.buffer()->isLiterate())
+       else if (buffer.isLiterate())
                exports.push_back("literate");
 
        // Loop over these native formats and ascertain what formats we
@@ -78,13 +99,7 @@ vector<Format const *> const ControlSendto::allFormats() const
 
        // Remove repeated formats.
        std::sort(to.begin(), to.end());
-
-       vector<Format const *>::iterator to_begin = to.begin();
-       vector<Format const *>::iterator to_end   = to.end();
-       vector<Format const *>::iterator to_it =
-               std::unique(to_begin, to_end);
-       if (to_it != to_end)
-               to.erase(to_it, to_end);
+       to.erase(std::unique(to.begin(), to.end()), to.end());
 
        return to;
 }
@@ -101,40 +116,5 @@ void ControlSendto::setCommand(string const & cmd)
        command_ = trim(cmd);
 }
 
-
-void ControlSendto::apply()
-{
-       if (!lv_.view()->available())
-               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(lv_.buffer()->getLatexName(false),
-                                          format_->extension());
-               if (!lv_.buffer()->tmppath.empty())
-                       filename = AddName(lv_.buffer()->tmppath, filename);
-
-               lv_.buffer()->writeFile(filename, true);
-
-       } else {
-               Exporter::Export(lv_.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