]> git.lyx.org Git - features.git/commitdiff
Improve Inset dissolve capability (bug 2201).
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 8 Sep 2006 14:08:26 +0000 (14:08 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 8 Sep 2006 14:08:26 +0000 (14:08 +0000)
* 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

src/insets/insettabular.C
src/insets/insettext.C
src/lyxtext.h
src/text.C
src/text3.C

index 35912ba4e3454a42b180f0a3bf01bb534cbcc20f..055ca76456e1df49b372495ed62f94ab696bc76c 100644 (file)
@@ -1045,28 +1045,6 @@ bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
                        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 ea646457d6722aa4fb5e3d0837e8f2cfb816218f..e3ef6234c2dd7dcda530426c559bb44c00c0df04 100644 (file)
@@ -22,7 +22,6 @@
 #include "dispatchresult.h"
 #include "errorlist.h"
 #include "funcrequest.h"
-#include "FuncStatus.h"
 #include "gettext.h"
 #include "intl.h"
 #include "LColor.h"
@@ -268,47 +267,14 @@ void InsetText::doDispatch(LCursor & cur, FuncRequest & cmd)
                             << " [ 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 4356776a5d6747e5dc7ed534b50e6d09070c7e7e..c4e345234f8d77aad73dec12c6ddc107d050e45d 100644 (file)
@@ -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 b212ecea602ac686ca2ffb36a72980591dd4040f..4cb9e50b6684532a477f18d040a07c8efaf79b04 100644 (file)
@@ -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 b678f35a6bf0ef2186972fc9325def265882fba3..b4ea505061ca45ac8999f55a2cc1a13420120227 100644 (file)
@@ -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, FuncRequest & cmd)
                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, FuncRequest const & cmd,
                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: