]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
EmbeddedObjects.lyx, Math.lyx, UserGuide.lyx: Spanish translation updates by Ignacio
[lyx.git] / src / Text3.cpp
index 22408657cb4ddcb97a7d58c88f9ec1cbff53e8a9..ee7865cfa8cca98c2bfb5dae309f8e06f48900c4 100644 (file)
@@ -1,14 +1,14 @@
 /**
- * \file text3.cpp
+ * \file Text3.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
  * \author Asger Alstrup
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Alfredo Braunstein
  * \author Angus Leeming
  * \author John Levon
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -48,6 +48,9 @@
 
 #include "frontends/Clipboard.h"
 #include "frontends/Selection.h"
+#include "frontends/Application.h"
+#include "frontends/LyXView.h"
+#include "frontends/WorkArea.h"
 
 #include "insets/InsetCollapsable.h"
 #include "insets/InsetCommand.h"
@@ -67,7 +70,6 @@
 
 #include "mathed/InsetMathHull.h"
 #include "mathed/MathMacroTemplate.h"
-#include "mathed/MathParser.h"
 
 #include <boost/next_prior.hpp>
 
@@ -85,6 +87,8 @@ using cap::pasteFromStack;
 using cap::pasteClipboardText;
 using cap::pasteClipboardGraphics;
 using cap::replaceSelection;
+using cap::grabAndEraseSelection;
+using cap::selClearOrDel;
 
 // globals...
 static Font freefont(ignore_font, ignore_language);
@@ -164,14 +168,11 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
                        istringstream is(selstr);
                        Lexer lex;
                        lex.setStream(is);
-                       mathed_parser_warn_contents(false);
-                       formula->read(lex);
-                       if (formula->getType() == hullNone) {
+                       if (!formula->readQuiet(lex)) {
                                // No valid formula, let's try with delims
                                is.str("$" + selstr + "$");
                                lex.setStream(is);
-                               formula->read(lex);
-                               if (formula->getType() == hullNone) {
+                               if (!formula->readQuiet(lex)) {
                                        // Still not valid, leave it as is
                                        valid = false;
                                        delete formula;
@@ -180,7 +181,6 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
                                        cur.insert(formula);
                        } else
                                cur.insert(formula);
-                       mathed_parser_warn_contents(true);
                } else {
                        cur.insert(new MathMacroTemplate(sel));
                }
@@ -192,6 +192,26 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
 }
 
 
+void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
+{
+       BOOST_ASSERT(cmd.action == LFUN_REGEXP_MODE);
+       if (cur.inRegexped()) {
+               cur.message(_("Already in regexp mode"));
+               return;
+       }
+       cur.recordUndo();
+       docstring const save_selection = grabAndEraseSelection(cur);
+       selClearOrDel(cur);
+       // replaceSelection(cur);
+
+       cur.insert(new InsetMathHull(hullRegexp));
+       cur.nextInset()->edit(cur, true);
+       cur.niceInsert(save_selection);
+
+       cur.message(_("Regexp editor mode"));
+}
+
+
 static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
 {
        cur.recordUndo();
@@ -220,7 +240,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
                if (edit)
                        inset->edit(cur, true);
                // Now put this into inset
-               static_cast<InsetCollapsable *>(inset)->text().insertStringAsParagraphs(cur, ds);
+               static_cast<InsetCollapsable *>(inset)->
+                               text().insertStringAsParagraphs(cur, ds);
                return true;
        }
 
@@ -238,8 +259,8 @@ static bool doInsertInset(Cursor & cur, Text * text,
        if (!gotsel || !pastesel)
                return true;
 
-       pasteFromStack(cur, cur.buffer().errorList("Paste"), 0);
-       cur.buffer().errors("Paste");
+       pasteFromStack(cur, cur.buffer()->errorList("Paste"), 0);
+       cur.buffer()->errors("Paste");
        cur.clearSelection(); // bug 393
        cur.finishUndo();
        InsetText * insetText = dynamic_cast<InsetText *>(inset);
@@ -284,7 +305,7 @@ enum OutlineOp {
 
 static void outline(OutlineOp mode, Cursor & cur)
 {
-       Buffer & buf = cur.buffer();
+       Buffer & buf = *cur.buffer();
        pit_type & pit = cur.pit();
        ParagraphList & pars = buf.text().paragraphs();
        ParagraphList::iterator bgn = pars.begin();
@@ -452,7 +473,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                recUndo(cur, pit, pit + 1);
                cur.finishUndo();
                swap(pars_[pit], pars_[pit + 1]);
-               updateLabels(cur.buffer());
+               cur.buffer()->updateLabels();
                needsUpdate = true;
                ++cur.pit();
                break;
@@ -463,7 +484,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                recUndo(cur, pit - 1, pit);
                cur.finishUndo();
                swap(pars_[pit], pars_[pit - 1]);
-               updateLabels(cur.buffer());
+               cur.buffer()->updateLabels();
                --cur.pit();
                needsUpdate = true;
                break;
@@ -489,30 +510,30 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                par.params().startOfAppendix(start);
 
                // we can set the refreshing parameters now
-               updateLabels(cur.buffer());
+               cur.buffer()->updateLabels();
                break;
        }
 
        case LFUN_WORD_DELETE_FORWARD:
-               if (cur.selection()) {
+               if (cur.selection())
                        cutSelection(cur, true, false);
-               else
+               else
                        deleteWordForward(cur);
                finishChange(cur, false);
                break;
 
        case LFUN_WORD_DELETE_BACKWARD:
-               if (cur.selection()) {
+               if (cur.selection())
                        cutSelection(cur, true, false);
-               else
+               else
                        deleteWordBackward(cur);
                finishChange(cur, false);
                break;
 
        case LFUN_LINE_DELETE:
-               if (cur.selection()) {
+               if (cur.selection())
                        cutSelection(cur, true, false);
-               else
+               else
                        tm.deleteLineForward(cur);
                finishChange(cur, false);
                break;
@@ -520,22 +541,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_BUFFER_BEGIN:
        case LFUN_BUFFER_BEGIN_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT);
-               if (cur.depth() == 1) {
+               if (cur.depth() == 1)
                        needsUpdate |= cursorTop(cur);
-               } else {
+               else
                        cur.undispatched();
-               }
                cur.updateFlags(Update::FitCursor);
                break;
 
        case LFUN_BUFFER_END:
        case LFUN_BUFFER_END_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT);
-               if (cur.depth() == 1) {
+               if (cur.depth() == 1)
                        needsUpdate |= cursorBottom(cur);
-               } else {
+               else
                        cur.undispatched();
-               }
                cur.updateFlags(Update::FitCursor);
                break;
 
@@ -619,16 +638,24 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // stop/start the selection
                bool select = cmd.action == LFUN_DOWN_SELECT ||
                        cmd.action == LFUN_UP_SELECT;
-               cur.selHandle(select);
 
                // move cursor up/down
                bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
-               bool const successful = cur.upDownInText(up, needsUpdate);
-               if (successful) {
-                       // redraw if you leave mathed (for the decorations)
+               bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
+
+               if (!atFirstOrLastRow) {
+                       needsUpdate |= cur.selHandle(select);   
+                       cur.selHandle(select);
+                       cur.upDownInText(up, needsUpdate);
                        needsUpdate |= cur.beforeDispatchCursor().inMathed();
-               } else
+               } else {
+                       // if the cursor cannot be moved up or down do not remove
+                       // the selection right now, but wait for the next dispatch.
+                       if (select)
+                               needsUpdate |= cur.selHandle(select);   
+                       cur.upDownInText(up, needsUpdate);
                        cur.undispatched();
+               }
 
                break;
        }
@@ -1315,10 +1342,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        cutSelection(cur, false, false);
 
                cur.clearSelection();
-               Font const old_font = cur.real_current_font;
 
                docstring::const_iterator cit = cmd.argument().begin();
-               docstring::const_iterator end = cmd.argument().end();
+               docstring::const_iterator const end = cmd.argument().end();
                for (; cit != end; ++cit)
                        bv->translateAndInsert(*cit, this, cur);
 
@@ -1397,7 +1423,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cur.posForward();
                // Some insets are numbered, others are shown in the outline pane so
                // let's update the labels and the toc backend.
-               updateLabels(bv->buffer());
+               bv->buffer().updateLabels();
                break;
 
        case LFUN_TABULAR_INSERT:
@@ -1412,10 +1438,18 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_FLOAT_INSERT:
        case LFUN_FLOAT_WIDE_INSERT:
        case LFUN_WRAP_INSERT: {
-               bool content = cur.selection();  // will some text be moved into the inset?
+               // will some text be moved into the inset?
+               bool content = cur.selection();
 
                doInsertInset(cur, this, cmd, true, true);
                cur.posForward();
+
+               // If some text is moved into the inset, doInsertInset 
+               // puts the cursor outside the inset. To insert the
+               // caption we put it back into the inset.
+               if (content)
+                       cur.backwardPos();
+
                ParagraphList & pars = cur.text()->paragraphs();
 
                DocumentClass const & tclass = bv->buffer().params().documentClass();
@@ -1442,7 +1476,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // We cannot use Cursor::dispatch here it needs access to up to
                // date metrics.
                FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
-               cur.text()->dispatch(cur, cmd_caption);
+               doInsertInset(cur, cur.text(), cmd_caption, true, false);
+               bv->buffer().updateLabels();
                cur.updateFlags(Update::Force);
                // FIXME: When leaving the Float (or Wrap) inset we should
                // delete any empty paragraph left above or below the
@@ -1483,6 +1518,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                mathDispatch(cur, cmd, true);
                break;
 
+       case LFUN_REGEXP_MODE:
+               regexpDispatch(cur, cmd);
+               break;
+
        case LFUN_MATH_MODE:
                if (cmd.argument() == "on")
                        // don't pass "on" as argument
@@ -1543,6 +1582,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_FONT_ITAL: {
+               Font font(ignore_font, ignore_language);
+               font.fontInfo().setShape(ITALIC_SHAPE);
+               toggleAndShow(cur, this, font);
+               break;
+       }
+
        case LFUN_FONT_BOLD:
        case LFUN_FONT_BOLDSYMBOL: {
                Font font(ignore_font, ignore_language);
@@ -1757,6 +1803,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                // Get word or selection
                                selectWordWhenUnderCursor(cur, WHOLE_WORD);
                                arg = cur.selectionAsString(false);
+                               arg += " lang=" + from_ascii(cur.getFont().language()->lang());
                        }
                }
                bv->showDialog("thesaurus", to_utf8(arg));
@@ -1799,26 +1846,26 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_OUTLINE_UP:
                outline(OutlineUp, cur);
                setCursor(cur, cur.pit(), 0);
-               updateLabels(cur.buffer());
+               cur.buffer()->updateLabels();
                needsUpdate = true;
                break;
 
        case LFUN_OUTLINE_DOWN:
                outline(OutlineDown, cur);
                setCursor(cur, cur.pit(), 0);
-               updateLabels(cur.buffer());
+               cur.buffer()->updateLabels();
                needsUpdate = true;
                break;
 
        case LFUN_OUTLINE_IN:
                outline(OutlineIn, cur);
-               updateLabels(cur.buffer());
+               cur.buffer()->updateLabels();
                needsUpdate = true;
                break;
 
        case LFUN_OUTLINE_OUT:
                outline(OutlineOut, cur);
-               updateLabels(cur.buffer());
+               cur.buffer()->updateLabels();
                needsUpdate = true;
                break;
 
@@ -1875,8 +1922,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 {
        LASSERT(cur.text() == this, /**/);
 
