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."));
88 bool Importer::IsImportable(string const & format)
90 vector<string> loaders = Loaders();
91 for (vector<string>::const_iterator it = loaders.begin();
92 it != loaders.end(); ++it)
93 if (converters.IsReachable(format, *it))
99 vector<Format const *> const Importer::GetImportableFormats()
101 vector<string> loaders = Loaders();
102 vector<Format const *> result =
103 converters.GetReachableTo(loaders[0], true);
104 for (vector<string>::const_iterator it = loaders.begin() + 1;
105 it != loaders.end(); ++it) {
106 vector<Format const *> r =
107 converters.GetReachableTo(*it, false);
108 result.insert(result.end(), r.begin(), r.end());
114 vector<string> const Importer::Loaders()
119 v.push_back("textparagraph");