]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
Collapse all those LFUN_XYZ_APPLY to a single LFUN_INSET_APPLY.
[lyx.git] / src / paragraph.C
index a37ee9b3a01cda4d69f3f07919462b7c36eceb15..0f848a48df03eca04438be6f9784c0a615a93b1b 100644 (file)
@@ -26,7 +26,7 @@
 #include "gettext.h"
 #include "changes.h"
 
-#include "insets/insetbib.h"
+#include "insets/insetbibitem.h"
 #include "insets/insetoptarg.h"
 
 #include "support/filetools.h"
@@ -78,7 +78,6 @@ Paragraph::Paragraph()
 #endif
        enumdepth = 0;
        itemdepth = 0;
-       bibkey = 0; // ale970302
        params().clear();
 }
 
@@ -99,7 +98,6 @@ Paragraph::Paragraph(Paragraph * par)
        previous_->next_ = this;
        // end
 
-       bibkey = 0; // ale970302
        params().clear();
 }
 #endif
@@ -118,14 +116,6 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
        // follow footnotes
        layout_ = lp.layout();
 
-       // ale970302
-       if (lp.bibkey) {
-               bibkey = static_cast<InsetBibKey *>
-                       (lp.bibkey->clone(*current_view->buffer()));
-       } else {
-               bibkey = 0;
-       }
-
        // copy everything behind the break-position to the new paragraph
        insetlist = lp.insetlist;
        InsetList::iterator it = insetlist.begin();
@@ -149,9 +139,6 @@ Paragraph::~Paragraph()
                next_->previous_ = previous_;
 #endif
 
-       // ale970302
-       delete bibkey;
-
        delete pimpl_;
        //
        //lyxerr << "Paragraph::paragraph_id = "
@@ -234,10 +221,6 @@ void Paragraph::write(Buffer const * buf, ostream & os,
                os << "\\align " << string_align[h] << ' ';
        }
 
-       // bibitem  ale970302
-       if (bibkey)
-               bibkey->write(buf, os);
-
        LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
 
        Change running_change = Change(Change::UNCHANGED);
@@ -519,9 +502,7 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
 
        LyXLayout_ptr const & lout = layout();
 
-       pos_type main_body = 0;
-       if (lout->labeltype == LABEL_MANUAL)
-               main_body = beginningOfMainBody();
+       pos_type const main_body = beginningOfMainBody();
 
        LyXFont layoutfont;
        if (pos < main_body)
@@ -866,6 +847,9 @@ void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
 
 int Paragraph::beginningOfMainBody() const
 {
+       if (layout()->labeltype != LABEL_MANUAL)
+               return 0;
+
        // Unroll the first two cycles of the loop
        // and remember the previous character to
        // remove unnecessary GetChar() calls
@@ -951,17 +935,21 @@ int Paragraph::getPositionOfInset(Inset const * inset) const
        // Find the entry.
        InsetList::iterator it = insetlist.begin();
        InsetList::iterator end = insetlist.end();
-       for (; it != end; ++it) {
-               if (it.getInset() == inset) {
+       for (; it != end; ++it)
+               if (it.getInset() == inset) 
                        return it.getPos();
-               }
-       }
-       if (inset == bibkey)
-               return 0;
-
        return -1;
 }
 
+
+InsetBibitem * Paragraph::bibitem()
+{
+       InsetList::iterator it = insetlist.begin();
+       if (it != insetlist.end() && it.getInset()->lyxCode() == Inset::BIBTEX_CODE)
+               return static_cast<InsetBibitem *>(it.getInset()); 
+       return 0;
+}
+
 namespace {
 
 InsetOptArg * optArgInset(Paragraph const & par)
@@ -1078,27 +1066,24 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
 
        switch (style->latextype) {
        case LATEX_COMMAND:
-               os << '\\'
-                  << style->latexname();
+               os << '\\' << style->latexname();
 
                // Separate handling of optional argument inset.
                if (style->optionalargs == 1) {
                        InsetOptArg * it = optArgInset(*this);
-                       if (it != 0)
+                       if (it)
                                it->latexOptional(buf, os, false, false);
                }
                else
                        os << style->latexparam();
                break;
        case LATEX_ITEM_ENVIRONMENT:
-               if (bibkey) {
-                       bibkey->latex(buf, os, false, false);
-               } else
-                       os << "\\item ";
-               break;
        case LATEX_LIST_ENVIRONMENT:
                os << "\\item ";
                break;
+       case LATEX_BIB_ENVIRONMENT:
+               // ignore this, the inset will write itself
+               break;
        default:
                break;
        }
@@ -1356,10 +1341,14 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
 
        // Maybe we have to create a optional argument.
        pos_type main_body;
-       if (style->labeltype != LABEL_MANUAL)
+
+       // FIXME: can we actually skip this check and just call
+       // beginningOfMainBody() ??
+       if (style->labeltype != LABEL_MANUAL) {
                main_body = 0;
-       else
+       } else {
                main_body = beginningOfMainBody();
+       }
 
        unsigned int column = 0;
 
@@ -1973,12 +1962,6 @@ ParagraphParameters const & Paragraph::params() const
 }
 
 
-Paragraph * Paragraph::getParFromID(int id) const
-{
-       return pimpl_->getParFromID(id);
-}
-
-
 bool Paragraph::isFreeSpacing() const
 {
        // for now we just need this, later should we need this in some