]> git.lyx.org Git - features.git/commitdiff
* remove the need of an active GuiView
authorStefan Schimanski <sts@lyx.org>
Fri, 14 Mar 2008 16:33:16 +0000 (16:33 +0000)
committerStefan Schimanski <sts@lyx.org>
Fri, 14 Mar 2008 16:33:16 +0000 (16:33 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23718 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXFunc.cpp
src/frontends/qt4/Action.cpp
src/frontends/qt4/Action.h
src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/Menus.cpp
src/frontends/qt4/Menus.h

index 7e2f25f5df69da2a96ce9bc7bdd187afe4126256..a290de8d95b00d06de7c29f58bb2cbcbc7fdd7cd 100644 (file)
@@ -105,10 +105,11 @@ namespace {
 
 // This function runs "configure" and then rereads lyx.defaults to
 // reconfigure the automatic settings.
-void reconfigure(LyXView & lv, string const & option)
+void reconfigure(LyXView * lv, string const & option)
 {
        // emit message signal.
-       lv.message(_("Running configure..."));
+       if (lv)
+               lv->message(_("Running configure..."));
 
        // Run configure in user lyx directory
        PathChanger p(package().user_support());
@@ -118,7 +119,8 @@ void reconfigure(LyXView & lv, string const & option)
        int ret = one.startscript(Systemcall::Wait, configure_command);
        p.pop();
        // emit message signal.
-       lv.message(_("Reloading configuration..."));
+       if (lv)
+               lv->message(_("Reloading configuration..."));
        lyxrc.read(libFileSearch(string(), "lyxrc.defaults"));
        // Re-read packages.lst
        LaTeXFeatures::getAvailable();
@@ -293,7 +295,8 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
 
        if (keysym.isModifier()) {
                LYXERR(Debug::KEY, "isModifier true");
-               lyx_view_->restartCursor();
+               if (lyx_view_)
+                       lyx_view_->restartCursor();
                return;
        }
 
@@ -384,7 +387,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        //lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
        FuncStatus flag;
 
-       Buffer * buf = lyx_view_? lyx_view_->buffer() : 0;
+       Buffer * buf = lyx_view_ ? lyx_view_->buffer() : 0;
 
        if (cmd.action == LFUN_NOACTION) {
                flag.message(from_utf8(N_("Nothing to do")));
@@ -1039,9 +1042,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_RECONFIGURE:
-                       BOOST_ASSERT(lyx_view_);
                        // argument is any additional parameter to the configure.py command
-                       reconfigure(*lyx_view_, argument);
+                       reconfigure(lyx_view_, argument);
                        break;
 
                case LFUN_HELP_OPEN: {
@@ -1659,8 +1661,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                // Nothing more to do.
                                return;
 
+                       // Everything below is only for active lyx_view_
+                       if (lyx_view_ == 0)
+                               break;
+
                        // Let the current LyXView dispatch its own actions.
-                       BOOST_ASSERT(lyx_view_);
                        if (lyx_view_->dispatch(cmd)) {
                                if (lyx_view_->view())
                                        updateFlags = lyx_view_->view()->cursor().result().update();
index 006cf3a9fa3055dbb09bfe08eae5785811274386..724d9daf8ba2ba658a7bd09f69e1fda69dd1d6ef 100644 (file)
@@ -25,10 +25,10 @@ namespace lyx {
 namespace frontend {
 
 
-Action::Action(GuiView & lyxView, QIcon const & icon,
+Action::Action(GuiView * lyxView, QIcon const & icon,
          QString const & text, FuncRequest const & func,
-         QString const & tooltip)
-       : QAction(&lyxView), func_(func), lyxView_(lyxView)
+         QString const & tooltip, QObject * parent)
+       : QAction(parent), func_(func), lyxView_(lyxView)
 {
        // only Qt/Mac handles that
        setMenuRole(NoRole);
@@ -62,7 +62,10 @@ void Action::update()
 void Action::action()
 {
        //LYXERR(Debug::ACTION, "calling LyXFunc::dispatch: func_: ");
-       theLyXFunc().setLyXView(&lyxView_);
+
+       if (lyxView_)
+               theLyXFunc().setLyXView(lyxView_);
+
        lyx::dispatch(func_);
        triggered(this);
 }
index 7376a433d29ef14de023a6f841a23b2b4c5e7169..11a862b7887f278149638a74d16dac6c5e7bf0fd 100644 (file)
@@ -34,8 +34,8 @@ class Action : public QAction
        Q_OBJECT
 
 public:
-       Action(GuiView & lyxView, QIcon const & icon, QString const & text,
-               FuncRequest const & func, QString const & tooltip);
+       Action(GuiView * lyxView, QIcon const & icon, QString const & text,
+               FuncRequest const & func, QString const & tooltip, QObject * parent);
 
        void update();
 
@@ -48,7 +48,7 @@ private Q_SLOTS:
 
 private:
        FuncRequest const & func_ ;
-       GuiView & lyxView_;
+       GuiView * lyxView_;
 };
 
 
index f5563faa0038a299e534f3f613a612f8293f6c6a..577d1094333a004442f04a1b8f11c10d20fd0e7f 100644 (file)
@@ -839,9 +839,8 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
 
 Action * GuiToolbar::addItem(ToolbarItem const & item)
 {
-       Action * act = new Action(owner_,
-               getIcon(item.func_, false),
-         toqstr(item.label_), item.func_, toqstr(item.label_));
+       Action * act = new Action(&owner_, getIcon(item.func_, false),
+               toqstr(item.label_), item.func_, toqstr(item.label_), this);
        actions_.append(act);
        return act;
 }
index 1f4ffe114dd31e7ef3f80b75259e974a56b693ba..4ff601ef91cbd078c0923fd8b312439b84490120 100644 (file)
@@ -278,7 +278,7 @@ GuiView::GuiView(int id)
        d.toolbars_ = new GuiToolbars(*this);
 
        // Fill up the menu bar.
-       guiApp->menus().fillMenuBar(this);
+       guiApp->menus().fillMenuBar(menuBar(), this);
 
        setCentralWidget(d.stack_widget_);
 
@@ -2024,7 +2024,7 @@ void GuiView::resetDialogs()
        // FIXME: the "math panels" toolbar takes an awful lot of time to
        // initialise so we don't do that for the time being.
        //d.toolbars_->init();
-       guiApp->menus().fillMenuBar(this);
+       guiApp->menus().fillMenuBar(menuBar(), this);
        if (d.layout_)
                d.layout_->updateContents(true);
        // Now update controls with current buffer.
index 27b2f980906e740d52c18858e9b3f346de6bb39e..4ea1e0d27ceed72c870816a7e5bd0dba2f42090f 100644 (file)
@@ -1114,8 +1114,8 @@ void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
                        populate(*subMenu, m->submenu());
                } else {
                        // we have a MenuItem::Command
-                       qMenu.addAction(new Action(*view, QIcon(), label(*m), m->func(),
-                               QString()));
+                       qMenu.addAction(new Action(view, QIcon(), label(*m), 
+                               m->func(), QString(), &qMenu));
                }
        }
 }
@@ -1167,10 +1167,10 @@ struct Menus::Impl {
            ViewFormats, ExportFormats, UpdateFormats, Branches
        */
        void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
-                   Buffer const *) const;
+               Buffer const *) const;
 
        /// Initialize specific MACOS X menubar
-       void macxMenuBarInit(GuiView * view);
+       void macxMenuBarInit(GuiView * view, QMenuBar * qmb);
 
        /// Mac special menu.
        /** This defines a menu whose entries list the FuncRequests
@@ -1211,7 +1211,7 @@ struct Menus::Impl {
   that this menubar will be used also when one of LyX' dialogs has
   focus. (JMarc)
 */
-void Menus::Impl::macxMenuBarInit(GuiView * view)
+void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb)
 {
        // The Mac menubar initialisation must be done only once!
        static bool done = false;
@@ -1260,12 +1260,12 @@ void Menus::Impl::macxMenuBarInit(GuiView * view)
 
        // add the entries to a QMenu that will eventually be empty
        // and therefore invisible.
-       QMenu * qMenu = view->menuBar()->addMenu("special");
+       QMenu * qMenu = qmb->addMenu("special");
        MenuDefinition::const_iterator cit = specialmenu_.begin();
        MenuDefinition::const_iterator end = specialmenu_.end();
        for (size_t i = 0 ; cit != end ; ++cit, ++i) {
-               Action * action = new Action(*view, QIcon(), cit->label(),
-                                            cit->func(), QString());
+               Action * action = new Action(view, QIcon(), cit->label(),
+                       cit->func(), QString(), qMenu);
                action->setMenuRole(entries[i].role);
                qMenu->addAction(action);
        }
@@ -1464,14 +1464,14 @@ bool Menus::searchMenu(FuncRequest const & func,
 }
 
 
-void Menus::fillMenuBar(GuiView * view)
+void Menus::fillMenuBar(QMenuBar * qmb, GuiView * view)
 {
        // Clear all menubar contents before filling it.
-       view->menuBar()->clear();
+       qmb->clear();
        
 #ifdef Q_WS_MACX
        // setup special mac specific menu item
-       d->macxMenuBarInit(view);
+       d->macxMenuBarInit(view, qmb);
 #endif
 
        LYXERR(Debug::GUI, "populating menu bar" << fromqstr(d->menubar_.name()));
@@ -1487,7 +1487,10 @@ void Menus::fillMenuBar(GuiView * view)
        }
 
        MenuDefinition menu;
-       d->expand(d->menubar_, menu, view->buffer());
+       Buffer * buf = 0;
+       if (view)
+               buf = view->buffer();
+       d->expand(d->menubar_, menu, buf);
 
        MenuDefinition::const_iterator m = menu.begin();
        MenuDefinition::const_iterator end = menu.end();
@@ -1537,7 +1540,10 @@ void Menus::updateMenu(Menu * qmenu)
        }
 
        MenuDefinition const & fromLyxMenu = d->getMenu(qmenu->d->name);
-       d->expand(fromLyxMenu, *qmenu->d->top_level_menu, qmenu->d->view->buffer());
+       Buffer * buf = 0;
+       if (qmenu->d->view)
+               buf = qmenu->d->view->buffer();
+       d->expand(fromLyxMenu, *qmenu->d->top_level_menu, buf);
        qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
 }
 
index 80de0da29201c46cd58343881e1c20aeda5d4e9b..9ba0c10d58ce07b8522c9b53c6486150c94b6d17 100644 (file)
@@ -63,7 +63,7 @@ public:
        bool searchMenu(FuncRequest const & func,
                std::vector<docstring> & names) const;
        ///
-       void fillMenuBar(GuiView * view);
+       void fillMenuBar(QMenuBar * qmb, GuiView * view);
 
        /// \return a top-level submenu given its name.
        Menu * menu(QString const & name, GuiView & view);