]> git.lyx.org Git - lyx.git/blob - src/importer.C
Dekel's import/export patch
[lyx.git] / src / importer.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *        
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "importer.h"
18 #include "converter.h"
19 #include "LyXView.h"
20 #include "lyxfunc.h"
21 #include "minibuffer.h"
22 #include "bufferlist.h"
23 #include "support/filetools.h"
24
25 extern BufferList bufferlist;
26 extern void InsertAsciiFile(BufferView *, string const &, bool);
27
28
29 void Importer::Import(LyXView * lv, string const & filename, 
30                       string const & format)
31 {
32         string displaypath = MakeDisplayPath(filename);
33         lv->getMiniBuffer()->Set(_("Importing"), displaypath, "...");
34
35         string lyxfile = ChangeExtension(filename, ".lyx");
36
37         bool result = true;
38         if (format == "text" || format == "textparagraph") {
39                 lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
40                 bool as_paragraphs = format == "textparagraph";
41                 InsertAsciiFile(lv->view(), filename, as_paragraphs);
42                 lv->getLyXFunc()->Dispatch(LFUN_MARK_OFF);
43         } else {
44                 result = Converter::Convert(0, filename, filename, format, "lyx");
45                 if (result) {
46                         Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
47                         if (buffer)
48                                 lv->view()->buffer(buffer);
49                         else
50                                 result = false;
51                 }
52         }
53
54         // we are done
55         if (result)
56                 lv->getMiniBuffer()->Set(displaypath, _("imported."));
57         else
58                 lv->getMiniBuffer()->Set(displaypath, _(": import failed."));
59
60 }
61
62
63 bool Importer::IsImportable(string const & format)
64 {
65         if (format == "text" || format == "textparagraph")
66                 return true;
67         else
68                 return Converter::IsReachable(format, "lyx");
69 }