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 bool Exporter::IsExportable(Buffer const * buffer, string const & format)
87 // This is not efficient (Dekel)
88 vector<pair<string, string> > const v = GetExportableFormats(buffer);
89 for (vector<pair<string, string> >::const_iterator it = v.begin();
90 it != v.end(); ++it) {
92 split((*it).first, format2, ':');
93 if (format == format2)
100 vector<pair<string, string> > const
101 Exporter::GetExportableFormats(Buffer const * buffer)
103 vector<pair<string, string> > result =
104 Converter::GetReachable(BufferExtension(buffer), false);
105 result.push_back(pair<string,string>("txt", "Ascii"));
110 vector<pair<string, string> > const
111 Exporter::GetViewableFormats(Buffer const * buffer)
113 vector<pair<string, string> > result =
114 Converter::GetReachable(BufferExtension(buffer), true);
115 Format * format = Formats::GetFormat("txt");
116 if (format && !format->viewer.empty())
117 result.push_back(pair<string,string>("txt", "Ascii"));
122 string const Exporter::BufferExtension(Buffer const * buffer)
124 if (buffer->isLinuxDoc())
126 else if (buffer->isDocBook())
128 else if (buffer->isLiterate())
129 return lyxrc.literate_extension;