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
20 #include "converter.h"
24 #include "bufferlist.h"
25 #include "support/filetools.h"
26 #include "lyx_gui_misc.h" //WriteAlert
28 #include "BufferView.h"
33 extern BufferList bufferlist;
34 extern void InsertAsciiFile(BufferView *, string const &, bool);
37 bool Importer::Import(LyXView * lv, string const & filename,
38 string const & format)
40 string const displaypath = MakeDisplayPath(filename);
42 s1 << _("Importing") << ' ' << displaypath << "...";
43 lv->message(s1.str().c_str());
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 WriteAlert(_("Cannot import file"),
62 _("No information for importing from ")
63 + formats.prettyName(format));
67 loader_format = format;
70 if (loader_format == "lyx") {
71 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
73 lv->view()->buffer(buffer);
75 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
76 bool as_paragraphs = loader_format == "textparagraph";
77 string filename2 = (loader_format == format) ? filename
78 : ChangeExtension(filename,
79 formats.extension(loader_format));
80 InsertAsciiFile(lv->view(), filename2, as_paragraphs);
81 lv->getLyXFunc()->dispatch(LFUN_MARK_OFF);
85 lv->message(_("imported."));
91 bool Importer::IsImportable(string const & format)
93 vector<string> loaders = Loaders();
94 for (vector<string>::const_iterator it = loaders.begin();
95 it != loaders.end(); ++it)
96 if (converters.IsReachable(format, *it))
103 vector<Format const *> const Importer::GetImportableFormats()
105 vector<string> loaders = Loaders();
106 vector<Format const *> result =
107 converters.getReachableTo(loaders[0], true);
108 for (vector<string>::const_iterator it = loaders.begin() + 1;
109 it != loaders.end(); ++it) {
110 vector<Format const *> r =
111 converters.getReachableTo(*it, false);
112 result.insert(result.end(), r.begin(), r.end());
118 vector<string> const Importer::Loaders()
123 v.push_back("textparagraph");