From: Vincent van Ravesteijn Date: Mon, 26 Oct 2009 23:49:43 +0000 (+0000) Subject: Move (part of) LFUN_DISSOLVE_INSET into InsetText. X-Git-Tag: 2.0.0~5297 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6e8312d1a46fc79af62f01fde116f7b12974c210;p=features.git Move (part of) LFUN_DISSOLVE_INSET into InsetText. - 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 --- diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 93db78d00a..de1cb4c320 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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). diff --git a/src/Text3.cpp b/src/Text3.cpp index b7605efc1a..281ef70058 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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 diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 76b338004d..378705eb68 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -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 diff --git a/src/insets/InsetFlex.h b/src/insets/InsetFlex.h index ee52e4729c..d5902be949 100644 --- a/src/insets/InsetFlex.h +++ b/src/insets/InsetFlex.h @@ -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_; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index c057c0ca58..cb4d69a3fc 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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).