]> 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 70379d9582e4aa8432e959311a6dce856788da10..e150b08758af7676f79bc8a864511cffabbd5a4f 100644 (file)
@@ -71,6 +71,9 @@
 #include <QList>
 #include <QMenuBar>
 #include <QString>
+#if QT_VERSION >= 0x040600
+#include <QProxyStyle>
+#endif
 
 #include "support/shared_ptr.h"
 
@@ -130,7 +133,7 @@ public:
                    typically for the File->Export menu. */
                ExportFormats,
                /** This is a list of importable formats
-                   typically for the File->Export menu. */
+                   typically for the File->Import menu. */
                ImportFormats,
                /** This is the list of elements available
                 * for insertion into document. */
@@ -310,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.
@@ -653,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();
@@ -753,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;
@@ -1055,7 +1068,7 @@ void MenuDefinition::expandFormats(MenuItem::Kind kind, Buffer const * buf)
                                continue;
                        }
                case MenuItem::ExportFormats:
-                       if (!(*fit)->documentFormat())
+                       if (!(*fit)->inExportMenu())
                                continue;
                        break;
                default:
@@ -1096,16 +1109,21 @@ void MenuDefinition::expandFloatListInsert(Buffer const * buf)
        FloatList::const_iterator end = floats.end();
        set<string> seen;
        for (; cit != end; ++cit) {
-               // Different floats could declare the same ListCommand. We only
-               // want it on the list once, though.
-               string const & list_cmd = cit->second.listCommand();
-               // This form of insert returns an iterator pointing to the newly
-               // inserted element OR the existing element with that value, and
-               // a bool indicating whether we inserted a new element. So we can
-               // see if one is there and insert it if not all at once.
-               pair<set<string>::iterator, bool> ret = seen.insert(list_cmd);
-               if (!ret.second)
-                       continue;
+               if (!cit->second.usesFloatPkg()) {
+                       // Different floats could declare the same ListCommand. We only
+                       // want it on the list once, though.
+                       string const & list_cmd = cit->second.listCommand();
+                       if (list_cmd.empty())
+                               // we do not know how to generate such a list
+                               continue;
+                       // This form of insert returns an iterator pointing to the newly
+                       // inserted element OR the existing element with that value, and
+                       // a bool indicating whether we inserted a new element. So we can
+                       // see if one is there and insert it if not all at once.
+                       pair<set<string>::iterator, bool> ret = seen.insert(list_cmd);
+                       if (!ret.second)
+                               continue;
+               }
                string const & list_name = cit->second.listName();
                addWithStatusCheck(MenuItem(MenuItem::Command, qt_(list_name),
                        FuncRequest(LFUN_FLOAT_LIST_INSERT, cit->second.floattype())));
@@ -1564,19 +1582,38 @@ void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
        }
 }
 
+#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,
+               QStyleHintReturn *returnData = 0) const 
+       {
+               if (hint == QStyle::SH_UnderlineShortcut)
+                       return 1;
+               return QProxyStyle::styleHint(hint, opt, widget, returnData);
+       }
+};
+#endif
+
 /////////////////////////////////////////////////////////////////////
 // Menu implementation
 /////////////////////////////////////////////////////////////////////
 
-Menu::Menu(GuiView * gv, QString const & name, bool top_level)
+Menu::Menu(GuiView * gv, QString const & name, bool top_level, bool keyboard)
 : QMenu(gv), d(new Menu::Impl)
 {
+#if defined(Q_WS_WIN) && (QT_VERSION >= 0x040600)
+       if (keyboard)
+               setStyle(new AlwaysMnemonicStyle);
+#else
+       (void) keyboard;
+#endif
        d->top_level_menu = top_level? new MenuDefinition : 0;
        d->view = gv;
        d->name = name;
        setTitle(name);
        if (d->top_level_menu)
-               connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView()));
+               connect(this, SIGNAL(aboutToShow()), this, SLOT(updateView())); 
 }
 
 
@@ -2040,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));
        }
 
@@ -2057,7 +2102,7 @@ void Menus::updateMenu(Menu * qmenu)
 }
 
 
-Menu * Menus::menu(QString const & name, GuiView & view)
+Menu * Menus::menu(QString const & name, GuiView & view, bool keyboard)
 {
        LYXERR(Debug::GUI, "Context menu requested: " << name);
        Menu * menu = d->name_map_[&view].value(name, 0);
@@ -2066,7 +2111,7 @@ Menu * Menus::menu(QString const & name, GuiView & view)
                return 0;
        }
 
-       menu = new Menu(&view, name, true);
+       menu = new Menu(&view, name, true, keyboard);
        d->name_map_[&view][name] = menu;
        return menu;
 }