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 "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-10-16 13:27:56 +00:00
|
|
|
#include "converter.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
bool Exporter::Export(Buffer * buffer, string const & format0,
|
2000-10-23 12:16:05 +00:00
|
|
|
bool put_in_tempdir, string & result_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-10-23 12:16:05 +00:00
|
|
|
string backend_format = (format == "text")
|
|
|
|
? format : BufferFormat(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);
|
2000-10-23 12:16:05 +00:00
|
|
|
filename = ChangeExtension(filename,
|
2000-11-06 11:20:22 +00:00
|
|
|
formats.Extension(backend_format));
|
2000-08-30 03:40:51 +00:00
|
|
|
|
2000-09-11 15:42:17 +00:00
|
|
|
// Ascii backend
|
2000-10-23 12:16:05 +00:00
|
|
|
if (backend_format == "text")
|
2000-09-11 15:42:17 +00:00
|
|
|
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-10-23 12:16:05 +00:00
|
|
|
string outfile_base = (put_in_tempdir)
|
|
|
|
? filename : buffer->getLatexName(false);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
if (!Converter::Convert(buffer, filename, outfile_base,
|
|
|
|
backend_format, format, using_format,
|
|
|
|
result_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 ")
|
2000-11-06 11:20:22 +00:00
|
|
|
+ formats.PrettyName(format)
|
2000-08-30 03:40:51 +00:00
|
|
|
+ _(" to file `")
|
2000-10-23 12:16:05 +00:00
|
|
|
+ MakeDisplayPath(result_file) +'\'');
|
2000-08-30 03:40:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
bool Exporter::Export(Buffer * buffer, string const & format,
|
|
|
|
bool put_in_tempdir)
|
|
|
|
{
|
|
|
|
string result_file;
|
|
|
|
return Export(buffer, format, put_in_tempdir, result_file);
|
|
|
|
}
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
|
|
bool Exporter::Preview(Buffer * buffer, string const & format0)
|
|
|
|
{
|
2000-10-23 12:16:05 +00:00
|
|
|
string result_file;
|
|
|
|
if (!Export(buffer, format0, true, result_file))
|
2000-08-30 03:40:51 +00:00
|
|
|
return false;
|
2000-10-23 12:16:05 +00:00
|
|
|
string format;
|
|
|
|
Converter::SplitFormat(format0, format);
|
2000-11-06 11:20:22 +00:00
|
|
|
return formats.View(buffer, result_file, format);
|
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-23 12:16:05 +00:00
|
|
|
return format == "text" ||
|
|
|
|
Converter::IsReachable(BufferFormat(buffer), format);
|
2000-10-02 16:44:47 +00:00
|
|
|
}
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
2000-10-16 13:27:56 +00:00
|
|
|
vector<FormatPair> const
|
2000-11-06 11:20:22 +00:00
|
|
|
Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
|
2000-08-30 03:40:51 +00:00
|
|
|
{
|
2000-10-16 13:27:56 +00:00
|
|
|
vector<FormatPair> result =
|
2000-11-06 11:20:22 +00:00
|
|
|
Converter::GetReachable(BufferFormat(buffer), only_viewable);
|
|
|
|
Format * format = formats.GetFormat("text");
|
|
|
|
if (format && (!only_viewable || !format->viewer.empty()))
|
2000-10-16 13:27:56 +00:00
|
|
|
result.push_back(FormatPair(format , 0, ""));
|
2000-09-11 15:42:17 +00:00
|
|
|
return result;
|
2000-08-30 03:40:51 +00:00
|
|
|
}
|
|
|
|
|
2000-08-30 04:38:32 +00:00
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
string const Exporter::BufferFormat(Buffer const * buffer)
|
2000-08-30 03:40:51 +00:00
|
|
|
{
|
|
|
|
if (buffer->isLinuxDoc())
|
2000-10-23 12:16:05 +00:00
|
|
|
return "linuxdoc";
|
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())
|
2000-10-23 12:16:05 +00:00
|
|
|
return "literate";
|
2000-08-30 03:40:51 +00:00
|
|
|
else
|
2000-10-23 12:16:05 +00:00
|
|
|
return "latex";
|
2000-08-30 03:40:51 +00:00
|
|
|
}
|