]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
convert author names and status messages to docstring
[lyx.git] / src / text.C
index 2cebea4251bc66358c56239110cdd92eb0404450..cab2ac41353cbda9c2ad9bf847c2dffd8a361e22 100644 (file)
@@ -1074,10 +1074,6 @@ void LyXText::setHeightOfRow(BufferView const & bv, pit_type const pit,
 }
 
 
-namespace {
-
-}
-
 void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
 {
        BOOST_ASSERT(this == cur.text());
@@ -1090,8 +1086,8 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
 
        // this is only allowed, if the current paragraph is not empty
        // or caption and if it has not the keepempty flag active
-       if (cur.lastpos() == 0 && !cpar.allowEmpty()
-          && layout->labeltype != LABEL_SENSITIVE)
+       if (cur.lastpos() == 0 && !cpar.allowEmpty() &&
+           layout->labeltype != LABEL_SENSITIVE)
                return;
 
        // a layout change may affect also the following paragraph
@@ -1100,10 +1096,9 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
        // Always break behind a space
        // It is better to erase the space (Dekel)
        if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos()))
-               // FIXME: change tracking (MG)
                cpar.eraseChar(cur.pos(), cur.buffer().params().trackChanges);
 
-       // How should the layout for the new paragraph be?
+       // What should the layout for the new paragraph be?
        int preserve_layout = 0;
        if (keep_layout)
                preserve_layout = 2;
@@ -1136,7 +1131,6 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
        }
 
        while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
-               // FIXME: change tracking (MG)
                pars_[next_par].eraseChar(0, cur.buffer().params().trackChanges);
 
        ParIterator current_it(cur);
@@ -1146,13 +1140,6 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
 
        updateLabels(cur.buffer(), current_it, last_it);
 
-       // Mark "carriage return" as inserted if change tracking:
-       if (cur.buffer().params().trackChanges) {
-               // FIXME: Change tracking (MG)
-               cur.paragraph().setChange(cur.paragraph().size(),
-                       Change(Change::INSERTED));
-       }
-
        // FIXME: Breaking a paragraph has nothing to do with setting a cursor.
        // Because of the mix between the model (the paragraph contents) and the
        // view (the paragraph breaking in rows, we have to do this here before
@@ -1163,7 +1150,6 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
                // A singlePar update is not enough in this case.
                cur.updateFlags(Update::Force);
 
-
        // This check is necessary. Otherwise the new empty paragraph will
        // be deleted automatically. And it is more friendly for the user!
        if (cur.pos() != 0 || isempty)
