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);
44 s1 << boost::format(_("Importing %1$s...")) % 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()) {
63 Alert::alert(_("Cannot import file"),
64 boost::io::str(boost::format(_("No information for importing from %1$s"))
65 % formats.prettyName(format)));
69 loader_format = format;
72 if (loader_format == "lyx") {
73 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
75 lv->view()->buffer(buffer);
77 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
78 bool as_paragraphs = loader_format == "textparagraph";
79 string filename2 = (loader_format == format) ? filename
80 : ChangeExtension(filename,
81 formats.extension(loader_format));
82 InsertAsciiFile(lv->view().get(), filename2, as_paragraphs);
83 lv->dispatch(FuncRequest(LFUN_MARK_OFF));
87 lv->message(_("imported."));
92 vector<Format const *> const Importer::GetImportableFormats()
94 vector<string> loaders = Loaders();
95 vector<Format const *> result =
96 converters.getReachableTo(loaders[0], true);
97 for (vector<string>::const_iterator it = loaders.begin() + 1;
98 it != loaders.end(); ++it) {
99 vector<Format const *> r =
100 converters.getReachableTo(*it, false);
101 result.insert(result.end(), r.begin(), r.end());
107 vector<string> const Importer::Loaders()
112 v.push_back("textparagraph");