Implement LFUN_INSET_DISSOLVE (bug 2201):

* src/LyXAction.C:
        * src/lfuns.h:
		- add new lfun LFUN_INSET_DISSOLVE.

        * src/insets/insettext.C
        (void InsetText::doDispatch):
		- dissolve inset when hitting backspace in the 
		  very first or delete in the very last position
		  of an inset.

        * src/text3.C
        (void LyXText::dispatch):
        (bool LyXText::getStatus):
		- implement new lfun LFUN_INSET_DISSOLVE.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14572 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2006-08-08 13:34:02 +00:00
parent a9f2042082
commit 0ce73aa2c4
4 changed files with 83 additions and 3 deletions

View File

@ -328,6 +328,7 @@ void LyXAction::init()
{ LFUN_DIALOG_HIDE, "dialog-hide", Noop },
{ LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset", Noop },
{ LFUN_INSET_APPLY, "inset-apply", Noop },
{ LFUN_INSET_DISSOLVE, "inset-dissolve", Noop },
{ LFUN_INSET_INSERT, "inset-insert", Noop },
{ LFUN_INSET_MODIFY, "", Noop },
{ LFUN_INSET_DIALOG_UPDATE, "", Noop },

View File

@ -22,6 +22,7 @@
#include "dispatchresult.h"
#include "errorlist.h"
#include "funcrequest.h"
#include "FuncStatus.h"
#include "gettext.h"
#include "intl.h"
#include "LColor.h"
@ -263,16 +264,50 @@ void InsetText::forceParagraphsToDefault(LCursor & cur)
void InsetText::doDispatch(LCursor & cur, FuncRequest & cmd)
{
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
<< " [ cmd.action = " << cmd.action << ']' << endl;
<< " [ cmd.action = "
<< cmd.action << ']' << endl;
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,
FuncStatus & status) const
{
return text_.getStatus(cur, cmd, status);
switch (cmd.action) {
case LFUN_CHAR_DELETE_FORWARD:
case LFUN_CHAR_DELETE_BACKWARD:
status.enabled(true);
return true;
default:
return text_.getStatus(cur, cmd, status);
}
}

View File

@ -367,6 +367,7 @@ enum kb_action {
// 280
LFUN_MATH_BIGDELIM,
LFUN_CLIPBOARD_PASTE,
LFUN_INSET_DISSOLVE, // jspitzm 20060807
LFUN_LASTACTION // end of the table
};

View File

@ -705,6 +705,44 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
break;
}
case LFUN_INSET_DISSOLVE: {
recordUndo(cur);
cur.selHandle(false);
// save position
lyx::pos_type spos = cur.pos();
lyx::pit_type spit = cur.pit();
bool content = false;
if (cur.lastpit() != 0 || cur.lastpos() != 0) {
setCursor(cur, 0, 0);
cur.resetAnchor();
cur.pit() = cur.lastpit();
cur.pos() = cur.lastpos();
cur.setSelection();
copySelection(cur);
content = true;
}
cur.popLeft();
cur.resetAnchor();
// store cursor offset
if (spit == 0)
spos += cur.pos();
spit += cur.pit();
cur.pos()++;
cur.setSelection();
if (content) {
lyx::cap::replaceSelection(cur);
pasteSelection(cur, 0);
cur.clearSelection();
// restore position
cur.pit() = std::min(cur.lastpit(), spit);
cur.pos() = std::min(cur.lastpos(), spos);
cur.resetAnchor();
} else
cutSelection(cur, false, false);
needsUpdate = true;
break;
}
case LFUN_INSET_SETTINGS:
cur.inset().showInsetDialog(bv);
break;
@ -1711,6 +1749,11 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
break;
}
case LFUN_INSET_DISSOLVE: {
enable = &cur.inset() && cur.inTexted();
break;
}
case LFUN_WORD_DELETE_FORWARD:
case LFUN_WORD_DELETE_BACKWARD:
case LFUN_LINE_DELETE: