From d533ee39957efe9ce61941944706275da9124fc3 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 3 Apr 2003 00:36:31 +0000 Subject: [PATCH] merge decDepth(), killing some non-parlist code git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6695 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 1 + src/ChangeLog | 8 +++ src/bufferview_funcs.C | 15 ++-- src/bufferview_funcs.h | 15 +++- src/frontends/controllers/ControlCharacter.C | 1 + .../controllers/ControlCommandBuffer.C | 1 + src/frontends/qt2/QtView.C | 1 + src/lyxfunc.C | 5 +- src/lyxtext.h | 27 ++++---- src/paragraph_pimpl.C | 2 +- src/text.C | 1 + src/text2.C | 69 +++---------------- 12 files changed, 58 insertions(+), 88 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 2d0aa34f85..51a1d48818 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -72,6 +72,7 @@ using std::make_pair; using std::min; using lyx::pos_type; +using namespace bv_funcs; extern BufferList bufferlist; diff --git a/src/ChangeLog b/src/ChangeLog index e227b809e6..a2347b2e68 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-04-03 John Levon + + * bufferview_funcs.h: + * bufferview_funcs.C: + * lyxfunc.C: + * lyxtext.h: + * text2.C: parlistize decDepth(), by merging it with incDepth() + 2003-04-03 Lars Gullik Bjønnes * lyxrow.h: store a ParagraphList::iterator instead of a diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 6821ad8157..0064047ecd 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -38,10 +38,13 @@ #include "support/BoostFormat.h" namespace { + LyXFont freefont(LyXFont::ALL_IGNORE); bool toggleall(false); + } +namespace bv_funcs { // Set data using font and toggle // If successful, returns true @@ -214,20 +217,14 @@ void lang(BufferView * bv, string const & l) } -// Change environment depth. -// if decInc >= 0, increment depth -// if decInc < 0, decrement depth -void changeDepth(BufferView * bv, LyXText * text, int decInc) +void changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type) { if (!bv->available() || !text) return; bv->hideCursor(); bv->update(BufferView::SELECT); - if (decInc >= 0) - text->incDepth(); - else - text->decDepth(); + text->changeDepth(type); if (text->inset_owner) bv->updateInset((Inset *)text->inset_owner); bv->update(BufferView::SELECT); @@ -401,3 +398,5 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall) false, !cursor.boundary()); } } + +}; // namespace bv_funcs diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index e829c53dcd..b847825df3 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -20,6 +20,8 @@ class BufferView; class LyXFont; class LyXText; +namespace bv_funcs { + /** Set \param data using \param font and \param toggle. * If successful, returns true. */ @@ -40,6 +42,14 @@ void update_and_apply_freefont(BufferView * bv, string const & data); */ void apply_freefont(BufferView * bv); +/// what type of depth change to make +enum DEPTH_CHANGE { + INC_DEPTH, + DEC_DEPTH +}; + +/// change the nesting depth of the selection +extern void changeDepth(BufferView *, LyXText *, DEPTH_CHANGE); /// extern void emph(BufferView *); @@ -54,8 +64,6 @@ extern void number(BufferView *); /// extern void tex(BufferView *); /// -extern void changeDepth(BufferView *, LyXText *, int); -/// extern void code(BufferView *); /// extern void sans(BufferView *); @@ -72,4 +80,7 @@ extern string const currentState(BufferView *); /// extern void toggleAndShow(BufferView *, LyXFont const &, bool toggleall = true); + +}; // namespace bv_funcs + #endif diff --git a/src/frontends/controllers/ControlCharacter.C b/src/frontends/controllers/ControlCharacter.C index afafd939bb..54cdab5760 100644 --- a/src/frontends/controllers/ControlCharacter.C +++ b/src/frontends/controllers/ControlCharacter.C @@ -19,6 +19,7 @@ #include "gettext.h" #include "language.h" +using namespace bv_funcs; ControlCharacter::ControlCharacter(Dialog & parent) : Dialog::Controller(parent), diff --git a/src/frontends/controllers/ControlCommandBuffer.C b/src/frontends/controllers/ControlCommandBuffer.C index e87e1bd2b7..e3468234c0 100644 --- a/src/frontends/controllers/ControlCommandBuffer.C +++ b/src/frontends/controllers/ControlCommandBuffer.C @@ -25,6 +25,7 @@ using std::vector; using std::back_inserter; using std::transform; using std::endl; +using namespace bv_funcs; namespace { diff --git a/src/frontends/qt2/QtView.C b/src/frontends/qt2/QtView.C index d51e8e1b32..8be43d0d6c 100644 --- a/src/frontends/qt2/QtView.C +++ b/src/frontends/qt2/QtView.C @@ -41,6 +41,7 @@ #include using std::endl; +using namespace bv_funcs; namespace { diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 5aa7e7c40e..b2bc4533ef 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -85,6 +85,7 @@ using std::find_if; using std::vector; using std::transform; using std::back_inserter; +using namespace bv_funcs; extern BufferList bufferlist; extern LyXServer * lyxserver; @@ -1109,11 +1110,11 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) break; case LFUN_DEPTH_MIN: - changeDepth(view(), TEXT(false), -1); + changeDepth(view(), TEXT(false), bv_funcs::DEC_DEPTH); break; case LFUN_DEPTH_PLUS: - changeDepth(view(), TEXT(false), 1); + changeDepth(view(), TEXT(false), bv_funcs::INC_DEPTH); break; case LFUN_FREEFONT_APPLY: diff --git a/src/lyxtext.h b/src/lyxtext.h index b5764ad3f5..dbaa3e3c24 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -1,13 +1,15 @@ // -*- C++ -*- -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor +/** + * \file lyxtext.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team. + * \author unknown + * \author Lars Gullik Bjønnes + * \author John Levon * - * ====================================================== */ + * Full author contact details are available in file CREDITS + */ #ifndef LYXTEXT_H #define LYXTEXT_H @@ -18,6 +20,7 @@ #include "LColor.h" #include "insets/inset.h" #include "RowList.h" +#include "bufferview_funcs.h" class Buffer; class BufferParams; @@ -126,14 +129,8 @@ public: /// void setLayout(string const & layout); - /** increment depth over selection and make a total rebreak of those - paragraphs - */ - void incDepth(); - - /** decrement depth over selection and make a total rebreak of those - paragraphs */ - void decDepth(); + /// increase or decrease the nesting depth of the selected paragraph(s) + void changeDepth(bv_funcs::DEPTH_CHANGE type); /// get the depth at current cursor position int getDepth() const; diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index ceb99edfec..b9adef80c7 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -252,7 +252,7 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end) Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const { -#if 0 +#if 1 // This is in the critical path for loading! pos_type const siz = size(); diff --git a/src/text.C b/src/text.C index 2b2ea5a610..0572b7c71d 100644 --- a/src/text.C +++ b/src/text.C @@ -48,6 +48,7 @@ using std::min; using std::endl; using std::pair; using lyx::pos_type; +using namespace bv_funcs; /// top, right, bottom pixel margin extern int const PAPER_MARGIN = 20; diff --git a/src/text2.C b/src/text2.C index 4d6d10b4ff..0e599ce305 100644 --- a/src/text2.C +++ b/src/text2.C @@ -457,7 +457,7 @@ void LyXText::setLayout(string const & layout) } -void LyXText::incDepth() +void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type) { ParagraphList::iterator pit(cursor.par()); ParagraphList::iterator end(cursor.par()); @@ -480,10 +480,14 @@ void LyXText::incDepth() while (true) { int const depth = pit->params().depth(); - - if (depth < prev_after_depth - && pit->layout()->labeltype != LABEL_BIBLIO) { - pit->params().depth(depth + 1); + if (type == bv_funcs::INC_DEPTH) { + if (depth < prev_after_depth + && pit->layout()->labeltype != LABEL_BIBLIO) { + pit->params().depth(depth + 1); + } + } else { + if (depth) + pit->params().depth(depth - 1); } prev_after_depth = pit->getMaxDepthAfter(); @@ -517,61 +521,6 @@ void LyXText::incDepth() } -// decrement depth over selection and -// make a total rebreak of those paragraphs -void LyXText::decDepth() -{ - // if there is no selection just set the layout - // of the current paragraph - if (!selection.set()) { - selection.start = cursor; // dummy selection - selection.end = cursor; - } - Paragraph * endpar = selection.end.par()->next(); - Paragraph * undoendpar = endpar; - - if (endpar && endpar->getDepth()) { - while (endpar && endpar->getDepth()) { - endpar = endpar->next(); - undoendpar = endpar; - } - } else if (endpar) { - endpar = endpar->next(); // because of parindents etc. - } - - setUndo(bv(), Undo::EDIT, - selection.start.par(), undoendpar); - - LyXCursor tmpcursor = cursor; // store the current cursor - - // ok we have a selection. This is always between sel_start_cursor - // and sel_end cursor - cursor = selection.start; - - while (true) { - if (cursor.par()->params().depth()) { - cursor.par()->params() - .depth(cursor.par()->params().depth() - 1); - } - if (cursor.par() == selection.end.par()) { - break; - } - cursor.par(cursor.par()->next()); - } - - redoParagraphs(selection.start, endpar); - - // we have to reset the visual selection because the - // geometry could have changed - setCursor(selection.start.par(), selection.start.pos()); - selection.cursor = cursor; - setCursor(selection.end.par(), selection.end.pos()); - updateCounters(); - setSelection(); - setCursor(tmpcursor.par(), tmpcursor.pos()); -} - - // set font over selection and make a total rebreak of those paragraphs void LyXText::setFont(LyXFont const & font, bool toggleall) { -- 2.39.2