@@ -1472,6 +1458,8 @@ bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
 
 void LyXText::acceptChange(LCursor & cur)
 {
+       // FIXME: change tracking (MG)
+
        BOOST_ASSERT(this == cur.text());
 
        if (!cur.selection() && cur.lastpos() != 0)
@@ -1484,25 +1472,17 @@ void LyXText::acceptChange(LCursor & cur)
        DocIterator it = cur.selectionBegin();
        DocIterator et = cur.selectionEnd();
        pit_type pit = it.pit();
-       bool isDeleted = pars_[pit].isDeleted(it.pos());
        for (; pit <= et.pit(); ++pit) {
-               pos_type left  = ( pit == it.pit() ? it.pos() : 0 );
-               pos_type right =
-                   ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
+               pos_type left  = (pit == it.pit() ? it.pos() : 0);
+               pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
                pars_[pit].acceptChanges(left, right);
-       }
-       if (isDeleted) {
-               ParagraphList & plist = paragraphs();
-               if (it.pit() + 1 < et.pit())
-                       pars_.erase(boost::next(plist.begin(), it.pit() + 1),
-                                   boost::next(plist.begin(), et.pit()));
 
-               // Paragraph merge if appropriate:
-               // FIXME: change tracking (MG)
-               if (pars_[it.pit()].isDeleted(pars_[it.pit()].size())) {
-                       setCursorIntern(cur, it.pit() + 1, 0);
-                       backspacePos0(cur);
-               }
+               // merge paragraph if appropriate:
+               // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
+               //    pars_[pit].isDeleted(pars_[pit].size())) {
+               //      setCursorIntern(cur, pit + 1, 0);
+               //      backspacePos0(cur);
+               //}
        }
        finishUndo();
        cur.clearSelection();
@@ -1512,6 +1492,8 @@ void LyXText::acceptChange(LCursor & cur)
 
 void LyXText::rejectChange(LCursor & cur)
 {
+       // FIXME: change tracking (MG)
+
        BOOST_ASSERT(this == cur.text());
 
        if (!cur.selection() && cur.lastpos() != 0)
@@ -1524,24 +1506,17 @@ void LyXText::rejectChange(LCursor & cur)
        DocIterator it = cur.selectionBegin();
        DocIterator et = cur.selectionEnd();
        pit_type pit = it.pit();
-       bool isInserted = pars_[pit].isInserted(it.pos());
        for (; pit <= et.pit(); ++pit) {
-               pos_type left  = ( pit == it.pit() ? it.pos() : 0 );
-               pos_type right =
-                   ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
+               pos_type left  = (pit == it.pit() ? it.pos() : 0);
+               pos_type right = (pit == et.pit() ? et.pos() : pars_[pit].size());
                pars_[pit].rejectChanges(left, right);
-       }
-       if (isInserted) {
-               ParagraphList & plist = paragraphs();
-               if (it.pit() + 1 < et.pit())
-                       pars_.erase(boost::next(plist.begin(), it.pit() + 1),
-                                   boost::next(plist.begin(), et.pit()));
-               // Paragraph merge if appropriate:
-               // FIXME: change tracking (MG)
-               if (pars_[it.pit()].isInserted(pars_[it.pit()].size())) {
-                       setCursorIntern(cur, it.pit() + 1, 0);
-                       backspacePos0(cur);
-               }
+
+               // merge paragraph if appropriate:      
+               // if (right >= pars_[pit].size() && pit + 1 < et.pit() &&
+               //    pars_[pit].isInserted(pars_[pit].size())) {
+               //      setCursorIntern(cur, pit + 1, 0);
+               //      backspacePos0(cur);
+               //}
        }
        finishUndo();
        cur.clearSelection();
@@ -1668,7 +1643,10 @@ bool LyXText::erase(LCursor & cur)
                if (par.isDeleted(cur.pos()))
                        cur.forwardPosNoDescend();
                needsUpdate = true;
-       } else if (cur.pit() != cur.lastpit()) {
+       } else {
+               if (cur.pit() == cur.lastpit())
+                       return dissolveInset(cur);
+
                if (!par.isMergedOnEndOfParDeletion(cur.buffer().params().trackChanges)) {
                        par.setChange(cur.pos(), Change(Change::DELETED));
                        cur.forwardPos();
@@ -1677,8 +1655,6 @@ bool LyXText::erase(LCursor & cur)
                        setCursorIntern(cur, cur.pit() + 1, 0);
                        needsUpdate = backspacePos0(cur);
                }
-       } else {
-               needsUpdate = dissolveInset(cur);
        }
 
        // FIXME: Inserting characters has nothing to do with setting a cursor.
@@ -1857,6 +1833,8 @@ bool LyXText::redoParagraph(BufferView & bv, pit_type const pit)
        Paragraph & par = pars_[pit];
        Buffer const & buffer = *bv.buffer();
 
+       bool changed = false;
+
        // Add bibitem insets if necessary
        if (par.layout()->labeltype == LABEL_BIBLIO) {
                bool hasbibitem(false);
@@ -1895,7 +1873,7 @@ bool LyXText::redoParagraph(BufferView & bv, pit_type const pit)
                        bufferfont :
                        getFont(buffer, par, ii->pos);
                MetricsInfo mi(&bv, font, w);
-               ii->inset->metrics(mi, dim);
+               changed |= ii->inset->metrics(mi, dim);
        }
 
        // rebreak the paragraph
@@ -1932,16 +1910,16 @@ bool LyXText::redoParagraph(BufferView & bv, pit_type const pit)
        dim.asc += par.rows()[0].ascent();
        dim.des -= par.rows()[0].ascent();
 
-       bool const same = dim.height() == par.dim().height();
+       changed |= dim.height() != par.dim().height();
 
        par.dim() = dim;
        //lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
 
-       return !same;
+       return changed;
 }
 
 
