2003-03-31 01:15:44 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file Exporter.cpp
|
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 Alfredo Braunstein
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
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-08-30 03:40:51 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Exporter.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2003-06-24 20:42:15 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "BufferParams.h"
|
|
|
|
|
#include "Converter.h"
|
|
|
|
|
#include "Format.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXRC.h"
|
|
|
|
|
#include "Mover.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "output_plaintext.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "OutputParams.h"
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "support/filetools.h"
|
2004-06-01 13:39:33 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
#include "support/Package.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
|
2005-01-31 10:42:26 +00:00
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::addName;
|
|
|
|
|
using support::bformat;
|
|
|
|
|
using support::changeExtension;
|
|
|
|
|
using support::contains;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::makeAbsPath;
|
|
|
|
|
using support::makeDisplayPath;
|
|
|
|
|
using support::onlyFilename;
|
|
|
|
|
using support::onlyPath;
|
|
|
|
|
using support::package;
|
|
|
|
|
using support::prefixIs;
|
2006-09-11 08:54:10 +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;
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace Alert = frontend::Alert;
|
2005-01-31 10:42:26 +00:00
|
|
|
|
namespace fs = boost::filesystem;
|
2003-06-24 20:42:15 +00:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
vector<string> const Backends(Buffer const & buffer)
|
2003-06-24 20:42:15 +00:00
|
|
|
|
{
|
|
|
|
|
vector<string> v;
|
2007-04-29 19:53:54 +00:00
|
|
|
|
if (buffer.params().getTextClass().isTeXClassAvailable()) {
|
2006-04-09 00:26:19 +00:00
|
|
|
|
v.push_back(bufferFormat(buffer));
|
2006-03-28 18:49:46 +00:00
|
|
|
|
// FIXME: Don't hardcode format names here, but use a flag
|
|
|
|
|
if (v.back() == "latex")
|
|
|
|
|
v.push_back("pdflatex");
|
|
|
|
|
}
|
2003-06-24 20:42:15 +00:00
|
|
|
|
v.push_back("text");
|
2006-02-03 21:47:25 +00:00
|
|
|
|
v.push_back("lyx");
|
2003-06-24 20:42:15 +00:00
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
|
|
|
|
|
|
/// ask the user what to do if a file already exists
|
2006-11-30 16:59:50 +00:00
|
|
|
|
int checkOverwrite(FileName const & filename)
|
2004-06-01 13:39:33 +00:00
|
|
|
|
{
|
2006-11-30 16:59:50 +00:00
|
|
|
|
if (fs::exists(filename.toFilesystemEncoding())) {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring text = bformat(_("The file %1$s already exists.\n\n"
|
|
|
|
|
"Do you want to over-write that file?"),
|
2006-11-30 16:59:50 +00:00
|
|
|
|
makeDisplayPath(filename.absFilename()));
|
2006-09-11 08:54:10 +00:00
|
|
|
|
return Alert::prompt(_("Over-write file?"),
|
2006-04-05 23:56:29 +00:00
|
|
|
|
text, 0, 2,
|
2006-09-11 08:54:10 +00:00
|
|
|
|
_("&Over-write"), _("Over-write &all"),
|
|
|
|
|
_("&Cancel export"));
|
2004-06-01 13:39:33 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum CopyStatus {
|
|
|
|
|
SUCCESS,
|
|
|
|
|
FORCE,
|
|
|
|
|
CANCEL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** copy file \p sourceFile to \p destFile. If \p force is false, the user
|
|
|
|
|
* will be asked before existing files are overwritten.
|
2004-10-05 10:11:42 +00:00
|
|
|
|
* \return
|
2004-06-01 13:39:33 +00:00
|
|
|
|
* - SUCCESS if this file got copied
|
|
|
|
|
* - FORCE if subsequent calls should not ask for confirmation before
|
|
|
|
|
* overwriting files anymore.
|
|
|
|
|
* - CANCEL if the export should be cancelled
|
|
|
|
|
*/
|
2004-11-01 08:50:42 +00:00
|
|
|
|
CopyStatus copyFile(string const & format,
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const & sourceFile, FileName const & destFile,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
string const & latexFile, bool force)
|
2004-06-01 13:39:33 +00:00
|
|
|
|
{
|
|
|
|
|
CopyStatus ret = force ? FORCE : SUCCESS;
|
|
|
|
|
|
|
|
|
|
// Only copy files that are in our tmp dir, all other files would
|
|
|
|
|
// overwrite themselves. This check could be changed to
|
|
|
|
|
// boost::filesystem::equivalent(sourceFile, destFile) if export to
|
|
|
|
|
// other directories than the document directory is desired.
|
2007-04-06 13:09:54 +00:00
|
|
|
|
if (!prefixIs(onlyPath(sourceFile.absFilename()), package().temp_dir().absFilename()))
|
2004-06-01 13:39:33 +00:00
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
if (!force) {
|
2006-11-30 16:59:50 +00:00
|
|
|
|
switch(checkOverwrite(destFile)) {
|
2004-06-01 13:39:33 +00:00
|
|
|
|
case 0:
|
|
|
|
|
ret = SUCCESS;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
ret = FORCE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return CANCEL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-18 08:42:53 +00:00
|
|
|
|
Mover const & mover = getMover(format);
|
2004-11-01 08:50:42 +00:00
|
|
|
|
if (!mover.copy(sourceFile, destFile, latexFile))
|
2006-09-11 08:54:10 +00:00
|
|
|
|
Alert::error(_("Couldn't copy file"),
|
|
|
|
|
bformat(_("Copying %1$s to %2$s failed."),
|
2006-11-26 21:30:39 +00:00
|
|
|
|
makeDisplayPath(sourceFile.absFilename()),
|
|
|
|
|
makeDisplayPath(destFile.absFilename())));
|
2004-06-01 13:39:33 +00:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-24 20:42:15 +00:00
|
|
|
|
} //namespace anon
|
|
|
|
|
|
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
bool Exporter::Export(Buffer * buffer, string const & format,
|
2000-10-23 12:16:05 +00:00
|
|
|
|
bool put_in_tempdir, string & result_file)
|
2000-08-30 03:40:51 +00:00
|
|
|
|
{
|
2000-11-13 10:35:02 +00:00
|
|
|
|
string backend_format;
|
2007-03-18 10:59:16 +00:00
|
|
|
|
OutputParams runparams(&buffer->params().encoding());
|
2003-11-05 12:06:20 +00:00
|
|
|
|
runparams.flavor = OutputParams::LATEX;
|
2007-01-15 22:49:14 +00:00
|
|
|
|
runparams.linelen = lyxrc.plaintext_linelen;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
vector<string> backends = Backends(*buffer);
|
2007-02-15 20:14:12 +00:00
|
|
|
|
if (find(backends.begin(), backends.end(), format) == backends.end()) {
|
|
|
|
|
// Get shortest path to format
|
|
|
|
|
Graph::EdgePath path;
|
2000-11-13 10:35:02 +00:00
|
|
|
|
for (vector<string>::const_iterator it = backends.begin();
|
|
|
|
|
it != backends.end(); ++it) {
|
2007-01-17 13:18:16 +00:00
|
|
|
|
Graph::EdgePath p = theConverters().getPath(*it, format);
|
2007-02-15 20:14:12 +00:00
|
|
|
|
if (!p.empty() && (path.empty() || p.size() < path.size())) {
|
2000-11-13 10:35:02 +00:00
|
|
|
|
backend_format = *it;
|
2007-02-15 20:14:12 +00:00
|
|
|
|
path = p;
|
2000-11-13 10:35:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-02-15 20:14:12 +00:00
|
|
|
|
if (!path.empty())
|
|
|
|
|
runparams.flavor = theConverters().getFlavor(path);
|
|
|
|
|
else {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
Alert::error(_("Couldn't export file"),
|
|
|
|
|
bformat(_("No information for exporting the format %1$s."),
|
2003-05-13 09:48:57 +00:00
|
|
|
|
formats.prettyName(format)));
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2006-03-28 18:49:46 +00:00
|
|
|
|
} else {
|
2000-11-13 10:35:02 +00:00
|
|
|
|
backend_format = format;
|
2006-03-28 18:49:46 +00:00
|
|
|
|
// FIXME: Don't hardcode format names here, but use a flag
|
|
|
|
|
if (backend_format == "pdflatex")
|
|
|
|
|
runparams.flavor = OutputParams::PDFLATEX;
|
|
|
|
|
}
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2000-09-05 13:16:19 +00:00
|
|
|
|
string filename = buffer->getLatexName(false);
|
2006-04-08 22:31:11 +00:00
|
|
|
|
filename = addName(buffer->temppath(), filename);
|
|
|
|
|
filename = changeExtension(filename,
|
2001-07-30 11:56:00 +00:00
|
|
|
|
formats.extension(backend_format));
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2007-01-18 22:29:50 +00:00
|
|
|
|
// Plain text backend
|
2000-10-23 12:16:05 +00:00
|
|
|
|
if (backend_format == "text")
|
2007-01-18 22:29:50 +00:00
|
|
|
|
writePlaintextFile(*buffer, FileName(filename), runparams);
|
2006-02-03 21:47:25 +00:00
|
|
|
|
// no backend
|
|
|
|
|
else if (backend_format == "lyx")
|
2006-11-30 16:59:50 +00:00
|
|
|
|
buffer->writeFile(FileName(filename));
|
2000-09-11 15:42:17 +00:00
|
|
|
|
// Docbook backend
|
2003-10-31 18:45:43 +00:00
|
|
|
|
else if (buffer->isDocBook()) {
|
|
|
|
|
runparams.nice = !put_in_tempdir;
|
2006-12-04 15:46:57 +00:00
|
|
|
|
buffer->makeDocBookFile(FileName(filename), runparams);
|
2003-10-31 18:45:43 +00:00
|
|
|
|
}
|
2000-09-11 15:42:17 +00:00
|
|
|
|
// LaTeX backend
|
2003-05-22 21:10:22 +00:00
|
|
|
|
else if (backend_format == format) {
|
|
|
|
|
runparams.nice = true;
|
2006-12-04 15:46:57 +00:00
|
|
|
|
if (!buffer->makeLaTeXFile(FileName(filename), string(), runparams))
|
2006-10-26 15:01:45 +00:00
|
|
|
|
return false;
|
2005-04-26 11:12:20 +00:00
|
|
|
|
} else if (!lyxrc.tex_allows_spaces
|
2005-03-25 15:27:30 +00:00
|
|
|
|
&& contains(buffer->filePath(), ' ')) {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
Alert::error(_("File name error"),
|
|
|
|
|
_("The directory path to the document cannot contain spaces."));
|
2001-04-14 08:10:52 +00:00
|
|
|
|
return false;
|
2003-05-22 21:10:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
runparams.nice = false;
|
2006-12-04 15:46:57 +00:00
|
|
|
|
if (!buffer->makeLaTeXFile(FileName(filename), buffer->filePath(), runparams))
|
2006-10-26 15:01:45 +00:00
|
|
|
|
return false;
|
2003-05-22 21:10:22 +00:00
|
|
|
|
}
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2006-08-13 16:16:43 +00:00
|
|
|
|
string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
|
2006-11-13 10:27:57 +00:00
|
|
|
|
string const ext = formats.extension(format);
|
2006-11-30 16:59:50 +00:00
|
|
|
|
FileName const tmp_result_file(changeExtension(filename, ext));
|
2007-01-17 13:18:16 +00:00
|
|
|
|
bool const success = theConverters().convert(buffer, FileName(filename),
|
2006-11-30 16:59:50 +00:00
|
|
|
|
tmp_result_file, FileName(buffer->fileName()), backend_format, format,
|
2006-08-13 16:16:43 +00:00
|
|
|
|
buffer->errorList(error_type));
|
|
|
|
|
// Emit the signal to show the error list.
|
2007-01-25 13:10:27 +00:00
|
|
|
|
if (format != backend_format)
|
|
|
|
|
buffer->errors(error_type);
|
2006-08-13 16:16:43 +00:00
|
|
|
|
if (!success)
|
2000-09-05 13:16:19 +00:00
|
|
|
|
return false;
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2006-11-13 10:27:57 +00:00
|
|
|
|
if (put_in_tempdir)
|
2006-11-30 16:59:50 +00:00
|
|
|
|
result_file = tmp_result_file.absFilename();
|
2006-11-13 10:27:57 +00:00
|
|
|
|
else {
|
|
|
|
|
result_file = changeExtension(buffer->fileName(), ext);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
// We need to copy referenced files (e. g. included graphics
|
|
|
|
|
// if format == "dvi") to the result dir.
|
2004-06-03 13:08:50 +00:00
|
|
|
|
vector<ExportedFile> const files =
|
|
|
|
|
runparams.exportdata->externalFiles(format);
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const dest = onlyPath(result_file);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
CopyStatus status = SUCCESS;
|
|
|
|
|
for (vector<ExportedFile>::const_iterator it = files.begin();
|
2004-11-01 08:50:42 +00:00
|
|
|
|
it != files.end() && status != CANCEL; ++it) {
|
2004-11-09 19:08:34 +00:00
|
|
|
|
string const fmt =
|
|
|
|
|
formats.getFormatFromFile(it->sourceName);
|
2004-11-01 08:50:42 +00:00
|
|
|
|
status = copyFile(fmt, it->sourceName,
|
2006-12-27 10:56:11 +00:00
|
|
|
|
makeAbsPath(it->exportName, dest),
|
2006-04-05 23:56:29 +00:00
|
|
|
|
it->exportName, status == FORCE);
|
2004-11-01 08:50:42 +00:00
|
|
|
|
}
|
2004-06-01 13:39:33 +00:00
|
|
|
|
if (status == CANCEL) {
|
2006-09-11 08:54:10 +00:00
|
|
|
|
buffer->message(_("Document export cancelled."));
|
2006-11-30 16:59:50 +00:00
|
|
|
|
} else if (fs::exists(tmp_result_file.toFilesystemEncoding())) {
|
2004-06-01 13:39:33 +00:00
|
|
|
|
// Finally copy the main file
|
2006-11-30 16:59:50 +00:00
|
|
|
|
status = copyFile(format, tmp_result_file,
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName(result_file), result_file,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
status == FORCE);
|
2006-09-11 08:54:10 +00:00
|
|
|
|
buffer->message(bformat(_("Document exported as %1$s "
|
|
|
|
|
"to file `%2$s'"),
|
2006-04-05 23:56:29 +00:00
|
|
|
|
formats.prettyName(format),
|
2006-04-08 22:31:11 +00:00
|
|
|
|
makeDisplayPath(result_file)));
|
2005-12-07 14:09:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
// This must be a dummy converter like fax (bug 1888)
|
2006-09-11 08:54:10 +00:00
|
|
|
|
buffer->message(bformat(_("Document exported as %1$s"),
|
2006-04-05 23:56:29 +00:00
|
|
|
|
formats.prettyName(format)));
|
2004-06-01 13:39:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-30 03:40:51 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-29 15:22:25 +00:00
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
|
bool Exporter::Export(Buffer * buffer, string const & format,
|
|
|
|
|
bool put_in_tempdir)
|
|
|
|
|
{
|
|
|
|
|
string result_file;
|
|
|
|
|
return Export(buffer, format, put_in_tempdir, result_file);
|
|
|
|
|
}
|
2000-08-30 03:40:51 +00:00
|
|
|
|
|
2002-10-29 15:22:25 +00:00
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
bool Exporter::preview(Buffer * buffer, string const & format)
|
2000-08-30 03:40:51 +00:00
|
|
|
|
{
|
2000-10-23 12:16:05 +00:00
|
|
|
|
string result_file;
|
2000-11-13 10:35:02 +00:00
|
|
|
|
if (!Export(buffer, format, true, result_file))
|
2000-08-30 03:40:51 +00:00
|
|
|
|
return false;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
return formats.view(*buffer, FileName(result_file), format);
|
2000-08-30 03:40:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
bool Exporter::isExportable(Buffer const & buffer, string const & format)
|
2000-10-02 16:44:47 +00:00
|
|
|
|
{
|
2000-11-13 10:35:02 +00:00
|
|
|
|
vector<string> backends = Backends(buffer);
|
|
|
|
|
for (vector<string>::const_iterator it = backends.begin();
|
|
|
|
|
it != backends.end(); ++it)
|
2007-01-17 13:18:16 +00:00
|
|
|
|
if (theConverters().isReachable(*it, format))
|
2000-11-13 10:35:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2000-10-02 16:44:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2000-11-13 10:35:02 +00:00
|
|
|
|
vector<Format const *> const
|
2006-04-09 00:26:19 +00:00
|
|
|
|
Exporter::getExportableFormats(Buffer const & buffer, bool only_viewable)
|
2000-08-30 03:40:51 +00:00
|
|
|
|
{
|
2000-11-13 10:35:02 +00:00
|
|
|
|
vector<string> backends = Backends(buffer);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
vector<Format const *> result =
|
2007-01-17 13:18:16 +00:00
|
|
|
|
theConverters().getReachable(backends[0], only_viewable, true);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
for (vector<string>::const_iterator it = backends.begin() + 1;
|
|
|
|
|
it != backends.end(); ++it) {
|
|
|
|
|
vector<Format const *> r =
|
2007-01-17 13:18:16 +00:00
|
|
|
|
theConverters().getReachable(*it, only_viewable, false);
|
2000-11-13 10:35:02 +00:00
|
|
|
|
result.insert(result.end(), r.begin(), r.end());
|
|
|
|
|
}
|
2000-09-11 15:42:17 +00:00
|
|
|
|
return result;
|
2000-08-30 03:40:51 +00:00
|
|
|
|
}
|
2004-06-01 13:39:33 +00:00
|
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
ExportedFile::ExportedFile(FileName const & s, string const & e) :
|
2004-06-01 13:39:33 +00:00
|
|
|
|
sourceName(s), exportName(e) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(ExportedFile const & f1, ExportedFile const & f2)
|
|
|
|
|
{
|
|
|
|
|
return f1.sourceName == f2.sourceName &&
|
|
|
|
|
f1.exportName == f2.exportName;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ExportData::addExternalFile(string const & format,
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const & sourceName,
|
2004-10-05 10:11:42 +00:00
|
|
|
|
string const & exportName)
|
2004-06-01 13:39:33 +00:00
|
|
|
|
{
|
|
|
|
|
// Make sure that we have every file only once, otherwise copyFile()
|
|
|
|
|
// would ask several times if it should overwrite a file.
|
|
|
|
|
vector<ExportedFile> & files = externalfiles[format];
|
|
|
|
|
ExportedFile file(sourceName, exportName);
|
|
|
|
|
if (find(files.begin(), files.end(), file) == files.end())
|
|
|
|
|
files.push_back(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ExportData::addExternalFile(string const & format,
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const & sourceName)
|
2004-06-01 13:39:33 +00:00
|
|
|
|
{
|
2006-11-26 21:30:39 +00:00
|
|
|
|
addExternalFile(format, sourceName, onlyFilename(sourceName.absFilename()));
|
2004-06-01 13:39:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<ExportedFile> const
|
|
|
|
|
ExportData::externalFiles(string const & format) const
|
|
|
|
|
{
|
|
|
|
|
FileMap::const_iterator cit = externalfiles.find(format);
|
|
|
|
|
if (cit != externalfiles.end())
|
|
|
|
|
return cit->second;
|
|
|
|
|
return vector<ExportedFile>();
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|