]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Const.
[lyx.git] / src / BufferView.cpp
index ad8ed46e582c6036c8a054c2228a41eace8ff0f9..819b478b9884a0b6f3991a1857a0cd88daac89e2 100644 (file)
@@ -65,6 +65,7 @@
 #include "insets/InsetText.h"
 
 #include "mathed/MathData.h"
+#include "mathed/InsetMathNest.h"
 
 #include "frontends/alert.h"
 #include "frontends/Application.h"
@@ -164,7 +165,7 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
 
        if (!findNextInset(tmpdit, codes, contents)) {
                if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
-                       Inset * inset = &tmpdit.bottom().inset();
+                       inset = &tmpdit.bottom().inset();
                        tmpdit = doc_iterator_begin(&inset->buffer(), inset);
                        if (!findNextInset(tmpdit, codes, contents))
                                return false;
@@ -1134,7 +1135,6 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        case LFUN_WORD_FIND_FORWARD:
        case LFUN_WORD_FIND_BACKWARD:
        case LFUN_WORD_REPLACE:
-       case LFUN_BUFFER_ANONYMIZE:
        case LFUN_MARK_OFF:
        case LFUN_MARK_ON:
        case LFUN_MARK_TOGGLE:
@@ -1464,14 +1464,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                for (Buffer * b = &buffer_; i == 0 || b != &buffer_;
                        b = theBufferList().next(b)) {
 
-                       Cursor cur(*this);
-                       cur.setCursor(b->getParFromID(id));
-                       if (cur.atEnd()) {
+                       Cursor curs(*this);
+                       curs.setCursor(b->getParFromID(id));
+                       if (curs.atEnd()) {
                                LYXERR(Debug::INFO, "No matching paragraph found! [" << id << "].");
                                ++i;
                                continue;
                        }
-                       LYXERR(Debug::INFO, "Paragraph " << cur.paragraph().id()
+                       LYXERR(Debug::INFO, "Paragraph " << curs.paragraph().id()
                                << " found in buffer `"
                                << b->absFileName() << "'.");
 
@@ -1479,8 +1479,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                bool success;
                                if (str_id_end.empty() || str_pos_end.empty()) {
                                        // Set the cursor
-                                       cur.pos() = pos;
-                                       mouseSetCursor(cur);
+                                       curs.pos() = pos;
+                                       mouseSetCursor(curs);
                                        success = true;
                                } else {
                                        int const id_end = convert<int>(str_id_end);
@@ -1622,15 +1622,6 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                break;
        }
 
-       case LFUN_BUFFER_ANONYMIZE: {
-               for (char c = '0'; c <= 'Z'; c++) {
-                       odocstringstream ss;
-                       ss << "a\n" << c << "\n0 0 1 1 0";
-                       lyx::dispatch(FuncRequest(LFUN_WORD_REPLACE, ss.str()));
-               }
-               break;
-       }
-
        case LFUN_WORD_FINDADV: {
                FindAndReplaceOptions opt;
                istringstream iss(to_utf8(cmd.argument()));
@@ -1709,11 +1700,12 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                from = cur.selectionBegin();
                to = cur.selectionEnd();
 
-               string newId = cmd.getArg(0);
-               bool fetchId=newId.empty(); //if we wait for groupId from first graphics inset
+               string const newId = cmd.getArg(0);
+               bool fetchId = newId.empty(); //if we wait for groupId from first graphics inset
 
                InsetGraphicsParams grp_par;
-               InsetGraphics::string2params(graphics::getGroupParams(buffer_, newId), buffer_, grp_par);
+               if (!fetchId)
+                       InsetGraphics::string2params(graphics::getGroupParams(buffer_, newId), buffer_, grp_par);
 
                if (!from.nextInset())  //move to closest inset
                        from.forwardInset();
@@ -1722,15 +1714,12 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        Inset * inset = from.nextInset();
                        if (!inset)
                                break;
-                       if (inset->lyxCode() == GRAPHICS_CODE) {
-                               InsetGraphics * ig = inset->asInsetGraphics();
-                               if (!ig)
-                                       break;
+                       InsetGraphics * ig = inset->asInsetGraphics();
+                       if (ig) {
                                InsetGraphicsParams inspar = ig->getParams();
                                if (fetchId) {
                                        grp_par = inspar;
                                        fetchId = false;
-
                                } else {
                                        grp_par.filename = inspar.filename;
                                        ig->setParams(grp_par);
@@ -1919,6 +1908,33 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        }
 
 
+       case LFUN_UNICODE_INSERT: {
+               if (cmd.argument().empty())
+                       break;
+
+               FuncCode code = cur.inset().currentMode() == Inset::MATH_MODE ?
+                       LFUN_MATH_INSERT : LFUN_SELF_INSERT;
+               int i = 0;
+               while (true) {
+                       docstring const arg = from_utf8(cmd.getArg(i));
+                       if (arg.empty())
+                               break;
+                       if (!isHex(arg)) {
+                               LYXERR0("Not a hexstring: " << arg);
+                               ++i;
+                               continue;
+                       }
+                       char_type c = hexToInt(arg);
+                       if (c >= 32 && c < 0x10ffff) {
+                               LYXERR(Debug::KEY, "Inserting c: " << c);
+                               lyx::dispatch(FuncRequest(code, docstring(1, c)));
+                       }
+                       ++i;
+               }
+               break;
+       }
+
+
        // This would be in Buffer class if only Cursor did not
        // require a bufferview
        case LFUN_INSET_FORALL: {
@@ -1929,20 +1945,20 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                // an arbitrary number to limit number of iterations
                const int max_iter = 100000;
                int iterations = 0;
-               Cursor & cur = d->cursor_;
-               Cursor const savecur = cur;
-               cur.reset();
-               if (!cur.nextInset())
-                       cur.forwardInset();
-               cur.beginUndoGroup();
-               while(cur && iterations < max_iter) {
-                       Inset * const ins = cur.nextInset();
+               Cursor & curs = d->cursor_;
+               Cursor const savecur = curs;
+               curs.reset();
+               if (!curs.nextInset())
+                       curs.forwardInset();
+               curs.beginUndoGroup();
+               while(curs && iterations < max_iter) {
+                       Inset * const ins = curs.nextInset();
                        if (!ins)
                                break;
                        docstring insname = ins->layoutName();
                        while (!insname.empty()) {
                                if (insname == name || name == from_utf8("*")) {
-                                       cur.recordUndo();
+                                       curs.recordUndo();
                                        lyx::dispatch(fr, dr);
                                        ++iterations;
                                        break;
@@ -1953,11 +1969,11 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                insname = insname.substr(0, i);
                        }
                        // if we did not delete the inset, skip it
-                       if (!cur.nextInset() || cur.nextInset() == ins)
-                               cur.forwardInset();
+                       if (!curs.nextInset() || curs.nextInset() == ins)
+                               curs.forwardInset();
                }
-               cur = savecur;
-               cur.fixIfBroken();
+               curs = savecur;
+               curs.fixIfBroken();
                /** This is a dummy undo record only to remember the cursor
                 * that has just been set; this will be used on a redo action
                 * (see ticket #10097)
@@ -1965,8 +1981,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                 * FIXME: a better fix would be to have a way to set the
                 * cursor value directly, but I am not sure it is worth it.
                 */
-               cur.recordUndo();
-               cur.endUndoGroup();
+               curs.recordUndo();
+               curs.endUndoGroup();
                dr.screenUpdate(Update::Force);
                dr.forceBufferUpdate();
 
@@ -2061,6 +2077,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                icp["key"] = from_utf8(arg);
                if (!opt1.empty())
                        icp["before"] = from_utf8(opt1);
+               icp["literal"] = 
+                       from_ascii(InsetCitation::last_literal ? "true" : "false");
                string icstr = InsetCommand::params2string(icp);
                FuncRequest fr(LFUN_INSET_INSERT, icstr);
                lyx::dispatch(fr);