]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Menus.cpp
#7452, no spellcheck menu needed when no text is below cursor
[lyx.git] / src / frontends / qt4 / Menus.cpp
index 84dc1933123cd8639090017cfabaf15ee38055b4..e150b08758af7676f79bc8a864511cffabbd5a4f 100644 (file)
@@ -313,6 +313,8 @@ public:
        const_iterator end() const { return items_.end(); }
        ///
        void cat(MenuDefinition const & other);
+       ///
+       void catSub(docstring const & name);
        
        // search for func in this menu iteratively, and put menu
        // names in a stack.
@@ -656,6 +658,12 @@ bool MenuDefinition::hasFunc(FuncRequest const & func) const
 }
 
 
+void MenuDefinition::catSub(docstring const & name)
+{
+       add(MenuItem(MenuItem::Submenu,
+                    qt_("More...|M"), toqstr(name), QString(), false));
+}
+
 void MenuDefinition::cat(MenuDefinition const & other)
 {
        const_iterator et = other.end();
@@ -756,9 +764,11 @@ void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
 {
        if (!bv)
                return;
+       Cursor const & cur = bv->cursor();
+       if (!cur.inTexted())
+               return;
        WordLangTuple wl;
        docstring_list suggestions;
-       Cursor const & cur = bv->cursor();
        Paragraph const & par = cur.paragraph();
        pos_type from = cur.pos();
        pos_type to = from;
@@ -1572,7 +1582,7 @@ void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
        }
 }
 
-#ifdef Q_WS_WIN && QT_VERSION >= 0x040600
+#if defined(Q_WS_WIN) && (QT_VERSION >= 0x040600)
 class AlwaysMnemonicStyle : public QProxyStyle {
 public:
        int styleHint(StyleHint hint, const QStyleOption *opt = 0, const QWidget *widget = 0,
@@ -1592,7 +1602,7 @@ public:
 Menu::Menu(GuiView * gv, QString const & name, bool top_level, bool keyboard)
 : QMenu(gv), d(new Menu::Impl)
 {
-#ifdef Q_WS_WIN && QT_VERSION >= 0x040600
+#if defined(Q_WS_WIN) && (QT_VERSION >= 0x040600)
        if (keyboard)
                setStyle(new AlwaysMnemonicStyle);
 #else
@@ -2067,7 +2077,15 @@ void Menus::updateMenu(Menu * qmenu)
                        continue;
                }
 
-               fromLyxMenu.cat(d->getMenu(toqstr(menu_name)));
+               MenuDefinition cat_menu = d->getMenu(toqstr(menu_name));
+               //FIXME: 50 is a wild guess. We should take into account here
+               //the expansion of menu items, disabled optional items etc.
+               bool const in_sub_menu = fromLyxMenu.size() > 0 
+                       && fromLyxMenu.size() + cat_menu.size() > 50 ;
+               if (in_sub_menu)
+                       fromLyxMenu.catSub(menu_name);
+               else
+                       fromLyxMenu.cat(cat_menu);
                fromLyxMenu.add(MenuItem(MenuItem::Separator));
        }