Pavel Sanda wrote: > Scott Kostyshak wrote: > > > + OptItem "Unify Graphics Groups|U" "graphics-unify" > > > > Do we want to add this unconditionally to the context menu? For example, > > start a new document, type "hello", select it, right-click, and you will > > see that "Unify Graphics Groups" is an option even though the selection > > does not contain a graphic. There are other irrelevant options (e.g. > > "Accept Change"), but Vincent (7108b8e4) is not around for me to complain to > > about it :). > > > > For example, I think that Jürgen's "Insert separated <environment>" is > > only added conditionally to the menu (see > > MenuDefinition::expandEnvironmentSeparators()).
Would this patch make you happy? The routine itself could be used for different type of insets if you intend to make a crussade against useless items in context menu. Pavel
diff --git a/src/BufferView.cpp b/src/BufferView.cpp index ed559b1524..bb5587b130 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1154,7 +1154,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) break; case LFUN_GRAPHICS_UNIFY: - flag.setEnabled(cur.selection()); + flag.setEnabled(cur.insetInSelection(GRAPHICS_CODE)); break; case LFUN_WORD_FINDADV: { diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 07dc08dd73..21b454ca4d 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -496,6 +496,30 @@ void CursorData::clearSelection() } +bool CursorData::insetInSelection(InsetCode const & inset_code) +{ + if (!selection_) + return false; + + DocIterator from, to; + from = selectionBegin(); + to = selectionEnd(); + + if (!from.nextInset()) //move to closest inset + from.forwardInset(); + + while (!from.empty() && from < to) { + Inset * inset = from.nextInset(); + if (!inset) + break; + if (inset->lyxCode() == inset_code) + return true; + from.forwardInset(); + } + return false; +} + + bool CursorData::fixIfBroken() { bool const broken_cursor = DocIterator::fixIfBroken(); diff --git a/src/Cursor.h b/src/Cursor.h index efce063c50..7231d902dc 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -129,6 +129,8 @@ public: void setSelection(DocIterator const & where, int n); /// void clearSelection(); + /// check whether selection contains specific type of inset + bool insetInSelection(InsetCode const & inset); /// access to normalized selection anchor CursorSlice normalAnchor() const;