| 1278 | } |
| 1279 | |
| 1280 | void |
| 1281 | AbstractMenu::build (QMenuBar *mbar, QToolBar *tbar) |
| 1282 | { |
| 1283 | // Build the menu bar |
| 1284 | if (mbar) { |
| 1285 | |
| 1286 | std::set<std::pair<size_t, QAction *> > present_actions; |
| 1287 | |
| 1288 | QList<QAction *> a = mbar->actions (); |
| 1289 | for (QList<QAction *>::const_iterator i = a.begin (); i != a.end (); ++i) { |
| 1290 | present_actions.insert (std::make_pair (id_from_action (*i), *i)); |
| 1291 | } |
| 1292 | |
| 1293 | // NOTE: on MacOS, once the top level menu is created, we should not |
| 1294 | // modify it and place menu items into the "Extras" menu instead. |
| 1295 | bool menu_frozen = ! s_can_move_menu && ! present_actions.empty (); |
| 1296 | |
| 1297 | // NOTE: the "extras" menu is relevant on MacOS only |
| 1298 | QMenu *extras_menu = find_extras_menu (mbar); |
| 1299 | if (extras_menu) { |
| 1300 | extras_menu->clear (); |
| 1301 | } |
| 1302 | |
| 1303 | QAction *prev_action = 0; |
| 1304 | |
| 1305 | for (std::list<AbstractMenuItem>::iterator c = m_root.children.begin (); c != m_root.children.end (); ++c) { |
| 1306 | |
| 1307 | if (c->has_submenu ()) { |
| 1308 | |
| 1309 | if (c->name ().find ("@") == 0) { |
| 1310 | |
| 1311 | // done later. |
| 1312 | |
| 1313 | } else { |
| 1314 | |
| 1315 | if (c->menu () == 0) { |
| 1316 | |
| 1317 | // NOTE: we intentionally do not make the item owner of the menu action |
| 1318 | // as implicitly deleting it might cause trouble on MacOS. Instead we |
| 1319 | // explicitly delete below or keep the action. |
| 1320 | QMenu *menu = new QMenu (mp_dispatcher->menu_parent_widget ()); |
| 1321 | menu->setTitle (tl::to_qstring (c->action ()->get_title ())); |
| 1322 | c->set_action (new Action (menu, false), true); |
| 1323 | |
| 1324 | // This case happens when we dynamically create menus. |
| 1325 | // MacOS does not like generating top-level menus dynamically, so |
| 1326 | // we put them into the "_extra" top level one. |
| 1327 | if (menu_frozen) { |
| 1328 | if (extras_menu) { |
| 1329 | extras_menu->addMenu (menu); |
| 1330 | } |
| 1331 | } else { |
| 1332 | prev_action = insert_action_after (mbar, prev_action, menu->menuAction ()); |
| 1333 | } |
| 1334 | |
| 1335 | } else { |
| 1336 | |
| 1337 | // Move the action to the end if present in the menu already |
no test coverage detected