]> git.lyx.org Git - features.git/commitdiff
Don't pretend we have multiple menu backends: transfer the singleton to GuiApplication.
authorAbdelrazak Younes <younes@lyx.org>
Tue, 25 Dec 2007 22:27:32 +0000 (22:27 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 25 Dec 2007 22:27:32 +0000 (22:27 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22303 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/LyX.cpp
src/MenuBackend.cpp
src/MenuBackend.h
src/frontends/Application.h
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiMenubar.cpp
src/frontends/qt4/GuiMenubar.h
src/frontends/qt4/GuiPopupMenu.cpp
src/frontends/qt4/GuiView.cpp
src/insets/InsetInfo.cpp

index a13a3df033ab49b5a8d3c1e8001e12dcb740d585..3cab67b0957b18b6f245daf88b38c312fb67f1e0 100644 (file)
@@ -59,6 +59,7 @@
 #include "insets/InsetText.h"
 
 #include "frontends/alert.h"
+#include "frontends/Application.h"
 #include "frontends/Delegates.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
@@ -494,7 +495,7 @@ docstring BufferView::toolTip(int x, int y) const
 Menu const & BufferView::contextMenu(int x, int y) const
 {
        // FIXME: Do something more elaborate here.
-       return menubackend.getMenu(from_ascii("edit"));
+       return theApp()->menuBackend().getMenu(from_ascii("edit"));
 }
 
 
index 99350f8fba6aa5e1e74713d43ae3bbe8998b7910..b7a0376455c131597d2301ae49a8b44833070bb0 100644 (file)
@@ -1109,7 +1109,7 @@ bool LyX::readUIFile(string const & name, bool include)
                        break;
                }
                case ui_menuset:
-                       menubackend.read(lex);
+                       theApp()->menuBackend().read(lex);
                        break;
 
                case ui_toolbarset:
index 2e4f4532f2bb7e4bfc8fb2c6c4eb5c90c0496360..8686177146c7cf861c49bfab1caf00d4612ebd3c 100644 (file)
@@ -39,6 +39,8 @@
 #include "TocBackend.h"
 #include "ToolbarBackend.h"
 
+#include "frontends/Application.h"
+
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/convert.h"
@@ -70,10 +72,6 @@ private:
 } // namespace anon
 
 
-// This is the global menu definition
-MenuBackend menubackend;
-
-
 MenuItem::MenuItem(Kind kind)
        : kind_(kind), optional_(false)
 {}
@@ -416,7 +414,7 @@ bool Menu::searchFunc(FuncRequest & func, stack<docstring> & names)
                        return true;
                } else if (m->kind() == MenuItem::Submenu) {
                        names.push(m->label());
-                       Menu submenu = menubackend.getMenu(m->submenuname());
+                       Menu submenu = theApp()->menuBackend().getMenu(m->submenuname());
                        if (submenu.searchFunc(func, names))
                                return true;
                        else
index 76f4ca3722386ad04859749e0decb1421b78065c..cfe380180b909aac334c1497bb32de54820ff630 100644 (file)
@@ -259,10 +259,6 @@ private:
        Menu specialmenu_;
 };
 
-///
-extern MenuBackend menubackend;
-
-
 } // namespace lyx
 
 #endif // MENUBACKEND_H
index 6bcb53acfc46ddc3a2b4412a9ae9fb3f6cd02807..826b9a3e2ae5b43d61b02823c2ef83fd3ca1c09f 100644 (file)
@@ -25,6 +25,7 @@ class Buffer;
 class FuncRequest;
 class FuncStatus;
 class Inset;
+class MenuBackend;
 struct RGBColor;
 
 namespace frontend {
@@ -208,6 +209,10 @@ public:
        * @param fd socket descriptor (file/socket/etc)
        */
        virtual void unregisterSocketCallback(int fd) = 0;
+
+       ///
+       virtual MenuBackend const & menuBackend() const = 0;
+       virtual MenuBackend & menuBackend() = 0;
 };
 
 } // namespace frontend
index 65fa5b76faf8baa91efc1011f716b3d4ba815e70..851ffbba4534fb8e313475ece2db3db6866f28bc 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "frontends/Application.h"
 
+#include "MenuBackend.h"
+
 #include <QObject>
 #include <QApplication>
 #include <QTranslator>
@@ -62,6 +64,8 @@ public:
        virtual Clipboard & clipboard();
        virtual Selection & selection();
        virtual FontLoader & fontLoader() { return font_loader_; }
