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"
21 #include "bufferlist.h"
22 #include "support/filetools.h"
23 #include "frontends/Alert.h"
25 #include "BufferView.h"
27 using namespace lyx::support;
33 extern BufferList bufferlist;
34 extern void InsertAsciiFile(BufferView *, string const &, bool);
37 bool Importer::Import(LyXView * lv, string const & filename,
38 string const & format)
40 string const displaypath = MakeDisplayPath(filename);
41 lv->message(bformat(_("Importing %1$s..."), displaypath));
43 string const lyxfile = ChangeExtension(filename, ".lyx");
46 vector<string> loaders = Loaders();
47 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
48 for (vector<string>::const_iterator it = loaders.begin();
49 it != loaders.end(); ++it) {
50 if (converters.isReachable(format, *it)) {
51 if (!converters.convert(0, filename, filename,
58 if (loader_format.empty()) {
59 Alert::error(_("Couldn't import file"),
60 bformat(_("No information for importing the format %1$s."),
61 formats.prettyName(format)));
65 loader_format = format;
68 if (loader_format == "lyx") {
69 lv->view()->loadLyXFile(lyxfile);
71 lv->view()->newFile(lyxfile, string(), true);
72 bool as_paragraphs = loader_format == "textparagraph";
73 string filename2 = (loader_format == format) ? filename
74 : ChangeExtension(filename,
75 formats.extension(loader_format));
76 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
77 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
81 lv->message(_("imported."));
86 vector<Format const *> const Importer::GetImportableFormats()
88 vector<string> loaders = Loaders();
89 vector<Format const *> result =
90 converters.getReachableTo(loaders[0], true);
91 for (vector<string>::const_iterator it = loaders.begin() + 1;
92 it != loaders.end(); ++it) {
93 vector<Format const *> r =
94 converters.getReachableTo(*it, false);
95 result.insert(result.end(), r.begin(), r.end());
101 vector<string> const Importer::Loaders()
106 v.push_back("textparagraph");