]> git.lyx.org Git - features.git/commitdiff
Move (part of) LFUN_DISSOLVE_INSET into InsetText.
authorVincent van Ravesteijn <vfr@lyx.org>
Mon, 26 Oct 2009 23:49:43 +0000 (23:49 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Mon, 26 Oct 2009 23:49:43 +0000 (23:49 +0000)
- put the InsetFlex specific part into InsetFlex,
- honor the argument given to the LFUN also for normal Insets as the description already stated,
- fix bug #6285: context menu action goes to the wrong inset.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31756 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXAction.cpp
src/Text3.cpp
src/insets/InsetFlex.cpp
src/insets/InsetFlex.h
src/insets/InsetText.cpp

index 93db78d00a3ca364b4aa4b29cf04a5ad038a0860..de1cb4c320fd5b15d485b2caf6510bb8dac0f78e 100644 (file)
@@ -2282,7 +2282,7 @@ void LyXAction::init()
  * \li Origin: JSpitz, 7 Aug 2006
  * \endvar
  */
-               { LFUN_INSET_DISSOLVE, "inset-dissolve", Noop, Edit },
+               { LFUN_INSET_DISSOLVE, "inset-dissolve", AtPoint, Edit },
 /*!
  * \var lyx::FuncCode lyx::LFUN_INSET_INSERT
  * \li Action: Insert new inset (type given by the parameters).
index b7605efc1a164ec245bec592c28c052233c1e1de..281ef7005818b1544984007bcc0ecc77ae77f51e 100644 (file)
@@ -1094,26 +1094,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_INSET_DISSOLVE: {
-               // first, try if there's an inset at cursor
-               // FIXME: this first part should be moved to
-               // a LFUN_NEXT_INSET_DISSOLVE, or be called via
-               // some generic "next-inset inset-dissolve"
-               Inset * inset = cur.nextInset();
-               if (inset && inset->isActive()) {
-                       Cursor tmpcur = cur;
-                       tmpcur.pushBackward(*inset);
-                       inset->dispatch(tmpcur, cmd);
-                       if (tmpcur.result().dispatched()) {
-                               cur.dispatched();
-                               break;
-                       }
-               }
-               // if it did not work, try the underlying inset
-               if (dissolveInset(cur)) {
+               if (dissolveInset(cur))
                        needsUpdate = true;
-                       break;
-               }
-               // if it did not work, do nothing.
                break;
        }
 
@@ -2522,21 +2504,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                enable = cur.pit() < cur.lastpit() && !cur.selection();
                break;
 
-       case LFUN_INSET_DISSOLVE:
-               if (!cmd.argument().empty()) {
-                       InsetLayout const & il = cur.inset().getLayout();
-                       InsetLayout::InsetLyXType const type = 
-                                       translateLyXType(to_utf8(cmd.argument()));
-                       enable = cur.inset().lyxCode() == FLEX_CODE
-                                && il.lyxtype() == type;
-               } else {
-                       enable = ((!isMainText()
-                                     && cur.inset().nargs() == 1)
-                                 || (cur.nextInset()
-                                     && cur.nextInset()->nargs() == 1));
-               }
-               break;
-
        case LFUN_CHANGE_ACCEPT:
        case LFUN_CHANGE_REJECT:
                // In principle, these LFUNs should only be enabled if there
index 76b338004d3e7115b8e433de1e7f41ec07389286..378705eb684fd2c60fe4c98efcf1059357658aaf 100644 (file)
@@ -16,6 +16,9 @@
 
 #include "Buffer.h"
 #include "BufferParams.h"
+#include "Cursor.h"
+#include "FuncRequest.h"
+#include "FuncStatus.h"
 #include "Lexer.h"
 
 #include "support/gettext.h"
@@ -54,4 +57,50 @@ void InsetFlex::write(ostream & os) const
 }
 
 
+bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+       case LFUN_INSET_DISSOLVE:
+               if (!cmd.argument().empty()) {
+                       InsetLayout const & il = getLayout();
+                       InsetLayout::InsetLyXType const type = 
+                               translateLyXType(to_utf8(cmd.argument()));
+                       if (il.lyxtype() == type) {
+                               FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
+                               return InsetCollapsable::getStatus(cur, temp_cmd, flag);
+                       } else
+                               return false;
+               }
+               // fall-through
+       default:
+               return InsetCollapsable::getStatus(cur, cmd, flag);
+       }
+}
+
+
+void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
+{
+       switch (cmd.action) {
+       case LFUN_INSET_DISSOLVE:
+               if (!cmd.argument().empty()) {
+                       InsetLayout const & il = getLayout();
+                       InsetLayout::InsetLyXType const type = 
+                               translateLyXType(to_utf8(cmd.argument()));
+                       
+                       if (il.lyxtype() == type) {
+                               FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
+                               InsetCollapsable::doDispatch(cur, temp_cmd);
+                       } else
+                               cur.undispatched();
+                       break;
+               }
+               // fall-through
+       default:
+               InsetCollapsable::doDispatch(cur, cmd);
+               break;
+       }
+}
+
+
 } // namespace lyx
index ee52e4729c111c1f31c26cb4daf790e347a9c890..d5902be949ae0bb6ed8946b9444f0e372aa4e561 100644 (file)
@@ -36,11 +36,18 @@ public:
        bool neverIndent() const { return true; }
        ///
        bool hasSettings() const { return false; }
+       ///
+       bool getStatus(Cursor & cur, FuncRequest const & cmd,
+               FuncStatus &) const;
+       ///
+       void doDispatch(Cursor & cur, FuncRequest & cmd);
 
 protected:
+       ///
        InsetFlex(InsetFlex const &);
 
 private:
+       ///
        Inset * clone() const { return new InsetFlex(*this); }
        ///
        std::string name_;
index c057c0ca58a9c992a147f586e35b9ae7f4e68f62..cb4d69a3fc97f30e088df0c70da5b3f7dbcade06 100644 (file)
@@ -290,6 +290,26 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
                // FIXME: Change only the pasted paragraphs
                fixParagraphsFont();
                break;
+
+       case LFUN_INSET_DISSOLVE: {
+               bool const main_inset = &buffer().inset() == this;
+               bool const target_inset = cmd.argument().empty() 
+                       || cmd.getArg(0) == insetName(lyxCode());
+               bool const one_cell = cur.inset().nargs() == 1;
+
+               if (!main_inset && target_inset && one_cell) {
+                       // Text::dissolveInset assumes that the cursor
+                       // is inside the Inset.
+                       if (&cur.inset() != this)
+                               cur.pushBackward(*this);
+                       cur.beginUndoGroup();
+                       text_.dispatch(cur, cmd);
+                       cur.endUndoGroup();
+               } else
+                       cur.undispatched();
+               break;
+       }
+
        default:
                text_.dispatch(cur, cmd);
        }
@@ -313,6 +333,16 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_PARAGRAPH_UPDATE:
                status.setEnabled(allowParagraphCustomization());
                return true;
+
+       case LFUN_INSET_DISSOLVE: {
+               bool const main_inset = &buffer().inset() == this;
+               bool const target_inset = cmd.argument().empty() 
+                       || cmd.getArg(0) == insetName(lyxCode());
+               bool const one_cell = cur.inset().nargs() == 1;
+
+               return !main_inset && target_inset && one_cell;
+       }
+
        default:
                // Dispatch only to text_ if the cursor is inside
                // the text_. It is not for context menus (bug 5797).