]> git.lyx.org Git - lyx.git/blobdiff - src/CutAndPaste.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / CutAndPaste.C
index 566d63016fb676e4f726ca00baf14a47ed9fb26c..7a22cfc335d20ada62e9787142683096571c98b6 100644 (file)
@@ -39,9 +39,9 @@
 #include "insets/insetcharstyle.h"
 #include "insets/insettabular.h"
 
-#include "mathed/math_data.h"
-#include "mathed/math_inset.h"
-#include "mathed/math_support.h"
+#include "mathed/MathData.h"
+#include "mathed/InsetMath.h"
+#include "mathed/MathSupport.h"
 
 #include "support/lstrings.h"
 
@@ -91,7 +91,7 @@ public:
                // to the buffer language.
                if (p.ownerCode() == InsetBase::ERT_CODE) {
                        p.changeLanguage(buffer_.params(), latex_language,
-                                        buffer_.getLanguage());
+                                        buffer_.getLanguage());
                }
                p.setInsetOwner(0);
        }
@@ -402,10 +402,11 @@ void switchBetweenClasses(textclass_type c1, textclass_type c2,
                        it->layout(tclass2.defaultLayout());
 
                if (!hasLayout && name != tclass1.defaultLayoutName()) {
-                       string const s = bformat(
-                               _("Layout had to be changed from\n%1$s to %2$s\n"
-                               "because of class conversion from\n%3$s to %4$s"),
-                        name, it->layout()->name(), tclass1.name(), tclass2.name());
+                       docstring const s = bformat(
+                                                _("Layout had to be changed from\n%1$s to %2$s\n"
+                                               "because of class conversion from\n%3$s to %4$s"),
+                        lyx::from_utf8(name), lyx::from_utf8(it->layout()->name()),
+                        lyx::from_utf8(tclass1.name()), lyx::from_utf8(tclass2.name()));
                        // To warn the user that something had to be done.
                        errorlist.push_back(ErrorItem(_("Changed Layout"), s,
                                                      it->id(), 0,
@@ -425,16 +426,16 @@ void switchBetweenClasses(textclass_type c1, textclass_type c2,
                        if (found_cs == tclass2.charstyles().end()) {
                                // The character style is undefined in tclass2
                                inset.setUndefined();
-                               string const s = bformat(_(
+                               docstring const s = bformat(_(
                                        "Character style %1$s is "
                                        "undefined because of class "
                                        "conversion from\n%2$s to %3$s"),
-                                        name, tclass1.name(), tclass2.name());
+                                        lyx::from_utf8(name), lyx::from_utf8(tclass1.name()),
+                                        lyx::from_utf8(tclass2.name()));
                                // To warn the user that something had to be done.
                                errorlist.push_back(ErrorItem(
-                                               _("Undefined character style"),
-                                               s, it.paragraph().id(),
-                                               it.pos(), it.pos() + 1));
+                                       _("Undefined character style"),
+                                       s, it.paragraph().id(), it.pos(), it.pos() + 1));
                        } else if (inset.undefined()) {
                                // The character style is undefined in
                                // tclass1 and is defined in tclass2
@@ -500,7 +501,7 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut)
                // faster we need to be more clever and probably also have more
                // calls to cur.bv().owner()->gui().selection().put. (Lgb)
 //             cur.bv().owner()->gui().selection().put(cur.selectionAsString(true));
-       
+
 
                // make sure that the depth behind the selection are restored, too
                recordUndoSelection(cur);
@@ -634,7 +635,7 @@ void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
                text->setCursor(cur, ppp.first, ppp.second);
        }
 
-       // mathed is handled in MathNestInset/MathGridInset
+       // mathed is handled in InsetMathNest/InsetMathGrid
        BOOST_ASSERT(!cur.inMathed());
 }
 
@@ -651,33 +652,19 @@ void pasteSelection(LCursor & cur, ErrorList & errorList, size_t sel_index)
 }
 
 
-void setSelectionRange(LCursor & cur, pos_type length)
-{
-       LyXText * text = cur.text();
-       BOOST_ASSERT(text);
-       if (!length)
-               return;
-       cur.resetAnchor();
-       while (length--)
-               text->cursorRight(cur);
-       cur.setSelection();
-}
-
-
 // simple replacing. The font of the first selected character is used
-void replaceSelectionWithString(LCursor & cur, string const & str)
+void replaceSelectionWithString(LCursor & cur, string const & str, bool backwards)
 {
-       LyXText * text = cur.text();
-       BOOST_ASSERT(text);
        recordUndo(cur);
+       DocIterator selbeg = cur.selectionBegin();
 
        // Get font setting before we cut
-       pos_type pos = cur.selEnd().pos();
-       Paragraph & par = text->getPar(cur.selEnd().pit());
        LyXFont const font =
-               par.getFontSettings(cur.buffer().params(), cur.selBegin().pos());
+               selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos());
 
        // Insert the new string
+       pos_type pos = cur.selEnd().pos();
+       Paragraph & par = cur.selEnd().paragraph();
        string::const_iterator cit = str.begin();
        string::const_iterator end = str.end();
        for (; cit != end; ++cit, ++pos)
@@ -685,6 +672,13 @@ void replaceSelectionWithString(LCursor & cur, string const & str)
 
        // Cut the selection
        cutSelection(cur, true, false);
+
+       // select the replacement
+       if (backwards) {
+               selbeg.pos() += str.length();
+               cur.setSelection(selbeg, -str.length());
+       } else
+               cur.setSelection(selbeg, str.length());
 }
 
 
