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 lyx::support::bformat;
28 using lyx::support::ChangeExtension;
29 using lyx::support::MakeDisplayPath;
36 extern BufferList bufferlist;
37 extern void InsertAsciiFile(BufferView *, string const &, bool);
40 bool Importer::Import(LyXView * lv, string const & filename,
41 string const & format)
43 string const displaypath = MakeDisplayPath(filename);
44 lv->message(bformat(_("Importing %1$s..."), displaypath));
46 string const lyxfile = ChangeExtension(filename, ".lyx");
49 vector<string> loaders = Loaders();
50 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
51 for (vector<string>::const_iterator it = loaders.begin();
52 it != loaders.end(); ++it) {
53 if (converters.isReachable(format, *it)) {
54 if (!converters.convert(0, filename, filename,
61 if (loader_format.empty()) {
62 Alert::error(_("Couldn't import file"),
63 bformat(_("No information for importing the format %1$s."),
64 formats.prettyName(format)));
68 loader_format = format;
71 if (loader_format == "lyx") {
72 lv->view()->loadLyXFile(lyxfile);
74 lv->view()->newFile(lyxfile, string(), true);
75 bool as_paragraphs = loader_format == "textparagraph";
76 string filename2 = (loader_format == format) ? filename
77 : ChangeExtension(filename,
78 formats.extension(loader_format));
79 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
80 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
84 lv->message(_("imported."));
89 vector<Format const *> const Importer::GetImportableFormats()
91 vector<string> loaders = Loaders();
92 vector<Format const *> result =
93 converters.getReachableTo(loaders[0], true);
94 for (vector<string>::const_iterator it = loaders.begin() + 1;
95 it != loaders.end(); ++it) {
96 vector<Format const *> r =
97 converters.getReachableTo(*it, false);
98 result.insert(result.end(), r.begin(), r.end());
104 vector<string> const Importer::Loaders()
109 v.push_back("textparagraph");