// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-int const LYX_FORMAT = 372; // jspitzm: buffer param fontenc
+int const LYX_FORMAT = 374; // rgheck: HTML output options
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);
+ Impl(Buffer & parent, FileName const & file, bool readonly, Buffer const * cloned_buffer);
~Impl()
{
LYXERR0("Warning: a buffer should not have two parents!");
parent_buffer = pb;
}
+
+ /// If non zero, this buffer is a clone of existing buffer \p cloned_buffer_
+ /// This one is useful for preview detached in a thread.
+ Buffer const * cloned_buffer_;
+
private:
/// So we can force access via the accessors.
mutable Buffer const * parent_buffer;
+
};
}
-Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
+Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_,
+ Buffer const * cloned_buffer)
: 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), undo_(parent), bibinfoCacheValid_(false),
- parent_buffer(0)
+ cloned_buffer_(cloned_buffer), parent_buffer(0)
{
- temppath = createBufferTmpDir();
- lyxvc.setBuffer(&parent);
- if (use_gui)
- wa_ = new frontend::WorkAreaManager;
+ if (!cloned_buffer_) {
+ temppath = createBufferTmpDir();
+ lyxvc.setBuffer(&parent);
+ if (use_gui)
+ wa_ = new frontend::WorkAreaManager;
+ return;
+ }
+ temppath = cloned_buffer_->d->temppath;
+ file_fully_loaded = true;
+ params = cloned_buffer_->d->params;
}
-Buffer::Buffer(string const & file, bool readonly)
- : d(new Impl(*this, FileName(file), readonly)), gui_(0)
+Buffer::Buffer(string const & file, bool readonly, Buffer const * cloned_buffer)
+ : d(new Impl(*this, FileName(file), readonly, cloned_buffer)), gui_(0)
{
LYXERR(Debug::INFO, "Buffer::Buffer()");
-
- d->inset = new InsetText(this);
+ if (cloned_buffer) {
+ d->inset = static_cast<InsetText *>(cloned_buffer->d->inset->clone());
+ d->inset->setBuffer(*this);
+ } else
+ d->inset = new InsetText(this);
d->inset->setAutoBreakRows(true);
d->inset->getText(0)->setMacrocontextPosition(par_iterator_begin());
}
if (!isClean()) {
docstring msg = _("LyX attempted to close a document that had unsaved changes!\n");
msg += emergencyWrite();
- frontend::Alert::warning(_("Attempting to close changed document!"), msg);
+ Alert::warning(_("Attempting to close changed document!"), msg);
}
// clear references to children in macro tables
d->children_positions.clear();
d->position_to_children.clear();
- if (!d->temppath.destroyDirectory()) {
+ if (!d->cloned_buffer_ && !d->temppath.destroyDirectory()) {
Alert::warning(_("Could not remove temporary directory"),
bformat(_("Could not remove the temporary directory %1$s"),
from_utf8(d->temppath.absFilename())));
}
+Buffer * Buffer::clone() const
+{
+ return new Buffer(fileName().absFilename(), false, this);
+}
+
+
+bool Buffer::isClone() const
+{
+ return d->cloned_buffer_;
+}
+
+
void Buffer::changed() const
{
if (d->wa_)
{
LaTeXFeatures features(*this, params(), runparams);
validate(features);
+ updateLabels(UpdateMaster, true);
d->texrow.reset();
}
+bool Buffer::isExportableFormat(string const & format) const
+{
+ typedef vector<Format const *> Formats;
+ Formats formats;
+ formats = exportableFormats(true);
+ Formats::const_iterator fit = formats.begin();
+ Formats::const_iterator end = formats.end();
+ for (; fit != end ; ++fit) {
+ if ((*fit)->name() == format)
+ return true;
+ }
+ return false;
+}
+
+
bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
{
if (isInternal()) {
break;
}
- case LFUN_MASTER_BUFFER_UPDATE:
- case LFUN_MASTER_BUFFER_VIEW:
- enable = parent() != 0;
- break;
- case LFUN_BUFFER_UPDATE:
- case LFUN_BUFFER_VIEW: {
- string format = to_utf8(cmd.argument());
- if (cmd.argument().empty())
- format = getDefaultOutputFormat();
- typedef vector<Format const *> Formats;
- Formats formats;
- formats = exportableFormats(true);
- Formats::const_iterator fit = formats.begin();
- Formats::const_iterator end = formats.end();
- enable = false;
- for (; fit != end ; ++fit) {
- if ((*fit)->name() == format)
- enable = true;
- }
- break;
- }
case LFUN_BUFFER_CHKTEX:
enable = isLatex() && !lyxrc.chktex_command.empty();
break;
break;
case LFUN_BUFFER_EXPORT: {
- if (argument == "custom") {
- lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
- break;
- }
bool success = doExport(argument, false);
dr.setError(success);
if (!success)
break;
}
- case LFUN_BUFFER_UPDATE: {
- string format = argument;
- if (argument.empty())
- format = getDefaultOutputFormat();
- doExport(format, true);
- break;
- }
-
- case LFUN_BUFFER_VIEW: {
- string format = argument;
- if (argument.empty())
- format = getDefaultOutputFormat();
- preview(format);
- break;
- }
-
- case LFUN_MASTER_BUFFER_UPDATE: {
- string format = argument;
- if (argument.empty())
- format = masterBuffer()->getDefaultOutputFormat();
- masterBuffer()->doExport(format, true);
- break;
- }
-
- case LFUN_MASTER_BUFFER_VIEW: {
- string format = argument;
- if (argument.empty())
- format = masterBuffer()->getDefaultOutputFormat();
- masterBuffer()->preview(format);
- break;
- }
-
case LFUN_BUILD_PROGRAM:
doExport("program", true);
break;
}
-std::vector<Buffer *> Buffer::getChildren(bool grand_children) const
+void Buffer::getChildren(std::vector<Buffer *> & clist, bool grand_children) const
{
- std::vector<Buffer *> clist;
// loop over children
Impl::BufferPositionMap::iterator it = d->children_positions.begin();
Impl::BufferPositionMap::iterator end = d->children_positions.end();
clist.push_back(*git);
}
}
- return clist;
+}
+
+
+std::vector<Buffer *> Buffer::getChildren(bool grand_children) const
+{
+ std::vector<Buffer *> v;
+ getChildren(v, grand_children);
+ return v;
}
LYXERR(Debug::MACROS, "updateMacroInstances for "
<< d->filename.onlyFileName());
DocIterator it = doc_iterator_begin(this);
- DocIterator end = doc_iterator_end(this);
- for (; it != end; it.forwardPos()) {
- // look for MathData cells in InsetMathNest insets
- Inset * inset = it.nextInset();
- if (!inset)
- continue;
-
- InsetMath * minset = inset->asInsetMath();
+ it.forwardInset();
+ DocIterator const end = doc_iterator_end(this);
+ for (; it != end; it.forwardInset()) {
+ // look for MathData cells in InsetMathNest insets
+ InsetMath * minset = it.nextInset()->asInsetMath();
if (!minset)
continue;
path = p;
}
}
- if (!path.empty())
- runparams.flavor = theConverters().getFlavor(path);
- else {
- Alert::error(_("Couldn't export file"),
- bformat(_("No information for exporting the format %1$s."),
- formats.prettyName(format)));
+ if (path.empty()) {
+ if (!put_in_tempdir) {
+ // Only show this alert if this is an export to a non-temporary
+ // file (not for previewing).
+ Alert::error(_("Couldn't export file"), bformat(
+ _("No information for exporting the format %1$s."),
+ formats.prettyName(format)));
+ }
return false;
}
+ runparams.flavor = theConverters().getFlavor(path);
+
} else {
backend_format = format;
// FIXME: Don't hardcode format names here, but use a flag
}
-void Buffer::updateLabels(UpdateScope scope) const
+void Buffer::updateLabels(UpdateScope scope, bool out) 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();
+ master->updateLabels(UpdateMaster, out);
// 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->gui_)
// do the real work
ParIterator parit = cbuf.par_iterator_begin();
- updateLabels(parit);
+ updateLabels(parit, out);
if (master != this)
// TocBackend update will be done later.
if (par.params().startOfAppendix()) {
// FIXME: only the counter corresponding to toplevel
- // sectionning should be reset
+ // sectioning should be reset
counters.reset();
counters.appendix(true);
}
}
-void Buffer::updateLabels(ParIterator & parit) const
+void Buffer::updateLabels(ParIterator & parit, bool out) const
{
LASSERT(parit.pit() == 0, /**/);
InsetList::const_iterator end = parit->insetList().end();
for (; iit != end; ++iit) {
parit.pos() = iit->pos;
- iit->inset->updateLabels(parit);
+ iit->inset->updateLabels(parit, out);
}
}
}
DocIterator const end = doc_iterator_end(this);
for (; from != end; from.forwardPos()) {
// We are only interested in text so remove the math CursorSlice.
- while (from.inMathed())
- from.forwardInset();
+ while (from.inMathed()) {
+ from.pop_back();
+ from.pos()++;
+ }
+ // If from is at the end of the document (which is possible
+ // when leaving the mathed) LyX will crash later.
+ if (from == end)
+ break;
to = from;
if (from.paragraph().spellCheck(from.pos(), to.pos(), wl, suggestions)) {
word_lang = wl;
break;
}
- from = to;
- ++progress;
+
+ // Do not increase progress when from == to, otherwise the word
+ // count will be wrong.
+ if (from != to) {
+ from = to;
+ ++progress;
+ }
}
return progress;
}