1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
19 #include "lyx_cb.h" //ShowMessage()
20 #include "support/filetools.h"
22 #include "converter.h"
26 bool Exporter::Export(Buffer * buffer, string const & format0,
27 bool put_in_tempdir, string & result_file)
30 string using_format = Converter::SplitFormat(format0, format);
32 string backend_format = (format == "text")
33 ? format : BufferFormat(buffer);
34 bool only_backend = backend_format == format;
36 string filename = buffer->getLatexName(false);
37 if (!buffer->tmppath.empty())
38 filename = AddName(buffer->tmppath, filename);
39 filename = ChangeExtension(filename,
40 formats.Extension(backend_format));
43 if (backend_format == "text")
44 buffer->writeFileAscii(filename, lyxrc.ascii_linelen);
46 else if (buffer->isLinuxDoc())
47 buffer->makeLinuxDocFile(filename, true);
49 else if (buffer->isDocBook())
50 buffer->makeDocBookFile(filename, true);
52 else if (only_backend)
53 buffer->makeLaTeXFile(filename, string(), true);
55 buffer->makeLaTeXFile(filename, buffer->filepath, false);
57 string outfile_base = (put_in_tempdir)
58 ? filename : buffer->getLatexName(false);
60 if (!Converter::Convert(buffer, filename, outfile_base,
61 backend_format, format, using_format,
67 _("Document exported as ")
68 + formats.PrettyName(format)
70 + MakeDisplayPath(result_file) +'\'');
74 bool Exporter::Export(Buffer * buffer, string const & format,
78 return Export(buffer, format, put_in_tempdir, result_file);
81 bool Exporter::Preview(Buffer * buffer, string const & format0)
84 if (!Export(buffer, format0, true, result_file))
87 Converter::SplitFormat(format0, format);
88 return formats.View(buffer, result_file, format);
92 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
94 return format == "text" ||
95 Converter::IsReachable(BufferFormat(buffer), format);
99 vector<FormatPair> const
100 Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
102 vector<FormatPair> result =
103 Converter::GetReachable(BufferFormat(buffer), only_viewable);
104 Format * format = formats.GetFormat("text");
105 if (format && (!only_viewable || !format->viewer.empty()))
106 result.push_back(FormatPair(format , 0, ""));
111 string const Exporter::BufferFormat(Buffer const * buffer)
113 if (buffer->isLinuxDoc())
115 else if (buffer->isDocBook())
117 else if (buffer->isLiterate())