-       Font const & font = cur.real_current_font;
-       FontInfo const & fontinfo = font.fontInfo();
+       FontInfo const & fontinfo = cur.real_current_font.fontInfo();
        bool enable = true;
        InsetCode code = NO_CODE;
 
@@ -1987,11 +2033,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                code = FLEX_CODE;
                string s = cmd.getArg(0);
                InsetLayout il =
-                       cur.buffer().params().documentClass().insetLayout(from_utf8(s));
-               if (il.lyxtype() != "charstyle" &&
-                   il.lyxtype() != "custom" &&
-                   il.lyxtype() != "element" &&
-                   il.lyxtype ()!= "standard")
+                       cur.buffer()->params().documentClass().insetLayout(from_utf8(s));
+               if (il.lyxtype() != InsetLayout::CHARSTYLE &&
+                   il.lyxtype() != InsetLayout::CUSTOM &&
+                   il.lyxtype() != InsetLayout::ELEMENT &&
+                   il.lyxtype ()!= InsetLayout::STANDARD)
                        enable = false;
                break;
                }
@@ -2000,7 +2046,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                break;
        case LFUN_BRANCH_INSERT:
                code = BRANCH_CODE;
-               if (cur.buffer().masterBuffer()->params().branchlist().empty())
+               if (cur.buffer()->masterBuffer()->params().branchlist().empty())
                        enable = false;
                break;
        case LFUN_LABEL_INSERT:
@@ -2065,6 +2111,10 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                flag.setOnOff(fontinfo.emph() == FONT_ON);
                break;
 
+       case LFUN_FONT_ITAL:
+               flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
+               break;
+
        case LFUN_FONT_NOUN:
                flag.setOnOff(fontinfo.noun() == FONT_ON);
                break;
@@ -2141,9 +2191,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_INSET_DISSOLVE:
                if (!cmd.argument().empty()) {
-                       InsetLayout il = cur.inset().getLayout(cur.buffer().params());
+                       InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
+                       InsetLayout::InsetLyXType const type = 
+                                       translateLyXType(to_utf8(cmd.argument()));
                        enable = cur.inset().lyxCode() == FLEX_CODE
-                                && il.lyxtype() == to_utf8(cmd.argument());
+                                && il.lyxtype() == type;
                } else {
                        enable = !isMainText(cur.bv().buffer())
                                 && cur.inset().nargs() == 1;