]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Add AllowedInInsets and AllowedInLayouts InsetLayout tags
[lyx.git] / src / Text.cpp
index 3dae5c78ffd344f937784b72f41f2bcd7a74bfd1..9dff2b37ab837f6fd5a3e0a67380237f97792a08 100644 (file)
@@ -716,9 +716,8 @@ double Text::spacing(Paragraph const & par) const
 /**
  * This breaks a paragraph at the specified position.
  * The new paragraph will:
- * - Decrease depth by one (or change layout to default layout) when
- *    keep_layout == false
- * - keep current depth and layout when keep_layout == true
+ * - change layout to default layout when keep_layout == false
+ * - keep layout when keep_layout == true
  */
 static void breakParagraph(Text & text, pit_type par_offset, pos_type pos,
                    bool keep_layout)
@@ -733,21 +732,13 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos,
 
        // remember to set the inset_owner
        tmp->setInsetOwner(&par.inInset());
-       // without doing that we get a crash when typing <Return> at the
-       // end of a paragraph
-       tmp->setPlainOrDefaultLayout(bparams.documentClass());
+       tmp->params().depth(par.params().depth());
 
        if (keep_layout) {
                tmp->setLayout(par.layout());
                tmp->setLabelWidthString(par.params().labelWidthString());
-               tmp->params().depth(par.params().depth());
-       } else if (par.params().depth() > 0) {
-               Paragraph const & hook = pars[text.outerHook(par_offset)];
-               tmp->setLayout(hook.layout());
-               // not sure the line below is useful
-               tmp->setLabelWidthString(par.params().labelWidthString());
-               tmp->params().depth(hook.params().depth());
-       }
+       } else
+               tmp->setPlainOrDefaultLayout(bparams.documentClass());
 
        bool const isempty = (par.allowEmpty() && par.empty());
 
@@ -2917,7 +2908,8 @@ void Text::setParagraphs(Cursor const & cur, docstring const & arg, bool merge)
        Layout priorlayout;
        Cursor c(cur.bv());
        c.setCursor(cur.selectionBegin());
-       for ( ; c <= cur.selectionEnd() ; ++c.pit()) {
+       pit_type const last_pit = cur.selectionEnd().pit();
+       for ( ; c.pit() <= last_pit ; ++c.pit()) {
                Paragraph & par = c.paragraph();
                ParagraphParameters params = par.params();
                params.read(argument, merge);
@@ -2943,7 +2935,8 @@ void Text::setParagraphs(Cursor const & cur, ParagraphParameters const & p)
        Layout priorlayout;
        Cursor c(cur.bv());
        c.setCursor(cur.selectionBegin());
-       for ( ; c < cur.selectionEnd() ; ++c.pit()) {
+       pit_type const last_pit = cur.selectionEnd().pit();
+       for ( ; c.pit() <= last_pit ; ++c.pit()) {
                Paragraph & par = c.paragraph();
                // Changes to label width string apply to all paragraphs
                // with same layout in a sequence.
@@ -3746,7 +3739,7 @@ void insertSeparator(Cursor const & cur, depth_type const depth)
 }
 
 
-void outline(OutlineOp mode, Cursor & cur)
+void outline(OutlineOp mode, Cursor & cur, bool local)
 {
        Buffer & buf = *cur.buffer();
        Text & text = *cur.text();
@@ -3767,11 +3760,13 @@ void outline(OutlineOp mode, Cursor & cur)
        if (finish != end)
                ++finish;
 
-       // Seek the one (on same level) below
-       for (; finish != end; ++finish) {
-               toclevel = text.getTocLevel(distance(bgn, finish));
-               if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
-                       break;
+       if (!local || (mode != OutlineIn && mode != OutlineOut)) {
+               // Seek the one (on same level) below
+               for (; finish != end; ++finish) {
+                       toclevel = text.getTocLevel(distance(bgn, finish));
+                       if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
+                               break;
+               }
        }
 
        switch (mode) {
@@ -6248,7 +6243,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_OUTLINE_UP: {
                pos_type const opos = cur.pos();
-               outline(OutlineUp, cur);
+               outline(OutlineUp, cur, false);
                setCursor(cur, cur.pit(), opos);
                cur.forceBufferUpdate();
                needsUpdate = true;
@@ -6257,7 +6252,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_OUTLINE_DOWN: {
                pos_type const opos = cur.pos();
-               outline(OutlineDown, cur);
+               outline(OutlineDown, cur, false);
                setCursor(cur, cur.pit(), opos);
                cur.forceBufferUpdate();
                needsUpdate = true;
@@ -6265,13 +6260,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_OUTLINE_IN:
-               outline(OutlineIn, cur);
+               outline(OutlineIn, cur, cmd.getArg(0) == "local");
                cur.forceBufferUpdate();
                needsUpdate = true;
                break;
 
        case LFUN_OUTLINE_OUT:
-               outline(OutlineOut, cur);
+               outline(OutlineOut, cur, cmd.getArg(0) == "local");
                cur.forceBufferUpdate();
                needsUpdate = true;
                break;
@@ -6549,6 +6544,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                        s = from_ascii("Flex:") + s;
                if (!cur.buffer()->params().documentClass().hasInsetLayout(s))
                        enable = false;
+               else if (!cur.paragraph().allowedInContext(cur, cur.buffer()->params().documentClass().insetLayout(s)))
+                       enable = false;
                else {
                        InsetLyXType ilt =
                                cur.buffer()->params().documentClass().insetLayout(s).lyxtype();