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 #pragma implementation
18 #include "converter.h"
19 #include "frontends/LyXView.h"
20 #include "funcrequest.h"
22 #include "bufferlist.h"
23 #include "support/filetools.h"
24 #include "frontends/Alert.h"
26 #include "BufferView.h"
28 #include "BoostFormat.h"
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);
45 s1 << boost::format(_("Importing %1$s...")) % displaypath;
47 s1 << _("Importing ") << displaypath << _("...");
49 lv->message(STRCONV(s1.str()));
51 string const lyxfile = ChangeExtension(filename, ".lyx");
54 vector<string> loaders = Loaders();
55 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
56 for (vector<string>::const_iterator it = loaders.begin();
57 it != loaders.end(); ++it) {
58 if (converters.isReachable(format, *it)) {
59 if (!converters.convert(0, filename, filename,
66 if (loader_format.empty()) {
68 Alert::alert(_("Cannot import file"),
69 boost::io::str(boost::format(_("No information for importing from %1$s"))
70 % formats.prettyName(format)));
72 Alert::alert(_("Cannot import file"),
73 _("No information for importing from ")
74 + formats.prettyName(format));
79 loader_format = format;
82 if (loader_format == "lyx") {
83 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
85 lv->view()->buffer(buffer);
87 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
88 bool as_paragraphs = loader_format == "textparagraph";
89 string filename2 = (loader_format == format) ? filename
90 : ChangeExtension(filename,
91 formats.extension(loader_format));
92 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
93 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
97 lv->message(_("imported."));
102 vector<Format const *> const Importer::GetImportableFormats()
104 vector<string> loaders = Loaders();
105 vector<Format const *> result =
106 converters.getReachableTo(loaders[0], true);
107 for (vector<string>::const_iterator it = loaders.begin() + 1;
108 it != loaders.end(); ++it) {
109 vector<Format const *> r =
110 converters.getReachableTo(*it, false);
111 result.insert(result.end(), r.begin(), r.end());
117 vector<string> const Importer::Loaders()
122 v.push_back("textparagraph");