1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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);
40 string const s1 = _("Importing") + ' ' + displaypath + "...";
43 string const lyxfile = ChangeExtension(filename, ".lyx");
46 vector<string> loaders = Loaders();
47 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
48 for (vector<string>::const_iterator it = loaders.begin();
49 it != loaders.end(); ++it) {
50 if (converters.IsReachable(format, *it)) {
51 if (!converters.Convert(0, filename, filename,
58 if (loader_format.empty()) {
59 WriteAlert(_("Can not import file"),
60 _("No information for importing from ")
61 + formats.PrettyName(format));
65 loader_format = format;
68 if (loader_format == "lyx") {
69 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
71 lv->view()->buffer(buffer);
73 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
74 bool as_paragraphs = loader_format == "textparagraph";
75 string filename2 = (loader_format == format) ? filename
76 : ChangeExtension(filename,
77 formats.Extension(loader_format));
78 InsertAsciiFile(lv->view(), filename2, as_paragraphs);
79 lv->getLyXFunc()->Dispatch(LFUN_MARK_OFF);
83 lv->message(_("imported."));
89 bool Importer::IsImportable(string const & format)
91 vector<string> loaders = Loaders();
92 for (vector<string>::const_iterator it = loaders.begin();
93 it != loaders.end(); ++it)
94 if (converters.IsReachable(format, *it))
101 vector<Format const *> const Importer::GetImportableFormats()
103 vector<string> loaders = Loaders();
104 vector<Format const *> result =
105 converters.GetReachableTo(loaders[0], true);
106 for (vector<string>::const_iterator it = loaders.begin() + 1;
107 it != loaders.end(); ++it) {
108 vector<Format const *> r =
109 converters.GetReachableTo(*it, false);
110 result.insert(result.end(), r.begin(), r.end());
116 vector<string> const Importer::Loaders()
121 v.push_back("textparagraph");