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 "bufferlist.h"
23 #include "support/filetools.h"
24 #include "frontends/Alert.h"
26 #include "BufferView.h"
27 #include "buffer_funcs.h"
29 using lyx::support::bformat;
30 using lyx::support::changeExtension;
31 using lyx::support::makeDisplayPath;
38 extern BufferList bufferlist;
41 bool Importer::Import(LyXView * lv, string const & filename,
42 string const & format, ErrorList & errorList)
44 string const displaypath = makeDisplayPath(filename);
45 lv->message(bformat(_("Importing %1$s..."), displaypath));
47 string const lyxfile = changeExtension(filename, ".lyx");
50 vector<string> loaders = Loaders();
51 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
52 for (vector<string>::const_iterator it = loaders.begin();
53 it != loaders.end(); ++it) {
54 if (converters.isReachable(format, *it)) {
55 if (!converters.convert(0, filename, filename,
56 format, *it, errorList))
62 if (loader_format.empty()) {
63 Alert::error(_("Couldn't import file"),
64 bformat(_("No information for importing the format %1$s."),
65 formats.prettyName(format)));
69 loader_format = format;
72 if (loader_format == "lyx") {
73 lv->loadLyXFile(lyxfile);
75 Buffer * const b = newFile(lyxfile, string(), true);
80 bool as_paragraphs = loader_format == "textparagraph";
81 string filename2 = (loader_format == format) ? filename
82 : changeExtension(filename,
83 formats.extension(loader_format));
84 insertAsciiFile(lv->view(), filename2, as_paragraphs);
85 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
89 lv->message(_("imported."));
94 vector<Format const *> const Importer::GetImportableFormats()
96 vector<string> loaders = Loaders();
97 vector<Format const *> result =
98 converters.getReachableTo(loaders[0], true);
99 for (vector<string>::const_iterator it = loaders.begin() + 1;
100 it != loaders.end(); ++it) {
101 vector<Format const *> r =
102 converters.getReachableTo(*it, false);
103 result.insert(result.end(), r.begin(), r.end());
109 vector<string> const Importer::Loaders()
114 v.push_back("textparagraph");