2003-03-31 01:15:44 +00:00
|
|
|
/**
|
|
|
|
* \file exporter.C
|
|
|
|
* 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
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-03-31 01:15:44 +00:00
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
*/
|
|
|
|
|
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"
|
2001-04-24 17:33:01 +00:00
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
#include "bufferlist.h"
|
|
|
|
#include "support/filetools.h"
|
2001-11-26 10:19:58 +00:00
|
|
|
#include "frontends/Alert.h"
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "gettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2000-11-13 10:35:02 +00:00
|
|
|
|
2003-03-30 20:25:44 +00:00
|
|
|
#include "support/BoostFormat.h"
|
2002-11-21 18:33:09 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::find;
|
2000-10-23 12:16:05 +00:00
|
|
|
|
|
|
|
extern BufferList bufferlist;
|
|
|
|
extern void InsertAsciiFile(BufferView *, string const &, bool);
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
bool Importer::Import(LyXView * lv, string const & filename,
|
2000-10-23 12:16:05 +00:00
|
|
|
string const & format)
|
|
|
|
{
|
2001-04-17 15:15:59 +00:00
|
|
|
string const displaypath = MakeDisplayPath(filename);
|
2001-06-14 17:58:49 +00:00
|
|
|
ostringstream s1;
|
2002-11-24 15:20:31 +00:00
|
|
|
#if USE_BOOST_FORMAT
|
2002-11-21 18:33:09 +00:00
|
|
|
s1 << boost::format(_("Importing %1$s...")) % displaypath;
|
2002-11-24 15:20:31 +00:00
|
|
|
#else
|
|
|
|
s1 << _("Importing ") << displaypath << _("...");
|
|
|
|
#endif
|
2002-11-04 02:12:42 +00:00
|
|
|
lv->message(STRCONV(s1.str()));
|
2000-10-23 12:16:05 +00:00
|
|
|
|
2001-04-17 15:15:59 +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,
|
2000-11-13 10:35:02 +00:00
|
|
|
format, *it))
|
|
|
|
return false;
|
|
|
|
loader_format = *it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (loader_format.empty()) {
|
2002-11-24 15:20:31 +00:00
|
|
|
#if USE_BOOST_FORMAT
|
2003-03-31 01:15:44 +00:00
|
|
|
// FIXME: better english ...
|
|
|
|
Alert::error(_("Couldn't import file"),
|
|
|
|
boost::io::str(boost::format(_("No information for importing the format %1$s."))
|
2002-11-21 18:33:09 +00:00
|
|
|
% formats.prettyName(format)));
|
2002-11-24 15:20:31 +00:00
|
|
|
#else
|
2003-03-31 01:15:44 +00:00
|
|
|
Alert::error(_("Couldn't import file"),
|
|
|
|
_("No information for importing the format ")
|
|
|
|
+ formats.prettyName(format) + ".");
|
2002-11-24 15:20:31 +00:00
|
|
|
#endif
|
2000-11-13 10:35:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
loader_format = format;
|
|
|
|
|
|
|
|
|
|
|
|
if (loader_format == "lyx") {
|
|
|
|
Buffer * buffer = bufferlist.loadLyXFile(lyxfile);
|
|
|
|
if (buffer)
|
|
|
|
lv->view()->buffer(buffer);
|
|
|
|
} else {
|
2000-10-23 12:16:05 +00:00
|
|
|
lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true));
|
2000-11-13 10:35:02 +00:00
|
|
|
bool as_paragraphs = loader_format == "textparagraph";
|
|
|
|
string filename2 = (loader_format == format) ? filename
|
|
|
|
: ChangeExtension(filename,
|
2001-07-30 11:56:00 +00:00
|
|
|
formats.extension(loader_format));
|
2002-08-02 09:21:50 +00:00
|
|
|
InsertAsciiFile(lv->view().get(), 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
|
2001-04-24 17:33:01 +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
|
|
|
}
|