Improve Inset dissolve capability (bug 2201).

* src/insets/insettabular.C (getStatus):
	* src/insets/insettext.C (doDispatch,getStatus): remove special code
	for LFUN_INSET_DISSOLVE.

	* src/text.C (dissolveInset): new method.
	(erase, backspace): use dissolveInset. 

	* src/text3.C (dispatch): use dissolveInset for LFUN_INSET_DISSOLVE.
	(getStatus): disable LFUN_INSET_DISSOLVE if the inset has more than one 	cell.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14940 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2006-09-08 14:08:26 +00:00
parent 45808381d0
commit fe8d08d72f
5 changed files with 51 additions and 94 deletions

View File

@ -1045,28 +1045,6 @@ bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
return true; return true;
} }
case LFUN_INSET_DISSOLVE: {
status.enabled(false);
return true;
}
// because of the dissolve handling in insettext:
case LFUN_CHAR_DELETE_FORWARD:
if (!cur.selection() && cur.depth() > 1
&& cur.pit() == cur.lastpit()
&& cur.pos() == cur.lastpos()) {
status.enabled(false);
return true;
}
// Fall through
case LFUN_CHAR_DELETE_BACKWARD:
if (cur.depth() > 1 && cur.pit() == 0 && cur.pos() == 0) {
status.enabled(false);
return true;
}
// Fall through
case LFUN_INSET_MODIFY: case LFUN_INSET_MODIFY:
if (translate(cmd.getArg(0)) == TABULAR_CODE) { if (translate(cmd.getArg(0)) == TABULAR_CODE) {
status.enabled(true); status.enabled(true);

View File

@ -22,7 +22,6 @@
#include "dispatchresult.h" #include "dispatchresult.h"
#include "errorlist.h" #include "errorlist.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h" #include "gettext.h"
#include "intl.h" #include "intl.h"
#include "LColor.h" #include "LColor.h"
@ -268,47 +267,14 @@ void InsetText::doDispatch(LCursor & cur, FuncRequest & cmd)
<< " [ cmd.action = " << " [ cmd.action = "
<< cmd.action << ']' << endl; << cmd.action << ']' << endl;
setViewCache(&cur.bv()); setViewCache(&cur.bv());
text_.dispatch(cur, cmd);
switch (cmd.action) {
case LFUN_CHAR_DELETE_FORWARD: {
if (!cur.selection() && cur.depth() > 1
&& cur.pit() == cur.lastpit()
&& cur.pos() == cur.lastpos())
// Merge inset with owner
cmd = FuncRequest(LFUN_INSET_DISSOLVE);
text_.dispatch(cur, cmd);
break;
}
case LFUN_CHAR_DELETE_BACKWARD: {
if (cur.depth() > 1 && cur.pit() == 0 && cur.pos() == 0)
// Merge inset with owner
cmd = FuncRequest(LFUN_INSET_DISSOLVE);
text_.dispatch(cur, cmd);
break;
}
default:
text_.dispatch(cur, cmd);
break;
}
} }
bool InsetText::getStatus(LCursor & cur, FuncRequest const & cmd, bool InsetText::getStatus(LCursor & cur, FuncRequest const & cmd,
FuncStatus & status) const FuncStatus & status) const
{ {
switch (cmd.action) { return text_.getStatus(cur, cmd, status);
case LFUN_CHAR_DELETE_FORWARD:
case LFUN_CHAR_DELETE_BACKWARD:
status.enabled(true);
return true;
default:
return text_.getStatus(cur, cmd, status);
}
} }

View File

@ -232,6 +232,8 @@ public:
bool backspacePos0(LCursor & cur); bool backspacePos0(LCursor & cur);
/// Delete character before cursor. Honour CT /// Delete character before cursor. Honour CT
bool backspace(LCursor & cur); bool backspace(LCursor & cur);
// Dissolve the inset under cursor
bool dissolveInset(LCursor & cur);
/// ///
bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location); bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
/// ///

View File

