]> git.lyx.org Git - features.git/commitdiff
I don't think that a single function that's only use once should have a
authorAndré Pönitz <poenitz@gmx.net>
Sat, 29 Sep 2007 20:25:50 +0000 (20:25 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 29 Sep 2007 20:25:50 +0000 (20:25 +0000)
pair of files of its own

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20599 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/Makefile.am
src/toc.cpp [deleted file]
src/toc.h [deleted file]

index 39874ee0174840ef72373aef86cf361318ff524b..79662d07d27b083ace12c0625dc214e5a14b0c0a 100644 (file)
@@ -49,7 +49,6 @@
 #include "TexRow.h"
 #include "Text.h"
 #include "TextClass.h"
-#include "toc.h"
 #include "Undo.h"
 #include "VSpace.h"
 #include "WordLangTuple.h"
@@ -203,9 +202,139 @@ void gotoInset(BufferView * bv, Inset_code code, bool same_content)
 }
 
 
+
+/// the type of outline operation
+enum OutlineOp {
+       OutlineUp, // Move this header with text down
+       OutlineDown,   // Move this header with text up
+       OutlineIn, // Make this header deeper
+       OutlineOut // Make this header shallower
+};
+
+
+void outline(OutlineOp mode, Cursor & cur)
+{
+       Buffer & buf = cur.buffer();
+       pit_type & pit = cur.pit();
+       ParagraphList & pars = buf.text().paragraphs();
+       ParagraphList::iterator bgn = pars.begin();
+       // The first paragraph of the area to be copied:
+       ParagraphList::iterator start = boost::next(bgn, pit);
+       // The final paragraph of area to be copied:
+       ParagraphList::iterator finish = start;
+       ParagraphList::iterator end = pars.end();
+
+       TextClass::const_iterator lit =
+               buf.params().getTextClass().begin();
+       TextClass::const_iterator const lend =
+               buf.params().getTextClass().end();
+
+       int const thistoclevel = start->layout()->toclevel;
+       int toclevel;
+       switch (mode) {
+               case OutlineUp: {
+                       // Move out (down) from this section header
+                       if (finish != end)
+                               ++finish;
+                       // Seek the one (on same level) below
+                       for (; finish != end; ++finish) {
+                               toclevel = finish->layout()->toclevel;
+                               if (toclevel != Layout::NOT_IN_TOC
+                                   && toclevel <= thistoclevel) {
+                                       break;
+                               }
+                       }
+                       ParagraphList::iterator dest = start;
+                       // Move out (up) from this header
+                       if (dest == bgn)
+                               break;
+                       // Search previous same-level header above
+                       do {
+                               --dest;
+                               toclevel = dest->layout()->toclevel;
+                       } while(dest != bgn
+                               && (toclevel == Layout::NOT_IN_TOC
+                                   || toclevel > thistoclevel));
+                       // Not found; do nothing
+                       if (toclevel == Layout::NOT_IN_TOC || toclevel > thistoclevel)
+                               break;
+                       pit_type const newpit = std::distance(bgn, dest);
+                       pit_type const len = std::distance(start, finish);
+                       pit_type const deletepit = pit + len;
+                       recordUndo(cur, Undo::ATOMIC, newpit, deletepit - 1);
+                       pars.insert(dest, start, finish);
+                       start = boost::next(pars.begin(), deletepit);
+                       pit = newpit;
+                       pars.erase(start, finish);
+                       break;
+               }
+               case OutlineDown: {
+                       // Go down out of current header:
+                       if (finish != end)
+                               ++finish;
+                       // Find next same-level header:
+                       for (; finish != end; ++finish) {
+                               toclevel = finish->layout()->toclevel;
+                               if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
+                                       break;
+                       }
+                       ParagraphList::iterator dest = finish;
+                       // Go one down from *this* header:
+                       if (dest != end)
+                               ++dest;
+                       else
+                               break;
+                       // Go further down to find header to insert in front of:
+                       for (; dest != end; ++dest) {
+                               toclevel = dest->layout()->toclevel;
+                               if (toclevel != Layout::NOT_IN_TOC && toclevel <= thistoclevel)
+                                       break;
+                       }
+                       // One such was found:
+                       pit_type newpit = std::distance(bgn, dest);
+                       pit_type const len = std::distance(start, finish);
+                       recordUndo(cur, Undo::ATOMIC, pit, newpit - 1);
+                       pars.insert(dest, start, finish);
+                       start = boost::next(bgn, pit);
+                       pit = newpit - len;
+                       pars.erase(start, finish);
+                       break;
+               }
+               case OutlineIn:
+                       recordUndo(cur);
+                       for (; lit != lend; ++lit) {
+                               if ((*lit)->toclevel == thistoclevel + 1 &&
+                                   start->layout()->labeltype == (*lit)->labeltype) {
+                                       start->layout((*lit));
+                                       break;
+                               }
+                       }
+                       break;
+               case OutlineOut:
+                       recordUndo(cur);
+                       for (; lit != lend; ++lit) {
+                               if ((*lit)->toclevel == thistoclevel - 1 &&
+                                   start->layout()->labeltype == (*lit)->labeltype) {
+                                       start->layout((*lit));
+                                       break;
+                               }
+                       }
+                       break;
+               default:
+                       break;
+       }
+}
+
 } // anon namespace
 
 
