[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-devel
Subject: RE: Re: feature request
From: "Leuven, E." <E.Leuven () uva ! nl>
Date: 2006-04-09 19:14:45
Message-ID: D1B515FFD30A1B4289F6E13EA363CAFDA17D98 () struik ! uva ! nl
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
> 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?
[Attachment #5 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>RE: Re: feature request</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>> I had to do that in text.C. Cursor inherits DocIterator so<BR>
> you can use that. "ParIterator it(cur)" should do the trick.<BR>
<BR>
that's what i did, see attached.<BR>
<BR>
it get's quite ugly though because selections can be set both forward and \
backward.<BR> <BR>
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).<BR> <BR>
suggestions on how to make it nicer are appreciated.<BR>
<BR>
thanks, edwin<BR>
<BR>
PS is there a way to undo the moving around?<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>
["par6.diff" (text/x-diff)]
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)
+ 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
+ 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;
+ }
+
+ // 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]);
+
+ // 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;
+ }
+ case LFUN_PARAGRAPH_MOVE_UP: {
+ // 1. FIXME: check wether we need to update counters
+ bool counterUpdate = false;
+ ParIterator pariter;
+ ParIterator pariter_end;
+ if (cur.anchor_.pit()<cur.pit()) {
+ // include par before the range we are moving
+ --cur.anchor_.pit();
+ pariter = ParIterator(cur.anchor_);
+ ++cur.anchor_.pit();
+ pariter_end = ParIterator(cur);
+ } else {
+ // include par before the range we are moving
+ --cur.pit();
+ pariter = ParIterator(cur);
+ ++cur.pit();
+ pariter_end = ParIterator(cur.anchor_);
+ }
+
+ // 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;
+ }
+
+ // 2. move par (range) up
+ pit_type endpit = cur.selEnd().pit()+1;
+ for (pit_type pit = cur.selBegin().pit(); pit!=endpit; ++pit)
+ std::swap(pars_[pit], pars_[pit-1]);
+
+ // 3. realign cursor (and selection)
+ if (cur.selection())
+ --cur.anchor_.pit();
+ --cur.pit();
+
+ // 4. update counters
+ if (counterUpdate) {
+ lyxerr << "COUNTER UPDATE on UP!! " << endl;
+ updateCounters(cur.buffer());
+ }
+
+ needsUpdate = true;
+ break;
+ }
case LFUN_APPENDIX: {
Paragraph & par = cur.paragraph();
bool start = !par.params().startOfAppendix();
Index: src/lfuns.h
===================================================================
--- src/lfuns.h (revision 13601)
+++ src/lfuns.h (working copy)
@@ -358,6 +358,9 @@
LFUN_BIBDB_DEL,
LFUN_INSERT_CITATION,
LFUN_OUTLINE, // Vermeer 20060323
+ // 275
+ LFUN_PARAGRAPH_MOVE_DOWN, // Edwin 20060408
+ LFUN_PARAGRAPH_MOVE_UP, // Edwin 20060408
LFUN_LASTACTION // end of the table
};
Index: lib/bind/cua.bind
===================================================================
--- lib/bind/cua.bind (revision 13601)
+++ lib/bind/cua.bind (working copy)
@@ -102,6 +102,8 @@
# Motion group
#
+\bind "M-Up" "paragraph-move-up"
+\bind "M-Down" "paragraph-move-down"
\bind "C-Right" "word-forward"
\bind "C-Left" "word-backward"
\bind "C-Up" "paragraph-up"
Index: lib/bind/emacs.bind
===================================================================
--- lib/bind/emacs.bind (revision 13601)
+++ lib/bind/emacs.bind (working copy)
@@ -139,6 +139,8 @@
# Motion group
#
+\bind "M-Up" "paragraph-move-up"
+\bind "M-Down" "paragraph-move-down"
\bind "C-Right" "word-forward"
\bind "C-Left" "word-backward"
\bind "C-Up" "paragraph-up"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic