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
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);
41 s1 << _("Importing") << ' ' << displaypath << "...";
42 lv->message(s1.str().c_str());
44 string const lyxfile = ChangeExtension(filename, ".lyx");
47 vector<string> loaders = Loaders();
48 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
49 for (vector<string>::const_iterator it = loaders.begin();
50 it != loaders.end(); ++it) {
51 if (converters.IsReachable(format, *it)) {
52 if (!converters.Convert(0, filename, filename,
59 if (loader_format.empty()) {
60 WriteAlert(_("Can not import file"),
61 _("No information for importing from ")
62 + formats.PrettyName(format));
66 loader_format = format;
69 if (loader_format == "lyx") {
70 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
72 lv->view()->buffer(buffer);
74 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
75 bool as_paragraphs = loader_format == "textparagraph";
76 string filename2 = (loader_format == format) ? filename
77 : ChangeExtension(filename,
78 formats.Extension(loader_format));
79 InsertAsciiFile(lv->view(), filename2, as_paragraphs);
80 lv->getLyXFunc()->Dispatch(LFUN_MARK_OFF);
84 lv->message(_("imported."));
90 bool Importer::IsImportable(string const & format)
92 vector<string> loaders = Loaders();
93 for (vector<string>::const_iterator it = loaders.begin();
94 it != loaders.end(); ++it)
95 if (converters.IsReachable(format, *it))
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");