]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/Menubar_pimpl.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / Menubar_pimpl.C
index f820fb938d34f73a394b93f27b99e88086ca63ac..042ba49280c332033240ca881afe274ea9b772a6 100644 (file)
@@ -1,9 +1,11 @@
 /**
- * \file Menubar_pimpl.C
- * Copyright 1999-2001 The LyX Team.
- * See the file COPYING.
+ * \file xforms/Menubar_pimpl.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author  Lars Gullik Bjønnes, larsbj@lyx.org
+ * \author  Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
@@ -38,7 +40,6 @@ using std::for_each;
 typedef vector<int>::size_type size_type;
 
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
-extern LyXAction lyxaction;
 
 namespace {
 
@@ -91,6 +92,10 @@ Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb)
 }
 
 
+Menubar::Pimpl::~Pimpl()
+{}
+
+
 void Menubar::Pimpl::makeMenubar(Menu const & menu)
 {
        FL_FORM * form = owner_->getForm();
@@ -233,18 +238,21 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
                if (i->kind() == MenuItem::Separator)
                        *last = "%l";
                else if (!i->optional() ||
-                        !(view->getLyXFunc()->getStatus(i->action()).disabled()))
+                        !(view->getLyXFunc().getStatus(i->action()).disabled()))
                        last = it;
 
        it = extra_labels.begin();
        size_type count = 0;
+       all_disabled = true;
        int curmenuid = menuid;
        for (Menu::const_iterator i = menu.begin(); i != end; ++i, ++it) {
                MenuItem const & item = (*i);
                string & extra_label = *it;
 
                ++count;
-               if (count > max_number_of_items) {
+               // add a More... submenu if the menu is too long (but
+               // not just for one extra entry!)
+               if (count > max_number_of_items && (i+1) != end) {
                        int tmpmenuid = get_new_submenu(smn, win);
                        lyxerr[Debug::GUI] << "Too many items, creating "
                                           << "new menu " << tmpmenuid << endl;
@@ -258,7 +266,7 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
                switch (item.kind()) {
                case MenuItem::Command: {
                        FuncStatus const flag =
-                               view->getLyXFunc()->getStatus(item.action());
+                               view->getLyXFunc().getStatus(item.action());
                        // handle optional entries.
                        if (item.optional()
                            && (flag.disabled())) {
@@ -319,14 +327,16 @@ int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
                }
 
                case MenuItem::Submenu: {
+                       bool sub_all_disabled;
                        int submenuid = create_submenu(win, view,
                                                       *item.submenu(), smn,
-                                                      all_disabled);
+                                                      sub_all_disabled);
+                       all_disabled &= sub_all_disabled;
                        if (submenuid == -1)
                                return -1;
                        string label = fixlabel(item.label());
                        label += extra_label + "%m";
-                       if (all_disabled)
+                       if (sub_all_disabled)
                                label += "%i";
                        string shortcut = item.shortcut();
                        if (!shortcut.empty()) {
@@ -400,7 +410,7 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
                // If the action value is too low, then it is not a
                // valid action, but something else.
                if (choice >= action_offset + 1) {
-                       view->getLyXFunc()->dispatch(choice - action_offset, true);
+                       view->getLyXFunc().dispatch(choice - action_offset, true);
                } else {
                        lyxerr[Debug::GUI]
                                << "MenuCallback: ignoring bogus action "
@@ -415,3 +425,15 @@ void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
        fl_set_tabstop(default_tabstop);
 
 }
+
+
+Menubar::Pimpl::ItemInfo::ItemInfo
+       (Menubar::Pimpl * p, MenuItem const * i, FL_OBJECT * o)
+       : pimpl_(p), obj_(o)
+{
+       item_.reset(i);
+}
+
+
+Menubar::Pimpl::ItemInfo::~ItemInfo()
+{}