/**
* \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>
-#include <fstream>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-#include "ViewBase.h"
-#include "ButtonControllerBase.h"
#include "ControlSendto.h"
-#include "Dialogs.h"
-#include "LyXView.h"
-#include "BufferView.h"
+#include "ViewBase.h"
#include "buffer.h"
#include "converter.h"
+#include "format.h"
#include "exporter.h"
#include "gettext.h"
#include "lyxrc.h"
+
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
+using namespace lyx::support;
+
using std::vector;
: ControlDialogBD(lv, d),
format_(0),
command_(lyxrc.custom_export_command)
-{
- d_.showSendto.connect(SigC::slot(this, &ControlSendto::show));
-}
+{}
vector<Format const *> const ControlSendto::allFormats() const
{
- // Well, we can start with "lyx"
- vector<Format const *> lyx_formats;
- lyx_formats.push_back(formats.getFormat("lyx"));
-
- // lyx can export to latex, what formats can be reached from latex?
- Formats::const_iterator it = formats.begin();
- Formats::const_iterator end = formats.end();
- vector<Format const *>::const_iterator lbegin = lyx_formats.begin();
- for (; it != end; ++it) {
- if (converters.isReachable("latex", it->name())) {
- vector<Format const *>::const_iterator lend =
- lyx_formats.end();
-
- if (std::find(lbegin, lend, it) == lend)
- lyx_formats.push_back(it);
+ // What formats can we output natively?
+ vector<string> exports;
+ exports.push_back("lyx");
+ exports.push_back("text");
+
+ if (buffer()->isLatex())
+ exports.push_back("latex");
+ if (buffer()->isLinuxDoc())
+ exports.push_back("linuxdoc");
+ if (buffer()->isDocBook())
+ exports.push_back("docbook");
+ if (buffer()->isLiterate())
+ exports.push_back("literate");
+
+ // Loop over these native formats and ascertain what formats we
+ // can convert to
+ vector<Format const *> to;
+
+ vector<string>::const_iterator ex_it = exports.begin();
+ vector<string>::const_iterator ex_end = exports.end();
+ for (; ex_it != ex_end; ++ex_it) {
+ // Start off with the native export format.
+ // "formats" is LyX's list of recognised formats
+ to.push_back(formats.getFormat(*ex_it));
+
+ Formats::const_iterator fo_it = formats.begin();
+ Formats::const_iterator fo_end = formats.end();
+ for (; fo_it != fo_end; ++fo_it) {
+ // we need to hide the default graphic export formats
+ // from the external menu, because we need them only
+ // for the internal lyx-view and external latex run
+ string const name = fo_it->name();
+ if (name != "eps" && name != "xpm" && name != "png" &&
+ converters.isReachable(*ex_it, name))
+ to.push_back(&(*fo_it));
}
}
- return lyx_formats;
+ // 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);
+
+ return to;
}
void ControlSendto::setCommand(string const & cmd)
{
- command_ = strip(frontStrip(cmd));
+ command_ = trim(cmd);
}
void ControlSendto::apply()
{
- if (!lv_.view()->available())
+ if (!bufferIsAvailable())
return;
-
+
view().apply();
if (command_.empty() || !format_)
return;
// The name of the file created by the conversion process
- string filename = lv_.buffer()->getLatexName(false);
- if (!lv_.buffer()->tmppath.empty())
- filename = AddName(lv_.buffer()->tmppath, filename);
- filename = ChangeExtension(filename, format_->extension());
+ string filename;
// Output to filename
if (format_->name() == "lyx") {
- lv_.buffer()->writeFile(filename, true);
+ filename = ChangeExtension(buffer()->getLatexName(false),
+ format_->extension());
+ if (!buffer()->tmppath.empty())
+ filename = AddName(buffer()->tmppath, filename);
+
+ buffer()->writeFile(filename);
} else {
- Exporter::Export(lv_.buffer(), format_->name(), true,
- filename);
+ Exporter::Export(buffer(), format_->name(), true, filename);
}
// Substitute $$FName for filename
Systemcall call;
call.startscript(Systemcall::DontWait, command);
}
-