3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
15 #include "converter.h"
17 #include "frontends/LyXView.h"
18 #include "funcrequest.h"
20 #include "bufferlist.h"
21 #include "support/filetools.h"
22 #include "frontends/Alert.h"
24 #include "BufferView.h"
26 #include "support/BoostFormat.h"
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);
43 s1 << boost::format(_("Importing %1$s...")) % displaypath;
45 s1 << _("Importing ") << displaypath << _("...");
47 lv->message(STRCONV(s1.str()));
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)) {
57 if (!converters.convert(0, filename, filename,
64 if (loader_format.empty()) {
66 // FIXME: better english ...
67 Alert::error(_("Couldn't import file"),
68 boost::io::str(boost::format(_("No information for importing the format %1$s."))
69 % formats.prettyName(format)));
71 Alert::error(_("Couldn't import file"),
72 _("No information for importing the format ")
73 + formats.prettyName(format) + ".");
78 loader_format = format;
81 if (loader_format == "lyx") {
82 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
84 lv->view()->buffer(buffer);
86 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
87 bool as_paragraphs = loader_format == "textparagraph";
88 string filename2 = (loader_format == format) ? filename
89 : ChangeExtension(filename,
90 formats.extension(loader_format));
91 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
92 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
96 lv->message(_("imported."));
101 vector<Format const *> const Importer::GetImportableFormats()
103 vector<string> loaders = Loaders();
104 vector<Format const *> result =
105 converters.getReachableTo(loaders[0], true);
106 for (vector<string>::const_iterator it = loaders.begin() + 1;
107 it != loaders.end(); ++it) {
108 vector<Format const *> r =
109 converters.getReachableTo(*it, false);
110 result.insert(result.end(), r.begin(), r.end());
116 vector<string> const Importer::Loaders()
121 v.push_back("textparagraph");