]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
Scons: update_po target, part one: language_l10n.pot
[lyx.git] / src / text.C
index a44447850a15fcec3b594a7889080ea9f9f50435..905ee32d556433b9c75e2413be4c03121aa9c29a 100644 (file)
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
-#include "frontends/Selection.h"
 
 #include "insets/insettext.h"
 #include "insets/insetbibitem.h"
+#include "insets/insetcaption.h"
 #include "insets/insethfill.h"
-#include "insets/insetlatexaccent.h"
 #include "insets/insetline.h"
 #include "insets/insetnewline.h"
 #include "insets/insetpagebreak.h"
@@ -240,10 +239,6 @@ void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
                        par.insertInset(par.size(), inset.release(),
                                        font, change);
                }
-       } else if (token == "\\i") {
-               auto_ptr<InsetBase> inset(new InsetLatexAccent);
-               inset->read(buf, lex);
-               par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\backslash") {
                par.insertChar(par.size(), '\\', font, change);
        } else if (token == "\\newline") {
@@ -750,6 +745,7 @@ void LyXText::insertChar(LCursor & cur, char_type c)
        }
 
        par.insertChar(cur.pos(), c, current_font, cur.buffer().params().trackChanges);
+       checkBufferStructure(cur.buffer(), cur);
 
 //             cur.updateFlags(Update::Force);
        setCursor(cur.top(), cur.pit(), cur.pos() + 1);
@@ -829,7 +825,7 @@ void LyXText::selectWord(LCursor & cur, word_location loc)
        cur.resetAnchor();
        setCursor(cur, to.pit(), to.pos());
        cur.setSelection();
-       theSelection().haveSelection(cur.selection());
+       cap::saveSelection(cur);
 }
 
 
@@ -951,7 +947,7 @@ void LyXText::acceptOrRejectChanges(LCursor & cur, ChangeOp op)
 
 void LyXText::acceptChanges(BufferParams const & bparams)
 {
-       pit_type pars_size = (pit_type) pars_.size();
+       pit_type pars_size = static_cast<pit_type>(pars_.size());
 
        // first, accept changes within each individual paragraph
        // (do not consider end-of-par)
@@ -986,7 +982,7 @@ void LyXText::acceptChanges(BufferParams const & bparams)
 
 void LyXText::rejectChanges(BufferParams const & bparams)
 {
-       pit_type pars_size = (pit_type) pars_.size();
+       pit_type pars_size = static_cast<pit_type>(pars_.size());
 
        // first, reject changes within each individual paragraph
        // (do not consider end-of-par)         
@@ -1031,6 +1027,7 @@ void LyXText::deleteWordForward(LCursor & cur)
                cursorRightOneWord(cur);
                cur.setSelection();
                cutSelection(cur, true, false);
+               checkBufferStructure(cur.buffer(), cur);
        }
 }
 
@@ -1047,6 +1044,7 @@ void LyXText::deleteWordBackward(LCursor & cur)
                cursorLeftOneWord(cur);
                cur.setSelection();
                cutSelection(cur, true, false);
+               checkBufferStructure(cur.buffer(), cur);
        }
 }
 
@@ -1068,6 +1066,7 @@ void LyXText::deleteLineForward(LCursor & cur)
                        deleteWordForward(cur);
                else
                        cutSelection(cur, true, false);
+               checkBufferStructure(cur.buffer(), cur);
        }
 }
 
@@ -1121,6 +1120,7 @@ void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
                //pars_[pit].setChar(pos, c);
                ++pos;
        }
+       checkBufferStructure(cur.buffer(), cur);
 }
 
 
@@ -1138,6 +1138,7 @@ bool LyXText::erase(LCursor & cur)
                        // the character has been logically deleted only => skip it
                        cur.forwardPosNoDescend();
                }
+               checkBufferStructure(cur.buffer(), cur);
                needsUpdate = true;
        } else {
                if (cur.pit() == cur.lastpit())
@@ -1157,6 +1158,7 @@ bool LyXText::erase(LCursor & cur)
                // Make sure the cursor is correct. Is this really needed?
                // No, not really... at least not here!
                cur.text()->setCursor(cur.top(), cur.pit(), cur.pos());
+               checkBufferStructure(cur.buffer(), cur);
        }
        
        return needsUpdate;
@@ -1244,6 +1246,7 @@ bool LyXText::backspace(LCursor & cur)
                setCursorIntern(cur, cur.pit(), cur.pos() - 1,
                                false, cur.boundary());
                cur.paragraph().eraseChar(cur.pos(), cur.buffer().params().trackChanges);
