merge decDepth(), killing some non-parlist code

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6695 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-04-03 00:36:31 +00:00
parent c543071cb3
commit d533ee3995
12 changed files with 58 additions and 88 deletions

View File

@ -72,6 +72,7 @@ using std::make_pair;
using std::min; using std::min;
using lyx::pos_type; using lyx::pos_type;
using namespace bv_funcs;
extern BufferList bufferlist; extern BufferList bufferlist;

View File

@ -1,3 +1,11 @@
2003-04-03 John Levon <levon@movementarian.org>
* 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 <larsbj@gullik.net> 2003-04-03 Lars Gullik Bjønnes <larsbj@gullik.net>
* lyxrow.h: store a ParagraphList::iterator instead of a * lyxrow.h: store a ParagraphList::iterator instead of a

View File

@ -38,10 +38,13 @@
#include "support/BoostFormat.h" #include "support/BoostFormat.h"
namespace { namespace {
LyXFont freefont(LyXFont::ALL_IGNORE); LyXFont freefont(LyXFont::ALL_IGNORE);
bool toggleall(false); bool toggleall(false);
} }
namespace bv_funcs {
// Set data using font and toggle // Set data using font and toggle
// If successful, returns true // If successful, returns true
@ -214,20 +217,14 @@ void lang(BufferView * bv, string const & l)
} }
// Change environment depth. void changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type)
// if decInc >= 0, increment depth
// if decInc < 0, decrement depth
void changeDepth(BufferView * bv, LyXText * text, int decInc)
{ {
if (!bv->available() || !text) if (!bv->available() || !text)
return; return;
bv->hideCursor(); bv->hideCursor();
bv->update(BufferView::SELECT); bv->update(BufferView::SELECT);
if (decInc >= 0) text->changeDepth(type);
text->incDepth();
else
text->decDepth();
if (text->inset_owner) if (text->inset_owner)
bv->updateInset((Inset *)text->inset_owner); bv->updateInset((Inset *)text->inset_owner);
bv->update(BufferView::SELECT); bv->update(BufferView::SELECT);
@ -401,3 +398,5 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
false, !cursor.boundary()); false, !cursor.boundary());
} }
} }
}; // namespace bv_funcs

View File

@ -20,6 +20,8 @@ class BufferView;
class LyXFont; class LyXFont;
class LyXText; class LyXText;
namespace bv_funcs {
/** Set \param data using \param font and \param toggle. /** Set \param data using \param font and \param toggle.
* If successful, returns true. * If successful, returns true.
*/ */
@ -40,6 +42,14 @@ void update_and_apply_freefont(BufferView * bv, string const & data);
*/ */
void apply_freefont(BufferView * bv); 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 *); extern void emph(BufferView *);
@ -54,8 +64,6 @@ extern void number(BufferView *);
/// ///
extern void tex(BufferView *); extern void tex(BufferView *);
/// ///
extern void changeDepth(BufferView *, LyXText *, int);
///
extern void code(BufferView *); extern void code(BufferView *);
/// ///
extern void sans(BufferView *); extern void sans(BufferView *);
@ -72,4 +80,7 @@ extern string const currentState(BufferView *);
/// ///
extern void toggleAndShow(BufferView *, LyXFont const &, extern void toggleAndShow(BufferView *, LyXFont const &,
bool toggleall = true); bool toggleall = true);
}; // namespace bv_funcs
#endif #endif

View File

@ -19,6 +19,7 @@
#include "gettext.h" #include "gettext.h"
#include "language.h" #include "language.h"
using namespace bv_funcs;
ControlCharacter::ControlCharacter(Dialog & parent) ControlCharacter::ControlCharacter(Dialog & parent)
: Dialog::Controller(parent), : Dialog::Controller(parent),

View File

