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 "minibuffer.h"
24 #include "bufferlist.h"
25 #include "support/filetools.h"
26 #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 displaypath = MakeDisplayPath(filename);
39 lv->getMiniBuffer()->Set(_("Importing"), displaypath, "...");
41 string lyxfile = ChangeExtension(filename, ".lyx");
44 vector<string> loaders = Loaders();
45 if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
46 for (vector<string>::const_iterator it = loaders.begin();
47 it != loaders.end(); ++it) {
48 if (converters.IsReachable(format, *it)) {
49 if (!converters.Convert(0, filename, filename,
56 if (loader_format.empty()) {
57 WriteAlert(_("Can not import file"),
58 _("No information for importing from ")
59 + formats.PrettyName(format));
63 loader_format = format;
66 if (loader_format == "lyx") {
67 Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
69 lv->view()->buffer(buffer);
71 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
72 bool as_paragraphs = loader_format == "textparagraph";
73 string filename2 = (loader_format == format) ? filename
74 : ChangeExtension(filename,
75 formats.Extension(loader_format));
76 InsertAsciiFile(lv->view(), filename2, as_paragraphs);
77 lv->getLyXFunc()->Dispatch(LFUN_MARK_OFF);
81 lv->getMiniBuffer()->Set(displaypath, _("imported."));
86 bool Importer::IsImportable(string const & format)
88 vector<string> loaders = Loaders();
89 for (vector<string>::const_iterator it = loaders.begin();
90 it != loaders.end(); ++it)
91 if (converters.IsReachable(format, *it))
97 vector<Format const *> const Importer::GetImportableFormats()
99 vector<string> loaders = Loaders();
100 vector<Format const *> result =
101 converters.GetReachableTo(loaders[0], true);
102 for (vector<string>::const_iterator it = loaders.begin() + 1;
103 it != loaders.end(); ++it) {
104 vector<Format const *> r =
105 converters.GetReachableTo(*it, false);
106 result.insert(result.end(), r.begin(), r.end());
112 vector<string> const Importer::Loaders()
117 v.push_back("textparagraph");