]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Add a Buffer::fully_loaded member function, returning true only when
[lyx.git] / src / buffer.C
index 45f9484dbb1ede7c322467a07882c607fe20c0db..5fa662477800cf598057e9cc4304f2b75faef88e 100644 (file)
@@ -22,6 +22,7 @@
 #include "errorlist.h"
 #include "exporter.h"
 #include "format.h"
+#include "funcrequest.h"
 #include "gettext.h"
 #include "iterators.h"
 #include "language.h"
@@ -32,6 +33,7 @@
 #include "lyxrc.h"
 #include "lyxvc.h"
 #include "messages.h"
+#include "paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "sgml.h"
@@ -51,7 +53,6 @@
 #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;
@@ -86,8 +123,7 @@ using std::ofstream;
 using std::pair;
 using std::stack;
 using std::vector;
-
-using lyx::pos_type;
+using std::string;
 
 
 // all these externs should eventually be removed.
@@ -115,7 +151,7 @@ bool openFileWrite(ofstream & ofs, string const & fname)
 
 typedef std::map<string, bool> DepClean;
 
-struct Buffer::Impl 
+struct Buffer::Impl
 {
        Impl(Buffer & parent, string const & file, bool readonly);
 
@@ -150,13 +186,19 @@ struct Buffer::Impl
        string filepath;
 
        boost::scoped_ptr<Messages> messages;
+
+       /** 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;
 };
 
 
 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))
+         filename(file), filepath(OnlyPath(file)), file_fully_loaded(false)
 {
        lyxvc.buffer(&parent);
        if (readonly_ || lyxrc.use_tempdir)
@@ -445,7 +487,7 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
 
 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;
@@ -570,10 +612,16 @@ bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
 }
 
 
+bool Buffer::fully_loaded() const
+{
+       return pimpl_->file_fully_loaded;
+}
+
+
 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"),
@@ -661,6 +709,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
                                       " that it is probably corrupted."),
                                       filename));
        }
+       pimpl_->file_fully_loaded = true;
        return true;
 }
 
@@ -1021,7 +1070,7 @@ string const Buffer::asciiParagraph(Paragraph const & par,
                }
        }
        buffer << word;
-       return STRCONV(buffer.str());
+       return buffer.str();
 }
 
 
@@ -1077,7 +1126,7 @@ void Buffer::makeLaTeXFile(ostream & os,
 
        // 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;
 
@@ -1216,7 +1265,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
 
        niceFile() = nice; // this will be used by included files.
 
-       LaTeXFeatures features(params());
+       LaTeXFeatures features(*this, params());
 
        validate(features);
 
@@ -1447,7 +1496,7 @@ void reset(PAR_TAG & p1, PAR_TAG const & p2)
 // 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();
 
@@ -1646,7 +1695,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 
        niceFile() = nice; // this will be used by Insetincludes.
 
-       LaTeXFeatures features(params());
+       LaTeXFeatures features(*this, params());
        validate(features);
 
        texrow().reset();
@@ -1917,7 +1966,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 
 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;
 
@@ -2106,7 +2155,7 @@ void Buffer::getLabelList(std::vector<string> & list) const
 
        for (inset_iterator it = inset_const_iterator_begin();
             it != inset_const_iterator_end(); ++it) {
-               it->getLabelList(list);
+               it->getLabelList(*this, list);
        }
 }
 
@@ -2127,14 +2176,19 @@ void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) con
 
        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));
@@ -2160,22 +2214,17 @@ void Buffer::markDepClean(string const & name)
 
 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;