@@ -695,27 +689,12 @@ void replaceSelection(LCursor & cur)
 }
 
 
-// only used by the spellchecker
-void replaceWord(LCursor & cur, string const & replacestring)
-{
-       LyXText * text = cur.text();
-       BOOST_ASSERT(text);
-
-       replaceSelectionWithString(cur, replacestring);
-       setSelectionRange(cur, replacestring.length());
-
-       // Go back so that replacement string is also spellchecked
-       for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
-               text->cursorLeft(cur);
-}
-
-
 void eraseSelection(LCursor & cur)
 {
        //lyxerr << "LCursor::eraseSelection begin: " << cur << endl;
        CursorSlice const & i1 = cur.selBegin();
        CursorSlice const & i2 = cur.selEnd();
-       if (i1.inset().asMathInset()) {
+       if (i1.inset().asInsetMath()) {
                cur.top() = i1;
                if (i1.idx() == i2.idx()) {
                        i1.cell().erase(i1.pos(), i2.pos());
@@ -724,7 +703,7 @@ void eraseSelection(LCursor & cur)
                        if (cur.pos() > cur.lastpos())
                                cur.pos() = cur.lastpos();
                } else {
-                       MathInset * p = i1.asMathInset();
+                       InsetMath * p = i1.asInsetMath();
                        InsetBase::row_type r1, r2;
                        InsetBase::col_type c1, c2;
                        region(i1, i2, r1, r2, c1, c2);
@@ -779,7 +758,7 @@ string grabSelection(LCursor const & cur)
        CursorSlice i2 = cur.selEnd();
 
        if (i1.idx() == i2.idx()) {
-               if (i1.inset().asMathInset()) {
+               if (i1.inset().asInsetMath()) {
                        MathArray::const_iterator it = i1.cell().begin();
                        return asString(MathArray(it + i1.pos(), it + i2.pos()));
                } else {
@@ -792,15 +771,15 @@ string grabSelection(LCursor const & cur)
        region(i1, i2, r1, r2, c1, c2);
 
        string data;
-       if (i1.inset().asMathInset()) {
+       if (i1.inset().asInsetMath()) {
                for (InsetBase::row_type row = r1; row <= r2; ++row) {
                        if (row > r1)
                                data += "\\\\";
                        for (InsetBase::col_type col = c1; col <= c2; ++col) {
                                if (col > c1)
                                        data += '&';
-                               data += asString(i1.asMathInset()->
-                                       cell(i1.asMathInset()->index(row, col)));
+                               data += asString(i1.asInsetMath()->
+                                       cell(i1.asInsetMath()->index(row, col)));
                        }
                }
        } else {