2002-03-07 15:06:57 +00:00
|
|
|
/**
|
|
|
|
* \file ControlSendto.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-07 15:06:57 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-03-07 15:06:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "ControlSendto.h"
|
2002-06-18 15:44:30 +00:00
|
|
|
#include "ViewBase.h"
|
2002-03-07 15:06:57 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "converter.h"
|
2003-02-28 09:49:49 +00:00
|
|
|
#include "format.h"
|
2002-03-07 15:06:57 +00:00
|
|
|
#include "exporter.h"
|
|
|
|
#include "lyxrc.h"
|
2002-05-29 16:21:03 +00:00
|
|
|
|
2002-03-07 15:06:57 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/systemcall.h"
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::AddName;
|
|
|
|
using lyx::support::ChangeExtension;
|
|
|
|
using lyx::support::contains;
|
|
|
|
using lyx::support::subst;
|
|
|
|
using lyx::support::Systemcall;
|
|
|
|
using lyx::support::trim;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2002-03-07 15:46:34 +00:00
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2002-03-07 15:06:57 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2002-03-07 15:06:57 +00:00
|
|
|
ControlSendto::ControlSendto(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlDialogBD(lv, d),
|
|
|
|
format_(0),
|
|
|
|
command_(lyxrc.custom_export_command)
|
2002-06-18 15:44:30 +00:00
|
|
|
{}
|
2002-03-07 15:06:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
vector<Format const *> const ControlSendto::allFormats() const
|
|
|
|
{
|
2002-03-07 15:46:34 +00:00
|
|
|
// What formats can we output natively?
|
|
|
|
vector<string> exports;
|
|
|
|
exports.push_back("lyx");
|
|
|
|
exports.push_back("text");
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
#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())
|
2002-03-07 15:46:34 +00:00
|
|
|
exports.push_back("latex");
|
2003-08-28 07:41:31 +00:00
|
|
|
if (buffer().isLinuxDoc())
|
2002-03-07 15:46:34 +00:00
|
|
|
exports.push_back("linuxdoc");
|
2003-08-28 07:41:31 +00:00
|
|
|
if (buffer().isDocBook())
|
2002-03-07 15:46:34 +00:00
|
|
|
exports.push_back("docbook");
|
2003-08-28 07:41:31 +00:00
|
|
|
if (buffer().isLiterate())
|
2002-03-07 15:46:34 +00:00
|
|
|
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) {
|
2002-04-29 09:50:34 +00:00
|
|
|
// 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))
|
2002-03-07 18:59:07 +00:00
|
|
|
to.push_back(&(*fo_it));
|
2002-03-07 15:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-07 15:46:34 +00:00
|
|
|
// Remove repeated formats.
|
|
|
|
std::sort(to.begin(), to.end());
|
2004-01-07 17:57:47 +00:00
|
|
|
to.erase(std::unique(to.begin(), to.end()), to.end());
|
2002-03-07 15:46:34 +00:00
|
|
|
|
|
|
|
return to;
|
2002-03-07 15:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlSendto::setFormat(Format const * fmt)
|
|
|
|
{
|
|
|
|
format_ = fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlSendto::setCommand(string const & cmd)
|
|
|
|
{
|
2002-07-28 22:50:13 +00:00
|
|
|
command_ = trim(cmd);
|
2002-03-07 15:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlSendto::apply()
|
|
|
|
{
|
2002-08-12 20:17:41 +00:00
|
|
|
if (!bufferIsAvailable())
|
2002-03-07 15:06:57 +00:00
|
|
|
return;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-03-07 15:06:57 +00:00
|
|
|
view().apply();
|
|
|
|
|
|
|
|
if (command_.empty() || !format_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The name of the file created by the conversion process
|
2002-03-07 15:46:34 +00:00
|
|
|
string filename;
|
2002-03-07 15:06:57 +00:00
|
|
|
|
|
|
|
// Output to filename
|
|
|
|
if (format_->name() == "lyx") {
|
2002-08-12 20:17:41 +00:00
|
|
|
filename = ChangeExtension(buffer()->getLatexName(false),
|
2002-03-07 15:46:34 +00:00
|
|
|
format_->extension());
|
2004-02-25 12:00:53 +00:00
|
|
|
filename = AddName(buffer()->temppath(), filename);
|
2002-03-07 15:46:34 +00:00
|
|
|
|
2004-02-25 12:00:53 +00:00
|
|
|
if (!buffer()->writeFile(filename))
|
|
|
|
return;
|
2002-03-07 15:06:57 +00:00
|
|
|
|
|
|
|
} else {
|
2002-08-12 20:17:41 +00:00
|
|
|
Exporter::Export(buffer(), format_->name(), true, filename);
|
2002-03-21 21:21:28 +00:00
|
|
|
}
|
2002-03-07 15:06:57 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|