]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiMenubar.cpp
reduce line noise
[lyx.git] / src / frontends / qt4 / GuiMenubar.cpp
index 13254c204607acdcdfb348b19e67d1bb76983cfb..194095ddffe0662b277a2014bb54900fbf0bdf0f 100644 (file)
@@ -38,21 +38,21 @@ namespace frontend {
 // MacOSX specific stuff is at the end.
 
 GuiMenubar::GuiMenubar(LyXView * view, MenuBackend & mbe)
-       : owner_(static_cast<GuiViewBase*>(view)), menubackend_(mbe)
+       : owner_(static_cast<GuiView*>(view)), menubackend_(mbe)
 {
        macxMenuBarInit();
 
-       LYXERR(Debug::GUI) << "populating menu bar" << to_utf8(menubackend_.getMenubar().name()) << endl;
+       LYXERR(Debug::GUI, "populating menu bar" << to_utf8(menubackend_.getMenubar().name()));
 
        if (menubackend_.getMenubar().size() == 0) {
-               LYXERR(Debug::GUI) << "\tERROR: empty menu bar"
-                       << to_utf8(menubackend_.getMenubar().name()) << endl;
+               LYXERR(Debug::GUI, "\tERROR: empty menu bar"
+                       << to_utf8(menubackend_.getMenubar().name()));
                return;
                //                      continue;
        }
        else {
-               LYXERR(Debug::GUI) << "menu bar entries "
-                       << menubackend_.getMenubar().size();
+               LYXERR(Debug::GUI, "menu bar entries "
+                       << menubackend_.getMenubar().size());
        }
 
        Menu menu;
@@ -64,18 +64,17 @@ GuiMenubar::GuiMenubar(LyXView * view, MenuBackend & mbe)
        for (; m != end; ++m) {
 
                if (m->kind() != MenuItem::Submenu) {
-                       LYXERR(Debug::GUI) << "\tERROR: not a submenu "
-                               << to_utf8(m->label()) << endl;
+                       LYXERR(Debug::GUI, "\tERROR: not a submenu " << to_utf8(m->label()));
                        continue;
                }
 
-               LYXERR(Debug::GUI) << "menu bar item " << to_utf8(m->label())
-                       << " is a submenu named " << to_utf8(m->submenuname()) << endl;
+               LYXERR(Debug::GUI, "menu bar item " << to_utf8(m->label())
+                       << " is a submenu named " << to_utf8(m->submenuname()));
 
                docstring name = m->submenuname();
                if (!menubackend_.hasMenu(name)) {
-                       LYXERR(Debug::GUI) << "\tERROR: " << to_utf8(name)
-                               << " submenu has no menu!" << endl;
+                       LYXERR(Debug::GUI, "\tERROR: " << to_utf8(name)
+                               << " submenu has no menu!");
                        continue;
                }
 
@@ -85,11 +84,7 @@ GuiMenubar::GuiMenubar(LyXView * view, MenuBackend & mbe)
                GuiPopupMenu * qMenu = new GuiPopupMenu(this, *m, true);
                owner_->menuBar()->addMenu(qMenu);
 
-               pair<NameMap::iterator, bool> I = name_map_.insert(make_pair(name, qMenu));
-               if (!I.second) {
-                       LYXERR(Debug::GUI) << "\tERROR: " << to_utf8(name)
-                               << " submenu is already there!" << endl;
-               }
+               name_map_[toqstr(name)] = qMenu;
 /*
                QObject::connect(qMenu, SIGNAL(aboutToShow()), this, SLOT(update()));
                QObject::connect(qMenu, SIGNAL(triggered(QAction *)), this, SLOT(update()));
@@ -99,15 +94,17 @@ GuiMenubar::GuiMenubar(LyXView * view, MenuBackend & mbe)
        //QObject::connect(owner_->menuBar(), SIGNAL(triggered()), this, SLOT(update()));
 }
 
-void GuiMenubar::openByName(docstring const & name)
-{
-       NameMap::const_iterator const cit = name_map_.find(name);
-       if (cit == name_map_.end())
-               return;
 
-       // I (Abdel) don't understand this comment:
-       // this will have to do I'm afraid.
-       cit->second->exec(QCursor::pos());
+GuiMenubar::~GuiMenubar() {
+#ifdef Q_WS_MACX
+       delete mac_menubar_;
+#endif
+}
+
+void GuiMenubar::openByName(QString const & name)
+{
+       if (QMenu * menu = name_map_.value(name))
+               menu->exec(QCursor::pos());
 }
 
 
@@ -137,7 +134,7 @@ void GuiMenubar::openByName(docstring const & name)
 QMenuBar * GuiMenubar::menuBar() const
 {
 #ifdef Q_WS_MACX
-       return mac_menubar_.get();
+       return mac_menubar_;
 #else
        return owner_->menuBar();
 #endif
@@ -150,9 +147,8 @@ extern void qt_mac_set_menubar_merge(bool b);
 void GuiMenubar::macxMenuBarInit()
 {
 #ifdef Q_WS_MACX
-       mac_menubar_.reset(new QMenuBar);
+       mac_menubar_ = new QMenuBar;
 
-# if QT_VERSION >= 0x040200
        /* Since Qt 4.2, the qt/mac menu code has special code for
           specifying the role of a menu entry. However, it does not
           work very well with our scheme of creating menus on demand,
@@ -206,15 +202,13 @@ void GuiMenubar::macxMenuBarInit()
        Menu::const_iterator cit = menubackend_.specialMenu().begin();
        Menu::const_iterator end = menubackend_.specialMenu().end();
        for (size_t i = 0 ; cit != end ; ++cit, ++i) {
-               Action * action = new Action(*owner_, cit->label(),
-                                            cit->func());
+               Action * action = new Action(*owner_, QIcon(), 
+                                            toqstr(cit->label()),
+                                            cit->func(), QString());
                action->setMenuRole(entries[i].role);
                qMenu->addAction(action);
 
        }
-# else
-       qt_mac_set_menubar_merge(false);
-# endif // QT_VERSION >= 0x040200
 #endif // Q_WS_MACX
 }