[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-devel
Subject: Re: feature request
From: Abdelrazak Younes <younes.a () free ! fr>
Date: 2006-04-09 21:55:36
Message-ID: e1bvsq$f3v$1 () sea ! gmane ! org
[Download RAW message or body]
Leuven, E. a écrit :
> > I had to do that in text.C. Cursor inherits DocIterator so
> > you can use that. "ParIterator it(cur)" should do the trick.
>
> that's what i did, see attached.
>
> it get's quite ugly though because selections can be set both forward
> and backward.
>
> it becomes especially nasty in the case when we are moving pars up
> because ParIterator is a forward iterator and i need the paragraph
> before the pars we are moving (am now moving the cursors temporarily
> backwards).
>
> suggestions on how to make it nicer are appreciated.
>
> thanks, edwin
>
> PS is there a way to undo the moving around?
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> Index: src/LyXAction.C
> ===================================================================
> --- src/LyXAction.C (revision 13601)
> +++ src/LyXAction.C (working copy)
> @@ -353,6 +353,8 @@
> { LFUN_MOUSE_RELEASE, "", ReadOnly },
> { LFUN_MOUSE_DOUBLE, "", ReadOnly },
> { LFUN_MOUSE_TRIPLE, "", ReadOnly },
> + { LFUN_PARAGRAPH_MOVE_DOWN, "paragraph-move-down", Noop },
> + { LFUN_PARAGRAPH_MOVE_UP, "paragraph-move-up", Noop },
> { LFUN_NOACTION, "", Noop }
> };
>
> Index: src/lyxfunc.C
> ===================================================================
> --- src/lyxfunc.C (revision 13601)
> +++ src/lyxfunc.C (working copy)
> @@ -558,6 +558,18 @@
> flag = getStatus(func);
> }
>
> + case LFUN_PARAGRAPH_MOVE_UP: {
> + if (cur)
What does (cur) mean? cur is not a pointer, is it?
> + enable = cur.pit()>0;
> + break;
> + }
> +
> + case LFUN_PARAGRAPH_MOVE_DOWN: {
> + if (cur)
> + enable = cur.pit()<cur.lastpit();
> + break;
> + }
> +
> case LFUN_MENUNEW:
> case LFUN_MENUNEWTMPLT:
> case LFUN_WORDFINDFORWARD:
> Index: src/text3.C
> ===================================================================
> --- src/text3.C (revision 13601)
> +++ src/text3.C (working copy)
> @@ -44,6 +44,7 @@
> #include "ParagraphParameters.h"
> #include "undo.h"
> #include "vspace.h"
> +#include "pariterator.h"
>
> #include "frontends/Dialogs.h"
> #include "frontends/LyXView.h"
> @@ -320,6 +321,92 @@
>
> switch (cmd.action) {
>
> + case LFUN_PARAGRAPH_MOVE_DOWN: {
> + // 1. FIXME: check wether we need to update counters
Is this comment still valid?
> + bool counterUpdate = false;
> + ParIterator pariter;
> + ParIterator pariter_end;
> + if (cur.anchor_.pit()<cur.pit()) {
> + pariter = ParIterator(cur.anchor_);
> + pariter_end = ParIterator(cur);
> + } else {
> + pariter = ParIterator(cur);
> + pariter_end = ParIterator(cur.anchor_);
> + }
> + // include par after range we are moving down
> + ++pariter_end;
> +
> + // one more to keep the unequal cond in the for loop
> + ++pariter_end;
> + for (; pariter!=pariter_end; ++pariter) {
> + if (needsUpdateCounters(cur.buffer(), pariter))
> + counterUpdate = true;
> + }
I would put these tests in step 4 as (as you know) they are not only tests.
> +
> + // 2. move par (range) down
> + pit_type begpit = cur.selBegin().pit()-1;
> + for (pit_type pit = cur.selEnd().pit(); pit!=begpit; --pit)
> + std::swap(pars_[pit], pars_[pit+1]);
Here we could use the splice method I proposed in RandomAccessList but
Lars rejected that. I suppose that the number of selected paragraphs to
move won't be too big so that's OK to swap consecutively the
paragraph... but it is suboptimal. I believe you could also use CutAndPaste.
> +
> + // 3. realign cursor (and selection)
> + if (cur.selection())
> + ++cur.anchor_.pit();
> + ++cur.pit();
> +
> + // 4. update counters
> + if (counterUpdate) {
> + lyxerr << "COUNTER UPDATE on DOWN!! " << endl;
> + updateCounters(cur.buffer());
> + }
> +
> + needsUpdate = true;
> + break;
> + }
I guess my comments above are the same for the other LFUN so I stop here.
Abdel.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic