1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #include "converter.h"
15 #include "frontends/LyXView.h"
16 #include "funcrequest.h"
18 #include "bufferlist.h"
19 #include "support/filetools.h"
20 #include "frontends/Alert.h"
22 #include "BufferView.h"
24 #include "BoostFormat.h"
31 extern BufferList bufferlist;
32 extern void InsertAsciiFile(BufferView *, string const &, bool);
35 bool Importer::Import(LyXView * lv, string const & filename,
36 string const & format)
38 string const displaypath = MakeDisplayPath(filename);
41 s1 << boost::format(_("Importing %1$s...")) % displaypath;
43 s1 << _("Importing ") << displaypath << _("...");
45 lv->message(STRCONV(s1.str()));
47 string const lyxfile = ChangeExtension(filename, ".lyx");
50 vector<string> loaders = Loaders();
51 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
52 for (vector<string>::const_iterator it = loaders.begin();
53 it != loaders.end(); ++it) {
54 if (converters.isReachable(format, *it)) {
55 if (!converters.convert(0, filename, filename,
62 if (loader_format.empty()) {
64 Alert::alert(_("Cannot import file"),
65 boost::io::str(boost::format(_("No information for importing from %1$s"))
66 % formats.prettyName(format)));
68 Alert::alert(_("Cannot import file"),
69 _("No information for importing from ")
70 + formats.prettyName(format));
75 loader_format = format;
78 if (loader_format == "lyx") {
79 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
81 lv->view()->buffer(buffer);
83 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
84 bool as_paragraphs = loader_format == "textparagraph";
85 string filename2 = (loader_format == format) ? filename
86 : ChangeExtension(filename,
87 formats.extension(loader_format));
88 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
89 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
93 lv->message(_("imported."));
98 vector<Format const *> const Importer::GetImportableFormats()
100 vector<string> loaders = Loaders();
101 vector<Format const *> result =
102 converters.getReachableTo(loaders[0], true);
103 for (vector<string>::const_iterator it = loaders.begin() + 1;
104 it != loaders.end(); ++it) {
105 vector<Format const *> r =
106 converters.getReachableTo(*it, false);
107 result.insert(result.end(), r.begin(), r.end());
113 vector<string> const Importer::Loaders()
118 v.push_back("textparagraph");