From 0113ce8310ec425939c035c1deb688af37fd9b23 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Mon, 7 Sep 2009 08:40:40 +0000 Subject: [PATCH] branch: Fix #6045: Possible to insert table floats into figure floats. The lfuns, LFUN_FLOAT_INSERT and LFUN_WRAP_INSERT are now only enabled when they should be. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@31318 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Text3.cpp | 37 +++++++++++++++++++++++++++++++++---- src/insets/InsetFloat.cpp | 13 ++++++++++--- status.16x | 3 +++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/Text3.cpp b/src/Text3.cpp index 3c3e8a8b28..cc879cf833 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -52,13 +52,15 @@ #include "insets/InsetCollapsable.h" #include "insets/InsetCommand.h" #include "insets/InsetExternal.h" +#include "insets/InsetFloat.h" +#include "insets/InsetGraphics.h" +#include "insets/InsetGraphicsParams.h" #include "insets/InsetFloatList.h" #include "insets/InsetNewline.h" #include "insets/InsetQuotes.h" #include "insets/InsetSpecialChar.h" #include "insets/InsetText.h" -#include "insets/InsetGraphics.h" -#include "insets/InsetGraphicsParams.h" +#include "insets/InsetWrap.h" #include "support/convert.h" #include "support/debug.h" @@ -2062,9 +2064,36 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, break; case LFUN_FLOAT_INSERT: case LFUN_FLOAT_WIDE_INSERT: + // FIXME: If there is a selection, we should check whether there + // are floats in the selection, but this has performance issues, see + // LFUN_CHANGE_ACCEPT/REJECT. code = FLOAT_CODE; - // not allowed in description items - enable = !inDescriptionItem(cur); + if (inDescriptionItem(cur)) + // not allowed in description items + enable = false; + else { + InsetCode const inset_code = cur.inset().lyxCode(); + + // algorithm floats cannot be put in another float + if (to_utf8(cmd.argument()) == "algorithm") { + enable = inset_code != WRAP_CODE && inset_code != FLOAT_CODE; + break; + } + + // for figures and tables: only allow in another + // float or wrap if it is of the same type and + // not a subfloat already + if(cur.inset().lyxCode() == code) { + InsetFloat const & ins = + static_cast(cur.inset()); + enable = ins.params().type == to_utf8(cmd.argument()) + && !ins.params().subfloat; + } else if(cur.inset().lyxCode() == WRAP_CODE) { + InsetWrap const & ins = + static_cast(cur.inset()); + enable = ins.params().type == to_utf8(cmd.argument()); + } + } break; case LFUN_WRAP_INSERT: code = WRAP_CODE; diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 14e01ae880..c4e9efdc26 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -380,9 +380,16 @@ int InsetFloat::docbook(odocstream & os, OutputParams const & runparams) const bool InsetFloat::insetAllowed(InsetCode code) const { - return code != FOOT_CODE - && code != MARGIN_CODE - && (code != FLOAT_CODE || !params_.subfloat); + // The case that code == FLOAT_CODE is handled in Text3.cpp, + // because we need to know what type of float is meant. + switch(code) { + case WRAP_CODE: + case FOOT_CODE: + case MARGIN_CODE: + return false; + default: + return InsetCollapsable::insetAllowed(code); + } } diff --git a/status.16x b/status.16x index 90e9410315..4943204849 100644 --- a/status.16x +++ b/status.16x @@ -65,6 +65,9 @@ What's new - Sort document classes case insensitively (bug 1492). +- Disable to insert floats into another float when this is not + allowed (bug 6045). + * DOCUMENTATION AND LOCALIZATION