See attached.

The Deeper and Shallower ("In" and "Out") functionalities are not yet
implemented.

You can test the moving of a sectioning header plus belonging text up
and down by entering into the minibuffer: "outline 0" or "outline 1".

I have this stuff also working from qt2, with buttons on the TOC pop-up
window ;-)

For now this is very preliminary. But is this the way we want to go for
implementing outlining?

- Martin

Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C  (revision 13473)
+++ BufferView_pimpl.C  (working copy)
@@ -49,6 +49,7 @@
 #include "ParagraphParameters.h"
 #include "pariterator.h"
 #include "rowpainter.h"
+#include "toc.h"
 #include "undo.h"
 #include "vspace.h"
 
@@ -1042,6 +1043,7 @@
        case LFUN_INSERT_LABEL:
        case LFUN_BOOKMARK_SAVE:
        case LFUN_GOTO_PARAGRAPH:
+       case LFUN_OUTLINE:
        case LFUN_GOTOERROR:
        case LFUN_GOTONOTE:
        case LFUN_REFERENCE_GOTO:
@@ -1196,6 +1198,16 @@
                break;
        }
 
+       case LFUN_OUTLINE: {
+               lyx::toc::OutlineOp const op =
+                   
static_cast<lyx::toc::OutlineOp>(convert<int>(cmd.argument));
+               lyx::toc::Outline(op, buffer_, cursor_.pit());
+               bv_->text()->setCursor(cursor_, cursor_.pit(), 0);
+               buffer_->markDirty();
+               updateCounters(*buffer_);
+               update();
+       }
+                                 
        case LFUN_GOTOERROR:
                bv_funcs::gotoInset(bv_, InsetBase::ERROR_CODE, false);
                break;
Index: toc.C
===================================================================
--- toc.C       (revision 13473)
+++ toc.C       (working copy)
@@ -167,5 +167,87 @@
 }
 
 
+void Outline(OutlineOp mode, Buffer * buf, pit_type & pit)
+{
+       ParagraphList & pars = buf->text().paragraphs();
+       ParagraphList::iterator bgn = pars.begin();
+       ParagraphList::iterator s = boost::next(bgn, pit);
+       ParagraphList::iterator p = s;
+       ParagraphList::iterator end = pars.end();
+       int const thistoclevel = s->layout()->toclevel;
+       int toclevel;
+       switch (mode) {
+               case UP: {
+                       if (p != end)
+                               ++p;
+                       for (; p != end; ++p) {
+                               toclevel = p->layout()->toclevel;
+                               if (toclevel != LyXLayout::NOT_IN_TOC 
+                                   && toclevel <= thistoclevel) {
+                                       break;  
+                               }
+                       }
+                       ParagraphList::iterator q = s;
+                       if (q != bgn)
+                               --q;
+                       for (; q != bgn; --q) {
+                               toclevel = q->layout()->toclevel;
+                               if (toclevel != LyXLayout::NOT_IN_TOC 
+                                   && toclevel <= thistoclevel) {
+                                       break;  
+                               }
+                       }
+                       pit_type const newpit = std::distance(pars.begin(), q);
+                       pit_type const len = std::distance(s, p);
+                       pit += len;
+                       pars.insert(q, s, p);
+                       s = boost::next(pars.begin(), pit);
+                       ParagraphList::iterator t = boost::next(s, len);
+                       pit = newpit;
+                       pars.erase(s, t);
+               break;
+               }
+               case DOWN: {
+                          if (p != end)
+                               ++p;
+                       for (; p != end; ++p) {
+                               toclevel = p->layout()->toclevel;
+                               if (toclevel != LyXLayout::NOT_IN_TOC 
+                                   && toclevel <= thistoclevel) {
+                                       break;  
+                               }
+                       }
+                       ParagraphList::iterator q = p;
+                       bool skip = toclevel < thistoclevel;
+                       if (q != end)
+                               ++q;
+                       if (!skip) {
+                               for (; q != end; ++q) {
+                                       toclevel = q->layout()->toclevel;
+                                       if (toclevel != LyXLayout::NOT_IN_TOC 
+                                           && toclevel <= thistoclevel) {
+                                               break;  
+                                       }
+                               }
+                       }
+                       pit_type const newpit = std::distance(pars.begin(), q);
+                       pit_type const len = std::distance(s, p);
+                       pars.insert(q, s, p);
+                       s = boost::next(pars.begin(), pit);
+                       ParagraphList::iterator t = boost::next(s, len);
+                       pit = newpit - len;
+                       pars.erase(s, t);
+               break;
+               }
+               case DEEPER:
+               break;
+               case SHALLOWER:
+               break;
+               default:
+               break;
+       }
+}
+
+
 } // namespace toc
 } // namespace lyx
Index: toc.h
===================================================================
--- toc.h       (revision 13473)
+++ toc.h       (working copy)
@@ -84,6 +84,18 @@
 }
 
 
+/// the type of outline operation
+enum OutlineOp {
+       DOWN, // Move this header with text down
+       UP,   // Move this header with text up
+       DEEPER, // Make this header deeper
+       SHALLOWER // Make this header shallower
+};
+
+
+void Outline(OutlineOp, Buffer *, pit_type &);
+
+
 } // namespace toc
 } // namespace lyx
 
Index: lfuns.h
===================================================================
--- lfuns.h     (revision 13473)
+++ lfuns.h     (working copy)
@@ -357,6 +357,7 @@
        LFUN_BIBDB_ADD,
        LFUN_BIBDB_DEL,
        LFUN_INSERT_CITATION,
+       LFUN_OUTLINE,                   // Vermeer 20060323
 
        LFUN_LASTACTION                  // end of the table
 };
Index: LyXAction.C
===================================================================
--- LyXAction.C (revision 13473)
+++ LyXAction.C (working copy)
@@ -240,6 +240,7 @@
                { LFUN_DOWN_PARAGRAPH, "paragraph-down", ReadOnly | NoUpdate},
                { LFUN_DOWN_PARAGRAPHSEL, "paragraph-down-select", ReadOnly },
                { LFUN_GOTO_PARAGRAPH, "paragraph-goto", ReadOnly },
+               { LFUN_OUTLINE, "outline", ReadOnly },
                { LFUN_PARAGRAPH_SPACING, "paragraph-spacing", Noop },
                { LFUN_UP_PARAGRAPH, "paragraph-up", ReadOnly | NoUpdate},
                { LFUN_UP_PARAGRAPHSEL, "paragraph-up-select", ReadOnly },

Attachment: pgpfLvDMe2NiO.pgp
Description: PGP signature

Reply via email to