]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Fix crash when running lyx -dbg insets -e ...
[lyx.git] / src / text2.C
index 575405f685f1d7dd8e8f215caed1b09b457759ab..99497d055529a6e1f79872f7cefe5806f5f12223 100644 (file)
@@ -360,6 +360,31 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
        }
 }
 
+Inset * LyXText::getInset() const
+{
+       Inset * inset = 0;
+       if (cursor.pos() == 0 && cursor.par()->bibkey){
+               inset = cursor.par()->bibkey;
+       } else if (cursor.pos() < cursor.par()->size() 
+                  && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
+               inset = cursor.par()->getInset(cursor.pos());
+       }
+       return inset;
+}
+
+void LyXText::toggleInset(BufferView * bview)
+{
+       Inset * inset = getInset();
+       if (!inset->editable())
+               return;
+       //bview->owner()->message(inset->editMessage());
+
+       // do we want to keep this?? (JMarc)
+       if (inset->editable() != Inset::HIGHLY_EDITABLE)
+               setCursorParUndo(bview);
+       inset->open(bview, !inset->isOpen());
+}
+
 
 /* used in setlayout */
 // Asger is not sure we want to do this...
@@ -1253,7 +1278,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                                        par->params().labelString(string());
                        }
 
-                       std::ostringstream s;
+                       ostringstream s;
 
                        if (!par->params().appendix()) {
                                switch (2 * LABEL_COUNTER_CHAPTER -
@@ -1395,7 +1420,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                        par->incCounter(i + par->enumdepth);
                        int number = par->getCounter(i + par->enumdepth);
 
-                       std::ostringstream s;
+                       ostringstream s;
 
                        switch (par->enumdepth) {
                        case 1:
@@ -1455,11 +1480,11 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                
                // the caption hack:
                if (layout.labeltype == LABEL_SENSITIVE) {
-                       bool isOK (par->InInset() && par->InInset()->owner() &&
-                                  (par->InInset()->owner()->lyxCode() == Inset::FLOAT_CODE));
+                       bool isOK (par->inInset() && par->inInset()->owner() &&
+                                  (par->inInset()->owner()->lyxCode() == Inset::FLOAT_CODE));
                        
                        if (isOK) {
-                               InsetFloat * tmp = static_cast<InsetFloat*>(par->InInset()->owner());
+                               InsetFloat * tmp = static_cast<InsetFloat*>(par->inInset()->owner());
                                Floating const & fl
                                        = floatList.getType(tmp->type());
                                // We should get the correct number here too.
@@ -1518,7 +1543,7 @@ void LyXText::updateCounters(BufferView * bview, Row * row) const
 
 void LyXText::insertInset(BufferView * bview, Inset * inset)
 {
-       if (!cursor.par()->insertInsetAllowed(inset))
+       if (!cursor.par()->insetAllowed(inset->lyxCode()))
                return;
        setUndo(bview, Undo::INSERT,
                cursor.par(), cursor.par()->next());
@@ -2079,7 +2104,7 @@ void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
                              Paragraph::size_type pos,
                              bool setfont, bool boundary) const
 {
-       InsetText * it = static_cast<InsetText *>(par->InInset());
+       InsetText * it = static_cast<InsetText *>(par->inInset());
        if (it && (it != inset_owner)) {
                it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont,
                                                       boundary);
@@ -2402,20 +2427,6 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
 }
 
 
-Paragraph * LyXText::getParFromID(int id) const
-{
-       if (id < 0)
-               return 0;
-       Paragraph * result = firstParagraph();
-       Paragraph * ires = 0;
-       while (result && result->id() != id) {
-               if ((ires = result->getParFromID(id)))
-                       return ires;
-               result = result->next();
-       }
-       return result;
-}
-
 void LyXText::toggleAppendix(BufferView * bview)
 {
        Paragraph * par = cursor.par();
@@ -2459,9 +2470,9 @@ Paragraph * LyXText::ownerParagraph(Paragraph * p) const
 
 Paragraph * LyXText::ownerParagraph(int id, Paragraph * p) const
 {
-       Paragraph * op = getParFromID(id);
-       if (op && op->InInset()) {
-               static_cast<InsetText *>(op->InInset())->paragraph(p);
+       Paragraph * op = bv_owner->buffer()->getParFromID(id);
+       if (op && op->inInset()) {
+               static_cast<InsetText *>(op->inInset())->paragraph(p);
        } else {
                if (inset_owner) {
                        inset_owner->paragraph(p);
@@ -2491,12 +2502,27 @@ void LyXText::status(BufferView * bview, LyXText::text_status st) const
                }
        }
 #else
-#warning Please tell what the intention is here.
+#warning Please tell what the intention is here. (Lgb)
        // The above does not make any sense, I changed it to what is here,
        // but it still does not make much sense. (Lgb)
+#warning Sure have a look now! (Jug)
+       // well as much as I know && binds more then || so the above and the
+       // below are identical (this for your known use of parentesis!)
+       // Now some explanation:
+       // We should only go up with refreshing code so this means that if
+       // we have a MORE refresh we should never set it to LITTLE if we still
+       // didn't handle it (and then it will be UNCHANGED. Now as long as
+       // we stay inside one LyXText this may work but we need to tell the
+       // outermost LyXText that it should REALLY draw us if there is some
+       // change in a Inset::LyXText. So you see that when we are inside a
+       // inset's LyXText we give the LITTLE to the outermost LyXText to
+       // tell'em that it should redraw the actual row (where the inset
+       // resides! Capito?!
+
        if ((status_ != NEED_MORE_REFRESH)
            || (status_ == NEED_MORE_REFRESH
-               && st != NEED_VERY_LITTLE_REFRESH)) {
+               && st != NEED_VERY_LITTLE_REFRESH))
+       {
                status_ = st;
                if (inset_owner && st != UNCHANGED) {
                        bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);