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"
16 #include "frontends/LyXView.h"
17 #include "funcrequest.h"
19 #include "bufferlist.h"
20 #include "support/filetools.h"
21 #include "frontends/Alert.h"
23 #include "BufferView.h"
25 #include "BoostFormat.h"
32 extern BufferList bufferlist;
33 extern void InsertAsciiFile(BufferView *, string const &, bool);
36 bool Importer::Import(LyXView * lv, string const & filename,
37 string const & format)
39 string const displaypath = MakeDisplayPath(filename);
42 s1 << boost::format(_("Importing %1$s...")) % displaypath;
44 s1 << _("Importing ") << displaypath << _("...");
46 lv->message(STRCONV(s1.str()));
48 string const lyxfile = ChangeExtension(filename, ".lyx");
51 vector<string> loaders = Loaders();
52 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
53 for (vector<string>::const_iterator it = loaders.begin();
54 it != loaders.end(); ++it) {
55 if (converters.isReachable(format, *it)) {
56 if (!converters.convert(0, filename, filename,
63 if (loader_format.empty()) {
65 Alert::alert(_("Cannot import file"),
66 boost::io::str(boost::format(_("No information for importing from %1$s"))
67 % formats.prettyName(format)));
69 Alert::alert(_("Cannot import file"),
70 _("No information for importing from ")
71 + formats.prettyName(format));
76 loader_format = format;
79 if (loader_format == "lyx") {
80 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
82 lv->view()->buffer(buffer);
84 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
85 bool as_paragraphs = loader_format == "textparagraph";
86 string filename2 = (loader_format == format) ? filename
87 : ChangeExtension(filename,
88 formats.extension(loader_format));
89 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
90 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
94 lv->message(_("imported."));
99 vector<Format const *> const Importer::GetImportableFormats()
101 vector<string> loaders = Loaders();
102 vector<Format const *> result =
103 converters.getReachableTo(loaders[0], true);
104 for (vector<string>::const_iterator it = loaders.begin() + 1;
105 it != loaders.end(); ++it) {
106 vector<Format const *> r =
107 converters.getReachableTo(*it, false);
108 result.insert(result.end(), r.begin(), r.end());
114 vector<string> const Importer::Loaders()
119 v.push_back("textparagraph");