The following pair of patch implement inset-dissolve in what I believe
to be a clean way. There is no code in insets directory (the disabling
for tabular insets is done by testing "inset.nargs() == 1" instead).

Please test.

JMarc

Index: src/insets/insettabular.C
===================================================================
--- src/insets/insettabular.C	(revision 14921)
+++ src/insets/insettabular.C	(working copy)
@@ -1045,28 +1045,6 @@ bool InsetTabular::getStatus(LCursor & c
 			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:
 		if (translate(cmd.getArg(0)) == TABULAR_CODE) {
 			status.enabled(true);
Index: src/insets/insettext.C
===================================================================
--- src/insets/insettext.C	(revision 14921)
+++ src/insets/insettext.C	(working copy)
@@ -268,47 +268,14 @@ void InsetText::doDispatch(LCursor & cur
 			     << " [ cmd.action = "
 			     << cmd.action << ']' << endl;
 	setViewCache(&cur.bv());
-
-	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;
-	}
+	text_.dispatch(cur, cmd);
 }
 
 
 bool InsetText::getStatus(LCursor & cur, FuncRequest const & cmd,
 	FuncStatus & status) const
 {
-	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);
-	}
+	return text_.getStatus(cur, cmd, status);
 }
 
 
Index: src/lyxtext.h
===================================================================
--- src/lyxtext.h	(revision 14921)
+++ src/lyxtext.h	(working copy)
@@ -232,6 +232,8 @@ public:
 	bool backspacePos0(LCursor & cur);
 	/// Delete character before cursor. Honour CT
 	bool backspace(LCursor & cur);
+	// Dissolve the inset under cursor
+	bool dissolveInset(LCursor & cur);
 	///
 	bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
 	///
Index: src/text3.C
===================================================================
--- src/text3.C	(revision 14921)
+++ src/text3.C	(working copy)
@@ -79,7 +79,6 @@ using lyx::pos_type;
 
 using lyx::cap::copySelection;
 using lyx::cap::cutSelection;
-using lyx::cap::pasteParagraphList;
 using lyx::cap::pasteSelection;
 using lyx::cap::replaceSelection;
 
@@ -709,34 +708,9 @@ void LyXText::dispatch(LCursor & cur, Fu
 		break;
 	}
 
-	case LFUN_INSET_DISSOLVE: {
-		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 = 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;
+	case LFUN_INSET_DISSOLVE:
+		needsUpdate = dissolveInset(cur);
 		break;
-	}
 
 	case LFUN_INSET_SETTINGS:
 		cur.inset().showInsetDialog(bv);
@@ -1720,20 +1694,17 @@ bool LyXText::getStatus(LCursor & cur, F
 		enable = lyx::cap::numberOfSelections() > 0;
 		break;
 
-	case LFUN_PARAGRAPH_MOVE_UP: {
+	case LFUN_PARAGRAPH_MOVE_UP:
 		enable = cur.pit() > 0 && !cur.selection();
 		break;
-	}
 
-	case LFUN_PARAGRAPH_MOVE_DOWN: {
+	case LFUN_PARAGRAPH_MOVE_DOWN:
 		enable = cur.pit() < cur.lastpit() && !cur.selection();
 		break;
-	}
 
-	case LFUN_INSET_DISSOLVE: {
-		enable = !isMainText() && cur.inTexted();
+	case LFUN_INSET_DISSOLVE:
+		enable = !isMainText() && cur.inset().nargs() == 1;
 		break;
-	}
 
 	case LFUN_WORD_DELETE_FORWARD:
 	case LFUN_WORD_DELETE_BACKWARD:
Index: src/text.C
===================================================================
--- src/text.C	(revision 14921)
+++ src/text.C	(working copy)
@@ -88,6 +88,7 @@ using lyx::support::split;
 using lyx::support::uppercase;
 
 using lyx::cap::cutSelection;
+using lyx::cap::pasteParagraphList;
 
 using std::auto_ptr;
 using std::advance;
@@ -1671,7 +1672,9 @@ bool LyXText::erase(LCursor & cur)
 		} else {
 			setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary());
 		}
-	}
+	} else
+		needsUpdate = dissolveInset(cur);
+	
 	return needsUpdate;
 }
 
