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
18 #include "converter.h"
20 #include "lyx_cb.h" //ShowMessage()
21 #include "support/filetools.h"
27 bool Exporter::Export(Buffer * buffer, string const & format0,
28 bool put_in_tempdir, string * view_file)
31 string using_format = Converter::SplitFormat(format0, format);
33 string backend_format = (format == "txt")
34 ? format : BufferExtension(buffer);
35 bool only_backend = backend_format == format;
37 string filename = buffer->getLatexName(false);
38 if (!buffer->tmppath.empty())
39 filename = AddName(buffer->tmppath, filename);
40 filename = ChangeExtension(filename, backend_format);
43 if (backend_format == "txt")
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 = (put_in_tempdir)
58 ? ChangeExtension(filename, format)
59 : ChangeExtension(buffer->getLatexName(false), format);
61 if (!Converter::Convert(buffer, filename, outfile, using_format,
67 _("Document exported as ")
68 + Formats::PrettyName(format)
70 + MakeDisplayPath(outfile) +'\'');
75 bool Exporter::Preview(Buffer * buffer, string const & format0)
78 if (!Export(buffer, format0, true, &view_file))
81 return Formats::View(buffer, view_file);
85 vector<pair<string, string> > const
86 Exporter::GetExportableFormats(Buffer const * buffer)
88 vector<pair<string, string> > result =
89 Converter::GetReachable(BufferExtension(buffer), false);
90 result.push_back(pair<string,string>("txt", "Ascii"));
95 vector<pair<string, string> > const
96 Exporter::GetViewableFormats(Buffer const * buffer)
98 vector<pair<string, string> > result =
99 Converter::GetReachable(BufferExtension(buffer), false);
100 Format * format = Formats::GetFormat("txt");
101 if (format && !format->viewer.empty())
102 result.push_back(pair<string,string>("txt", "Ascii"));
107 string const Exporter::BufferExtension(Buffer const * buffer)
109 if (buffer->isLinuxDoc())
111 else if (buffer->isDocBook())