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"
23 #include "bufferlist.h"
24 #include "support/filetools.h"
25 #include "lyx_gui_misc.h" //WriteAlert
31 extern BufferList bufferlist;
32 extern void InsertAsciiFile(BufferView *, string const &, bool);
35 bool Importer::Import(LyXView * lv, string const & filename,
36 string const & format)
38 string const displaypath = MakeDisplayPath(filename);
39 string const s1 = _("Importing") + ' ' + displaypath + "...";
40 lv->getLyXFunc()->Dispatch(LFUN_MESSAGE, s1);
42 string const lyxfile = ChangeExtension(filename, ".lyx");
45 vector<string> loaders = Loaders();
46 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
47 for (vector<string>::const_iterator it = loaders.begin();
48 it != loaders.end(); ++it) {
49 if (converters.IsReachable(format, *it)) {
50 if (!converters.Convert(0, filename, filename,
57 if (loader_format.empty()) {
58 WriteAlert(_("Can not import file"),
59 _("No information for importing from ")
60 + formats.PrettyName(format));
64 loader_format = format;
67 if (loader_format == "lyx") {
68 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
70 lv->view()->buffer(buffer);
72 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
73 bool as_paragraphs = loader_format == "textparagraph";
74 string filename2 = (loader_format == format) ? filename
75 : ChangeExtension(filename,
76 formats.Extension(loader_format));
77 InsertAsciiFile(lv->view(), filename2, as_paragraphs);
78 lv->getLyXFunc()->Dispatch(LFUN_MARK_OFF);
82 lv->getLyXFunc()->Dispatch(LFUN_MESSAGE, _("imported."));
87 bool Importer::IsImportable(string const & format)
89 vector<string> loaders = Loaders();
90 for (vector<string>::const_iterator it = loaders.begin();
91 it != loaders.end(); ++it)
92 if (converters.IsReachable(format, *it))
98 vector<Format const *> const Importer::GetImportableFormats()
100 vector<string> loaders = Loaders();
101 vector<Format const *> result =
102 converters.GetReachableTo(loaders[0], true);
103 for (vector<string>::const_iterator it = loaders.begin() + 1;
104 it != loaders.end(); ++it) {
105 vector<Format const *> r =
106 converters.GetReachableTo(*it, false);
107 result.insert(result.end(), r.begin(), r.end());
113 vector<string> const Importer::Loaders()
118 v.push_back("textparagraph");