3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
16 #include "Converter.h"
18 #include "frontends/LyXView.h"
19 #include "FuncRequest.h"
22 #include "support/filetools.h"
24 #include "frontends/alert.h"
27 #include "BufferView.h"
28 #include "buffer_funcs.h"
37 using support::bformat;
38 using support::changeExtension;
39 using support::FileName;
40 using support::makeDisplayPath;
41 using frontend::LyXView;
44 bool Importer::Import(LyXView * lv, FileName const & filename,
45 string const & format, ErrorList & errorList)
47 docstring const displaypath = makeDisplayPath(filename.absFilename());
48 lv->message(bformat(_("Importing %1$s..."), displaypath));
50 FileName const lyxfile(changeExtension(filename.absFilename(), ".lyx"));
53 vector<string> loaders = Loaders();
54 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
55 for (vector<string>::const_iterator it = loaders.begin();
56 it != loaders.end(); ++it) {
57 if (theConverters().isReachable(format, *it)) {
59 changeExtension(filename.absFilename(),
60 formats.extension(*it));
61 if (!theConverters().convert(0, filename, FileName(tofile),
62 filename, format, *it, errorList))
68 if (loader_format.empty()) {
69 frontend::Alert::error(_("Couldn't import file"),
70 bformat(_("No information for importing the format %1$s."),
71 formats.prettyName(format)));
75 loader_format = format;
79 if (loader_format == "lyx") {
80 Buffer * buf = lv->loadLyXFile(lyxfile);
83 lv->message(_("file not imported!"));
88 lv->showErrorList("Parse");
90 Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
95 bool as_paragraphs = loader_format == "textparagraph";
96 string filename2 = (loader_format == format) ? filename.absFilename()
97 : changeExtension(filename.absFilename(),
98 formats.extension(loader_format));
99 insertPlaintextFile(lv->view(), filename2, as_paragraphs);
100 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
104 lv->message(_("imported."));
109 vector<Format const *> const Importer::GetImportableFormats()
111 vector<string> loaders = Loaders();
112 vector<Format const *> result =
113 theConverters().getReachableTo(loaders[0], true);
114 for (vector<string>::const_iterator it = loaders.begin() + 1;
115 it != loaders.end(); ++it) {
116 vector<Format const *> r =
117 theConverters().getReachableTo(*it, false);
118 result.insert(result.end(), r.begin(), r.end());
124 vector<string> const Importer::Loaders()
129 v.push_back("textparagraph");