X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBuffer.cpp;h=ec11ac2c88b3ca433b9d3d04495dec41b4cfc863;hb=b536759c0769dab641993347baeb62400455be04;hp=d78b5f49bd92ca6398267ee303caf4f9d0a04293;hpb=0daceae649f9cf5633f06bb350f3309838a0a55f;p=lyx.git diff --git a/src/Buffer.cpp b/src/Buffer.cpp index d78b5f49bd..ec11ac2c88 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -201,40 +201,9 @@ public: /// need to regenerate .tex? DepClean dep_clean; - /// is save needed? - mutable bool lyx_clean; - - /// is autosave needed? - mutable bool bak_clean; - - /// is this an unnamed file (New...)? - bool unnamed; - - /// is this an internal bufffer? - bool internal_buffer; - - /// buffer is r/o - bool read_only; - /// name of the file the buffer is associated with. FileName filename; - /** Set to true only when the file is fully loaded. - * Used to prevent the premature generation of previews - * and by the citation inset. - */ - bool file_fully_loaded; - - /// original format of loaded file - int file_format; - - /// if the file was originally loaded from an older format, do - /// we need to back it up still? - bool need_format_backup; - - /// Ignore the parent (e.g. when exporting a child standalone)? - bool ignore_parent; - /// mutable TocBackend toc_backend; @@ -251,8 +220,6 @@ public: /// map from the macro name to the position map, /// which maps the macro definition position to the scope and the MacroData. NamePositionScopeMacroMap macros; - /// This seem to change the way Buffer::getMacro() works - mutable bool macro_lock; /// positions of child buffers in the buffer typedef map BufferPositionMap; @@ -304,25 +271,13 @@ public: // file, and then to construct the Buffer's bibinfo from that. /// A cache for bibliography info mutable BiblioInfo bibinfo_; - /// whether the bibinfo cache is valid - mutable bool bibinfo_cache_valid_; /// Cache of timestamps of .bib files map bibfile_status_; - /// Indicates whether the bibinfo has changed since the last time - /// we ran updateBuffer(), i.e., whether citation labels may need - /// to be updated. - mutable bool cite_labels_valid_; - /// Do we have a bibliography environment? - mutable bool have_bibitems_; /// These two hold the file name and format, written to by /// Buffer::preview and read from by LFUN_BUFFER_VIEW_CACHE. FileName preview_file_; string preview_format_; - /// If there was an error when previewing, on the next preview we do - /// a fresh compile (e.g. in case the user installed a package that - /// was missing). - bool require_fresh_start_; /// Cache the references associated to a label and their positions /// in the buffer. @@ -336,6 +291,81 @@ public: /// PreviewLoader * preview_loader_; + /// 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_; + /// + CloneList_ptr clone_list_; + +private: + /// So we can force access via the accessors. + mutable Buffer const * parent_buffer; + + FileMonitorPtr file_monitor_; + +/// ints and bools are all listed last so as to avoid alignment issues +public: + /// original format of loaded file + int file_format; + + /// are we in the process of exporting this buffer? + mutable bool doing_export; + + /// If there was an error when previewing, on the next preview we do + /// a fresh compile (e.g. in case the user installed a package that + /// was missing). + bool require_fresh_start_; + + /// Indicates whether the bibinfo has changed since the last time + /// we ran updateBuffer(), i.e., whether citation labels may need + /// to be updated. + mutable bool cite_labels_valid_; + /// Do we have a bibliography environment? + mutable bool have_bibitems_; + + /// is save needed? + mutable bool lyx_clean; + + /// is autosave needed? + mutable bool bak_clean; + + /// is this an unnamed file (New...)? + bool unnamed; + + /// is this an internal bufffer? + bool internal_buffer; + + /// buffer is r/o + bool read_only; + + /** Set to true only when the file is fully loaded. + * Used to prevent the premature generation of previews + * and by the citation inset. + */ + bool file_fully_loaded; + + /// if the file was originally loaded from an older format, do + /// we need to back it up still? + bool need_format_backup; + + /// Ignore the parent (e.g. when exporting a child standalone)? + bool ignore_parent; + + /// This seem to change the way Buffer::getMacro() works + mutable bool macro_lock; + + /// has been externally modified? Can be reset by the user. + mutable bool externally_modified_; + + /// whether the bibinfo cache is valid + mutable bool bibinfo_cache_valid_; + +private: + int word_count_; + int char_count_; + int blank_count_; + +public: /// This is here to force the test to be done whenever parent_buffer /// is accessed. Buffer const * parent() const @@ -368,14 +398,6 @@ public: parent_buffer->invalidateBibinfoCache(); } - /// 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_; - /// - CloneList_ptr clone_list_; - /// are we in the process of exporting this buffer? - mutable bool doing_export; - /// compute statistics /// \p from initial position /// \p to points to the end position @@ -398,24 +420,11 @@ public: /// Notify or clear of external modification void fileExternallyModified(bool exists); - /// has been externally modified? Can be reset by the user. - mutable bool externally_modified_; - ///Binding LaTeX lines with buffer positions. //Common routine for LaTeX and Reference errors listing. void traverseErrors(TeXErrors::Errors::const_iterator err, TeXErrors::Errors::const_iterator end, ErrorList & errorList) const; - -private: - /// So we can force access via the accessors. - mutable Buffer const * parent_buffer; - - int word_count_; - int char_count_; - int blank_count_; - - FileMonitorPtr file_monitor_; }; @@ -448,15 +457,15 @@ static FileName createBufferTmpDir() Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_, Buffer const * cloned_buffer) - : owner_(owner), lyx_clean(true), bak_clean(true), unnamed(false), - internal_buffer(false), read_only(readonly_), filename(file), - file_fully_loaded(false), file_format(LYX_FORMAT), need_format_backup(false), - ignore_parent(false), toc_backend(owner), macro_lock(false), - checksum_(0), wa_(nullptr), gui_(nullptr), undo_(*owner), bibinfo_cache_valid_(false), - cite_labels_valid_(false), have_bibitems_(false), require_fresh_start_(false), - inset(nullptr), preview_loader_(nullptr), cloned_buffer_(cloned_buffer), - clone_list_(nullptr), doing_export(false), - externally_modified_(false), parent_buffer(nullptr), + : owner_(owner), filename(file), toc_backend(owner), checksum_(0), + wa_(nullptr), gui_(nullptr), undo_(*owner), inset(nullptr), + preview_loader_(nullptr), cloned_buffer_(cloned_buffer), + clone_list_(nullptr), parent_buffer(nullptr), file_format(LYX_FORMAT), + doing_export(false), require_fresh_start_(false), cite_labels_valid_(false), + have_bibitems_(false), lyx_clean(true), bak_clean(true), unnamed(false), + internal_buffer(false), read_only(readonly_), file_fully_loaded(false), + need_format_backup(false), ignore_parent(false), macro_lock(false), + externally_modified_(false), bibinfo_cache_valid_(false), word_count_(0), char_count_(0), blank_count_(0) { refreshFileMonitor(); @@ -596,7 +605,7 @@ Buffer::~Buffer() Buffer * Buffer::cloneWithChildren() const { BufferMap bufmap; - cloned_buffers.push_back(CloneList_ptr(new CloneList)); + cloned_buffers.emplace_back(new CloneList); CloneList_ptr clones = cloned_buffers.back(); cloneWithChildren(bufmap, clones); @@ -660,7 +669,7 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, CloneList_ptr clones) const Buffer * Buffer::cloneBufferOnly() const { - cloned_buffers.push_back(CloneList_ptr(new CloneList)); + cloned_buffers.emplace_back(new CloneList); CloneList_ptr clones = cloned_buffers.back(); Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, this); @@ -2252,10 +2261,6 @@ Buffer::ExportStatus Buffer::writeLyXHTMLSource(odocstream & os, if (!styles.empty()) os << "\n\n" << styles << '\n'; - styles = features.getPreambleSnippets().str; - if (!styles.empty()) - os << "\n\n" << styles << '\n'; - // we will collect CSS information in a stream, and then output it // either here, as part of the header, or else in a separate file. odocstringstream css; @@ -3168,7 +3173,7 @@ Language const * Buffer::language() const } -docstring const Buffer::B_(string const & l10n) const +docstring Buffer::B_(string const & l10n) const { return params().B_(l10n); } @@ -3399,7 +3404,7 @@ vector> const Buffer::prepareBibFilePaths(OutputParams c enc = params().bibFileEncoding(utf8input); bool recorded = false; - for (pair pe : res) { + for (auto const & pe : res) { if (pe.first == path) { recorded = true; break; @@ -3987,7 +3992,7 @@ void Buffer::setInsetLabel(docstring const & label, InsetLabel const * il, InsetLabel const * Buffer::insetLabel(docstring const & label, bool const active) const { - for (auto & rc : masterBuffer()->d->label_cache_) { + for (auto const & rc : masterBuffer()->d->label_cache_) { if (rc.label == label && (rc.active || !active)) return rc.inset; } @@ -4226,91 +4231,6 @@ void Buffer::setGuiDelegate(frontend::GuiBufferDelegate * gui) } - -namespace { - -class AutoSaveBuffer : public ForkedProcess { -public: - /// - AutoSaveBuffer(Buffer const & buffer, FileName const & fname) - : buffer_(buffer), fname_(fname) {} - /// - virtual shared_ptr clone() const - { - return make_shared(*this); - } - /// - int start() - { - command_ = to_utf8(bformat(_("Auto-saving %1$s"), - from_utf8(fname_.absFileName()))); - return run(DontWait); - } -private: - /// - virtual int generateChild(); - /// - Buffer const & buffer_; - FileName fname_; -}; - - -int AutoSaveBuffer::generateChild() -{ -#if defined(__APPLE__) - /* FIXME fork() is not usable for autosave on Mac OS X 10.6 (snow leopard) - * We should use something else like threads. - * - * Since I do not know how to determine at run time what is the OS X - * version, I just disable forking altogether for now (JMarc) - */ - pid_t const pid = -1; -#else - // tmp_ret will be located (usually) in /tmp - // will that be a problem? - // Note that this calls ForkedCalls::fork(), so it's - // ok cross-platform. - pid_t const pid = fork(); - // If you want to debug the autosave - // you should set pid to -1, and comment out the fork. - if (pid != 0 && pid != -1) - return pid; -#endif - - // pid = -1 signifies that lyx was unable - // to fork. But we will do the save - // anyway. - bool failed = false; - TempFile tempfile("lyxautoXXXXXX.lyx"); - tempfile.setAutoRemove(false); - FileName const tmp_ret = tempfile.name(); - if (!tmp_ret.empty()) { - if (!buffer_.writeFile(tmp_ret)) - failed = true; - else if (!tmp_ret.moveTo(fname_)) - failed = true; - } else - failed = true; - - if (failed) { - // failed to write/rename tmp_ret so try writing direct - if (!buffer_.writeFile(fname_)) { - // It is dangerous to do this in the child, - // but safe in the parent, so... - if (pid == -1) // emit message signal. - buffer_.message(_("Autosave failed!")); - } - } - - if (pid == 0) // we are the child so... - _exit(0); - - return pid; -} - -} // namespace - - FileName Buffer::getEmergencyFileName() const { return FileName(d->filename.absFileName() + ".emergency"); @@ -4407,7 +4327,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir string & result_file) const { bool const update_unincluded = - params().maintain_unincluded_children + params().maintain_unincluded_children != BufferParams::CM_None && !params().getIncludedChildren().empty(); // (1) export with all included children (omit \includeonly) @@ -4578,8 +4498,9 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir string const ext = theFormats().extension(format); FileName const tmp_result_file(changeExtension(filename, ext)); Converters::RetVal const retval = - converters.convert(this, FileName(filename), tmp_result_file, - FileName(absFileName()), backend_format, format, error_list); + converters.convert(this, FileName(filename), tmp_result_file, + FileName(absFileName()), backend_format, format, + error_list, Converters::none, includeall); if (retval == Converters::KILLED) return ExportCancel; bool success = (retval == Converters::SUCCESS); @@ -4694,7 +4615,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir Buffer::ExportStatus Buffer::preview(string const & format) const { bool const update_unincluded = - params().maintain_unincluded_children + params().maintain_unincluded_children != BufferParams::CM_None && !params().getIncludedChildren().empty(); return preview(format, update_unincluded); } @@ -5295,7 +5216,7 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const } -void Buffer::updateBuffer(ParIterator & parit, UpdateType utype) const +void Buffer::updateBuffer(ParIterator & parit, UpdateType utype, bool const deleted) const { // LASSERT: Is it safe to continue here, or should we just return? LASSERT(parit.pit() == 0, /**/); @@ -5341,7 +5262,7 @@ void Buffer::updateBuffer(ParIterator & parit, UpdateType utype) const // now the insets for (auto const & insit : parit->insetList()) { parit.pos() = insit.pos; - insit.inset->updateBuffer(parit, utype); + insit.inset->updateBuffer(parit, utype, deleted || parit->isDeleted(insit.pos)); changed |= insit.inset->isChanged(); }