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::makeDisplayPath;
42 bool Importer::Import(LyXView * lv, string const & filename,
43 string const & format, ErrorList & errorList)
45 docstring const displaypath = makeDisplayPath(filename);
46 lv->message(bformat(_("Importing %1$s..."), displaypath));
48 string const lyxfile = changeExtension(filename, ".lyx");
51 vector<string> loaders = Loaders();
52 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
53 for (vector<string>::const_iterator it = loaders.begin();
54 it != loaders.end(); ++it) {
55 if (converters.isReachable(format, *it)) {
56 if (!converters.convert(0, filename, filename,
57 format, *it, errorList))
63 if (loader_format.empty()) {
64 frontend::Alert::error(_("Couldn't import file"),
65 bformat(_("No information for importing the format %1$s."),
66 formats.prettyName(format)));
70 loader_format = format;
74 if (loader_format == "lyx") {
75 lv->loadLyXFile(lyxfile);
77 Buffer * const b = newFile(lyxfile, string(), true);
82 bool as_paragraphs = loader_format == "textparagraph";
83 string filename2 = (loader_format == format) ? filename
84 : changeExtension(filename,
85 formats.extension(loader_format));
86 insertAsciiFile(lv->view(), filename2, as_paragraphs);
87 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
91 lv->message(_("imported."));
96 vector<Format const *> const Importer::GetImportableFormats()
98 vector<string> loaders = Loaders();
99 vector<Format const *> result =
100 converters.getReachableTo(loaders[0], true);
101 for (vector<string>::const_iterator it = loaders.begin() + 1;
102 it != loaders.end(); ++it) {
103 vector<Format const *> r =
104 converters.getReachableTo(*it, false);
105 result.insert(result.end(), r.begin(), r.end());
111 vector<string> const Importer::Loaders()
116 v.push_back("textparagraph");