@@ -220,20 +220,22 @@ parse_menu_title (const std::string &s, std::string &title, std::string &shortcu
220220// AbstractMenuItem implementation
221221
222222AbstractMenuItem::AbstractMenuItem (Dispatcher *dispatcher)
223- : mp_action (new Action ()), mp_dispatcher (dispatcher), m_has_submenu (false ), m_remove_on_empty (false )
223+ : mp_action (new Action ()), mp_dispatcher (dispatcher), m_has_submenu (false ), m_remove_on_empty (false ), m_primary ( false )
224224{
225225 // ... nothing yet ..
226226}
227227
228228AbstractMenuItem::AbstractMenuItem (const AbstractMenuItem &item)
229- : mp_action (new Action ()), mp_dispatcher (item.dispatcher ()), m_has_submenu (false ), m_remove_on_empty (false )
229+ : mp_action (new Action ()), mp_dispatcher (item.dispatcher ()), m_has_submenu (false ), m_remove_on_empty (false ), m_primary ( false )
230230{
231231 // ... nothing yet ..
232232}
233233
234234void
235- AbstractMenuItem::setup_item (const std::string &pn, const std::string &s, Action *a)
235+ AbstractMenuItem::setup_item (const std::string &pn, const std::string &s, Action *a, bool primary )
236236{
237+ m_primary = primary;
238+
237239 m_basename.clear ();
238240
239241 tl::Extractor ex (s.c_str ());
@@ -1587,6 +1589,8 @@ AbstractMenu::items (const std::string &path) const
15871589void
15881590AbstractMenu::insert_item (const std::string &p, const std::string &name, Action *action)
15891591{
1592+ bool primary = true ;
1593+
15901594 tl::Extractor extr (p.c_str ());
15911595 while (! extr.at_end ()) {
15921596
@@ -1601,7 +1605,8 @@ AbstractMenu::insert_item (const std::string &p, const std::string &name, Action
16011605 parent->children .insert (iter, AbstractMenuItem (mp_dispatcher));
16021606 --iter;
16031607
1604- iter->setup_item (parent->name (), name, action);
1608+ iter->setup_item (parent->name (), name, action, primary);
1609+ primary = false ;
16051610
16061611 // find any items with the same name and remove them
16071612 for (std::list<AbstractMenuItem>::iterator existing = parent->children .begin (); existing != parent->children .end (); ) {
@@ -1635,7 +1640,7 @@ AbstractMenu::insert_separator (const std::string &p, const std::string &name)
16351640 --iter;
16361641 Action *action = new Action ();
16371642 action->set_separator (true );
1638- iter->setup_item (parent->name (), name, action);
1643+ iter->setup_item (parent->name (), name, action, true );
16391644
16401645 }
16411646
@@ -1655,7 +1660,7 @@ AbstractMenu::insert_menu (const std::string &p, const std::string &name, Action
16551660
16561661 parent->children .insert (iter, AbstractMenuItem (mp_dispatcher));
16571662 --iter;
1658- iter->setup_item (parent->name (), name, action);
1663+ iter->setup_item (parent->name (), name, action, true );
16591664 iter->set_has_submenu ();
16601665
16611666 // find any items with the same name and remove them
@@ -1945,7 +1950,7 @@ AbstractMenu::find_item (tl::Extractor &extr)
19451950 if (parent) {
19461951 parent->children .insert (iter, AbstractMenuItem (mp_dispatcher));
19471952 --iter;
1948- iter->setup_item (parent->name (), n, new Action ());
1953+ iter->setup_item (parent->name (), n, new Action (), true );
19491954 iter->set_has_submenu ();
19501955 iter->set_remove_on_empty ();
19511956 iter->set_action_title (ndesc.empty () ? n : ndesc);
@@ -2055,16 +2060,17 @@ AbstractMenu::get_shortcuts (const std::string &root, std::map<std::string, std:
20552060 std::vector<std::string> items = this ->items (root);
20562061 for (std::vector<std::string>::const_iterator i = items.begin (); i != items.end (); ++i) {
20572062 if (i->size () > 0 ) {
2058- if (is_valid (*i) && action (*i)->is_visible ()) {
2059- if (is_menu (*i)) {
2063+ const AbstractMenuItem *item = find_item_exact (*i);
2064+ if (item && item->action () && item->action ()->is_visible ()) {
2065+ if (item->has_submenu ()) {
20602066 // a menu must be listed (so it can be hidden), but does not have a shortcut
20612067 // but we don't include special menus
20622068 if (i->at (0 ) != ' @' ) {
20632069 bindings.insert (std::make_pair (*i, std::string ()));
20642070 }
20652071 get_shortcuts (*i, bindings, with_defaults);
2066- } else if (! is_separator (*i )) {
2067- bindings.insert (std::make_pair (*i, with_defaults ? action (*i )->get_default_shortcut () : action (*i )->get_effective_shortcut ()));
2072+ } else if (! item-> action ()-> is_separator () && item-> primary ( )) {
2073+ bindings.insert (std::make_pair (*i, with_defaults ? item-> action ()->get_default_shortcut () : item-> action ()->get_effective_shortcut ()));
20682074 }
20692075 }
20702076 }
0 commit comments