| 1605 | } |
| 1606 | |
| 1607 | void |
| 1608 | AbstractMenu::insert_item (const std::string &p, const std::string &name, Action *action) |
| 1609 | { |
| 1610 | bool primary = true; |
| 1611 | |
| 1612 | tl::Extractor extr (p.c_str ()); |
| 1613 | while (! extr.at_end ()) { |
| 1614 | |
| 1615 | typedef std::vector<std::pair<AbstractMenuItem *, std::list<AbstractMenuItem>::iterator > > path_type; |
| 1616 | path_type path = find_item (extr); |
| 1617 | if (! path.empty ()) { |
| 1618 | |
| 1619 | AbstractMenuItem *parent = path.back ().first; |
| 1620 | std::list<AbstractMenuItem>::iterator iter = path.back ().second; |
| 1621 | |
| 1622 | // insert the new item |
| 1623 | parent->children.insert (iter, AbstractMenuItem (mp_dispatcher)); |
| 1624 | --iter; |
| 1625 | |
| 1626 | iter->setup_item (parent->name (), name, action, primary); |
| 1627 | primary = false; |
| 1628 | |
| 1629 | // find any items with the same name and remove them |
| 1630 | for (std::list<AbstractMenuItem>::iterator existing = parent->children.begin (); existing != parent->children.end (); ) { |
| 1631 | std::list<AbstractMenuItem>::iterator existing_next = existing; |
| 1632 | ++existing_next; |
| 1633 | if (existing->name () == iter->name () && existing != iter) { |
| 1634 | parent->children.erase (existing); |
| 1635 | } |
| 1636 | existing = existing_next; |
| 1637 | } |
| 1638 | |
| 1639 | } |
| 1640 | |
| 1641 | } |
| 1642 | |
| 1643 | emit_changed (); |
| 1644 | } |
| 1645 | |
| 1646 | void |
| 1647 | AbstractMenu::insert_separator (const std::string &p, const std::string &name) |