+       MenuBackend const & menuBackend() const { return menu_backend_; }
+       MenuBackend & menuBackend() { return menu_backend_; }
        virtual int exec();
        virtual void exit(int status);
        virtual bool event(QEvent * e);
@@ -135,6 +139,8 @@ private:
        QTranslator qt_trans_;
        ///
        std::map<int, SocketNotifier *> socket_notifiers_;
+       ///
+       MenuBackend menu_backend_;
 
 #ifdef Q_WS_X11
 public:
index 9926ea0caf0faf3534eb950860943c30f632ff73..1c5ed1326317533200a6c4ad2c755a4c575fa773 100644 (file)
 
 #include <config.h>
 
-// Qt defines a macro 'signals' that clashes with a boost namespace.
-// All is well if the namespace is visible first.
-#include "GuiView.h"
+#include "GuiMenubar.h"
 
 #include "Action.h"
-#include "GuiMenubar.h"
+#include "GuiApplication.h"
 #include "GuiPopupMenu.h"
+#include "GuiView.h"
 
 #include "qt_helpers.h"
 
@@ -33,8 +32,8 @@ namespace frontend {
 
 // MacOSX specific stuff is at the end.
 
-GuiMenubar::GuiMenubar(GuiView * view, MenuBackend & mbe)
-       : owner_(view), menubackend_(mbe)
+GuiMenubar::GuiMenubar(GuiView * view)
+       : owner_(view)
 {
        init();
 }
@@ -50,21 +49,23 @@ void GuiMenubar::init()
        macxMenuBarInit();
 #endif
 
-       LYXERR(Debug::GUI, "populating menu bar" << to_utf8(menubackend_.getMenubar().name()));
+       /// menu controller
+       MenuBackend & menu_backend = guiApp->menuBackend();
+       LYXERR(Debug::GUI, "populating menu bar" << to_utf8(menu_backend.getMenubar().name()));
 
-       if (menubackend_.getMenubar().size() == 0) {
+       if (menu_backend.getMenubar().size() == 0) {
                LYXERR(Debug::GUI, "\tERROR: empty menu bar"
-                       << to_utf8(menubackend_.getMenubar().name()));
+                       << to_utf8(menu_backend.getMenubar().name()));
                return;
                //                      continue;
        }
        else {
                LYXERR(Debug::GUI, "menu bar entries "
-                       << menubackend_.getMenubar().size());
+                       << menu_backend.getMenubar().size());
        }
 
        Menu menu;
-       menubackend_.expand(menubackend_.getMenubar(), menu, owner_->buffer());
+       menu_backend.expand(menu_backend.getMenubar(), menu, owner_->buffer());
 
        Menu::const_iterator m = menu.begin();
        Menu::const_iterator end = menu.end();
@@ -80,26 +81,20 @@ void GuiMenubar::init()
                        << " is a submenu named " << to_utf8(m->submenuname()));
 
                docstring name = m->submenuname();
-               if (!menubackend_.hasMenu(name)) {
+               if (!menu_backend.hasMenu(name)) {
                        LYXERR(Debug::GUI, "\tERROR: " << to_utf8(name)
                                << " submenu has no menu!");
                        continue;
                }
 
                Menu menu;
-               menubackend_.expand(menubackend_.getMenubar(), menu, owner_->buffer());
+               menu_backend.expand(menu_backend.getMenubar(), menu, owner_->buffer());
 
                GuiPopupMenu * qMenu = new GuiPopupMenu(owner_, *m, true);
                owner_->menuBar()->addMenu(qMenu);
 
                name_map_[toqstr(name)] = qMenu;
-/*
-               QObject::connect(qMenu, SIGNAL(aboutToShow()), this, SLOT(update()));
-               QObject::connect(qMenu, SIGNAL(triggered(QAction *)), this, SLOT(update()));
-               QObject::connect(qMenu->menuAction(), SIGNAL(triggered()), this, SLOT(update()));
-*/
        }
-       //QObject::connect(owner_->menuBar(), SIGNAL(triggered()), this, SLOT(update()));
 }
 
 
@@ -185,7 +180,8 @@ void GuiMenubar::macxMenuBarInit()
                                     from_utf8(entries[i].label),
                                     func));
        }