@@ -1757,6 +1760,9 @@ bool LyXText::backspace(LCursor & cur)
 	BOOST_ASSERT(this == cur.text());
 	bool needsUpdate = false;
 	if (cur.pos() == 0) {
+		if (cur.pit() == 0)
+			return dissolveInset(cur);
+
 		// The cursor is at the beginning of a paragraph, so
 		// the the backspace will collapse two paragraphs into
 		// 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
 {
 	return *paragraphs().front().rows().begin();
Index: src/LyXAction.C
===================================================================
--- src/LyXAction.C	(revision 14921)
+++ src/LyXAction.C	(working copy)
@@ -323,6 +323,7 @@ void LyXAction::init()
 		{ LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset", Noop },
 		{ LFUN_INSET_APPLY, "inset-apply", Noop },
 		{ LFUN_INSET_INSERT, "inset-insert", Noop },
+		{ LFUN_INSET_DISSOLVE, "inset-dissolve", Noop },
 		{ LFUN_INSET_MODIFY, "", Noop },
 		{ LFUN_INSET_DIALOG_UPDATE, "", Noop },
 		{ LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
Index: src/lyxtext.h
===================================================================
--- src/lyxtext.h	(revision 14921)
+++ src/lyxtext.h	(working copy)
@@ -229,6 +229,8 @@ public:
 	bool backspacePos0(LCursor & cur);
 	/// Delete character before cursor. Honour CT
 	bool backspace(LCursor & cur);
+	// Dissolve the inset under cursor
+	bool dissolveInset(LCursor & cur);
 	///
 	bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
 	///
Index: src/text3.C
===================================================================
--- src/text3.C	(revision 14921)
+++ src/text3.C	(working copy)
@@ -670,6 +670,10 @@ void LyXText::dispatch(LCursor & cur, Fu
 		break;
 	}
 
+	case LFUN_INSET_DISSOLVE:
+		needsUpdate = dissolveInset(cur);
+		break;
+
 	case LFUN_INSET_SETTINGS:
 		cur.inset().showInsetDialog(bv);
 		break;
@@ -1659,6 +1663,10 @@ bool LyXText::getStatus(LCursor & cur, F
 		enable = lyx::cap::numberOfSelections() > 0;
 		break;
 
+	case LFUN_INSET_DISSOLVE:
+		enable = !isMainText() && cur.inset().nargs() == 1;
+		break;
+
 	case LFUN_DELETE_WORD_FORWARD:
 	case LFUN_DELETE_WORD_BACKWARD:
 	case LFUN_DELETE_LINE_FORWARD:
Index: src/lfuns.h
===================================================================
--- src/lfuns.h	(revision 14921)
+++ src/lfuns.h	(working copy)
@@ -358,6 +358,8 @@ enum kb_action {
 	LFUN_BIBDB_DEL,
 	LFUN_INSERT_CITATION,
 	LFUN_TOGGLE_COMPRESSION,         // bpeng 20060427
+	// 275
+	LFUN_INSET_DISSOLVE,                 // jspitzm 20060807
 
 	LFUN_LASTACTION                  // end of the table
 };
Index: src/text.C
===================================================================
--- src/text.C	(revision 14921)
+++ src/text.C	(working copy)
@@ -85,6 +85,7 @@ using lyx::support::split;
 using lyx::support::uppercase;
 
 using lyx::cap::cutSelection;
+using lyx::cap::pasteParagraphList;
 
 using std::auto_ptr;
 using std::advance;
@@ -1611,7 +1612,9 @@ bool LyXText::Delete(LCursor & cur)
 		} else {
 			setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary());
 		}
-	}
+	} else
+		needsUpdate = dissolveInset(cur);
+	
 	return needsUpdate;
 }
 
@@ -1695,6 +1698,9 @@ bool LyXText::backspace(LCursor & cur)
 	BOOST_ASSERT(this == cur.text());
 	bool needsUpdate = false;
 	if (cur.pos() == 0) {
+		if (cur.pit() == 0)
+			return dissolveInset(cur);
+
 		// The cursor is at the beginning of a paragraph, so
 		// the the backspace will collapse two paragraphs into
 		// one.
@@ -1735,6 +1741,39 @@ 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);
+		// 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
 {
 	return *paragraphs().front().rows().begin();

Reply via email to