]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Menus.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / Menus.cpp
index f3d0437932fb7e8fd753917f9779404b20b2fd59..707251dfbb27749c9d092b7cf6fcfd035f44abc0 100644 (file)
@@ -189,7 +189,7 @@ public:
                in the InsetCaption context menu. */
                SwitchCaptions,
                /** Commands to separate environments. */
-               EnvironmentSeparation
+               EnvironmentSeparators
        };
 
        explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
@@ -659,7 +659,7 @@ void MenuDefinition::read(Lexer & lex)
                        break;
 
                case md_env_separators:
-                       add(MenuItem(MenuItem::EnvironmentSeparation));
+                       add(MenuItem(MenuItem::EnvironmentSeparators));
                        break;
 
                case md_optsubmenu:
@@ -1554,9 +1554,10 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
        vector<docstring> const keys = getVectorFromString(key);
 
        vector<CitationStyle> const citeStyleList = buf->params().citeStyles();
+       static const size_t max_length = 40;
        vector<docstring> citeStrings =
                buf->masterBibInfo().getCiteStrings(keys, citeStyleList, bv->buffer(),
-               false, before, after, from_utf8("dialog"));
+               before, after, from_utf8("dialog"), max_length);
 
        vector<docstring>::const_iterator cit = citeStrings.begin();
        vector<docstring>::const_iterator end = citeStrings.end();
@@ -1665,19 +1666,23 @@ void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
 {
        if (!bv)
                return;
+       Text const * text = bv->cursor().text();
+       // no paragraphs and no separators exist in math
+       if (!text)
+               return;
 
-       Paragraph const par = bv->cursor().paragraph();
+       pit_type pit = bv->cursor().selBegin().pit();
+       Paragraph const & par = text->getPar(pit);
        docstring const curlayout = par.layout().name();
        docstring outerlayout;
        depth_type current_depth = par.params().depth();
        // check if we have an environment in our nesting hierarchy
-       pit_type pit = bv->cursor().pit();
-       Paragraph cpar = bv->buffer().text().getPar(pit);
+       Paragraph cpar = par;
        while (true) {
                if (pit == 0 || cpar.params().depth() == 0)
                        break;
                --pit;
-               cpar = bv->buffer().text().getPar(pit);
+               cpar = text->getPar(pit);
                if (cpar.params().depth() < current_depth
                    && cpar.layout().isEnvironment()) {
                                outerlayout = cpar.layout().name();
@@ -1846,7 +1851,7 @@ struct Menus::Impl {
            sequence of Command MenuItems: Lastfiles, Documents,
            ViewFormats, ExportFormats, UpdateFormats, Branches,
            Indices, Arguments, SwitchArguments, Captions, SwitchCaptions,
-           EnvironmentSeparation
+           EnvironmentSeparators
        */
        void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
                BufferView const *) const;
@@ -1930,8 +1935,11 @@ void Menus::Impl::macxMenuBarInit(QMenuBar * qmb)
                 QAction::AboutRole},
                {LFUN_DIALOG_SHOW, "prefs", "Preferences",
                 QAction::PreferencesRole},
-               /* {LFUN_RECONFIGURE, "", "Reconfigure",
-                QAction::ApplicationSpecificRole}, */
+#if !(defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 0x050000))
+               /* This doesn't work with Cocoa. */
+               {LFUN_RECONFIGURE, "", "Reconfigure",
+                QAction::ApplicationSpecificRole},
+#endif
                {LFUN_LYX_QUIT, "", "Quit LyX", QAction::QuitRole}
        };
        const size_t num_entries = sizeof(entries) / sizeof(entries[0]);
@@ -1953,19 +1961,10 @@ void Menus::Impl::macxMenuBarInit(QMenuBar * qmb)
        MenuDefinition::const_iterator cit = mac_special_menu_.begin();
        MenuDefinition::const_iterator end = mac_special_menu_.end();
        for (size_t i = 0 ; cit != end ; ++cit, ++i) {
-#if defined(QT_MAC_USE_COCOA) && (QT_MAC_USE_COCOA > 0)
-               if (first_call || entries[i].role != QAction::ApplicationSpecificRole) {
-                       Action * action = new Action(QIcon(), cit->label(),
-                                cit->func(), QString(), qMenu);
-                       action->setMenuRole(entries[i].role);
-                       qMenu->addAction(action);
-               }
-#else
                Action * action = new Action(QIcon(), cit->label(),
                        cit->func(), QString(), qMenu);
                action->setMenuRole(entries[i].role);
                qMenu->addAction(action);
-#endif
        }
 }
 
@@ -2083,7 +2082,7 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
                        tomenu.expandCaptions(buf, true);
                        break;
 
-               case MenuItem::EnvironmentSeparation:
+               case MenuItem::EnvironmentSeparators:
                        tomenu.expandEnvironmentSeparators(bv);
                        break;
 
@@ -2283,6 +2282,14 @@ void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view, bool initial)
 
                Menu * menu = new Menu(view, m->submenuname(), true);
                menu->setTitle(label(*m));
+
+#if defined(Q_WS_MACX) && (defined(QT_MAC_USE_COCOA) || (QT_VERSION >= 0x050000))
+               // On Mac OS with QT/cocoa, the menu is not displayed if there is no action
+               // so we create a temporary one here
+               QAction * action = new QAction(menu);
+               menu->addAction(action);
+#endif
+
                qmb->addMenu(menu);
 
                d->name_map_[view][name] = menu;