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-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
|
|
|
|
using support::changeExtension;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using 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
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
bool Importer::Import(LyXView * lv, FileName const & filename,
|
2006-08-13 16:16:43 +00:00
|
|
|
|
string const & format, ErrorList & errorList)
|
2000-10-23 12:16:05 +00:00
|
|
|
|
{
|
2006-12-02 16:07:15 +00:00
|
|
|
|
docstring const displaypath = makeDisplayPath(filename.absFilename());
|
2006-09-11 08:54:10 +00:00
|
|
|
|
lv->message(bformat(_("Importing %1$s..."), displaypath));
|
2000-10-23 12:16:05 +00:00
|
|
|
|
|
2006-12-02 16:07:15 +00:00
|
|
|
|
FileName const lyxfile(changeExtension(filename.absFilename(), ".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) {
|
2007-01-17 13:18:16 +00:00
|
|
|
|
if (theConverters().isReachable(format, *it)) {
|
2006-11-13 10:27:57 +00:00
|
|
|
|
string const tofile =
|
2006-12-02 16:07:15 +00:00
|
|
|
|
changeExtension(filename.absFilename(),
|
2006-11-13 10:27:57 +00:00
|
|
|
|
formats.extension(*it));
|
2007-01-17 13:18:16 +00:00
|
|
|
|
if (!theConverters().convert(0, filename, FileName(tofile),
|
2006-12-02 16:07:15 +00:00
|
|
|
|
filename, format, *it, errorList))
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
loader_format = *it;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (loader_format.empty()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
frontend::Alert::error(_("Couldn't import file"),
|
2006-09-11 08:54:10 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} else {
|
2000-11-13 10:35:02 +00:00
|
|
|
|
loader_format = format;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
}
|
2000-11-13 10:35:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-12-02 16:07:15 +00:00
|
|
|
|
Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
|
2006-07-17 15:13:49 +00:00
|
|
|
|
if (b)
|
|
|
|
|
lv->setBuffer(b);
|
|
|
|
|
else
|
|
|
|
|
return false;
|
2000-11-13 10:35:02 +00:00
|
|
|
|
bool as_paragraphs = loader_format == "textparagraph";
|
2006-12-02 16:07:15 +00:00
|
|
|
|
string filename2 = (loader_format == format) ? filename.absFilename()
|
|
|
|
|
: changeExtension(filename.absFilename(),
|
2001-07-30 11:56:00 +00:00
|
|
|
|
formats.extension(loader_format));
|
2007-01-15 22:49:14 +00:00
|
|
|
|
insertPlaintextFile(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 =
|
2007-01-17 13:18:16 +00:00
|
|
|
|
theConverters().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 =
|
2007-01-17 13:18:16 +00:00
|
|
|
|
theConverters().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
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|