#include "buffer.h"
+#include "author.h"
#include "buffer_funcs.h"
#include "bufferlist.h"
+#include "bufferparams.h"
+#include "Bullet.h"
#include "Chktex.h"
#include "debug.h"
#include "errorlist.h"
#include "exporter.h"
#include "format.h"
+#include "funcrequest.h"
#include "gettext.h"
#include "iterators.h"
#include "language.h"
#include "LyXAction.h"
#include "lyxlex.h"
#include "lyxrc.h"
+#include "lyxvc.h"
#include "messages.h"
+#include "paragraph.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "sgml.h"
+#include "texrow.h"
#include "undo.h"
#include "version.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/gzstream.h"
-#include "support/LAssert.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/path.h"
#ifdef HAVE_LOCALE
#endif
-using namespace lyx::support;
+using lyx::pos_type;
+
+using lyx::support::AddName;
+using lyx::support::ascii_lowercase;
+using lyx::support::atoi;
+using lyx::support::bformat;
+using lyx::support::ChangeExtension;
+using lyx::support::cmd_ret;
+using lyx::support::compare_ascii_no_case;
+using lyx::support::compare_no_case;
+using lyx::support::contains;
+using lyx::support::CreateBufferTmpDir;
+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;
+
+namespace os = lyx::support::os;
using std::endl;
using std::for_each;
using std::pair;
using std::stack;
using std::vector;
-
-using lyx::pos_type;
+using std::string;
// all these externs should eventually be removed.
return true;
}
-
} // namespace anon
+
+typedef std::map<string, bool> DepClean;
+
+struct Buffer::Impl
+{
+ Impl(Buffer & parent, string const & file, bool readonly);
+
+ limited_stack<Undo> undostack;
+ limited_stack<Undo> redostack;
+ BufferParams params;
+ ParagraphList paragraphs;
+ LyXVC lyxvc;
+ string temppath;
+ bool nicefile;
+ TexRow texrow;
+
+ /// need to regenerate .tex ?
+ DepClean dep_clean;
+
+ /// is save needed
+ mutable bool lyx_clean;
+
+ /// is autosave needed
+ mutable bool bak_clean;
+
+ /// is this a unnamed file (New...)
+ 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;
+};
+
+
+Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
+ : nicefile(true),
+ lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
+ filename(file), filepath(OnlyPath(file))
+{
+ lyxvc.buffer(&parent);
+ if (readonly_ || lyxrc.use_tempdir)
+ temppath = CreateBufferTmpDir();
+}
+
+
Buffer::Buffer(string const & file, bool ronly)
- : nicefile_(true), lyx_clean(true), bak_clean(true),
- unnamed(false), read_only(ronly),
- filename_(file)
+ : pimpl_(new Impl(*this, file, ronly))
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
- filepath_ = OnlyPath(file);
- lyxvc().buffer(this);
- if (read_only || lyxrc.use_tempdir) {
- temppath_ = CreateBufferTmpDir();
- } else {
- temppath_.erase();
- }
-
- // set initial author
- authors().record(Author(lyxrc.user_name, lyxrc.user_email));
}
limited_stack<Undo> & Buffer::undostack()
{
- return undostack_;
+ return pimpl_->undostack;
}
limited_stack<Undo> const & Buffer::undostack() const
{
- return undostack_;
+ return pimpl_->undostack;
}
limited_stack<Undo> & Buffer::redostack()
{
- return redostack_;
+ return pimpl_->redostack;
}
limited_stack<Undo> const & Buffer::redostack() const
{
- return redostack_;
+ return pimpl_->redostack;
}
BufferParams & Buffer::params()
{
- return params_;
+ return pimpl_->params;
}
BufferParams const & Buffer::params() const
{
- return params_;
+ return pimpl_->params;
}
ParagraphList & Buffer::paragraphs()
{
- return paragraphs_;
+ return pimpl_->paragraphs;
}
ParagraphList const & Buffer::paragraphs() const
{
- return paragraphs_;
+ return pimpl_->paragraphs;
}
LyXVC & Buffer::lyxvc()
{
- return lyxvc_;
+ return pimpl_->lyxvc;
}
LyXVC const & Buffer::lyxvc() const
{
- return lyxvc_;
+ return pimpl_->lyxvc;
}
string const & Buffer::temppath() const
{
- return temppath_;
+ return pimpl_->temppath;
}
bool & Buffer::niceFile()
{
- return nicefile_;
+ return pimpl_->nicefile;
}
bool Buffer::niceFile() const
{
- return nicefile_;
+ return pimpl_->nicefile;
}
TexRow & Buffer::texrow()
{
- return texrow_;
+ return pimpl_->texrow;
}
TexRow const & Buffer::texrow() const
{
- return texrow_;
+ return pimpl_->texrow;
}
void Buffer::setReadonly(bool flag)
{
- if (read_only != flag) {
- read_only = flag;
+ if (pimpl_->read_only != flag) {
+ pimpl_->read_only = flag;
readonly(flag);
}
}
-AuthorList & Buffer::authors()
-{
- return params().authorlist;
-}
-
-
void Buffer::setFileName(string const & newfile)
{
- filename_ = MakeAbsPath(newfile);
- filepath_ = OnlyPath(filename_);
- setReadonly(IsFileWriteable(filename_) == 0);
+ pimpl_->filename = MakeAbsPath(newfile);
+ pimpl_->filepath = OnlyPath(pimpl_->filename);
+ setReadonly(IsFileWriteable(pimpl_->filename) == 0);
updateTitles();
}
int Buffer::readParagraph(LyXLex & lex, string const & token,
ParagraphList & pars, ParagraphList::iterator & pit,
- Paragraph::depth_type & depth)
+ lyx::depth_type & depth)
{
static Change current_change;
int unknown = 0;
bool Buffer::readFile(LyXLex & lex, string const & filename,
ParagraphList::iterator pit)
{
- Assert(!filename.empty());
+ BOOST_ASSERT(!filename.empty());
if (!lex.isOK()) {
Alert::error(_("Document could not be read"),
bool Buffer::writeFile(string const & fname) const
{
- if (read_only && (fname == fileName())) {
+ if (pimpl_->read_only && (fname == fileName())) {
return false;
}
}
}
buffer << word;
- return STRCONV(buffer.str());
+ return buffer.str();
}
// validate the buffer.
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
- LaTeXFeatures features(params());
+ LaTeXFeatures features(*this, params());
validate(features);
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
niceFile() = nice; // this will be used by included files.
- LaTeXFeatures features(params());
+ LaTeXFeatures features(*this, params());
validate(features);
ofs << "<!doctype linuxdoc system";
string preamble = params().preamble;
- string const name = nice ? ChangeExtension(filename_, ".sgml")
+ string const name = nice ? ChangeExtension(pimpl_->filename, ".sgml")
: fname;
preamble += features.getIncludedFiles(name);
preamble += features.getLyXSGMLEntities();
// Handle internal paragraph parsing -- layout already processed.
void Buffer::simpleLinuxDocOnePar(ostream & os,
ParagraphList::iterator par,
- Paragraph::depth_type /*depth*/) const
+ lyx::depth_type /*depth*/) const
{
LyXLayout_ptr const & style = par->layout();
niceFile() = nice; // this will be used by Insetincludes.
- LaTeXFeatures features(params());
+ LaTeXFeatures features(*this, params());
validate(features);
texrow().reset();
<< " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
string preamble = params().preamble;
- string const name = nice ? ChangeExtension(filename_, ".sgml")
+ string const name = nice ? ChangeExtension(pimpl_->filename, ".sgml")
: fname;
preamble += features.getIncludedFiles(name);
preamble += features.getLyXSGMLEntities();
void Buffer::simpleDocBookOnePar(ostream & os,
ParagraphList::iterator par, int & desc_on,
- Paragraph::depth_type depth) const
+ lyx::depth_type depth) const
{
bool emph_flag = false;
// the bullet shapes are buffer level not paragraph level
// so they are tested here
for (int i = 0; i < 4; ++i) {
- if (params().user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
- int const font = params().user_defined_bullets[i].getFont();
+ if (params().user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
+ int const font = params().user_defined_bullet(i).getFont();
if (font == 0) {
int const c = params()
- .user_defined_bullets[i]
+ .user_defined_bullet(i)
.getCharacter();
if (c == 16
|| c == 17
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it) {
- it->getLabelList(list);
+ it->getLabelList(*this, list);
}
}
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it) {
- if (it->lyxCode() == InsetOld::BIBTEX_CODE)
- static_cast<InsetBibtex &>(*it).fillWithBibKeys(*this, keys);
- else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
- static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
- else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
- InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
- string const key = bib.getContents();
- string const opt = bib.getOptions();
+ 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();
string const ref; // = pit->asString(this, false);
string const info = opt + "TheBibliographyRef" + ref;
keys.push_back(pair<string, string>(key, info));
bool Buffer::isDepClean(string const & name) const
{
- DepClean::const_iterator it = dep_clean_.find(name);
- if (it == dep_clean_.end())
+ DepClean::const_iterator it = pimpl_->dep_clean.find(name);
+ if (it == pimpl_->dep_clean.end())
return true;
return it->second;
}
void Buffer::markDepClean(string const & name)
{
- dep_clean_[name] = true;
+ pimpl_->dep_clean[name] = true;
}
bool Buffer::dispatch(string const & command, bool * result)
{
- // Split command string into command and argument
- string cmd;
- string line = ltrim(command);
- string const arg = trim(split(line, cmd, ' '));
-
- return dispatch(lyxaction.LookupFunc(cmd), arg, result);
+ return dispatch(lyxaction.lookupFunc(command), result);
}
-bool Buffer::dispatch(int action, string const & argument, bool * result)
+bool Buffer::dispatch(FuncRequest const & func, bool * result)
{
bool dispatched = true;
- switch (action) {
+ switch (func.action) {
case LFUN_EXPORT: {
- bool const tmp = Exporter::Export(this, argument, false);
+ bool const tmp = Exporter::Export(this, func.argument, false);
if (result)
*result = tmp;
break;
void Buffer::updateDocLang(Language const * nlang)
{
- messages_.reset(new Messages(nlang->code()));
+ pimpl_->messages.reset(new Messages(nlang->code()));
}
string const Buffer::B_(string const & l10n) const
{
- if (messages_.get()) {
- return messages_->get(l10n);
+ if (pimpl_->messages.get()) {
+ return pimpl_->messages->get(l10n);
}
return _(l10n);
bool Buffer::isClean() const
{
- return lyx_clean;
+ return pimpl_->lyx_clean;
}
bool Buffer::isBakClean() const
{
- return bak_clean;
+ return pimpl_->bak_clean;
}
void Buffer::markClean() const
{
- if (!lyx_clean) {
- lyx_clean = true;
+ if (!pimpl_->lyx_clean) {
+ pimpl_->lyx_clean = true;
updateTitles();
}
// if the .lyx file has been saved, we don't need an
// autosave
- bak_clean = true;
+ pimpl_->bak_clean = true;
}
void Buffer::markBakClean()
{
- bak_clean = true;
+ pimpl_->bak_clean = true;
}
void Buffer::setUnnamed(bool flag)
{
- unnamed = flag;
+ pimpl_->unnamed = flag;
}
bool Buffer::isUnnamed()
{
- return unnamed;
+ return pimpl_->unnamed;
}
void Buffer::markDirty()
{
- if (lyx_clean) {
- lyx_clean = false;
+ if (pimpl_->lyx_clean) {
+ pimpl_->lyx_clean = false;
updateTitles();
}
- bak_clean = false;
+ pimpl_->bak_clean = false;
- DepClean::iterator it = dep_clean_.begin();
- DepClean::const_iterator const end = dep_clean_.end();
+ DepClean::iterator it = pimpl_->dep_clean.begin();
+ DepClean::const_iterator const end = pimpl_->dep_clean.end();
for (; it != end; ++it) {
it->second = false;
string const & Buffer::fileName() const
{
- return filename_;
+ return pimpl_->filename;
}
string const & Buffer::filePath() const
{
- return filepath_;
+ return pimpl_->filepath;
}
bool Buffer::isReadonly() const
{
- return read_only;
+ return pimpl_->read_only;
}