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"
33 using support::bformat;
34 using support::changeExtension;
35 using support::FileName;
36 using support::makeDisplayPath;
43 bool Importer::Import(LyXView * lv, string const & filename,
44 string const & format, ErrorList & errorList)
46 docstring const displaypath = makeDisplayPath(filename);
47 lv->message(bformat(_("Importing %1$s..."), displaypath));
49 string const lyxfile = changeExtension(filename, ".lyx");
52 vector<string> loaders = Loaders();
53 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
54 for (vector<string>::const_iterator it = loaders.begin();
55 it != loaders.end(); ++it) {
56 if (converters.isReachable(format, *it)) {
58 changeExtension(filename,
59 formats.extension(*it));
60 if (!converters.convert(0, FileName(filename), FileName(tofile),
61 FileName(filename), format, *it, errorList))
67 if (loader_format.empty()) {
68 frontend::Alert::error(_("Couldn't import file"),
69 bformat(_("No information for importing the format %1$s."),
70 formats.prettyName(format)));
74 loader_format = format;
78 if (loader_format == "lyx") {
79 lv->loadLyXFile(lyxfile);
81 Buffer * const b = newFile(lyxfile, string(), true);
86 bool as_paragraphs = loader_format == "textparagraph";
87 string filename2 = (loader_format == format) ? filename
88 : changeExtension(filename,
89 formats.extension(loader_format));
90 insertAsciiFile(lv->view(), filename2, as_paragraphs);
91 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
95 lv->message(_("imported."));
100 vector<Format const *> const Importer::GetImportableFormats()
102 vector<string> loaders = Loaders();
103 vector<Format const *> result =
104 converters.getReachableTo(loaders[0], true);
105 for (vector<string>::const_iterator it = loaders.begin() + 1;
106 it != loaders.end(); ++it) {
107 vector<Format const *> r =
108 converters.getReachableTo(*it, false);
109 result.insert(result.end(), r.begin(), r.end());
115 vector<string> const Importer::Loaders()
120 v.push_back("textparagraph");