2003-03-31 01:15:44 +00:00
|
|
|
|
/**
|
2003-06-28 01:23:11 +00:00
|
|
|
|
* \file importer.C
|
2003-03-31 01:15:44 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-03-31 01:15:44 +00:00
|
|
|
|
* \author unknown
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-03-31 01:15:44 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "importer.h"
|
|
|
|
|
#include "converter.h"
|
2003-02-28 09:49:49 +00:00
|
|
|
|
#include "format.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2002-08-13 17:43:40 +00:00
|
|
|
|
#include "funcrequest.h"
|
2006-04-09 00:26:19 +00:00
|
|
|
|
#include "lyx_cb.h"
|
2001-04-24 17:33:01 +00:00
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
|
#include "support/filetools.h"
|
2006-09-27 10:24:13 +00:00
|
|
|
|
|
2001-11-26 10:19:58 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2006-09-27 10:24:13 +00:00
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "gettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "BufferView.h"
|
2006-07-13 16:37:55 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2000-11-13 10:35:02 +00:00
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
|
using lyx::docstring;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::bformat;
|
2006-04-08 22:31:11 +00:00
|
|
|
|
using lyx::support::changeExtension;
|
|
|
|
|
using lyx::support::makeDisplayPath;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
using std::find;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::vector;
|
2000-10-23 12:16:05 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bool Importer::Import(LyXView * lv, string const & filename,
|
2006-08-13 16:16:43 +00:00
|
|
|
|
string const & format, ErrorList & errorList)
|
2000-10-23 12:16:05 +00:00
|
|
|
|
{
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring const displaypath = makeDisplayPath(filename);
|
|
|
|
|
lv->message(bformat(_("Importing %1$s..."), displaypath));
|
2000-10-23 12:16:05 +00:00
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const lyxfile = changeExtension(filename, ".lyx");
|
2000-10-23 12:16:05 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
string loader_format;
|
|
|
|
|
vector<string> loaders = Loaders();
|
|
|
|
|
if (find(loaders.begin(), loaders.end(), format) == loaders.end()) {
|
|
|
|
|
for (vector<string>::const_iterator it = loaders.begin();
|
|
|
|
|
it != loaders.end(); ++it) {
|
2001-07-30 11:56:00 +00:00
|
|
|
|
if (converters.isReachable(format, *it)) {
|
|
|
|
|
if (!converters.convert(0, filename, filename,
|
2006-08-13 16:16:43 +00:00
|
|
|
|
format, *it, errorList))
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
loader_format = *it;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (loader_format.empty()) {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
Alert::error(_("Couldn't import file"),
|
|
|
|
|
bformat(_("No information for importing the format %1$s."),
|
2006-04-05 23:56:29 +00:00
|
|
|
|
formats.prettyName(format)));
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
loader_format = format;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loader_format == "lyx") {
|
2006-07-13 16:37:55 +00:00
|
|
|
|
lv->loadLyXFile(lyxfile);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
} else {
|
2006-07-17 15:13:49 +00:00
|
|
|
|
Buffer * const b = newFile(lyxfile, string(), true);
|
|
|
|
|
if (b)
|
|
|
|
|
lv->setBuffer(b);
|
|
|
|
|
else
|
|
|
|
|
return false;
|
2000-11-13 10:35:02 +00:00
|
|
|
|
bool as_paragraphs = loader_format == "textparagraph";
|
|
|
|
|
string filename2 = (loader_format == format) ? filename
|
2006-04-08 22:31:11 +00:00
|
|
|
|
: changeExtension(filename,
|
2001-07-30 11:56:00 +00:00
|
|
|
|
formats.extension(loader_format));
|
2006-06-26 16:55:35 +00:00
|
|
|
|
insertAsciiFile(lv->view(), filename2, as_paragraphs);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
lv->dispatch(FuncRequest(LFUN_MARK_OFF));
|
2000-10-23 12:16:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we are done
|
2006-09-11 08:54:10 +00:00
|
|
|
|
lv->message(_("imported."));
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2000-10-23 12:16:05 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
vector<Format const *> const Importer::GetImportableFormats()
|
|
|
|
|
{
|
|
|
|
|
vector<string> loaders = Loaders();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
vector<Format const *> result =
|
2001-07-30 11:56:00 +00:00
|
|
|
|
converters.getReachableTo(loaders[0], true);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
for (vector<string>::const_iterator it = loaders.begin() + 1;
|
|
|
|
|
it != loaders.end(); ++it) {
|
|
|
|
|
vector<Format const *> r =
|
2001-07-30 11:56:00 +00:00
|
|
|
|
converters.getReachableTo(*it, false);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
result.insert(result.end(), r.begin(), r.end());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2000-10-23 12:16:05 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
|
|
|
|
|
vector<string> const Importer::Loaders()
|
2000-10-23 12:16:05 +00:00
|
|
|
|
{
|
2003-01-08 17:23:25 +00:00
|
|
|
|
vector<string> v;
|
2000-11-13 10:35:02 +00:00
|
|
|
|
v.push_back("lyx");
|
|
|
|
|
v.push_back("text");
|
|
|
|
|
v.push_back("textparagraph");
|
|
|
|
|
return v;
|
2000-10-23 12:16:05 +00:00
|
|
|
|
}
|