from_utf8(d->temppath.absFileName())));
}
- // Remove any previewed LaTeX snippets associated with this buffer.
if (!isClone())
- thePreviews().removeLoader(*this);
+ removePreviews();
delete d;
}
return readFile(tmpFile);
}
+ // InsetInfo needs to know if file is under VCS
+ lyxvc().file_found_hook(fn);
+
if (readDocument(lex)) {
Alert::error(_("Document format failure"),
bformat(_("%1$s ended unexpectedly, which means"
}
d->file_fully_loaded = true;
- // InsetInfo needs to know if file is under VCS
- lyxvc().file_found_hook(fn);
d->read_only = !fname.isWritable();
params().compressed = fname.isZippedFile();
+ saveCheckSum();
return ReadSuccess;
}
}
+void Buffer::updatePreviews() const
+{
+ if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
+ thePreviews().generateBufferPreviews(*this);
+}
+
+
+void Buffer::removePreviews() const
+{
+ thePreviews().removeLoader(*this);
+}
+
+
Buffer::ReadStatus Buffer::parseLyXFormat(Lexer & lex,
FileName const & fn, int & file_format) const
{
// see bug 6587
// removeAutosaveFile();
- saveCheckSum(d->filename);
+ saveCheckSum();
message(str + _(" done."));
return true;
d->bibfiles_cache_.clear();
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
if (it->lyxCode() == BIBTEX_CODE) {
- InsetBibtex const & inset =
- static_cast<InsetBibtex const &>(*it);
+ InsetBibtex const & inset = static_cast<InsetBibtex const &>(*it);
support::FileNameList const bibfiles = inset.getBibFiles();
d->bibfiles_cache_.insert(d->bibfiles_cache_.end(),
bibfiles.begin(),
bibfiles.end());
} else if (it->lyxCode() == INCLUDE_CODE) {
- InsetInclude & inset =
- static_cast<InsetInclude &>(*it);
+ InsetInclude & inset = static_cast<InsetInclude &>(*it);
Buffer const * const incbuf = inset.getChildBuffer();
if (!incbuf)
continue;
bool success = false;
for (; it != end; ++it) {
if (it->lyxCode() == BRANCH_CODE) {
- InsetBranch & ins = dynamic_cast<InsetBranch &>(*it);
+ InsetBranch & ins = static_cast<InsetBranch &>(*it);
if (ins.branch() == oldname) {
undo().recordUndo(it);
ins.rename(newname);
}
-void Buffer::saveCheckSum(FileName const & file) const
+void Buffer::saveCheckSum() const
{
+ FileName const & file = d->filename;
if (file.exists()) {
d->timestamp_ = file.lastModified();
d->checksum_ = file.checksum();
continue;
}
- if (doing_export && iit->inset->asInsetMath()) {
- InsetMath * im = static_cast<InsetMath *>(iit->inset);
- if (im->asHullInset()) {
- InsetMathHull * hull = static_cast<InsetMathHull *>(im);
+ InsetMath * im = iit->inset->asInsetMath();
+ if (doing_export && im) {
+ InsetMathHull * hull = im->asHullInset();
+ if (hull)
hull->recordLocation(it);
- }
}
if (iit->inset->lyxCode() != MATHMACRO_CODE)
// get macro data
MathMacroTemplate & macroTemplate =
- static_cast<MathMacroTemplate &>(*iit->inset);
+ *iit->inset->asInsetMath()->asMacroTemplate();
MacroContext mc(owner_, it);
macroTemplate.updateToContext(mc);
InsetIterator const end = inset_iterator_end(inset());
for (; it != end; ++it) {
if (it->lyxCode() == BRANCH_CODE) {
- InsetBranch & br = dynamic_cast<InsetBranch &>(*it);
+ InsetBranch & br = static_cast<InsetBranch &>(*it);
docstring const name = br.branch();
if (!from_master && !params().branchlist().find(name))
result.push_back(name);
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
if (it->lyxCode() == code) {
- InsetCommand & inset = static_cast<InsetCommand &>(*it);
- docstring const oldValue = inset.getParam(paramName);
+ InsetCommand * inset = it->asInsetCommand();
+ if (!inset)
+ continue;
+ docstring const oldValue = inset->getParam(paramName);
if (oldValue == from)
- inset.setParam(paramName, to);
+ inset->setParam(paramName, to);
}
}
}
ReadStatus const ret_llf = loadThisLyXFile(emergencyFile);
bool const success = (ret_llf == ReadSuccess);
if (success) {
- saveCheckSum(fn);
markDirty();
+ lyxvc().file_found_hook(fn);
str = _("Document was successfully recovered.");
} else
str = _("Document was NOT successfully recovered.");
// the file is not saved if we load the autosave file.
if (ret_llf == ReadSuccess) {
markDirty();
- saveCheckSum(fn);
+ lyxvc().file_found_hook(fn);
return ReadSuccess;
}
return ReadAutosaveFailure;
}
-bool Buffer::reload()
+Buffer::ReadStatus Buffer::reload()
{
setBusy(true);
// c.f. bug 6587
d->filename.refresh();
docstring const disp_fn = makeDisplayPath(d->filename.absFileName());
- bool const success = (loadLyXFile(d->filename) == ReadSuccess);
- if (success) {
+ ReadStatus const status = loadLyXFile(d->filename);
+ if (status == ReadSuccess) {
updateBuffer();
changed(true);
updateTitles();
markClean();
- saveCheckSum(d->filename);
message(bformat(_("Document %1$s reloaded."), disp_fn));
} else {
message(bformat(_("Could not reload document %1$s."), disp_fn));
}
setBusy(false);
- thePreviews().removeLoader(*this);
- if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
- thePreviews().generateBufferPreviews(*this);
+ removePreviews();
+ updatePreviews();
errors("Parse");
- return success;
+ return status;
}