+               checkBufferStructure(cur.buffer(), cur);
        }
 
        if (cur.pos() == cur.lastpos())
@@ -1711,9 +1714,13 @@ docstring LyXText::currentState(LCursor & cur)
        os << _(", Paragraph: ") << cur.pit();
        os << _(", Id: ") << par.id();
        os << _(", Position: ") << cur.pos();
-       // Force output of code point, not character
-       size_t const c = par.getChar(cur.pos());
-       os << _(", Char: 0x") << std::hex << c;
+       // FIXME: Why is the check for par.size() needed?
+       // We are called with cur.pos() == par.size() quite often.
+       if (!par.empty() && cur.pos() < par.size()) {
+               // Force output of code point, not character
+               size_t const c = par.getChar(cur.pos());
+               os << _(", Char: 0x") << std::hex << c;
+       }
        os << _(", Boundary: ") << cur.boundary();
 //     Row & row = cur.textRow();
 //     os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
@@ -1728,37 +1735,7 @@ docstring LyXText::getPossibleLabel(LCursor & cur) const
 
        LyXLayout_ptr layout = pars_[pit].layout();
 
-       if (layout->latextype == LATEX_PARAGRAPH && pit != 0) {
-               LyXLayout_ptr const & layout2 = pars_[pit - 1].layout();
-               if (layout2->latextype != LATEX_PARAGRAPH) {
-                       --pit;
-                       layout = layout2;
-               }
-       }
-
-       docstring name = from_ascii(layout->latexname());
-
-       // for captions, we want the abbreviation of the float type
-       if (layout->labeltype == LABEL_SENSITIVE) {
-               // Search for the first float or wrap inset in the iterator
-               for (int i = cur.depth(); --i >= 0; ) {
-                       InsetBase * const in = &cur[i].inset();
-                       if (in->lyxCode() == InsetBase::FLOAT_CODE
-                           || in->lyxCode() == InsetBase::WRAP_CODE) {
-                               name = in->getInsetName();
-                               break;
-                       }
-               }
-       }
-
-       docstring text = name.substr(0, 3);
-       if (name == "theorem")
-               text = from_ascii("thm"); // Create a correct prefix for prettyref
-
-       text += ':';
-       if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0)
-               text.erase();
-
+       docstring text;
        docstring par_text = pars_[pit].asString(cur.buffer(), false);
        for (int i = 0; i < lyxrc.label_init_length; ++i) {
                if (par_text.empty())
@@ -1771,6 +1748,46 @@ docstring LyXText::getPossibleLabel(LCursor & cur) const
                text += head;
        }
 
+       // No need for a prefix if the user said so.
+       if (lyxrc.label_init_length <= 0)
+               return text;
+
+       // Will contain the label type.
+       docstring name;
+
+       // For section, subsection, etc...
+       if (layout->latextype == LATEX_PARAGRAPH && pit != 0) {
+               LyXLayout_ptr const & layout2 = pars_[pit - 1].layout();
+               if (layout2->latextype != LATEX_PARAGRAPH) {
+                       --pit;
+                       layout = layout2;
+               }
+       }
+       if (layout->latextype != LATEX_PARAGRAPH)
+               name = from_ascii(layout->latexname());
+
+       // for captions, we just take the caption type
+       InsetBase * caption_inset = cur.innerInsetOfType(InsetBase::CAPTION_CODE);
+       if (caption_inset)
+               name = from_ascii(static_cast<InsetCaption *>(caption_inset)->type());
+
+       // Inside floats or wraps, if none of the above worked
+       // we want by default the abbreviation of the float type.
+       if (name.empty()) {
+               InsetBase * float_inset = cur.innerInsetOfType(InsetBase::FLOAT_CODE);
+               if (!float_inset)
+                       float_inset = cur.innerInsetOfType(InsetBase::WRAP_CODE);
+               if (float_inset)
+                       name = float_inset->getInsetName();
+       }
+
+       // Create a correct prefix for prettyref
+       if (name == "theorem")
+               name = from_ascii("thm");
+
+       if (!name.empty())
+               text = name.substr(0, 3) + ':' + text;
+
        return text;
 }
 
@@ -1876,6 +1893,8 @@ void LyXText::charsTranspose(LCursor & cur)
        par.insertChar(pos1, char2, font2, trackChanges);
        par.insertChar(pos2, char1, font1, trackChanges);
 
+       checkBufferStructure(cur.buffer(), cur);
+
        // After the transposition, move cursor to after the transposition.
        setCursor(cur, cur.pit(), pos2);
        cur.forwardPos();