lyx_mirror/src/importer.C

126 lines
3.0 KiB
C++
Raw Normal View History

/**
* \file importer.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author unknown
* \author Lars Gullik Bj<EFBFBD>nnes
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "importer.h"
#include "converter.h"
#include "format.h"
#include "frontends/LyXView.h"
#include "funcrequest.h"
#include "lyx_cb.h"
#include "support/filetools.h"
#include "frontends/Alert.h"
#include "gettext.h"
#include "BufferView.h"
#include "buffer_funcs.h"
namespace lyx {
using support::bformat;
using support::changeExtension;
using support::FileName;
using support::makeDisplayPath;
using std::find;
using std::string;
using std::vector;
bool Importer::Import(LyXView * lv, FileName const & filename,
This commit creates a error_lists map member inside the Buffer class. I had no choice but to use string for the map key. This is because the only information that could be passed to the controller is a string. With this new architecture, persistent error lists are now possible. * Buffer - errorList_, addError(), : deleted - std::map<std::string, ErrorList> errorLists_ : new member - errorList(std::string const & type): associated accessors * buffer_funcs.C - bufferErrors(Buffer const & buf, TeXErrors const & terr): now needs a third errorList argument - bufferErrors(Buffer const & buf, ErrorList const & el): deleted. * Converter - convert(): now needs an ErrorList argument instead of filling the Buffer errorList member directly. - runLaTeX(): ditto - scanLog(): ditto * CutAndPaste.C - pasteParagraphList(): ditto - pasteSelection(): ditto * lyxtext.h/text.C - readParagraph(): ditto - LyXText::read(): ditto * importer: - Importer::Import(): ditto * BufferView_pimpl.C - loadLyXFile(): send the Buffer::errors() signal instead of calling LyXView::showErrorList() directly. * exporter.C - Export(): send the Buffer::errors() signal instead of calling LyXView::showErrorList() directly in lyxfunc.C * ControlErrorList.C - initialiseParams(): translation operation transfered here from LyXView::showErrorList(). * LyXView.C - LoadLyXFile(): add a showErrorList("Parse") call. - showErrorList(): simplified due to code transferred to the ControlErrorList. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14652 a592a061-630c-0410-9148-cb99ea01b6c8
2006-08-13 16:16:43 +00:00
string const & format, ErrorList & errorList)
{
docstring const displaypath = makeDisplayPath(filename.absFilename());
lv->message(bformat(_("Importing %1$s..."), displaypath));
FileName const lyxfile(changeExtension(filename.absFilename(), ".lyx"));
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) {
if (theConverters().isReachable(format, *it)) {
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
string const tofile =
changeExtension(filename.absFilename(),
Add a cache for converted image files. This needs to be enabled in the preferences file with \use_converter_cache true. It is disabled by default, and no GUI support for changing the preferences is yet implemented. * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Use image file cache * src/insets/ExternalSupport.C (updateExternal): Use image file cache * src/exporter.C (Exporter::Export): Do not use image file cache * src/graphics/GraphicsCacheItem.C (CacheItem::Impl::imageConverted): Add the converted file to the image file cache (CacheItem::Impl::convertToDisplayFo): Use image file cache * src/converter.C (Converters::convert): Use image file cache if the caller allowed that * src/converter.h (Converters::convert): Adjust arguments * src/Makefile.am: Add new files * src/support/lyxlib.h (chmod): new function (copy): add mode argument * src/support/copy.C (chmod): new function (copy): implement mode argument * src/support/mkdir.C (lyx::support::mkdir): Add warning if permissions are ignored * src/lyxrc.[Ch]: Add new settings \converter_cache_maxage and \use_converter_cache * src/ConverterCache.[Ch]: New image file cache * src/importer.C (Importer::Import): Do nut use the image file cache * src/lyx_main.C (LyX::init): Initialize the image file cache * src/mover.[Ch] (Mover::do_copy): Add mode argument (SpecialisedMover::do_copy): ditto * configure.ac: Check for chmod * development/cmake/ConfigureChecks.cmake: ditto * development/cmake/config.h.cmake: ditto * development/scons/SConstruct: ditto * development/scons/scons_manifest.py: Add new files git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15897 a592a061-630c-0410-9148-cb99ea01b6c8
2006-11-13 10:27:57 +00:00
formats.extension(*it));
if (!theConverters().convert(0, filename, FileName(tofile),
filename, format, *it, errorList))
return false;
loader_format = *it;
break;
}
}
if (loader_format.empty()) {
frontend::Alert::error(_("Couldn't import file"),
bformat(_("No information for importing the format %1$s."),
formats.prettyName(format)));
return false;
}
} else {
loader_format = format;
}
if (loader_format == "lyx") {
lv->loadLyXFile(lyxfile);
} else {
Buffer * const b = newFile(lyxfile.absFilename(), string(), true);
if (b)
lv->setBuffer(b);
else
return false;
bool as_paragraphs = loader_format == "textparagraph";
string filename2 = (loader_format == format) ? filename.absFilename()
: changeExtension(filename.absFilename(),
formats.extension(loader_format));
insertPlaintextFile(lv->view(), filename2, as_paragraphs);
lv->dispatch(FuncRequest(LFUN_MARK_OFF));
}
// we are done
lv->message(_("imported."));
return true;
}
vector<Format const *> const Importer::GetImportableFormats()
{
vector<string> loaders = Loaders();
vector<Format const *> result =
theConverters().getReachableTo(loaders[0], true);
for (vector<string>::const_iterator it = loaders.begin() + 1;
it != loaders.end(); ++it) {
vector<Format const *> r =
theConverters().getReachableTo(*it, false);
result.insert(result.end(), r.begin(), r.end());
}
return result;
}
vector<string> const Importer::Loaders()
{
vector<string> v;
v.push_back("lyx");
v.push_back("text");
v.push_back("textparagraph");
return v;
}
} // namespace lyx