@ -25,6 +25,7 @@ using std::vector;
using std::back_inserter; using std::back_inserter;
using std::transform; using std::transform;
using std::endl; using std::endl;
using namespace bv_funcs;
namespace { namespace {

View File

@ -41,6 +41,7 @@
#include <qstatusbar.h> #include <qstatusbar.h>
using std::endl; using std::endl;
using namespace bv_funcs;
namespace { namespace {

View File

@ -85,6 +85,7 @@ using std::find_if;
using std::vector; using std::vector;
using std::transform; using std::transform;
using std::back_inserter; using std::back_inserter;
using namespace bv_funcs;
extern BufferList bufferlist; extern BufferList bufferlist;
extern LyXServer * lyxserver; extern LyXServer * lyxserver;
@ -1109,11 +1110,11 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
break; break;
case LFUN_DEPTH_MIN: case LFUN_DEPTH_MIN:
changeDepth(view(), TEXT(false), -1); changeDepth(view(), TEXT(false), bv_funcs::DEC_DEPTH);
break; break;
case LFUN_DEPTH_PLUS: case LFUN_DEPTH_PLUS:
changeDepth(view(), TEXT(false), 1); changeDepth(view(), TEXT(false), bv_funcs::INC_DEPTH);
break; break;
case LFUN_FREEFONT_APPLY: case LFUN_FREEFONT_APPLY:

View File

@ -1,13 +1,15 @@
// -*- C++ -*- // -*- C++ -*-
/* This file is part of /**
* ====================================================== * \file lyxtext.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
* *
* LyX, The Document Processor * \author unknown
* \author Lars Gullik Bjønnes
* \author John Levon
* *
* Copyright 1995 Matthias Ettrich * Full author contact details are available in file CREDITS
* Copyright 1995-2001 The LyX Team. */
*
* ====================================================== */
#ifndef LYXTEXT_H #ifndef LYXTEXT_H
#define LYXTEXT_H #define LYXTEXT_H
@ -18,6 +20,7 @@
#include "LColor.h" #include "LColor.h"
#include "insets/inset.h" #include "insets/inset.h"
#include "RowList.h" #include "RowList.h"
#include "bufferview_funcs.h"
class Buffer; class Buffer;
class BufferParams; class BufferParams;
@ -126,14 +129,8 @@ public:
/// ///
void setLayout(string const & layout); void setLayout(string const & layout);
/** increment depth over selection and make a total rebreak of those /// increase or decrease the nesting depth of the selected paragraph(s)
paragraphs void changeDepth(bv_funcs::DEPTH_CHANGE type);
*/
void incDepth();
/** decrement depth over selection and make a total rebreak of those
paragraphs */
void decDepth();
/// get the depth at current cursor position /// get the depth at current cursor position
int getDepth() const; int getDepth() const;

View File

@ -252,7 +252,7 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
{ {
#if 0 #if 1
// This is in the critical path for loading! // This is in the critical path for loading!
pos_type const siz = size(); pos_type const siz = size();

View File

@ -48,6 +48,7 @@ using std::min;
using std::endl; using std::endl;
using std::pair; using std::pair;
using lyx::pos_type; using lyx::pos_type;
using namespace bv_funcs;
/// top, right, bottom pixel margin /// top, right, bottom pixel margin
extern int const PAPER_MARGIN = 20; extern int const PAPER_MARGIN = 20;

View File

@ -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 pit(cursor.par());
ParagraphList::iterator end(cursor.par()); ParagraphList::iterator end(cursor.par());
@ -480,10 +480,14 @@ void LyXText::incDepth()
while (true) { while (true) {
int const depth = pit->params().depth(); int const depth = pit->params().depth();
if (type == bv_funcs::INC_DEPTH) {
if (depth < prev_after_depth if (depth < prev_after_depth
&& pit->layout()->labeltype != LABEL_BIBLIO) { && pit->layout()->labeltype != LABEL_BIBLIO) {
pit->params().depth(depth + 1); pit->params().depth(depth + 1);
}
} else {
if (depth)
pit->params().depth(depth - 1);
} }
prev_after_depth = pit->getMaxDepthAfter(); 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 // set font over selection and make a total rebreak of those paragraphs
void LyXText::setFont(LyXFont const & font, bool toggleall) void LyXText::setFont(LyXFont const & font, bool toggleall)
{ {