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 "buffer_funcs.h"
22 #include "support/filetools.h"
23 #include "frontends/Alert.h"
25 #include "BufferView.h"
29 using namespace lyx::support;
35 extern BufferList bufferlist;
36 extern void InsertAsciiFile(BufferView *, string const &, bool);
39 bool Importer::Import(LyXView * lv, string const & filename,
40 string const & format)
42 string const displaypath = MakeDisplayPath(filename);
43 lv->message(bformat(_("Importing %1$s..."), displaypath));
45 string const lyxfile = ChangeExtension(filename, ".lyx");
48 vector<string> loaders = Loaders();
49 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
50 for (vector<string>::const_iterator it = loaders.begin();
51 it != loaders.end(); ++it) {
52 if (converters.isReachable(format, *it)) {
53 if (!converters.convert(0, filename, filename,
60 if (loader_format.empty()) {
61 Alert::error(_("Couldn't import file"),
62 bformat(_("No information for importing the format %1$s."),
63 formats.prettyName(format)));
67 loader_format = format;
70 if (loader_format == "lyx") {
71 lv->view()->loadLyXFile(lyxfile);
73 lv->view()->newFile(lyxfile, string(), true);
74 bool as_paragraphs = loader_format == "textparagraph";
75 string filename2 = (loader_format == format) ? filename
76 : ChangeExtension(filename,
77 formats.extension(loader_format));
78 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
79 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
83 lv->message(_("imported."));
88 vector<Format const *> const Importer::GetImportableFormats()
90 vector<string> loaders = Loaders();
91 vector<Format const *> result =
92 converters.getReachableTo(loaders[0], true);
93 for (vector<string>::const_iterator it = loaders.begin() + 1;
94 it != loaders.end(); ++it) {
95 vector<Format const *> r =
96 converters.getReachableTo(*it, false);
97 result.insert(result.end(), r.begin(), r.end());
103 vector<string> const Importer::Loaders()
108 v.push_back("textparagraph");