-       menubackend_.specialMenu(special);
+       MenuBackend & menu_backend = guiApp->menuBackend();
+       menu_backend.specialMenu(special);
 
        // add the entries to a QMenu that will eventually be empty
        // and therefore invisible.
@@ -194,8 +190,8 @@ void GuiMenubar::macxMenuBarInit()
        // we do not use 'special' because it is a temporary variable,
        // whereas MenuBackend::specialMenu points to a persistent
        // copy.
-       Menu::const_iterator cit = menubackend_.specialMenu().begin();
-       Menu::const_iterator end = menubackend_.specialMenu().end();
+       Menu::const_iterator cit = menu_backend.specialMenu().begin();
+       Menu::const_iterator end = menu_backend.specialMenu().end();
        for (size_t i = 0 ; cit != end ; ++cit, ++i) {
                Action * action = new Action(*owner_, QIcon(), 
                                             toqstr(cit->label()),
index 545bd762912744ebd83ab389d26dc4020afa9bd9..05733dbb13e0380b5443d97b3370acf57b8d90d6 100644 (file)
@@ -19,9 +19,6 @@
 class QMenuBar;
 
 namespace lyx {
-
-class MenuBackend;
-
 namespace frontend {
 
 class GuiView;
@@ -32,7 +29,7 @@ class GuiMenubar : public QObject
 {
        Q_OBJECT
 public:
-       GuiMenubar(GuiView *, MenuBackend &);
+       GuiMenubar(GuiView *);
 
        ~GuiMenubar();
 
@@ -45,9 +42,6 @@ public:
        /// return the owning view
        GuiView * view() { return owner_; }
 
-       /// return the menu controller
-       MenuBackend const & backend() { return menubackend_; }
-
        /// update the state of the menuitems - not needed
        void updateView();
 
@@ -58,9 +52,6 @@ private:
        /// owning view
        GuiView * owner_;
 
-       /// menu controller
-       MenuBackend & menubackend_;
-
        typedef QHash<QString, GuiPopupMenu *> NameMap;
 
        /// name to menu for openByName
index e29a06954dd2aceeb373468e471b49c447f921b8..1fd16888986f0aa0229e06ecff9d9d76ae7c6de3 100644 (file)
@@ -14,6 +14,7 @@
 #include "GuiView.h"
 
 #include "Action.h"
+#include "GuiApplication.h"
 #include "GuiPopupMenu.h"
 #include "qt_helpers.h"
 
@@ -52,6 +53,7 @@ void GuiPopupMenu::updateView()
        // Here, We make sure that theLyXFunc points to the correct LyXView.
        theLyXFunc().setLyXView(owner_);
 
+       MenuBackend const & menubackend = guiApp->menuBackend();
        Menu const & fromLyxMenu = menubackend.getMenu(name_);
        menubackend.expand(fromLyxMenu, topLevelMenu_, owner_->buffer());
 
index d6919a4f4920399e071bf2a8fe094b97cda4606d..4f1b4ce51ebd0061281d254d7dae165cf805766f 100644 (file)
@@ -282,7 +282,7 @@ GuiView::GuiView(int id)
 {
        // GuiToolbars *must* be initialised before GuiMenubar.
        d.toolbars_ = new GuiToolbars(*this);
-       d.menubar_ = new GuiMenubar(this, menubackend);
+       d.menubar_ = new GuiMenubar(this);
 
        setCentralWidget(d.stack_widget_);
 
index d14a6889d04d199176da4ed69b450376b38abc74..daf533378daa9fae3e70aac3d87c00c9b51b5396 100644 (file)
@@ -19,7 +19,6 @@
 #include "BufferView.h"
 #include "support/debug.h"
 #include "FuncRequest.h"
-#include "support/gettext.h"
 #include "InsetSpecialChar.h"
 #include "KeyMap.h"
 #include "LaTeXFeatures.h"
 #include "ParagraphParameters.h"
 #include "TextClassList.h"
 
+#include "frontends/Application.h"
+
 #include "support/docstream.h"
 #include "support/FileName.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/ExceptionMessage.h"
 
@@ -214,7 +216,7 @@ void InsetInfo::updateInfo(Buffer const & buf)
                        break;
                }
                // iterate through the menubackend to find it
-               Menu menu = menubackend.getMenubar();
+               Menu menu = theApp()->menuBackend().getMenubar();
                if (!menu.searchFunc(func, names)) {
                        setText(_("No menu entry for "), bp.getFont(), false);
                        break;