+/////////////////////////////////////////////////////////////////////
+//
+// BufferView
+//
+/////////////////////////////////////////////////////////////////////
+
+
 BufferView::BufferView(Buffer & buf)
        : width_(0), height_(0), buffer_(buf), wh_(0),
          cursor_(*this),
@@ -831,21 +960,21 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_OUTLINE_UP:
-               toc::outline(toc::Up, cursor_);
+               outline(OutlineUp, cursor_);
                cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
                updateLabels(buffer_);
                break;
        case LFUN_OUTLINE_DOWN:
-               toc::outline(toc::Down, cursor_);
+               outline(OutlineDown, cursor_);
                cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
                updateLabels(buffer_);
                break;
        case LFUN_OUTLINE_IN:
-               toc::outline(toc::In, cursor_);
+               outline(OutlineIn, cursor_);
                updateLabels(buffer_);
                break;
        case LFUN_OUTLINE_OUT:
-               toc::outline(toc::Out, cursor_);
+               outline(OutlineOut, cursor_);
                updateLabels(buffer_);
                break;
 
index 4a339b6d4c367d6c9d0c2e87dc08bb8f22ca3935..068dbf99e576a5edd65230ecba03e0a6d25410df 100644 (file)
@@ -261,8 +261,6 @@ liblyxcore_la_SOURCES = \
        TextMetrics.h \
        TocBackend.cpp \
        TocBackend.h \
-       toc.cpp \
-       toc.h \
        ToolbarBackend.cpp \
        ToolbarBackend.h \
        Trans.cpp \
