#include "Lexer.h"
#include "LyXAction.h"
#include "LyX.h"
-#include "LyXFunc.h"
#include "LyXRC.h"
#include "LyXVC.h"
#include "output_docbook.h"
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-int const LYX_FORMAT = 376; // jspitzm: support for unincluded file maintenance
+int const LYX_FORMAT = 378; // ps: rev insetinfo
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
class Buffer::Impl
{
public:
- Impl(Buffer & parent, FileName const & file, bool readonly, Buffer const * cloned_buffer);
+ Impl(Buffer * owner, FileName const & file, bool readonly, Buffer const * cloned_buffer);
~Impl()
{
delete inset;
}
+ /// search for macro in local (buffer) table or in children
+ MacroData const * getBufferMacro(docstring const & name,
+ DocIterator const & pos) const;
+
+ /// Update macro table starting with position of it \param it in some
+ /// text inset.
+ void updateMacros(DocIterator & it, DocIterator & scope);
+ ///
+ void setLabel(ParIterator & it, UpdateType utype) const;
+ ///
+ void collectRelatives(BufferSet & bufs) const;
+
+ /** If we have branches that use the file suffix
+ feature, return the file name with suffix appended.
+ */
+ support::FileName exportFileName() const;
+
+ Buffer * owner_;
+
BufferParams params;
LyXVC lyxvc;
FileName temppath;
/// map from the macro name to the position map,
/// which maps the macro definition position to the scope and the MacroData.
NamePositionScopeMacroMap macros;
- bool macro_lock;
+ /// This seem to change the way Buffer::getMacro() works
+ mutable bool macro_lock;
/// positions of child buffers in the buffer
typedef map<Buffer const * const, DocIterator> BufferPositionMap;
}
-Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_,
+Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
Buffer const * cloned_buffer)
- : lyx_clean(true), bak_clean(true), unnamed(false),
+ : owner_(owner), lyx_clean(true), bak_clean(true), unnamed(false),
read_only(readonly_), filename(file), file_fully_loaded(false),
- toc_backend(&parent), macro_lock(false), timestamp_(0),
- checksum_(0), wa_(0), gui_(0), undo_(parent), bibinfo_cache_valid_(false),
+ toc_backend(owner), macro_lock(false), timestamp_(0),
+ checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
cloned_buffer_(cloned_buffer), parent_buffer(0)
{
if (!cloned_buffer_) {
temppath = createBufferTmpDir();
- lyxvc.setBuffer(&parent);
+ lyxvc.setBuffer(owner_);
if (use_gui)
wa_ = new frontend::WorkAreaManager;
return;
Buffer::Buffer(string const & file, bool readonly, Buffer const * cloned_buffer)
- : d(new Impl(*this, FileName(file), readonly, cloned_buffer))
+ : d(new Impl(this, FileName(file), readonly, cloned_buffer))
{
LYXERR(Debug::INFO, "Buffer::Buffer()");
if (cloned_buffer) {
string Buffer::latexName(bool const no_path) const
{
FileName latex_name =
- makeLatexName(exportFileName());
+ makeLatexName(d->exportFileName());
return no_path ? latex_name.onlyFileName()
: latex_name.absFilename();
}
-FileName Buffer::exportFileName() const
+FileName Buffer::Impl::exportFileName() const
{
docstring const branch_suffix =
- params().branchlist().getFilenameSuffix();
+ params.branchlist().getFilenameSuffix();
if (branch_suffix.empty())
- return fileName();
+ return filename;
- string const name = fileName().onlyFileNameWithoutExt()
+ string const name = filename.onlyFileNameWithoutExt()
+ to_utf8(branch_suffix);
- FileName res(fileName().onlyPath().absFilename() + "/" + name);
- res.changeExtension(fileName().extension());
+ FileName res(filename.onlyPath().absFilename() + "/" + name);
+ res.changeExtension(filename.extension());
return res;
}
<< ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
<< " -t " << convert<string>(LYX_FORMAT)
<< " -o " << quoteName(tmpfile.toFilesystemEncoding())
- << ' ' << quoteName(filename.toFilesystemEncoding());
+ << ' ' << quoteName(filename.toSafeFilesystemEncoding());
string const command_str = command.str();
LYXERR(Debug::INFO, "Running '" << command_str << '\'');
bformat(_("%1$s ended unexpectedly, which means"
" that it is probably corrupted."),
from_utf8(filename.absFilename())));
+ return failure;
}
d->file_fully_loaded = true;
}
-// Should probably be moved to somewhere else: BufferView? LyXView?
+// Should probably be moved to somewhere else: BufferView? GuiView?
bool Buffer::save() const
{
// We don't need autosaves in the immediate future. (Asger)
resetAutosaveTimers();
- string const encodedFilename = d->filename.toFilesystemEncoding();
-
FileName backupName;
bool madeBackup = false;
makeDisplayPath(fname.absFilename()));
message(str);
+ string const encoded_fname = fname.toSafeFilesystemEncoding(os::CREATE);
+
if (params().compressed) {
- gz::ogzstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+ gz::ogzstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
retval = ofs && write(ofs);
} else {
- ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+ ofstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
retval = ofs && write(ofs);
}
// FIXME UNICODE
// We don't know the encoding of inputpath
docstring const inputpath = from_utf8(latex_path(original_path));
- os << "\\makeatletter\n"
- << "\\def\\input@path{{"
- << inputpath << "/}}\n"
- << "\\makeatother\n";
- d->texrow.newline();
- d->texrow.newline();
- d->texrow.newline();
+ docstring uncodable_glyphs;
+ Encoding const * const enc = runparams.encoding;
+ if (enc) {
+ for (size_t n = 0; n < inputpath.size(); ++n) {
+ docstring const glyph =
+ docstring(1, inputpath[n]);
+ if (enc->latexChar(inputpath[n], true) != glyph) {
+ LYXERR0("Uncodable character '"
+ << glyph
+ << "' in input path!");
+ uncodable_glyphs += glyph;
+ }
+ }
+ }
+
+ // warn user if we found uncodable glyphs.
+ if (!uncodable_glyphs.empty()) {
+ frontend::Alert::warning(_("Uncodable character in file path"),
+ support::bformat(_("The path of your document\n"
+ "(%1$s)\n"
+ "contains glyphs that are unknown in the\n"
+ "current document encoding (namely %2$s).\n"
+ "This will likely result in incomplete output.\n\n"
+ "Chose an appropriate document encoding (such as utf8)\n"
+ "or change the file path name."), inputpath, uncodable_glyphs));
+ } else {
+ os << "\\makeatletter\n"
+ << "\\def\\input@path{{"
+ << inputpath << "/}}\n"
+ << "\\makeatother\n";
+ d->texrow.newline();
+ d->texrow.newline();
+ d->texrow.newline();
+ }
}
// get parent macros (if this buffer has a parent) which will be
// output the parent macros
MacroSet::iterator it = parentMacros.begin();
MacroSet::iterator end = parentMacros.end();
- for (; it != end; ++it)
- (*it)->write(os, true);
+ for (; it != end; ++it) {
+ int num_lines = (*it)->write(os, true);
+ d->texrow.newlines(num_lines);
+ }
+
} // output_preamble
d->texrow.start(paragraphs().begin()->id(), 0);
{
LaTeXFeatures features(*this, params(), runparams);
validate(features);
- updateLabels(UpdateMaster, OutputUpdate);
+ updateBuffer(UpdateMaster, OutputUpdate);
checkBibInfoCache();
d->bibinfo_.makeCitationLabels(*this);
updateMacros();
OutputParams runparams(¶ms().encoding());
runparams.flavor = OutputParams::LATEX;
runparams.nice = false;
+ runparams.linelen = lyxrc.plaintext_linelen;
makeLaTeXFile(FileName(name), org_path, runparams);
TeXErrors terr;
case LFUN_BUFFER_EXPORT: {
bool success = doExport(argument, false, false);
- dr.setError(success);
+ dr.setError(!success);
if (!success)
dr.setMessage(bformat(_("Error exporting to format: %1$s."),
func.argument()));
}
+std::set<Language const *> Buffer::getLanguages() const
+{
+ std::set<Language const *> languages;
+ getLanguages(languages);
+ return languages;
+}
+
+
+void Buffer::getLanguages(std::set<Language const *> & languages) const
+{
+ ParConstIterator end = par_iterator_end();
+ // add the buffer language, even if it's not actively used
+ languages.insert(language());
+ // iterate over the paragraphs
+ for (ParConstIterator it = par_iterator_begin(); it != end; ++it)
+ it->getLanguages(languages);
+ // also children
+ std::vector<Buffer *> clist = getChildren();
+ for (vector<Buffer *>::const_iterator cit = clist.begin();
+ cit != clist.end(); ++cit)
+ (*cit)->getLanguages(languages);
+}
+
+
DocIterator Buffer::getParFromID(int const id) const
{
Buffer * buf = const_cast<Buffer *>(this);
}
-void Buffer::collectRelatives(BufferSet & bufs) const
+void Buffer::Impl::collectRelatives(BufferSet & bufs) const
{
- bufs.insert(this);
+ bufs.insert(owner_);
if (parent())
- parent()->collectRelatives(bufs);
+ parent()->d->collectRelatives(bufs);
// loop over children
- Impl::BufferPositionMap::iterator it = d->children_positions.begin();
- Impl::BufferPositionMap::iterator end = d->children_positions.end();
+ BufferPositionMap::const_iterator it = children_positions.begin();
+ BufferPositionMap::const_iterator end = children_positions.end();
for (; it != end; ++it)
bufs.insert(const_cast<Buffer *>(it->first));
}
std::vector<Buffer const *> Buffer::allRelatives() const
{
BufferSet bufs;
- collectRelatives(bufs);
+ d->collectRelatives(bufs);
BufferSet::iterator it = bufs.begin();
std::vector<Buffer const *> ret;
for (; it != bufs.end(); ++it)
template<typename M>
-typename M::iterator greatest_below(M & m, typename M::key_type const & x)
+typename M::const_iterator greatest_below(M & m, typename M::key_type const & x)
{
if (m.empty())
return m.end();
- typename M::iterator it = m.lower_bound(x);
+ typename M::const_iterator it = m.lower_bound(x);
if (it == m.begin())
return m.end();
}
-MacroData const * Buffer::getBufferMacro(docstring const & name,
+MacroData const * Buffer::Impl::getBufferMacro(docstring const & name,
DocIterator const & pos) const
{
LYXERR(Debug::MACROS, "Searching for " << to_ascii(name) << " at " << pos);
return 0;
// we haven't found anything yet
- DocIterator bestPos = par_iterator_begin();
+ DocIterator bestPos = owner_->par_iterator_begin();
MacroData const * bestData = 0;
// find macro definitions for name
- Impl::NamePositionScopeMacroMap::iterator nameIt
- = d->macros.find(name);
- if (nameIt != d->macros.end()) {
+ NamePositionScopeMacroMap::const_iterator nameIt = macros.find(name);
+ if (nameIt != macros.end()) {
// find last definition in front of pos or at pos itself
- Impl::PositionScopeMacroMap::const_iterator it
+ PositionScopeMacroMap::const_iterator it
= greatest_below(nameIt->second, pos);
if (it != nameIt->second.end()) {
while (true) {
}
// find macros in included files
- Impl::PositionScopeBufferMap::const_iterator it
- = greatest_below(d->position_to_children, pos);
- if (it == d->position_to_children.end())
+ PositionScopeBufferMap::const_iterator it
+ = greatest_below(position_to_children, pos);
+ if (it == position_to_children.end())
// no children before
return bestData;
// scope ends behind pos?
if (pos < it->second.first) {
// look for macro in external file
- d->macro_lock = true;
+ macro_lock = true;
MacroData const * data
- = it->second.second->getMacro(name, false);
- d->macro_lock = false;
+ = it->second.second->getMacro(name, false);
+ macro_lock = false;
if (data) {
bestPos = it->first;
bestData = data;
}
// try previous file if there is one
- if (it == d->position_to_children.begin())
+ if (it == position_to_children.begin())
break;
--it;
}
return 0;
// query buffer macros
- MacroData const * data = getBufferMacro(name, pos);
+ MacroData const * data = d->getBufferMacro(name, pos);
if (data != 0)
return data;
}
-void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
+void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
{
pit_type const lastpit = it.lastpit();
// get buffer of external file
InsetInclude const & inset =
static_cast<InsetInclude const &>(*iit->inset);
- d->macro_lock = true;
+ macro_lock = true;
Buffer * child = inset.getChildBuffer();
- d->macro_lock = false;
+ macro_lock = false;
if (!child)
continue;
// register its position, but only when it is
// included first in the buffer
- if (d->children_positions.find(child) ==
- d->children_positions.end())
- d->children_positions[child] = it;
+ if (children_positions.find(child) ==
+ children_positions.end())
+ children_positions[child] = it;
// register child with its scope
- d->position_to_children[it] = Impl::ScopeBuffer(scope, child);
+ position_to_children[it] = Impl::ScopeBuffer(scope, child);
continue;
}
// get macro data
MathMacroTemplate & macroTemplate =
static_cast<MathMacroTemplate &>(*iit->inset);
- MacroContext mc(this, it);
+ MacroContext mc(owner_, it);
macroTemplate.updateToContext(mc);
// valid?
// register macro
// FIXME (Abdel), I don't understandt why we pass 'it' here
// instead of 'macroTemplate' defined above... is this correct?
- d->macros[macroTemplate.name()][it] =
- Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(this), it));
+ macros[macroTemplate.name()][it] =
+ Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(owner_), it));
}
// next paragraph
DocIterator it = par_iterator_begin();
DocIterator outerScope = it;
outerScope.pit() = outerScope.lastpit() + 2;
- updateMacros(it, outerScope);
+ d->updateMacros(it, outerScope);
}
void Buffer::moveAutosaveFile(support::FileName const & oldauto) const
{
FileName const newauto = getAutosaveFilename();
- if (!(oldauto == newauto || oldauto.moveTo(newauto)))
- LYXERR0("Unable to remove autosave file `" << oldauto << "'!");
+ oldauto.refresh();
+ if (newauto != oldauto && oldauto.exists())
+ if (!oldauto.moveTo(newauto))
+ LYXERR0("Unable to move autosave file `" << oldauto << "'!");
}
return true;
}
- result_file = changeExtension(exportFileName().absFilename(), ext);
+ result_file = changeExtension(d->exportFileName().absFilename(), ext);
// We need to copy referenced files (e. g. included graphics
// if format == "dvi") to the result dir.
vector<ExportedFile> const files =
&& !LyXVC::file_not_found_hook(s))
return false;
- if (s.isReadableFile()
- && readFileHelper(s)) {
+ if (s.isReadableFile()){
+ // InsetInfo needs to know if file is under VCS
lyxvc().file_found_hook(s);
- setReadonly(!s.isWritable());
- return true;
+ if (readFileHelper(s)) {
+ d->read_only = !s.isWritable();
+ return true;
+ }
}
return false;
}
}
-void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
+void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
{
// Use the master text class also for child documents
Buffer const * const master = masterBuffer();
// If this is a child document start with the master
if (master != this) {
bufToUpdate.insert(this);
- master->updateLabels(UpdateMaster, utype);
+ master->updateBuffer(UpdateMaster, utype);
// Do this here in case the master has no gui associated with it. Then,
// the TocModel is not updated and TocModel::toc_ is invalid (bug 5699).
if (!master->d->gui_)
// do the real work
ParIterator parit = cbuf.par_iterator_begin();
- updateLabels(parit, utype);
+ updateBuffer(parit, utype);
if (master != this)
// TocBackend update will be done later.
// set the label of a paragraph. This includes the counters.
-void Buffer::setLabel(ParIterator & it, UpdateType utype) const
+void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
{
- BufferParams const & bp = this->masterBuffer()->params();
+ BufferParams const & bp = owner_->masterBuffer()->params();
DocumentClass const & textclass = bp.documentClass();
Paragraph & par = it.paragraph();
Layout const & layout = par.layout();
string const & type = counters.current_float();
docstring full_label;
if (type.empty())
- full_label = this->B_("Senseless!!! ");
+ full_label = owner_->B_("Senseless!!! ");
else {
- docstring name = this->B_(textclass.floats().getType(type).name());
+ docstring name = owner_->B_(textclass.floats().getType(type).name());
if (counters.hasCounter(from_utf8(type))) {
string const & lang = par.getParLanguage(bp)->code();
counters.step(from_utf8(type), utype);
}
-void Buffer::updateLabels(ParIterator & parit, UpdateType utype) const
+void Buffer::updateBuffer(ParIterator & parit, UpdateType utype) const
{
LASSERT(parit.pit() == 0, /**/);
}
// set the counter for this paragraph
- setLabel(parit, utype);
+ d->setLabel(parit, utype);
// now the insets
InsetList::const_iterator iit = parit->insetList().begin();
InsetList::const_iterator end = parit->insetList().end();
for (; iit != end; ++iit) {
parit.pos() = iit->pos;
- iit->inset->updateLabels(parit, utype);
+ iit->inset->updateBuffer(parit, utype);
}
}
}
bool const success = loadLyXFile(d->filename);
if (success) {
- updateLabels();
+ updateBuffer();
changed(true);
markClean();
message(bformat(_("Document %1$s reloaded."), disp_fn));