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"
31 using lyx::support::bformat;
32 using lyx::support::changeExtension;
33 using lyx::support::makeDisplayPath;
40 bool Importer::Import(LyXView * lv, string const & filename,
41 string const & format, ErrorList & errorList)
43 docstring 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,
55 format, *it, errorList))
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->loadLyXFile(lyxfile);
74 Buffer * const b = newFile(lyxfile, string(), true);
79 bool as_paragraphs = loader_format == "textparagraph";
80 string filename2 = (loader_format == format) ? filename
81 : changeExtension(filename,
82 formats.extension(loader_format));
83 insertAsciiFile(lv->view(), filename2, as_paragraphs);
84 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
88 lv->message(_("imported."));
93 vector<Format const *> const Importer::GetImportableFormats()
95 vector<string> loaders = Loaders();
96 vector<Format const *> result =
97 converters.getReachableTo(loaders[0], true);
98 for (vector<string>::const_iterator it = loaders.begin() + 1;
99 it != loaders.end(); ++it) {
100 vector<Format const *> r =
101 converters.getReachableTo(*it, false);
102 result.insert(result.end(), r.begin(), r.end());
108 vector<string> const Importer::Loaders()
113 v.push_back("textparagraph");