diff --git a/src/toc.cpp b/src/toc.cpp
deleted file mode 100644 (file)
index a865d8d..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * \file toc.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jean-Marc Lasgouttes
- * \author Angus Leeming
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "toc.h"
-
-#include "Buffer.h"
-#include "BufferParams.h"
-#include "Cursor.h"
-#include "debug.h"
-#include "FuncRequest.h"
-#include "Layout.h"
-#include "LyXAction.h"
-#include "Paragraph.h"
-#include "ParIterator.h"
-#include "Text.h"
-#include "Undo.h"
-
-
-namespace lyx {
-namespace toc {
-
-void outline(OutlineOp mode, Cursor & cur)
-{
-       Buffer & buf = cur.buffer();
-       pit_type & pit = cur.pit();
-       ParagraphList & pars = buf.text().paragraphs();
-       ParagraphList::iterator bgn = pars.begin();
-       // The first paragraph of the area to be copied:
-       ParagraphList::iterator start = boost::next(bgn, pit);
-       // The final paragraph of area to be copied:
-       ParagraphList::iterator finish = start;
-       ParagraphList::iterator end = pars.end();
-
-       TextClass::const_iterator lit =
-               buf.params().getTextClass().begin();
-       TextClass::const_iterator const lend =
-               buf.params().getTextClass().end();
-
-       int const thistoclevel = start->layout()->toclevel;
-       int toclevel;
-       switch (mode) {
-               case Up: {
-                       // Move out (down) from this section header
-                       if (finish != end)
-                               ++finish;
-                       // Seek the one (on same level) below
-                       for (; finish != end; ++finish) {
-                               toclevel = finish->layout()->toclevel;
-                               if (toclevel != Layout::NOT_IN_TOC
-                                   && toclevel <= thistoclevel) {
-                                       break;
-                               }
-                       }
-                       ParagraphList::iterator dest = start;
-                       // Move out (up) from this header
-                       if (dest == bgn)
-                               break;
-                       // Search previous same-level header above
-                       do {
-                               --dest;
-                               toclevel = dest->layout()->toclevel;
-                       } while(dest != bgn
-                               && (toclevel == Layout::NOT_IN_TOC
-                                   || toclevel > thistoclevel));
-                       // Not found; do nothing
-                       if (toclevel == Layout::NOT_IN_TOC
-                           || toclevel > thistoclevel)
-                               break;
-                       pit_type const newpit = std::distance(bgn, dest);
-                       pit_type const len = std::distance(start, finish);
-                       pit_type const deletepit = pit + len;
-                       recordUndo(cur, Undo::ATOMIC, newpit, deletepit - 1);
-                       pars.insert(dest, start, finish);
-                       start = boost::next(pars.begin(), deletepit);
-                       pit = newpit;
-                       pars.erase(start, finish);
-               break;
-               }
-               case Down: {
-                       // Go down out of current header:
-                       if (finish != end)
-                               ++finish;
-                       // Find next same-level header:
-                       for (; finish != end; ++finish) {
-                               toclevel = finish->layout()->toclevel;
-                               if (toclevel != Layout::NOT_IN_TOC
-                                   && toclevel <= thistoclevel) {
-                                       break;
-                               }
-                       }
-                       ParagraphList::iterator dest = finish;
-                       // Go one down from *this* header:
-                       if (dest != end)
-                               ++dest;
-                       else
-                               break;
-                       // Go further down to find header to insert in front of:
-                       for (; dest != end; ++dest) {
-                               toclevel = dest->layout()->toclevel;
-                               if (toclevel != Layout::NOT_IN_TOC
-                                   && toclevel <= thistoclevel) {
-                                       break;
-                               }
-                       }
-                       // One such was found:
-                       pit_type newpit = std::distance(bgn, dest);
-                       pit_type const len = std::distance(start, finish);
-                       recordUndo(cur, Undo::ATOMIC, pit, newpit - 1);
-                       pars.insert(dest, start, finish);
-                       start = boost::next(bgn, pit);
-                       pit = newpit - len;
-                       pars.erase(start, finish);
-               break;
-               }
-               case In:
-                       recordUndo(cur);
-                       for (; lit != lend; ++lit) {
-                               if ((*lit)->toclevel == thistoclevel + 1 &&
-                                   start->layout()->labeltype == (*lit)->labeltype) {
-                                       start->layout((*lit));
-                                       break;
-                               }
-                       }
-               break;
-               case Out:
-                       recordUndo(cur);
-                       for (; lit != lend; ++lit) {
-                               if ((*lit)->toclevel == thistoclevel - 1 &&
-                                   start->layout()->labeltype == (*lit)->labeltype) {
-                                       start->layout((*lit));
-                                       break;
-                               }
-                       }
-               break;
-               default:
-               break;
-       }
-}
-
-
-} // namespace toc
-} // namespace lyx
diff --git a/src/toc.h b/src/toc.h
deleted file mode 100644 (file)
index 19e3469..0000000
--- a/src/toc.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// -*- C++ -*-
-/**
- * \file toc.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jean-Marc Lasgouttes
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- *
- * Nice functions and objects to handle TOCs
- */
-
-#ifndef TOC_H
-#define TOC_H
-
-class Cursor;
-
-namespace lyx {
-namespace toc {
-
-/// the type of outline operation
-enum OutlineOp {
-       Up, // Move this header with text down
-       Down,   // Move this header with text up
-       In, // Make this header deeper
-       Out // Make this header shallower
-};
-
-
-void outline(OutlineOp, Cursor &);
-
-
-} // namespace toc
-} // namespace lyx
-
-#endif // CONTROLTOC_H