2003-03-29 09:48:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file buffer.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 16:55:34 +00:00
|
|
|
|
*
|
2003-03-29 09:48:03 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "author.h"
|
2003-06-24 20:42:15 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "bufferlist.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-11-25 17:23:36 +00:00
|
|
|
|
#include "counters.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "Bullet.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "Chktex.h"
|
|
|
|
|
#include "debug.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "errorlist.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "exporter.h"
|
2003-02-28 09:49:49 +00:00
|
|
|
|
#include "format.h"
|
2003-09-21 23:00:47 +00:00
|
|
|
|
#include "funcrequest.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "gettext.h"
|
2004-03-27 12:46:30 +00:00
|
|
|
|
#include "insetiterator.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "language.h"
|
|
|
|
|
#include "LaTeX.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "LyXAction.h"
|
|
|
|
|
#include "lyxlex.h"
|
2003-11-28 15:08:38 +00:00
|
|
|
|
#include "lyxtext.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "lyxvc.h"
|
2004-02-25 12:00:53 +00:00
|
|
|
|
#include "lyx_main.h"
|
2003-04-24 23:19:41 +00:00
|
|
|
|
#include "messages.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
|
#include "output.h"
|
|
|
|
|
#include "output_docbook.h"
|
|
|
|
|
#include "output_latex.h"
|
|
|
|
|
#include "output_linuxdoc.h"
|
2003-09-16 12:12:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
|
|
|
|
#include "ParagraphParameters.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
|
#include "pariterator.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "sgml.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "texrow.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "undo.h"
|
|
|
|
|
#include "version.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
|
#include "insets/insetbibitem.h"
|
|
|
|
|
#include "insets/insetbibtex.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/insetinclude.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
|
#include "mathed/math_macrotemplate.h"
|
|
|
|
|
#include "mathed/math_macrotable.h"
|
|
|
|
|
#include "mathed/math_support.h"
|
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
|
#include "graphics/Previews.h"
|
|
|
|
|
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/FileInfo.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/filetools.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/gzstream.h"
|
|
|
|
|
#include "support/lyxlib.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
#include "support/os.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/path.h"
|
|
|
|
|
#include "support/textutils.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/tostr.h"
|
2004-03-27 12:46:30 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-08-14 22:15:18 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2001-12-08 14:20:11 +00:00
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
|
|
#include <utime.h>
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
using lyx::par_type;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
|
|
|
|
using lyx::support::AddName;
|
|
|
|
|
using lyx::support::atoi;
|
|
|
|
|
using lyx::support::bformat;
|
|
|
|
|
using lyx::support::ChangeExtension;
|
|
|
|
|
using lyx::support::cmd_ret;
|
2004-02-25 12:00:53 +00:00
|
|
|
|
using lyx::support::createBufferTmpDir;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::destroyDir;
|
|
|
|
|
using lyx::support::FileInfo;
|
|
|
|
|
using lyx::support::FileInfo;
|
|
|
|
|
using lyx::support::getExtFromContents;
|
|
|
|
|
using lyx::support::IsDirWriteable;
|
|
|
|
|
using lyx::support::IsFileWriteable;
|
|
|
|
|
using lyx::support::LibFileSearch;
|
|
|
|
|
using lyx::support::ltrim;
|
|
|
|
|
using lyx::support::MakeAbsPath;
|
|
|
|
|
using lyx::support::MakeDisplayPath;
|
|
|
|
|
using lyx::support::MakeLatexName;
|
|
|
|
|
using lyx::support::OnlyFilename;
|
|
|
|
|
using lyx::support::OnlyPath;
|
|
|
|
|
using lyx::support::Path;
|
|
|
|
|
using lyx::support::QuoteName;
|
|
|
|
|
using lyx::support::removeAutosaveFile;
|
|
|
|
|
using lyx::support::rename;
|
|
|
|
|
using lyx::support::RunCommand;
|
|
|
|
|
using lyx::support::split;
|
|
|
|
|
using lyx::support::strToInt;
|
|
|
|
|
using lyx::support::subst;
|
|
|
|
|
using lyx::support::tempName;
|
|
|
|
|
using lyx::support::trim;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-09-16 11:03:20 +00:00
|
|
|
|
namespace os = lyx::support::os;
|
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::for_each;
|
|
|
|
|
using std::make_pair;
|
2001-12-08 14:20:11 +00:00
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::ifstream;
|
|
|
|
|
using std::ios;
|
2004-04-13 06:27:29 +00:00
|
|
|
|
using std::map;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ofstream;
|
|
|
|
|
using std::pair;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
using std::stack;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// all these externs should eventually be removed.
|
|
|
|
|
extern BufferList bufferlist;
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2004-03-29 13:17:25 +00:00
|
|
|
|
const int LYX_FORMAT = 232;
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-09-09 11:24:33 +00:00
|
|
|
|
|
|
|
|
|
typedef std::map<string, bool> DepClean;
|
|
|
|
|
|
2003-09-09 17:25:35 +00:00
|
|
|
|
struct Buffer::Impl
|
2003-09-09 11:24:33 +00:00
|
|
|
|
{
|
|
|
|
|
Impl(Buffer & parent, string const & file, bool readonly);
|
|
|
|
|
|
|
|
|
|
limited_stack<Undo> undostack;
|
|
|
|
|
limited_stack<Undo> redostack;
|
|
|
|
|
BufferParams params;
|
|
|
|
|
LyXVC lyxvc;
|
|
|
|
|
string temppath;
|
|
|
|
|
TexRow texrow;
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// need to regenerate .tex?
|
2003-09-09 11:24:33 +00:00
|
|
|
|
DepClean dep_clean;
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// is save needed?
|
2003-09-09 11:24:33 +00:00
|
|
|
|
mutable bool lyx_clean;
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// is autosave needed?
|
2003-09-09 11:24:33 +00:00
|
|
|
|
mutable bool bak_clean;
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/// is this a unnamed file (New...)?
|
2003-09-09 11:24:33 +00:00
|
|
|
|
bool unnamed;
|
|
|
|
|
|
|
|
|
|
/// buffer is r/o
|
|
|
|
|
bool read_only;
|
|
|
|
|
|
|
|
|
|
/// name of the file the buffer is associated with.
|
|
|
|
|
string filename;
|
|
|
|
|
|
|
|
|
|
/// The path to the document file.
|
|
|
|
|
string filepath;
|
|
|
|
|
|
|
|
|
|
boost::scoped_ptr<Messages> messages;
|
2003-10-22 13:15:18 +00:00
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
/** Set to true only when the file is fully loaded.
|
2003-10-22 13:15:18 +00:00
|
|
|
|
* Used to prevent the premature generation of previews
|
|
|
|
|
* and by the citation inset.
|
|
|
|
|
*/
|
|
|
|
|
bool file_fully_loaded;
|
2003-11-28 15:08:38 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
/// our LyXText that should be wrapped in an InsetText
|
|
|
|
|
InsetText inset;
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
MacroTable macros;
|
2003-09-09 11:24:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
|
2004-01-21 17:52:07 +00:00
|
|
|
|
: lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
|
2003-11-28 15:08:38 +00:00
|
|
|
|
filename(file), filepath(OnlyPath(file)), file_fully_loaded(false),
|
2004-03-18 12:53:43 +00:00
|
|
|
|
inset(params)
|
2003-09-09 11:24:33 +00:00
|
|
|
|
{
|
|
|
|
|
lyxvc.buffer(&parent);
|
2004-02-25 12:00:53 +00:00
|
|
|
|
temppath = createBufferTmpDir();
|
|
|
|
|
// FIXME: And now do something if temppath == string(), because we
|
|
|
|
|
// assume from now on that temppath points to a valid temp dir.
|
|
|
|
|
// See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
|
2003-09-09 11:24:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Buffer::Buffer(string const & file, bool ronly)
|
2003-09-09 11:24:33 +00:00
|
|
|
|
: pimpl_(new Impl(*this, file, ronly))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::~Buffer()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// here the buffer should take care that it is
|
|
|
|
|
// saved properly, before it goes into the void.
|
|
|
|
|
|
2003-07-11 12:21:31 +00:00
|
|
|
|
closing();
|
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!temppath().empty() && destroyDir(temppath()) != 0) {
|
2003-05-21 21:20:50 +00:00
|
|
|
|
Alert::warning(_("Could not remove temporary directory"),
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bformat(_("Could not remove the temporary directory %1$s"), temppath()));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-08-22 08:47:32 +00:00
|
|
|
|
// Remove any previewed LaTeX snippets associated with this buffer.
|
2003-08-28 07:41:31 +00:00
|
|
|
|
lyx::graphics::Previews::get().removeLoader(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-28 15:08:38 +00:00
|
|
|
|
LyXText & Buffer::text() const
|
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return const_cast<LyXText &>(pimpl_->inset.text_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBase & Buffer::inset() const
|
|
|
|
|
{
|
|
|
|
|
return const_cast<InsetText &>(pimpl_->inset);
|
2003-11-28 15:08:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
limited_stack<Undo> & Buffer::undostack()
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->undostack;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
limited_stack<Undo> const & Buffer::undostack() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->undostack;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
limited_stack<Undo> & Buffer::redostack()
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->redostack;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
limited_stack<Undo> const & Buffer::redostack() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->redostack;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferParams & Buffer::params()
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->params;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferParams const & Buffer::params() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->params;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList & Buffer::paragraphs()
|
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return text().paragraphs();
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParagraphList const & Buffer::paragraphs() const
|
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
return text().paragraphs();
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXVC & Buffer::lyxvc()
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->lyxvc;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXVC const & Buffer::lyxvc() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->lyxvc;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & Buffer::temppath() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->temppath;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TexRow & Buffer::texrow()
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->texrow;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TexRow const & Buffer::texrow() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->texrow;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Buffer::getLatexName(bool no_path) const
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
|
2003-05-19 17:03:12 +00:00
|
|
|
|
return no_path ? OnlyFilename(name) : name;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
pair<Buffer::LogType, string> const Buffer::getLogName() const
|
2001-02-06 17:41:42 +00:00
|
|
|
|
{
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const filename = getLatexName(false);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
if (filename.empty())
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::latexlog, string());
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2004-02-25 12:00:53 +00:00
|
|
|
|
string const path = temppath();
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const fname = AddName(path,
|
|
|
|
|
OnlyFilename(ChangeExtension(filename,
|
|
|
|
|
".log")));
|
|
|
|
|
string const bname =
|
|
|
|
|
AddName(path, OnlyFilename(
|
|
|
|
|
ChangeExtension(filename,
|
2001-07-30 11:56:00 +00:00
|
|
|
|
formats.extension("literate") + ".out")));
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
// If no Latex log or Build log is newer, show Build log
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
FileInfo const f_fi(fname);
|
|
|
|
|
FileInfo const b_fi(bname);
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-02-06 17:41:42 +00:00
|
|
|
|
if (b_fi.exist() &&
|
2001-03-14 14:54:30 +00:00
|
|
|
|
(!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::buildlog, bname);
|
|
|
|
|
}
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::latexlog, fname);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
void Buffer::setReadonly(bool flag)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
if (pimpl_->read_only != flag) {
|
|
|
|
|
pimpl_->read_only = flag;
|
2003-07-10 12:26:40 +00:00
|
|
|
|
readonly(flag);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-12 00:11:06 +00:00
|
|
|
|
void Buffer::setFileName(string const & newfile)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
pimpl_->filename = MakeAbsPath(newfile);
|
|
|
|
|
pimpl_->filepath = OnlyPath(pimpl_->filename);
|
|
|
|
|
setReadonly(IsFileWriteable(pimpl_->filename) == 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
// We'll remove this later. (Lgb)
|
|
|
|
|
namespace {
|
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
void unknownClass(string const & unknown)
|
|
|
|
|
{
|
2003-05-21 21:20:50 +00:00
|
|
|
|
Alert::warning(_("Unknown document class"),
|
2003-05-13 09:48:57 +00:00
|
|
|
|
bformat(_("Using the default document class, because the "
|
2003-08-14 15:45:09 +00:00
|
|
|
|
"class %1$s is unknown."), unknown));
|
2003-03-12 02:39:12 +00:00
|
|
|
|
}
|
2001-07-09 23:12:04 +00:00
|
|
|
|
|
2001-08-30 07:13:15 +00:00
|
|
|
|
} // anon
|
|
|
|
|
|
2003-12-03 15:27:16 +00:00
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
int Buffer::readHeader(LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
int unknown_tokens = 0;
|
|
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (token == "\\end_header")
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::PARSER] << "Handling header token: `"
|
|
|
|
|
<< token << '\'' << endl;
|
|
|
|
|
|
2003-06-22 18:08:49 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string unknown = params().readToken(lex, token);
|
2003-03-12 02:39:12 +00:00
|
|
|
|
if (!unknown.empty()) {
|
|
|
|
|
if (unknown[0] != '\\') {
|
|
|
|
|
unknownClass(unknown);
|
|
|
|
|
} else {
|
2003-03-29 10:29:38 +00:00
|
|
|
|
++unknown_tokens;
|
2003-06-20 23:03:43 +00:00
|
|
|
|
string const s = bformat(_("Unknown token: "
|
2003-06-28 01:23:11 +00:00
|
|
|
|
"%1$s %2$s\n"),
|
|
|
|
|
token,
|
2003-06-20 23:03:43 +00:00
|
|
|
|
lex.getString());
|
2003-07-25 17:11:25 +00:00
|
|
|
|
error(ErrorItem(_("Header error"), s,
|
2003-07-07 08:37:02 +00:00
|
|
|
|
-1, 0, 0));
|
2003-03-12 02:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return unknown_tokens;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-30 07:13:15 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Uwe C. Schroeder
|
|
|
|
|
// changed to be public and have one parameter
|
2003-07-28 22:30:50 +00:00
|
|
|
|
// Returns false if "\end_document" is not read (Asger)
|
2003-12-03 15:27:16 +00:00
|
|
|
|
bool Buffer::readBody(LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (paragraphs().empty()) {
|
2003-06-22 18:08:49 +00:00
|
|
|
|
readHeader(lex);
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!params().getLyXTextClass().load()) {
|
|
|
|
|
string theclass = params().getLyXTextClass().name();
|
2003-05-13 09:48:57 +00:00
|
|
|
|
Alert::error(_("Can't load document class"), bformat(
|
|
|
|
|
"Using the default document class, because the "
|
|
|
|
|
" class %1$s could not be loaded.", theclass));
|
2003-09-09 09:47:59 +00:00
|
|
|
|
params().textclass = 0;
|
2003-03-12 02:39:12 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
// We don't want to adopt the parameters from the
|
2003-03-12 02:39:12 +00:00
|
|
|
|
// document we insert, so read them into a temporary buffer
|
|
|
|
|
// and then discard it
|
|
|
|
|
|
|
|
|
|
Buffer tmpbuf("", false);
|
|
|
|
|
tmpbuf.readHeader(lex);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return text().read(*this, lex);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// needed to insert the selection
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void Buffer::insertStringAsLines(ParagraphList & pars,
|
|
|
|
|
par_type & par, pos_type & pos,
|
|
|
|
|
LyXFont const & fn, string const & str)
|
2001-07-23 09:11:14 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars[par].layout();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2001-10-22 09:45:31 +00:00
|
|
|
|
LyXFont font = fn;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars[par].checkInsertChar(font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// insert the string, don't insert doublespace
|
|
|
|
|
bool space_inserted = true;
|
2004-04-08 15:03:33 +00:00
|
|
|
|
bool autobreakrows = pars[par].autoBreakRows();
|
2004-03-27 12:46:30 +00:00
|
|
|
|
for (string::const_iterator cit = str.begin();
|
2001-07-23 09:11:14 +00:00
|
|
|
|
cit != str.end(); ++cit) {
|
|
|
|
|
if (*cit == '\n') {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (autobreakrows && (!pars[par].empty() || pars[par].allowEmpty())) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
breakParagraph(params(), paragraphs(), par, pos,
|
2002-08-20 19:41:13 +00:00
|
|
|
|
layout->isEnvironment());
|
2003-04-16 08:12:22 +00:00
|
|
|
|
++par;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// do not insert consecutive spaces if !free_spacing
|
2001-10-22 09:45:31 +00:00
|
|
|
|
} else if ((*cit == ' ' || *cit == '\t') &&
|
2004-03-25 09:16:36 +00:00
|
|
|
|
space_inserted && !pars[par].isFreeSpacing()) {
|
2001-07-23 09:11:14 +00:00
|
|
|
|
continue;
|
|
|
|
|
} else if (*cit == '\t') {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars[par].isFreeSpacing()) {
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// tabs are like spaces here
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars[par].insertChar(pos, ' ', font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
++pos;
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
} else {
|
2004-02-11 14:45:44 +00:00
|
|
|
|
const pos_type n = 8 - pos % 8;
|
|
|
|
|
for (pos_type i = 0; i < n; ++i) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars[par].insertChar(pos, ' ', font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (!IsPrintable(*cit)) {
|
|
|
|
|
// Ignore unprintables
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
// just insert the character
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars[par].insertChar(pos, *cit, font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
++pos;
|
|
|
|
|
space_inserted = (*cit == ' ');
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
}
|
2001-07-23 09:11:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
bool Buffer::readFile(string const & filename)
|
2003-03-12 05:46:35 +00:00
|
|
|
|
{
|
2003-07-28 14:40:29 +00:00
|
|
|
|
// Check if the file is compressed.
|
|
|
|
|
string const format = getExtFromContents(filename);
|
|
|
|
|
if (format == "gzip" || format == "zip" || format == "compress") {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
params().compressed = true;
|
2003-07-28 14:40:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
// remove dummy empty par
|
|
|
|
|
paragraphs().clear();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bool ret = readFile(filename, paragraphs().size());
|
2003-04-24 23:19:41 +00:00
|
|
|
|
|
|
|
|
|
// After we have read a file, we must ensure that the buffer
|
|
|
|
|
// language is set and used in the gui.
|
|
|
|
|
// If you know of a better place to put this, please tell me. (Lgb)
|
2003-09-09 09:47:59 +00:00
|
|
|
|
updateDocLang(params().language);
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
return ret;
|
2003-03-12 05:46:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bool Buffer::readFile(string const & filename, par_type pit)
|
2003-09-02 08:26:20 +00:00
|
|
|
|
{
|
|
|
|
|
LyXLex lex(0, 0);
|
|
|
|
|
lex.setFile(filename);
|
|
|
|
|
return readFile(lex, filename, pit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-22 13:15:18 +00:00
|
|
|
|
bool Buffer::fully_loaded() const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->file_fully_loaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-22 14:40:24 +00:00
|
|
|
|
void Buffer::fully_loaded(bool value)
|
|
|
|
|
{
|
|
|
|
|
pimpl_->file_fully_loaded = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bool Buffer::readFile(LyXLex & lex, string const & filename, par_type pit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(!filename.empty());
|
2003-09-02 08:26:20 +00:00
|
|
|
|
|
2003-03-29 11:34:53 +00:00
|
|
|
|
if (!lex.isOK()) {
|
|
|
|
|
Alert::error(_("Document could not be read"),
|
2003-09-02 08:26:20 +00:00
|
|
|
|
bformat(_("%1$s could not be read."), filename));
|
2003-03-29 11:34:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token(lex.getString());
|
|
|
|
|
|
|
|
|
|
if (!lex.isOK()) {
|
|
|
|
|
Alert::error(_("Document could not be read"),
|
2003-09-02 08:26:20 +00:00
|
|
|
|
bformat(_("%1$s could not be read."), filename));
|
2003-03-29 11:34:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-05-22 12:33:02 +00:00
|
|
|
|
|
2003-03-29 11:34:53 +00:00
|
|
|
|
// the first token _must_ be...
|
|
|
|
|
if (token != "\\lyxformat") {
|
2003-07-28 23:05:58 +00:00
|
|
|
|
lyxerr << "Token: " << token << endl;
|
|
|
|
|
|
2003-03-29 11:34:53 +00:00
|
|
|
|
Alert::error(_("Document format failure"),
|
2003-09-02 08:26:20 +00:00
|
|
|
|
bformat(_("%1$s is not a LyX document."),
|
|
|
|
|
filename));
|
2003-03-29 11:34:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
string tmp_format = lex.getString();
|
|
|
|
|
//lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
|
|
|
|
|
// if present remove ".," from string.
|
|
|
|
|
string::size_type dot = tmp_format.find_first_of(".,");
|
|
|
|
|
//lyxerr << " dot found at " << dot << endl;
|
|
|
|
|
if (dot != string::npos)
|
|
|
|
|
tmp_format.erase(dot, 1);
|
2003-08-01 10:23:16 +00:00
|
|
|
|
int file_format = strToInt(tmp_format);
|
2003-03-29 11:34:53 +00:00
|
|
|
|
//lyxerr << "format: " << file_format << endl;
|
2003-09-02 08:26:20 +00:00
|
|
|
|
|
|
|
|
|
if (file_format > LYX_FORMAT) {
|
2003-03-29 11:34:53 +00:00
|
|
|
|
Alert::warning(_("Document format failure"),
|
2003-09-02 14:49:19 +00:00
|
|
|
|
bformat(_("%1$s was created with a newer"
|
|
|
|
|
" version of LyX. This is likely to"
|
|
|
|
|
" cause problems."),
|
2003-09-02 08:26:20 +00:00
|
|
|
|
filename));
|
2003-03-29 11:34:53 +00:00
|
|
|
|
} else if (file_format < LYX_FORMAT) {
|
2003-09-02 08:26:20 +00:00
|
|
|
|
string const tmpfile = tempName();
|
2004-02-25 12:00:53 +00:00
|
|
|
|
if (tmpfile.empty()) {
|
|
|
|
|
Alert::error(_("Conversion failed"),
|
|
|
|
|
bformat(_("%1$s is from an earlier"
|
|
|
|
|
" version of LyX, but a temporary"
|
|
|
|
|
" file for converting it could"
|
|
|
|
|
" not be created."),
|
|
|
|
|
filename));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-09-02 08:26:20 +00:00
|
|
|
|
string command = LibFileSearch("lyx2lyx", "lyx2lyx");
|
|
|
|
|
if (command.empty()) {
|
|
|
|
|
Alert::error(_("Conversion script not found"),
|
|
|
|
|
bformat(_("%1$s is from an earlier"
|
|
|
|
|
" version of LyX, but the"
|
|
|
|
|
" conversion script lyx2lyx"
|
|
|
|
|
" could not be found."),
|
|
|
|
|
filename));
|
2003-03-29 11:34:53 +00:00
|
|
|
|
return false;
|
2003-09-02 08:26:20 +00:00
|
|
|
|
}
|
|
|
|
|
command += " -t"
|
|
|
|
|
+ tostr(LYX_FORMAT)
|
|
|
|
|
+ " -o " + tmpfile + ' '
|
|
|
|
|
+ QuoteName(filename);
|
|
|
|
|
lyxerr[Debug::INFO] << "Running '"
|
|
|
|
|
<< command << '\''
|
|
|
|
|
<< endl;
|
|
|
|
|
cmd_ret const ret = RunCommand(command);
|
|
|
|
|
if (ret.first != 0) {
|
|
|
|
|
Alert::error(_("Conversion script failed"),
|
|
|
|
|
bformat(_("%1$s is from an earlier version"
|
|
|
|
|
" of LyX, but the lyx2lyx script"
|
|
|
|
|
" failed to convert it."),
|
|
|
|
|
filename));
|
2003-03-29 11:34:53 +00:00
|
|
|
|
return false;
|
2003-09-02 08:26:20 +00:00
|
|
|
|
} else {
|
|
|
|
|
bool ret = readFile(tmpfile, pit);
|
|
|
|
|
// Do stuff with tmpfile name and buffer name here.
|
|
|
|
|
return ret;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-09-02 08:26:20 +00:00
|
|
|
|
|
2003-03-29 09:48:03 +00:00
|
|
|
|
}
|
2003-09-02 08:26:20 +00:00
|
|
|
|
|
2003-12-03 15:27:16 +00:00
|
|
|
|
bool the_end = readBody(lex);
|
2003-09-09 09:47:59 +00:00
|
|
|
|
params().setPaperStuff();
|
2003-03-29 11:34:53 +00:00
|
|
|
|
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#warning Look here!
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2004-03-18 12:53:43 +00:00
|
|
|
|
#if 0
|
|
|
|
|
if (token == "\\end_document")
|
|
|
|
|
the_end_read = true;
|
|
|
|
|
|
2003-03-29 11:34:53 +00:00
|
|
|
|
if (!the_end) {
|
|
|
|
|
Alert::error(_("Document format failure"),
|
2003-09-02 08:26:20 +00:00
|
|
|
|
bformat(_("%1$s ended unexpectedly, which means"
|
|
|
|
|
" that it is probably corrupted."),
|
|
|
|
|
filename));
|
2003-03-29 11:34:53 +00:00
|
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
#endif
|
2003-10-22 13:15:18 +00:00
|
|
|
|
pimpl_->file_fully_loaded = true;
|
2003-03-29 11:34:53 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Should probably be moved to somewhere else: BufferView? LyXView?
|
2000-03-20 14:49:54 +00:00
|
|
|
|
bool Buffer::save() const
|
2000-02-22 00:36:17 +00:00
|
|
|
|
{
|
|
|
|
|
// We don't need autosaves in the immediate future. (Asger)
|
|
|
|
|
resetAutosaveTimers();
|
|
|
|
|
|
|
|
|
|
// make a backup
|
2000-03-20 14:49:54 +00:00
|
|
|
|
string s;
|
|
|
|
|
if (lyxrc.make_backup) {
|
|
|
|
|
s = fileName() + '~';
|
|
|
|
|
if (!lyxrc.backupdir_path.empty())
|
|
|
|
|
s = AddName(lyxrc.backupdir_path,
|
2001-05-17 15:11:01 +00:00
|
|
|
|
subst(os::slashify_path(s),'/','!'));
|
2000-03-20 14:49:54 +00:00
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Rename is the wrong way of making a backup,
|
|
|
|
|
// this is the correct way.
|
|
|
|
|
/* truss cp fil fil2:
|
|
|
|
|
lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
|
|
|
|
|
stat("LyXVC.lyx", 0xEFFFF688) = 0
|
|
|
|
|
open("LyXVC.lyx", O_RDONLY) = 3
|
|
|
|
|
open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
|
|
|
|
|
fstat(4, 0xEFFFF508) = 0
|
|
|
|
|
fstat(3, 0xEFFFF508) = 0
|
|
|
|
|
read(3, " # T h i s f i l e w".., 8192) = 5579
|
|
|
|
|
write(4, " # T h i s f i l e w".., 5579) = 5579
|
|
|
|
|
read(3, 0xEFFFD4A0, 8192) = 0
|
|
|
|
|
close(4) = 0
|
|
|
|
|
close(3) = 0
|
|
|
|
|
chmod("LyXVC3.lyx", 0100644) = 0
|
|
|
|
|
lseek(0, 0, SEEK_CUR) = 46440
|
|
|
|
|
_exit(0)
|
|
|
|
|
*/
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Should probably have some more error checking here.
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Doing it this way, also makes the inodes stay the same.
|
|
|
|
|
// This is still not a very good solution, in particular we
|
|
|
|
|
// might loose the owner of the backup.
|
|
|
|
|
FileInfo finfo(fileName());
|
|
|
|
|
if (finfo.exist()) {
|
|
|
|
|
mode_t fmode = finfo.getMode();
|
2000-03-28 02:18:55 +00:00
|
|
|
|
struct utimbuf times = {
|
|
|
|
|
finfo.getAccessTime(),
|
|
|
|
|
finfo.getModificationTime() };
|
2000-02-22 00:36:17 +00:00
|
|
|
|
|
|
|
|
|
ifstream ifs(fileName().c_str());
|
|
|
|
|
ofstream ofs(s.c_str(), ios::out|ios::trunc);
|
|
|
|
|
if (ifs && ofs) {
|
|
|
|
|
ofs << ifs.rdbuf();
|
|
|
|
|
ifs.close();
|
|
|
|
|
ofs.close();
|
|
|
|
|
::chmod(s.c_str(), fmode);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
if (::utime(s.c_str(), ×)) {
|
2000-02-22 00:36:17 +00:00
|
|
|
|
lyxerr << "utime error." << endl;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "LyX was not able to make "
|
2001-06-25 00:06:33 +00:00
|
|
|
|
"backup copy. Beware." << endl;
|
2000-02-22 00:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-01 22:26:30 +00:00
|
|
|
|
if (writeFile(fileName())) {
|
2002-08-04 23:11:50 +00:00
|
|
|
|
markClean();
|
2000-08-08 15:36:25 +00:00
|
|
|
|
removeAutosaveFile(fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Saving failed, so backup is not backup
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (lyxrc.make_backup)
|
2003-06-30 23:56:22 +00:00
|
|
|
|
rename(s, fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-01 22:26:30 +00:00
|
|
|
|
bool Buffer::writeFile(string const & fname) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (pimpl_->read_only && fname == fileName())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
FileInfo finfo(fname);
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (finfo.exist() && !finfo.writable())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
bool retval;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (params().compressed) {
|
2003-07-27 23:40:08 +00:00
|
|
|
|
gz::ogzstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs)
|
|
|
|
|
return false;
|
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
retval = do_writeFile(ofs);
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs)
|
|
|
|
|
return false;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
retval = do_writeFile(ofs);
|
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
return retval;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::do_writeFile(ostream & ofs) const
|
|
|
|
|
{
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#ifdef HAVE_LOCALE
|
|
|
|
|
// Use the standard "C" locale for file output.
|
2000-09-15 10:24:15 +00:00
|
|
|
|
ofs.imbue(std::locale::classic());
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
// The top of the file should not be written by params().
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// write out a comment in the top of the file
|
2003-07-28 14:09:05 +00:00
|
|
|
|
ofs << "#LyX " << lyx_version
|
2001-02-14 19:22:41 +00:00
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/\n"
|
|
|
|
|
<< "\\lyxformat " << LYX_FORMAT << "\n";
|
|
|
|
|
|
2003-12-02 12:39:14 +00:00
|
|
|
|
// now write out the buffer parameters.
|
2003-09-09 09:47:59 +00:00
|
|
|
|
params().writeFile(ofs);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
ofs << "\\end_header\n";
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2003-12-02 12:39:14 +00:00
|
|
|
|
// write the text
|
|
|
|
|
text().write(*this, ofs);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Write marker that shows file is complete
|
2003-07-28 22:30:50 +00:00
|
|
|
|
ofs << "\n\\end_document" << endl;
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
2003-07-27 23:40:08 +00:00
|
|
|
|
// Shouldn't really be needed....
|
|
|
|
|
//ofs.close();
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
// how to check if close went ok?
|
2000-10-13 12:20:38 +00:00
|
|
|
|
// Following is an attempt... (BE 20001011)
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-10-13 12:20:38 +00:00
|
|
|
|
// good() returns false if any error occured, including some
|
|
|
|
|
// formatting error.
|
|
|
|
|
// bad() returns true if something bad happened in the buffer,
|
|
|
|
|
// which should include file system full errors.
|
|
|
|
|
|
|
|
|
|
bool status = true;
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (!ofs) {
|
2000-10-13 12:20:38 +00:00
|
|
|
|
status = false;
|
2004-02-11 14:45:44 +00:00
|
|
|
|
lyxerr << "File was not closed properly." << endl;
|
2000-10-13 12:20:38 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-10-13 12:20:38 +00:00
|
|
|
|
return status;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
void Buffer::makeLaTeXFile(string const & fname,
|
2000-03-06 02:42:40 +00:00
|
|
|
|
string const & original_path,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams,
|
2003-07-26 21:37:10 +00:00
|
|
|
|
bool output_preamble, bool output_body)
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-07-26 20:09:56 +00:00
|
|
|
|
ofstream ofs;
|
2003-11-05 12:06:20 +00:00
|
|
|
|
if (!openFileWrite(ofs, fname))
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-05-22 18:59:10 +00:00
|
|
|
|
makeLaTeXFile(ofs, original_path,
|
2003-07-26 21:37:10 +00:00
|
|
|
|
runparams, output_preamble, output_body);
|
2002-07-05 19:21:29 +00:00
|
|
|
|
|
|
|
|
|
ofs.close();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (ofs.fail())
|
|
|
|
|
lyxerr << "File '" << fname << "' was not closed properly." << endl;
|
2002-07-05 19:21:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::makeLaTeXFile(ostream & os,
|
|
|
|
|
string const & original_path,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams_in,
|
2003-07-26 21:37:10 +00:00
|
|
|
|
bool output_preamble, bool output_body)
|
2002-07-05 19:21:29 +00:00
|
|
|
|
{
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams runparams = runparams_in;
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// validate the buffer.
|
|
|
|
|
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
|
2004-01-21 17:52:07 +00:00
|
|
|
|
LaTeXFeatures features(*this, params(), runparams.nice);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().reset();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// The starting paragraph of the coming rows is the
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// first paragraph of the document. (Asger)
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().start(paragraphs().begin()->id(), 0);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (output_preamble && runparams.nice) {
|
2003-07-28 14:09:05 +00:00
|
|
|
|
os << "%% LyX " << lyx_version << " created this file. "
|
2000-03-06 02:42:40 +00:00
|
|
|
|
"For more info, see http://www.lyx.org/.\n"
|
|
|
|
|
"%% Do not edit unless you really know what "
|
|
|
|
|
"you are doing.\n";
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
|
|
|
|
texrow().newline();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "lyx header finished" << endl;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// There are a few differences between nice LaTeX and usual files:
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// usual is \batchmode and has a
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// special input@path to allow the including of figures
|
|
|
|
|
// with either \input or \includegraphics (what figinsets do).
|
2002-08-09 00:42:12 +00:00
|
|
|
|
// input@path is set when the actual parameter
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// original_path is set. This is done for usual tex-file, but not
|
|
|
|
|
// for nice-latex-file. (Matthias 250696)
|
2004-03-25 10:12:44 +00:00
|
|
|
|
// Note that input@path is only needed for something the user does
|
|
|
|
|
// in the preamble, included .tex files or ERT, files included by
|
|
|
|
|
// LyX work without it.
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (output_preamble) {
|
2003-05-22 21:10:22 +00:00
|
|
|
|
if (!runparams.nice) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// code for usual, NOT nice-latex-file
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\batchmode\n"; // changed
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// from \nonstopmode
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
if (!original_path.empty()) {
|
2002-03-07 16:03:36 +00:00
|
|
|
|
string inputpath = os::external_path(original_path);
|
|
|
|
|
subst(inputpath, "~", "\\string~");
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\makeatletter\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\def\\input@path{{"
|
2002-03-07 16:03:36 +00:00
|
|
|
|
<< inputpath << "/}}\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\makeatother\n";
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
|
|
|
|
texrow().newline();
|
|
|
|
|
texrow().newline();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-02-16 00:54:43 +00:00
|
|
|
|
// Write the preamble
|
2003-09-09 09:47:59 +00:00
|
|
|
|
runparams.use_babel = params().writeLaTeX(os, features, texrow());
|
2002-07-05 19:21:29 +00:00
|
|
|
|
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (!output_body)
|
2002-07-05 19:21:29 +00:00
|
|
|
|
return;
|
2002-05-10 12:58:07 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// make the body.
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\begin{document}\n";
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
2003-07-26 21:37:10 +00:00
|
|
|
|
} // output_preamble
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
|
2001-03-01 15:57:10 +00:00
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (!lyxrc.language_auto_begin) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << subst(lyxrc.language_command_begin, "$$lang",
|
2003-09-09 09:47:59 +00:00
|
|
|
|
params().language->babel())
|
2000-03-17 10:14:46 +00:00
|
|
|
|
<< endl;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
2000-03-17 10:14:46 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
|
// if we are doing a real file with body, even if this is the
|
|
|
|
|
// child of some other buffer, let's cut the link here.
|
|
|
|
|
// This happens for example if only a child document is printed.
|
|
|
|
|
string save_parentname;
|
|
|
|
|
if (output_preamble) {
|
|
|
|
|
save_parentname = params().parentname;
|
|
|
|
|
params().parentname.erase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the real stuff
|
2003-09-09 09:47:59 +00:00
|
|
|
|
latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
|
2000-05-04 08:14:34 +00:00
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
|
// Restore the parenthood if needed
|
|
|
|
|
if (output_preamble)
|
|
|
|
|
params().parentname = save_parentname;
|
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
// add this just in case after all the paragraphs
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << endl;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
2000-05-04 08:14:34 +00:00
|
|
|
|
|
2001-03-01 15:57:10 +00:00
|
|
|
|
if (!lyxrc.language_auto_end) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << subst(lyxrc.language_command_end, "$$lang",
|
2003-09-09 09:47:59 +00:00
|
|
|
|
params().language->babel())
|
2000-05-04 08:14:34 +00:00
|
|
|
|
<< endl;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (output_preamble) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\end{document}\n";
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Just to be sure. (Asger)
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().newline();
|
2000-05-04 08:14:34 +00:00
|
|
|
|
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< '.' << endl;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLatex() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
return params().getLyXTextClass().outputType() == LATEX;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLinuxDoc() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
return params().getLyXTextClass().outputType() == LINUXDOC;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLiterate() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
return params().getLyXTextClass().outputType() == LITERATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isDocBook() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
return params().getLyXTextClass().outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isSGML() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
LyXTextClass const & tclass = params().getLyXTextClass();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
return tclass.outputType() == LINUXDOC ||
|
|
|
|
|
tclass.outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
void Buffer::makeLinuxDocFile(string const & fname,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams,
|
2004-02-25 12:00:53 +00:00
|
|
|
|
bool body_only)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-26 20:09:56 +00:00
|
|
|
|
ofstream ofs;
|
2003-11-05 12:06:20 +00:00
|
|
|
|
if (!openFileWrite(ofs, fname))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2004-01-21 17:52:07 +00:00
|
|
|
|
LaTeXFeatures features(*this, params(), runparams.nice);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().reset();
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
LyXTextClass const & tclass = params().getLyXTextClass();
|
2002-03-02 19:09:56 +00:00
|
|
|
|
|
|
|
|
|
string top_element = tclass.latexname();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
2003-11-27 16:52:07 +00:00
|
|
|
|
ofs << tclass.class_header();
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string preamble = params().preamble;
|
2003-10-31 18:45:43 +00:00
|
|
|
|
string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml")
|
2002-03-05 13:38:40 +00:00
|
|
|
|
: fname;
|
|
|
|
|
preamble += features.getIncludedFiles(name);
|
2001-10-23 09:42:14 +00:00
|
|
|
|
preamble += features.getLyXSGMLEntities();
|
|
|
|
|
|
|
|
|
|
if (!preamble.empty()) {
|
|
|
|
|
ofs << " [ " << preamble << " ]";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
2001-10-23 09:42:14 +00:00
|
|
|
|
ofs << ">\n\n";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (params().options.empty())
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top_element);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
else {
|
|
|
|
|
string top = top_element;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += ' ';
|
2003-09-09 09:47:59 +00:00
|
|
|
|
top += params().options;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-28 14:09:05 +00:00
|
|
|
|
ofs << "<!-- LyX " << lyx_version
|
2000-01-19 14:07:39 +00:00
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/"
|
|
|
|
|
<< " -->\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
linuxdocParagraphs(*this, paragraphs(), ofs, runparams);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
|
|
|
|
ofs << "\n\n";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, 0, false, top_element);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (ofs.fail())
|
|
|
|
|
lyxerr << "File '" << fname << "' was not closed properly." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
void Buffer::makeDocBookFile(string const & fname,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams,
|
2003-10-31 18:45:43 +00:00
|
|
|
|
bool only_body)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-26 20:09:56 +00:00
|
|
|
|
ofstream ofs;
|
2003-11-05 12:06:20 +00:00
|
|
|
|
if (!openFileWrite(ofs, fname))
|
2003-03-29 09:48:03 +00:00
|
|
|
|
return;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2004-01-21 17:52:07 +00:00
|
|
|
|
LaTeXFeatures features(*this, params(), runparams.nice);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
validate(features);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
texrow().reset();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
LyXTextClass const & tclass = params().getLyXTextClass();
|
2002-03-02 19:09:56 +00:00
|
|
|
|
string top_element = tclass.latexname();
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!only_body) {
|
2003-11-27 16:52:07 +00:00
|
|
|
|
ofs << subst(tclass.class_header(), "#", top_element);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string preamble = params().preamble;
|
2003-10-31 18:45:43 +00:00
|
|
|
|
string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml")
|
2002-03-05 13:38:40 +00:00
|
|
|
|
: fname;
|
|
|
|
|
preamble += features.getIncludedFiles(name);
|
2001-10-23 09:42:14 +00:00
|
|
|
|
preamble += features.getLyXSGMLEntities();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-10-23 09:42:14 +00:00
|
|
|
|
if (!preamble.empty()) {
|
|
|
|
|
ofs << "\n [ " << preamble << " ]";
|
|
|
|
|
}
|
|
|
|
|
ofs << ">\n\n";
|
2000-11-13 15:43:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string top = top_element;
|
2001-01-28 21:54:15 +00:00
|
|
|
|
top += " lang=\"";
|
2003-09-09 09:47:59 +00:00
|
|
|
|
top += params().language->code();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += '"';
|
2001-01-28 21:54:15 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!params().options.empty()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += ' ';
|
2003-09-09 09:47:59 +00:00
|
|
|
|
top += params().options;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-11-27 16:52:07 +00:00
|
|
|
|
ofs << "<!-- SGML/XML file was created by LyX " << lyx_version
|
2000-07-01 12:54:45 +00:00
|
|
|
|
<< "\n See http://www.lyx.org/ for more information -->\n";
|
|
|
|
|
|
2003-11-25 17:23:36 +00:00
|
|
|
|
params().getLyXTextClass().counters().reset();
|
2003-10-31 18:45:43 +00:00
|
|
|
|
docbookParagraphs(*this, paragraphs(), ofs, runparams);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-13 15:43:36 +00:00
|
|
|
|
ofs << "\n\n";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, 0, false, top_element);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (ofs.fail())
|
|
|
|
|
lyxerr << "File '" << fname << "' was not closed properly." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
|
|
|
|
|
// Other flags: -wall -v0 -x
|
|
|
|
|
int Buffer::runChktex()
|
|
|
|
|
{
|
2003-07-07 08:37:02 +00:00
|
|
|
|
busy(true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// get LaTeX-Filename
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const name = getLatexName();
|
2004-02-25 12:00:53 +00:00
|
|
|
|
string const path = temppath();
|
|
|
|
|
string const org_path = filePath();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-10-13 17:32:46 +00:00
|
|
|
|
Path p(path); // path to LaTeX file
|
2003-07-07 08:37:02 +00:00
|
|
|
|
message(_("Running chktex..."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Generate the LaTeX file if neccessary
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams runparams;
|
|
|
|
|
runparams.flavor = OutputParams::LATEX;
|
2003-05-22 21:10:22 +00:00
|
|
|
|
runparams.nice = false;
|
|
|
|
|
makeLaTeXFile(name, org_path, runparams);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
TeXErrors terr;
|
2002-01-14 23:31:23 +00:00
|
|
|
|
Chktex chktex(lyxrc.chktex_command, name, filePath());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int res = chktex.run(terr); // run chktex
|
|
|
|
|
|
|
|
|
|
if (res == -1) {
|
2003-03-29 09:48:03 +00:00
|
|
|
|
Alert::error(_("chktex failure"),
|
2003-06-20 23:03:43 +00:00
|
|
|
|
_("Could not run chktex successfully."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else if (res > 0) {
|
|
|
|
|
// Insert all errors as errors boxes
|
2003-07-07 08:37:02 +00:00
|
|
|
|
bufferErrors(*this, terr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
busy(false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
void Buffer::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
LyXTextClass const & tclass = params().getLyXTextClass();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (params().tracking_changes) {
|
2003-02-08 19:18:01 +00:00
|
|
|
|
features.require("dvipost");
|
|
|
|
|
features.require("color");
|
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// AMS Style is at document level
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (params().use_amsmath == BufferParams::AMS_ON
|
2003-03-06 11:07:55 +00:00
|
|
|
|
|| tclass.provides(LyXTextClass::amsmath))
|
2002-01-10 10:05:45 +00:00
|
|
|
|
features.require("amsmath");
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
for_each(paragraphs().begin(), paragraphs().end(),
|
2002-08-14 22:15:18 +00:00
|
|
|
|
boost::bind(&Paragraph::validate, _1, boost::ref(features)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// the bullet shapes are buffer level not paragraph level
|
|
|
|
|
// so they are tested here
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
2003-09-09 17:00:19 +00:00
|
|
|
|
if (params().user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
|
|
|
|
|
int const font = params().user_defined_bullet(i).getFont();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (font == 0) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
int const c = params()
|
2003-09-09 17:00:19 +00:00
|
|
|
|
.user_defined_bullet(i)
|
1999-11-04 01:40:20 +00:00
|
|
|
|
.getCharacter();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (c == 16
|
|
|
|
|
|| c == 17
|
|
|
|
|
|| c == 25
|
|
|
|
|
|| c == 26
|
|
|
|
|
|| c == 31) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("latexsym");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if (font == 1) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("amssymb");
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if ((font >= 2 && font <= 5)) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("pifont");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::LATEX)) {
|
2000-04-10 21:40:13 +00:00
|
|
|
|
features.showStruct();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-16 11:49:38 +00:00
|
|
|
|
void Buffer::getLabelList(std::vector<string> & list) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
|
|
|
|
/// Use the parent's list instead [ale990407]
|
2004-03-25 10:12:44 +00:00
|
|
|
|
Buffer const * tmp = getMasterBuffer();
|
2004-03-27 12:46:30 +00:00
|
|
|
|
if (!tmp) {
|
|
|
|
|
lyxerr << "getMasterBuffer() failed!" << endl;
|
|
|
|
|
BOOST_ASSERT(tmp);
|
|
|
|
|
}
|
2004-03-25 10:12:44 +00:00
|
|
|
|
if (tmp != this) {
|
|
|
|
|
tmp->getLabelList(list);
|
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-30 08:18:09 +00:00
|
|
|
|
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
|
2004-03-27 12:46:30 +00:00
|
|
|
|
it.nextInset()->getLabelList(*this, list);
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// This is also a buffer property (ale)
|
2003-12-03 15:27:16 +00:00
|
|
|
|
void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys)
|
|
|
|
|
const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
2003-02-18 13:25:18 +00:00
|
|
|
|
/// use the parent's list instead [ale990412]
|
2004-03-25 10:12:44 +00:00
|
|
|
|
Buffer const * tmp = getMasterBuffer();
|
2004-03-27 12:46:30 +00:00
|
|
|
|
BOOST_ASSERT(tmp);
|
2004-03-25 10:12:44 +00:00
|
|
|
|
if (tmp != this) {
|
|
|
|
|
tmp->fillWithBibKeys(keys);
|
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-30 08:18:09 +00:00
|
|
|
|
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
|
2003-09-18 20:18:39 +00:00
|
|
|
|
if (it->lyxCode() == InsetOld::BIBTEX_CODE) {
|
|
|
|
|
InsetBibtex const & inset =
|
|
|
|
|
dynamic_cast<InsetBibtex const &>(*it);
|
|
|
|
|
inset.fillWithBibKeys(*this, keys);
|
|
|
|
|
} else if (it->lyxCode() == InsetOld::INCLUDE_CODE) {
|
|
|
|
|
InsetInclude const & inset =
|
|
|
|
|
dynamic_cast<InsetInclude const &>(*it);
|
|
|
|
|
inset.fillWithBibKeys(*this, keys);
|
|
|
|
|
} else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
|
|
|
|
|
InsetBibitem const & inset =
|
|
|
|
|
dynamic_cast<InsetBibitem const &>(*it);
|
|
|
|
|
string const key = inset.getContents();
|
|
|
|
|
string const opt = inset.getOptions();
|
2003-02-18 12:36:02 +00:00
|
|
|
|
string const ref; // = pit->asString(this, false);
|
|
|
|
|
string const info = opt + "TheBibliographyRef" + ref;
|
2003-02-18 13:25:18 +00:00
|
|
|
|
keys.push_back(pair<string, string>(key, info));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
bool Buffer::isDepClean(string const & name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
DepClean::const_iterator it = pimpl_->dep_clean.find(name);
|
|
|
|
|
if (it == pimpl_->dep_clean.end())
|
2003-02-09 00:27:52 +00:00
|
|
|
|
return true;
|
|
|
|
|
return it->second;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void Buffer::markDepClean(string const & name)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
pimpl_->dep_clean[name] = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
bool Buffer::dispatch(string const & command, bool * result)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
2003-09-21 23:00:47 +00:00
|
|
|
|
return dispatch(lyxaction.lookupFunc(command), result);
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
bool Buffer::dispatch(FuncRequest const & func, bool * result)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
2000-04-28 11:18:04 +00:00
|
|
|
|
bool dispatched = true;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
switch (func.action) {
|
2002-05-30 19:49:00 +00:00
|
|
|
|
case LFUN_EXPORT: {
|
2003-09-21 23:00:47 +00:00
|
|
|
|
bool const tmp = Exporter::Export(this, func.argument, false);
|
2002-05-30 19:49:00 +00:00
|
|
|
|
if (result)
|
|
|
|
|
*result = tmp;
|
1999-12-15 17:42:22 +00:00
|
|
|
|
break;
|
2002-05-30 19:49:00 +00:00
|
|
|
|
}
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2000-04-28 11:18:04 +00:00
|
|
|
|
dispatched = false;
|
|
|
|
|
}
|
|
|
|
|
return dispatched;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::changeLanguage(Language const * from, Language const * to)
|
2000-04-10 21:40:13 +00:00
|
|
|
|
{
|
2003-04-25 01:54:04 +00:00
|
|
|
|
lyxerr << "Changing Language!" << endl;
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
// Take care of l10n/i18n
|
2003-04-25 01:54:04 +00:00
|
|
|
|
updateDocLang(to);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2001-09-01 21:26:34 +00:00
|
|
|
|
ParIterator end = par_iterator_end();
|
|
|
|
|
for (ParIterator it = par_iterator_begin(); it != end; ++it)
|
2003-09-09 09:47:59 +00:00
|
|
|
|
it->changeLanguage(params(), from, to);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-25 01:54:04 +00:00
|
|
|
|
void Buffer::updateDocLang(Language const * nlang)
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
pimpl_->messages.reset(new Messages(nlang->code()));
|
2003-04-25 01:54:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2004-02-25 12:00:53 +00:00
|
|
|
|
bool Buffer::isMultiLingual() const
|
2000-04-10 21:40:13 +00:00
|
|
|
|
{
|
2004-02-25 12:00:53 +00:00
|
|
|
|
ParConstIterator end = par_iterator_end();
|
|
|
|
|
for (ParConstIterator it = par_iterator_begin(); it != end; ++it)
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (it->isMultiLingual(params()))
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return true;
|
2001-09-01 21:26:34 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
ParIterator Buffer::getParFromID(int id) const
|
2001-07-09 09:16:00 +00:00
|
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
|
ParConstIterator it = par_iterator_begin();
|
|
|
|
|
ParConstIterator end = par_iterator_end();
|
2003-04-28 18:20:31 +00:00
|
|
|
|
|
|
|
|
|
if (id < 0) {
|
|
|
|
|
// John says this is called with id == -1 from undo
|
|
|
|
|
lyxerr << "getParFromID(), id: " << id << endl;
|
2003-05-22 08:01:41 +00:00
|
|
|
|
return end;
|
2003-04-28 18:20:31 +00:00
|
|
|
|
}
|
2002-08-14 22:15:18 +00:00
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
for (; it != end; ++it)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
if (it->id() == id)
|
2003-05-22 08:01:41 +00:00
|
|
|
|
return it;
|
2003-02-14 02:21:01 +00:00
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
return end;
|
2001-07-09 09:16:00 +00:00
|
|
|
|
}
|
2001-09-01 21:26:34 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-05 17:28:21 +00:00
|
|
|
|
bool Buffer::hasParWithID(int id) const
|
|
|
|
|
{
|
2003-06-12 11:09:55 +00:00
|
|
|
|
ParConstIterator it = par_iterator_begin();
|
|
|
|
|
ParConstIterator end = par_iterator_end();
|
2003-05-05 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
if (id < 0) {
|
|
|
|
|
// John says this is called with id == -1 from undo
|
|
|
|
|
lyxerr << "hasParWithID(), id: " << id << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (; it != end; ++it)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
if (it->id() == id)
|
2003-05-05 17:28:21 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-01 21:26:34 +00:00
|
|
|
|
ParIterator Buffer::par_iterator_begin()
|
|
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
|
return ::par_iterator_begin(inset());
|
2001-09-01 21:26:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParIterator Buffer::par_iterator_end()
|
|
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
|
return ::par_iterator_end(inset());
|
2001-09-01 21:26:34 +00:00
|
|
|
|
}
|
2002-08-20 17:18:21 +00:00
|
|
|
|
|
2003-08-26 14:50:16 +00:00
|
|
|
|
|
2002-11-08 01:08:27 +00:00
|
|
|
|
ParConstIterator Buffer::par_iterator_begin() const
|
|
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
|
return ::par_const_iterator_begin(inset());
|
2002-11-08 01:08:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParConstIterator Buffer::par_iterator_end() const
|
|
|
|
|
{
|
2004-03-30 08:18:09 +00:00
|
|
|
|
return ::par_const_iterator_end(inset());
|
2002-11-08 01:08:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
Language const * Buffer::getLanguage() const
|
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
return params().language;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
string const Buffer::B_(string const & l10n) const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
if (pimpl_->messages.get()) {
|
|
|
|
|
return pimpl_->messages->get(l10n);
|
2003-04-24 23:19:41 +00:00
|
|
|
|
}
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
return _(l10n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
bool Buffer::isClean() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->lyx_clean;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isBakClean() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->bak_clean;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markClean() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
if (!pimpl_->lyx_clean) {
|
|
|
|
|
pimpl_->lyx_clean = true;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
// if the .lyx file has been saved, we don't need an
|
|
|
|
|
// autosave
|
2003-09-09 11:24:33 +00:00
|
|
|
|
pimpl_->bak_clean = true;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markBakClean()
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
pimpl_->bak_clean = true;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::setUnnamed(bool flag)
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
pimpl_->unnamed = flag;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-25 12:00:53 +00:00
|
|
|
|
bool Buffer::isUnnamed() const
|
2002-08-20 17:18:21 +00:00
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->unnamed;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markDirty()
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
if (pimpl_->lyx_clean) {
|
|
|
|
|
pimpl_->lyx_clean = false;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
2003-09-09 11:24:33 +00:00
|
|
|
|
pimpl_->bak_clean = false;
|
2003-02-09 00:27:52 +00:00
|
|
|
|
|
2003-09-09 11:24:33 +00:00
|
|
|
|
DepClean::iterator it = pimpl_->dep_clean.begin();
|
|
|
|
|
DepClean::const_iterator const end = pimpl_->dep_clean.end();
|
2003-02-09 00:27:52 +00:00
|
|
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
it->second = false;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & Buffer::fileName() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->filename;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & Buffer::filePath() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->filepath;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isReadonly() const
|
|
|
|
|
{
|
2003-09-09 11:24:33 +00:00
|
|
|
|
return pimpl_->read_only;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::setParentName(string const & name)
|
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
params().parentname = name;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
|
Buffer const * Buffer::getMasterBuffer() const
|
|
|
|
|
{
|
|
|
|
|
if (!params().parentname.empty()
|
|
|
|
|
&& bufferlist.exists(params().parentname)) {
|
|
|
|
|
Buffer const * buf = bufferlist.getBuffer(params().parentname);
|
|
|
|
|
if (buf)
|
|
|
|
|
return buf->getMasterBuffer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MacroData const & Buffer::getMacro(std::string const & name) const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->macros.get(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::hasMacro(string const & name) const
|
|
|
|
|
{
|
|
|
|
|
return pimpl_->macros.has(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::insertMacro(string const & name, MacroData const & data)
|
|
|
|
|
{
|
|
|
|
|
pimpl_->macros.insert(name, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::buildMacros()
|
|
|
|
|
{
|
|
|
|
|
// Start with global table.
|
|
|
|
|
pimpl_->macros = MacroTable::globalMacros();
|
|
|
|
|
|
|
|
|
|
// Now add our own.
|
|
|
|
|
ParagraphList & pars = text().paragraphs();
|
|
|
|
|
for (size_t i = 0, n = pars.size(); i != n; ++i) {
|
|
|
|
|
//lyxerr << "searching main par " << i
|
|
|
|
|
// << " for macro definitions" << std::endl;
|
|
|
|
|
InsetList::iterator it = pars[i].insetlist.begin();
|
|
|
|
|
InsetList::iterator end = pars[i].insetlist.end();
|
|
|
|
|
for ( ; it != end; ++it) {
|
|
|
|
|
//lyxerr << "found inset code " << it->inset->lyxCode() << std::endl;
|
|
|
|
|
if (it->inset->lyxCode() == InsetBase::MATHMACRO_CODE) {
|
|
|
|
|
MathMacroTemplate & mac
|
|
|
|
|
= static_cast<MathMacroTemplate &>(*it->inset);
|
|
|
|
|
insertMacro(mac.name(), mac.asMacroData());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|