]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
* GuiTabular.cpp:
[lyx.git] / src / Text.cpp
index 33932d4e9f763b609c1dc6bcef70d0ad3fbe1cf5..d00d2d5356ee710b7fa26a2e9df288173a89a118 100644 (file)
 #include "insets/InsetText.h"
 #include "insets/InsetBibitem.h"
 #include "insets/InsetCaption.h"
-#include "insets/InsetLine.h"
 #include "insets/InsetNewline.h"
 #include "insets/InsetNewpage.h"
-#include "insets/InsetOptArg.h"
+#include "insets/InsetArgument.h"
 #include "insets/InsetSpace.h"
 #include "insets/InsetSpecialChar.h"
 #include "insets/InsetTabular.h"
@@ -259,37 +258,59 @@ Font const Text::outerFont(pit_type par_offset) const
 }
 
 
-void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
+static void acceptOrRejectChanges(ParagraphList & pars,
+       BufferParams const & bparams, Text::ChangeOp op)
 {
        pit_type pars_size = static_cast<pit_type>(pars.size());
 
-       // first, accept changes within each individual paragraph
-       // (do not consider end-of-par)
+       // first, accept or reject changes within each individual
+       // paragraph (do not consider end-of-par)
        for (pit_type pit = 0; pit < pars_size; ++pit) {
-               if (!pars[pit].empty())   // prevent assertion failure
-                       pars[pit].acceptChanges(0, pars[pit].size());
+               // prevent assertion failure
+               if (!pars[pit].empty()) {
+                       if (op == Text::ACCEPT)
+                               pars[pit].acceptChanges(0, pars[pit].size());
+                       else
+                               pars[pit].rejectChanges(0, pars[pit].size());
+               }
        }
 
-       // next, accept imaginary end-of-par characters
+       // next, accept or reject imaginary end-of-par characters
        for (pit_type pit = 0; pit < pars_size; ++pit) {
                pos_type pos = pars[pit].size();
-
-               if (pars[pit].isInserted(pos)) {
-                       pars[pit].setChange(pos, Change(Change::UNCHANGED));
-               } else if (pars[pit].isDeleted(pos)) {
-                       if (pit == pars_size - 1) {
-                               // we cannot remove a par break at the end of the last
-                               // paragraph; instead, we mark it unchanged
+               if (pars[pit].isChanged(pos)) {
+                       // keep the end-of-par char if it is inserted and accepted
+                       // or when it is deleted and rejected.
+                       if (pars[pit].isInserted(pos) == (op == Text::ACCEPT)) {
                                pars[pit].setChange(pos, Change(Change::UNCHANGED));
                        } else {
-                               mergeParagraph(bparams, pars, pit);
-                               --pit;
-                               --pars_size;
+                               if (pit == pars_size - 1) {
+                                       // we cannot remove a par break at the end of the last
+                                       // paragraph; instead, we mark it unchanged
+                                       pars[pit].setChange(pos, Change(Change::UNCHANGED));
+                               } else {
+                                       mergeParagraph(bparams, pars, pit);
+                                       --pit;
+                                       --pars_size;
+                               }
                        }
                }
        }
 }
 
+
+void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
+{
+       acceptOrRejectChanges(pars, bparams, Text::ACCEPT);
+}
+
+
+void rejectChanges(ParagraphList & pars, BufferParams const & bparams)
+{
+       acceptOrRejectChanges(pars, bparams, Text::REJECT);
+}
+
+
 InsetText const & Text::inset() const
 {
        return *owner_;
@@ -430,11 +451,6 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
                auto_ptr<Inset> inset(new InsetTabular(buf));
                inset->read(lex);
                par.insertInset(par.size(), inset.release(), font, change);
-       } else if (token == "\\lyxline") {
-               auto_ptr<Inset> inset;
-               inset.reset(new InsetLine);
-               inset->setBuffer(*buf);
-               par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\change_unchanged") {
                change = Change(Change::UNCHANGED);
        } else if (token == "\\change_inserted" || token == "\\change_deleted") {
@@ -503,6 +519,9 @@ void Text::readParagraph(Paragraph & par, Lexer & lex,
 
        // Initialize begin_of_body_ on load; redoParagraph maintains
        par.setBeginOfBody();
+       
+       // mark paragraph for spell checking on load
+       // par.requestSpellCheck();
 }
 
 
@@ -717,10 +736,9 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
                        break; // the character couldn't be deleted physically due to change tracking
        }
 
-       cur.buffer()->updateBuffer();
-
        // A singlePar update is not enough in this case.
-       cur.updateFlags(Update::Force);
+       cur.screenUpdateFlags(Update::Force);
+       cur.forceBufferUpdate();
 
        // This check is necessary. Otherwise the new empty paragraph will
        // be deleted automatically. And it is more friendly for the user!
@@ -918,23 +936,17 @@ void Text::insertChar(Cursor & cur, char_type c)
        // disable the double-space checking
        if (!freeSpacing && isLineSeparatorChar(c)) {
                if (cur.pos() == 0) {
-                       static bool sent_space_message = false;
-                       if (!sent_space_message) {
-                               cur.message(_("You cannot insert a space at the "
-                                                          "beginning of a paragraph. Please read the Tutorial."));
-                               sent_space_message = true;
-                       }
+                       cur.message(_(
+                                       "You cannot insert a space at the "
+                                       "beginning of a paragraph. Please read the Tutorial."));
                        return;
                }
                LASSERT(cur.pos() > 0, /**/);
                if ((par.isLineSeparator(cur.pos() - 1) || par.isNewline(cur.pos() - 1))
-                   && !par.isDeleted(cur.pos() - 1)) {
-                       static bool sent_space_message = false;
-                       if (!sent_space_message) {
-                               cur.message(_("You cannot type two spaces this way. "
-                                                          "Please read the Tutorial."));
-                               sent_space_message = true;
-                       }
+                               && !par.isDeleted(cur.pos() - 1)) {
+                       cur.message(_(
+                                       "You cannot type two spaces this way. "
+                                       "Please read the Tutorial."));
                        return;
                }
        }
@@ -943,7 +955,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                cur.buffer()->params().trackChanges);
        cur.checkBufferStructure();
 
-//             cur.updateFlags(Update::Force);
+//             cur.screenUpdateFlags(Update::Force);
        bool boundary = cur.boundary()
                || tm.isRTLBoundary(cur.pit(), cur.pos() + 1);
        setCursor(cur, cur.pit(), cur.pos() + 1, false, boundary);
@@ -1293,8 +1305,8 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
        cur.finishUndo();
        cur.clearSelection();
        setCursorIntern(cur, begPit, begPos);
-       cur.updateFlags(Update::Force);
-       cur.buffer()->updateBuffer();
+       cur.screenUpdateFlags(Update::Force);
+       cur.forceBufferUpdate();
 }
 
 