-void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
+bool LyXText::metrics(MetricsInfo & mi, Dimension & dim)
 {
        //BOOST_ASSERT(mi.base.textwidth);
        if (mi.base.textwidth)
@@ -1951,10 +1929,12 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
        // save the caller's font locally:
        font_ = mi.base.font;
 
+       bool changed = false;
+
        unsigned int h = 0;
        unsigned int w = 0;
        for (pit_type pit = 0, n = paragraphs().size(); pit != n; ++pit) {
-               redoParagraph(*mi.base.bv, pit);
+               changed |= redoParagraph(*mi.base.bv, pit);
                Paragraph & par = paragraphs()[pit];
                h += par.height();
                if (w < par.width())
@@ -1965,7 +1945,9 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
        dim.asc = pars_[0].ascent();
        dim.des = h - dim.asc;
 
+       changed |= dim_ != dim;
        dim_ = dim;
+       return changed;
 }
 
 
@@ -2320,12 +2302,12 @@ int LyXText::cursorY(CursorSlice const & sl, bool boundary) const
 
 
 // Returns the current font and depth as a message.
-string LyXText::currentState(LCursor & cur)
+docstring LyXText::currentState(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
        Buffer & buf = cur.buffer();
        Paragraph const & par = cur.paragraph();
-       std::ostringstream os;
+       odocstringstream os;
 
        if (buf.params().trackChanges)
                os << "[C] ";
@@ -2334,10 +2316,11 @@ string LyXText::currentState(LCursor & cur)
 
        if (change.type != Change::UNCHANGED) {
                Author const & a = buf.params().authors().get(change.author);
-               os << to_utf8(_("Change: ")) << a.name();
+               os << _("Change: ") << a.name();
                if (!a.email().empty())
                        os << " (" << a.email() << ")";
-               os << to_utf8(_(" at ")) << ctime(&change.changetime);
+               // FIXME ctime is english, we should translate that
+               os << _(" at ") << ctime(&change.changetime);
                os << " : ";
        }
 
@@ -2347,34 +2330,31 @@ string LyXText::currentState(LCursor & cur)
        LyXFont font = real_current_font;
        font.reduce(buf.params().getFont());
 
-       // avoid to_utf8(_(...)) re-entrance problem
-       string const s = font.stateText(&buf.params());
-       os << to_utf8(bformat(_("Font: %1$s"), from_utf8(s)));
-
-       // os << to_utf8(bformat(_("Font: %1$s"), font.stateText(&buf.params)));
+       // FIXME UNICODE
+       os << bformat(_("Font: %1$s"), from_utf8(font.stateText(&buf.params())));
 
        // The paragraph depth
        int depth = cur.paragraph().getDepth();
        if (depth > 0)
-               os << to_utf8(bformat(_(", Depth: %1$d"), depth));
+               os << bformat(_(", Depth: %1$d"), depth);
 
        // The paragraph spacing, but only if different from
        // buffer spacing.
        Spacing const & spacing = par.params().spacing();
        if (!spacing.isDefault()) {
-               os << to_utf8(_(", Spacing: "));
+               os << _(", Spacing: ");
                switch (spacing.getSpace()) {
                case Spacing::Single:
-                       os << to_utf8(_("Single"));
+                       os << _("Single");
                        break;
                case Spacing::Onehalf:
-                       os << to_utf8(_("OneHalf"));
+                       os << _("OneHalf");
                        break;
                case Spacing::Double:
-                       os << to_utf8(_("Double"));
+                       os << _("Double");
                        break;
                case Spacing::Other:
-                       os << to_utf8(_("Other (")) << spacing.getValueAsString() << ')';
+                       os << _("Other (") << from_ascii(spacing.getValueAsString()) << ')';
                        break;
                case Spacing::Default:
                        // should never happen, do nothing
@@ -2383,11 +2363,11 @@ string LyXText::currentState(LCursor & cur)
        }
 
 #ifdef DEVEL_VERSION
-       os << to_utf8(_(", Inset: ")) << &cur.inset();
-       os << to_utf8(_(", Paragraph: ")) << cur.pit();
-       os << to_utf8(_(", Id: ")) << par.id();
-       os << to_utf8(_(", Position: ")) << cur.pos();
-       os << to_utf8(_(", Boundary: ")) << cur.boundary();
+       os << _(", Inset: ") << &cur.inset();
+       os << _(", Paragraph: ") << cur.pit();
+       os << _(", Id: ") << par.id();
+       os << _(", Position: ") << cur.pos();
+       os << _(", Boundary: ") << cur.boundary();
 //     Row & row = cur.textRow();
 //     os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
 #endif
@@ -2468,6 +2448,7 @@ docstring LyXText::getPossibleLabel(LCursor & cur) const
 pos_type LyXText::x2pos(BufferView const & bv, pit_type pit, int row,
                int x) const
 {
+       BOOST_ASSERT(!pars_[pit].rows().empty());
        BOOST_ASSERT(row < int(pars_[pit].rows().size()));
        bool bound = false;
        Row const & r = pars_[pit].rows()[row];