2000-08-30 03:40:51 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "exporter.h"
|
|
|
|
#include "converter.h"
|
|
|
|
#include "buffer.h"
|
2000-09-05 13:16:19 +00:00
|
|
|
#include "lyx_cb.h" //ShowMessage()
|
|
|
|
#include "support/filetools.h"
|
2000-09-11 15:42:17 +00:00
|
|
|
#include "lyxrc.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::pair;
|
|
|
|
|
|
|
|
bool Exporter::Export(Buffer * buffer, string const & format0,
|
2000-09-11 15:42:17 +00:00
|
|
|
bool put_in_tempdir, string * view_file)
|
2000-08-30 03:40:51 +00:00
|
|
|
{
|
2000-08-30 04:38:32 +00:00
|
|
|
string format;
|
|
|
|
string using_format = Converter::SplitFormat(format0, format);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
2000-09-11 15:42:17 +00:00
|
|
|
string backend_format = (format == "txt")
|
|
|
|
? format : BufferExtension(buffer);
|
2000-08-30 03:40:51 +00:00
|
|
|
bool only_backend = backend_format == format;
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
string filename = buffer->getLatexName(false);
|
2000-08-30 03:40:51 +00:00
|
|
|
if (!buffer->tmppath.empty())
|
2000-09-05 13:16:19 +00:00
|
|
|
filename = AddName(buffer->tmppath, filename);
|
|
|
|
filename = ChangeExtension(filename, backend_format);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
2000-09-11 15:42:17 +00:00
|
|
|
// Ascii backend
|
|
|
|
if (backend_format == "txt")
|
|
|
|
buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
|
|
|
|
// Linuxdoc backend
|
|
|
|
else if (buffer->isLinuxDoc())
|
|
|
|
buffer->makeLinuxDocFile(filename, true);
|
|
|
|
// Docbook backend
|
|
|
|
else if (buffer->isDocBook())
|
|
|
|
buffer->makeDocBookFile(filename, true);
|
|
|
|
// LaTeX backend
|
2000-08-30 03:40:51 +00:00
|
|
|
else if (only_backend)
|
2000-09-05 13:16:19 +00:00
|
|
|
buffer->makeLaTeXFile(filename, string(), true);
|
2000-08-30 03:40:51 +00:00
|
|
|
else
|
2000-09-05 13:16:19 +00:00
|
|
|
buffer->makeLaTeXFile(filename, buffer->filepath, false);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
string outfile = (put_in_tempdir)
|
|
|
|
? ChangeExtension(filename, format)
|
|
|
|
: ChangeExtension(buffer->getLatexName(false), format);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
2000-09-11 15:42:17 +00:00
|
|
|
if (!Converter::Convert(buffer, filename, outfile, using_format,
|
|
|
|
view_file))
|
2000-09-05 13:16:19 +00:00
|
|
|
return false;
|
2000-08-30 03:40:51 +00:00
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
if (!put_in_tempdir)
|
2000-08-30 03:40:51 +00:00
|
|
|
ShowMessage(buffer,
|
|
|
|
_("Document exported as ")
|
|
|
|
+ Formats::PrettyName(format)
|
|
|
|
+ _(" to file `")
|
|
|
|
+ MakeDisplayPath(outfile) +'\'');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Exporter::Preview(Buffer * buffer, string const & format0)
|
|
|
|
{
|
2000-09-11 15:42:17 +00:00
|
|
|
string view_file;
|
|
|
|
if (!Export(buffer, format0, true, &view_file))
|
2000-08-30 03:40:51 +00:00
|
|
|
return false;
|
|
|
|
|
2000-09-11 15:42:17 +00:00
|
|
|
return Formats::View(buffer, view_file);
|
2000-08-30 03:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-02 16:44:47 +00:00
|
|
|
bool Exporter::IsExportable(Buffer const * buffer, string const & format)
|
|
|
|
{
|
2000-10-03 18:38:10 +00:00
|
|
|
#warning This is not efficient (Dekel)
|
2000-10-02 16:44:47 +00:00
|
|
|
vector<pair<string, string> > const v = GetExportableFormats(buffer);
|
|
|
|
for (vector<pair<string, string> >::const_iterator it = v.begin();
|
2000-10-03 18:38:10 +00:00
|
|
|
it != v.end(); ++it) {
|
|
|
|
string format2;
|
|
|
|
split((*it).first, format2, ':');
|
|
|
|
if (format == format2)
|
2000-10-02 16:44:47 +00:00
|
|
|
return true;
|
2000-10-03 18:38:10 +00:00
|
|
|
}
|
2000-10-02 16:44:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
vector<pair<string, string> > const
|
|
|
|
Exporter::GetExportableFormats(Buffer const * buffer)
|
2000-08-30 03:40:51 +00:00
|
|
|
{
|
2000-09-11 15:42:17 +00:00
|
|
|
vector<pair<string, string> > result =
|
|
|
|
Converter::GetReachable(BufferExtension(buffer), false);
|
|
|
|
result.push_back(pair<string,string>("txt", "Ascii"));
|
|
|
|
return result;
|
2000-08-30 03:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
vector<pair<string, string> > const
|
|
|
|
Exporter::GetViewableFormats(Buffer const * buffer)
|
2000-08-30 03:40:51 +00:00
|
|
|
{
|
2000-09-11 15:42:17 +00:00
|
|
|
vector<pair<string, string> > result =
|
2000-10-02 16:44:47 +00:00
|
|
|
Converter::GetReachable(BufferExtension(buffer), true);
|
2000-09-11 15:42:17 +00:00
|
|
|
Format * format = Formats::GetFormat("txt");
|
|
|
|
if (format && !format->viewer.empty())
|
|
|
|
result.push_back(pair<string,string>("txt", "Ascii"));
|
|
|
|
return result;
|
2000-08-30 03:40:51 +00:00
|
|
|
}
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
|
|
|
|
string const Exporter::BufferExtension(Buffer const * buffer)
|
2000-08-30 03:40:51 +00:00
|
|
|
{
|
|
|
|
if (buffer->isLinuxDoc())
|
|
|
|
return "sgml";
|
2000-09-11 15:42:17 +00:00
|
|
|
else if (buffer->isDocBook())
|
|
|
|
return "docbook";
|
2000-10-02 16:44:47 +00:00
|
|
|
else if (buffer->isLiterate())
|
|
|
|
return lyxrc.literate_extension;
|
2000-08-30 03:40:51 +00:00
|
|
|
else
|
|
|
|
return "tex";
|
|
|
|
}
|