@@ -1445,9 +1457,9 @@ bool Text::handleBibitems(Cursor & cur)
                cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
                mergeParagraph(bufparams, cur.text()->paragraphs(),
                                                        prevcur.pit());
-               cur.buffer()->updateBuffer();
+               cur.forceBufferUpdate();
                setCursorIntern(cur, prevcur.pit(), prevcur.pos());
-               cur.updateFlags(Update::Force);
+               cur.screenUpdateFlags(Update::Force);
                return true;
        } 
 
@@ -1473,7 +1485,7 @@ bool Text::erase(Cursor & cur)
                        cur.top().forwardPos();
 
                if (was_inset)
-                       cur.buffer()->updateBuffer();
+                       cur.forceBufferUpdate();
                else
                        cur.checkBufferStructure();
                needsUpdate = true;
@@ -1549,7 +1561,7 @@ bool Text::backspacePos0(Cursor & cur)
        }
 
        if (needsUpdate) {
-               cur.buffer()->updateBuffer();
+               cur.forceBufferUpdate();
                setCursorIntern(cur, prevcur.pit(), prevcur.pos());
        }
 
@@ -1589,7 +1601,7 @@ bool Text::backspace(Cursor & cur)
                bool const was_inset = cur.paragraph().isInset(cur.pos());
                cur.paragraph().eraseChar(cur.pos(), cur.buffer()->params().trackChanges);
                if (was_inset)
-                       cur.buffer()->updateBuffer();
+                       cur.forceBufferUpdate();
                else
                        cur.checkBufferStructure();
        }
@@ -1600,7 +1612,7 @@ bool Text::backspace(Cursor & cur)
        needsUpdate |= handleBibitems(cur);
 
        // A singlePar update is not enough in this case.
-//             cur.updateFlags(Update::Force);
+//             cur.screenUpdateFlags(Update::Force);
        setCursor(cur.top(), cur.pit(), cur.pos());
 
        return needsUpdate;
@@ -1645,9 +1657,7 @@ bool Text::dissolveInset(Cursor & cur)
                cur.pit() = min(cur.lastpit(), spit);
                cur.pos() = min(cur.lastpos(), spos);
        } else
-               // this is the least that needs to be done (bug 6003)
-               // in the above case, pasteParagraphList handles this
-               cur.buffer()->updateBuffer();
+               cur.forceBufferUpdate();
 
        // Ensure the current language is set correctly (bug 6292)
        cur.text()->setCursor(cur, cur.pit(), cur.pos());
@@ -2020,8 +2030,8 @@ bool Text::insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/
        LASSERT(cur.bv().cursor() == cur, /**/);
        cur.insert(s);
        cur.bv().cursor() = cur;
-       if (!(cur.disp_.update() & Update::Force))
-               cur.updateFlags(cur.disp_.update() | Update::SinglePar);
+       if (!(cur.result().screenUpdate() & Update::Force))
+               cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
        return true;
 }