@ -88,6 +88,7 @@ using lyx::support::split;
using lyx::support::uppercase; using lyx::support::uppercase;
using lyx::cap::cutSelection; using lyx::cap::cutSelection;
using lyx::cap::pasteParagraphList;
using std::auto_ptr; using std::auto_ptr;
using std::advance; using std::advance;
@ -1671,7 +1672,9 @@ bool LyXText::erase(LCursor & cur)
} else { } else {
setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary()); setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary());
} }
} } else
needsUpdate = dissolveInset(cur);
return needsUpdate; return needsUpdate;
} }
@ -1757,6 +1760,9 @@ bool LyXText::backspace(LCursor & cur)
BOOST_ASSERT(this == cur.text()); BOOST_ASSERT(this == cur.text());
bool needsUpdate = false; bool needsUpdate = false;
if (cur.pos() == 0) { if (cur.pos() == 0) {
if (cur.pit() == 0)
return dissolveInset(cur);
// The cursor is at the beginning of a paragraph, so // The cursor is at the beginning of a paragraph, so
// the the backspace will collapse two paragraphs into // the the backspace will collapse two paragraphs into
// one. // one.
@ -1797,6 +1803,40 @@ bool LyXText::backspace(LCursor & cur)
} }
bool LyXText::dissolveInset(LCursor & cur) {
BOOST_ASSERT(this == cur.text());
if (isMainText() || cur.inset().nargs() != 1)
return false;
recordUndoInset(cur);
cur.selHandle(false);
// save position
lyx::pos_type spos = cur.pos();
lyx::pit_type spit = cur.pit();
ParagraphList plist;
if (cur.lastpit() != 0 || cur.lastpos() != 0)
plist = paragraphs();
cur.popLeft();
// store cursor offset
if (spit == 0)
spos += cur.pos();
spit += cur.pit();
cur.paragraph().erase(cur.pos());
if (!plist.empty()) {
Buffer & b = cur.buffer();
pasteParagraphList(cur, plist, b.params().textclass,
b.errorList("Paste"));
// restore position
cur.pit() = std::min(cur.lastpit(), spit);
cur.pos() = std::min(cur.lastpos(), spos);
}
cur.clearSelection();
cur.resetAnchor();
return true;
}
Row const & LyXText::firstRow() const Row const & LyXText::firstRow() const
{ {
return *paragraphs().front().rows().begin(); return *paragraphs().front().rows().begin();

View File

@ -79,7 +79,6 @@ using lyx::pos_type;
using lyx::cap::copySelection; using lyx::cap::copySelection;
using lyx::cap::cutSelection; using lyx::cap::cutSelection;
using lyx::cap::pasteParagraphList;
using lyx::cap::pasteSelection; using lyx::cap::pasteSelection;
using lyx::cap::replaceSelection; using lyx::cap::replaceSelection;
@ -709,34 +708,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
break; break;
} }
case LFUN_INSET_DISSOLVE: { case LFUN_INSET_DISSOLVE:
recordUndoInset(cur); needsUpdate = dissolveInset(cur);
cur.selHandle(false);
// save position
lyx::pos_type spos = cur.pos();
lyx::pit_type spit = cur.pit();
ParagraphList plist;
if (cur.lastpit() != 0 || cur.lastpos() != 0)
plist = paragraphs();
cur.popLeft();
// store cursor offset
if (spit == 0)
spos += cur.pos();
spit += cur.pit();
cur.paragraph().erase(cur.pos());
if (!plist.empty()) {
Buffer * b = bv->buffer();
pasteParagraphList(cur, plist, b->params().textclass,
b->errorList("Paste"));
// restore position
cur.pit() = std::min(cur.lastpit(), spit);
cur.pos() = std::min(cur.lastpos(), spos);
}
cur.clearSelection();
cur.resetAnchor();
needsUpdate = true;
break; break;
}
case LFUN_INSET_SETTINGS: case LFUN_INSET_SETTINGS:
cur.inset().showInsetDialog(bv); cur.inset().showInsetDialog(bv);
@ -1720,20 +1694,17 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
enable = lyx::cap::numberOfSelections() > 0; enable = lyx::cap::numberOfSelections() > 0;
break; break;
case LFUN_PARAGRAPH_MOVE_UP: { case LFUN_PARAGRAPH_MOVE_UP:
enable = cur.pit() > 0 && !cur.selection(); enable = cur.pit() > 0 && !cur.selection();
break; break;
}
case LFUN_PARAGRAPH_MOVE_DOWN: { case LFUN_PARAGRAPH_MOVE_DOWN:
enable = cur.pit() < cur.lastpit() && !cur.selection(); enable = cur.pit() < cur.lastpit() && !cur.selection();
break; break;
}
case LFUN_INSET_DISSOLVE: { case LFUN_INSET_DISSOLVE:
enable = !isMainText() && cur.inTexted(); enable = !isMainText() && cur.inset().nargs() == 1;
break; break;
}
case LFUN_WORD_DELETE_FORWARD: case LFUN_WORD_DELETE_FORWARD:
case LFUN_WORD_DELETE_BACKWARD: case LFUN_WORD_DELETE_BACKWARD: