From f560947a18a3841234c8c40b369fc30327872e2c Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 10 Sep 2002 19:23:38 +0000 Subject: [PATCH] fix navigate git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5257 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 6 ++++ src/frontends/qt2/Menubar_pimpl.C | 2 +- src/frontends/qt2/QLPopupMenu.C | 51 ++++++++++++++++++------------- src/frontends/qt2/QLPopupMenu.h | 15 ++++++--- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index d23e086075..0bc3f626dd 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ +2002-09-10 John Levon + + * Menubar_pimpl.C: + * QLPopupMenu.h: + * QLPopupMenu.C: finally fix Navigate + 2002-09-10 John Levon * ui/QIncludeDialog.ui: diff --git a/src/frontends/qt2/Menubar_pimpl.C b/src/frontends/qt2/Menubar_pimpl.C index d0dbb5a9c8..16c0ddcd5e 100644 --- a/src/frontends/qt2/Menubar_pimpl.C +++ b/src/frontends/qt2/Menubar_pimpl.C @@ -44,7 +44,7 @@ Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe) Menu::const_iterator m = mbe.getMenubar().begin(); Menu::const_iterator end = mbe.getMenubar().end(); for (; m != end; ++m) { - createMenu(owner_->menuBar(), &(*m), this); + createMenu(owner_->menuBar(), &(*m), this, true); } } diff --git a/src/frontends/qt2/QLPopupMenu.C b/src/frontends/qt2/QLPopupMenu.C index ed8065215a..795b85d646 100644 --- a/src/frontends/qt2/QLPopupMenu.C +++ b/src/frontends/qt2/QLPopupMenu.C @@ -16,6 +16,9 @@ #include "support/lstrings.h" +using std::pair; +using std::make_pair; + namespace { string const getLabel(MenuItem const & mi) @@ -39,32 +42,31 @@ string const getLabel(MenuItem const & mi) } -int createMenu(QMenuData * parent, MenuItem const * item, Menubar::Pimpl * owner) +pair createMenu(QMenuData * parent, MenuItem const * item, Menubar::Pimpl * owner, bool is_toplevel) { // FIXME: leaks ?? - QLPopupMenu * pm = new QLPopupMenu(owner, item->submenuname()); - return parent->insertItem(getLabel(*item).c_str(), pm); + QLPopupMenu * pm = new QLPopupMenu(owner, item->submenuname(), is_toplevel); + int id = parent->insertItem(getLabel(*item).c_str(), pm); + return make_pair(id, pm); } -QLPopupMenu::QLPopupMenu(Menubar::Pimpl * owner, string const & name) +QLPopupMenu::QLPopupMenu(Menubar::Pimpl * owner, string const & name, bool toplevel) : owner_(owner), name_(name) { - connect(this, SIGNAL(aboutToShow()), this, SLOT(showing())); + if (toplevel) + connect(this, SIGNAL(aboutToShow()), this, SLOT(showing())); } -bool QLPopupMenu::disabled(string const & name) +bool QLPopupMenu::disabled(Menu * menu) { bool disable = true; - Menu tomenu; - Menu const frommenu = owner_->backend().getMenu(name); - owner_->backend().expand(frommenu, tomenu, owner_->view()->buffer()); - Menu::const_iterator m = tomenu.begin(); - Menu::const_iterator end = tomenu.end(); + Menu::const_iterator m = menu->begin(); + Menu::const_iterator end = menu->end(); for (; m != end; ++m) { - if (m->kind() == MenuItem::Submenu && !disabled(m->submenuname())) { + if (m->kind() == MenuItem::Submenu && !disabled(m->submenu())) { disable = false; } else { FuncStatus const status = @@ -77,20 +79,17 @@ bool QLPopupMenu::disabled(string const & name) } -void QLPopupMenu::showing() +void QLPopupMenu::populate(Menu * menu) { - clear(); - Menu tomenu; - Menu const frommenu = owner_->backend().getMenu(name_); - owner_->backend().expand(frommenu, tomenu, owner_->view()->buffer()); - Menu::const_iterator m = tomenu.begin(); - Menu::const_iterator end = tomenu.end(); + Menu::const_iterator m = menu->begin(); + Menu::const_iterator end = menu->end(); for (; m != end; ++m) { if (m->kind() == MenuItem::Separator) { insertSeparator(); } else if (m->kind() == MenuItem::Submenu) { - int id(createMenu(this, m, owner_)); - setItemEnabled(id, !disabled(m->submenuname())); + pair res = createMenu(this, m, owner_); + setItemEnabled(res.first, !disabled(m->submenu())); + res.second->populate(m->submenu()); } else { FuncStatus const status = owner_->view()->getLyXFunc().getStatus(m->action()); @@ -102,3 +101,13 @@ void QLPopupMenu::showing() } } } + + +void QLPopupMenu::showing() +{ + clear(); + Menu tomenu; + Menu const frommenu = owner_->backend().getMenu(name_); + owner_->backend().expand(frommenu, tomenu, owner_->view()->buffer()); + populate(&tomenu); +} diff --git a/src/frontends/qt2/QLPopupMenu.h b/src/frontends/qt2/QLPopupMenu.h index 13cae4475d..c8fd3e2e7a 100644 --- a/src/frontends/qt2/QLPopupMenu.h +++ b/src/frontends/qt2/QLPopupMenu.h @@ -16,26 +16,31 @@ #include "LString.h" class MenuBackend; -class QtView; class MenuItem; +class Menu; class QMenuData; +class QLPopupMenu; /// create a sub-menu -int createMenu(QMenuData * parent, MenuItem const * item, Menubar::Pimpl * owner); +std::pair + createMenu(QMenuData * parent, MenuItem const * item, Menubar::Pimpl * owner, bool is_toplevel = false); /// a submenu class QLPopupMenu : public QPopupMenu { Q_OBJECT public: - QLPopupMenu(Menubar::Pimpl * owner, string const & name); + QLPopupMenu(Menubar::Pimpl * owner, string const & name, bool toplevel); + + /// populate the menu + void populate(Menu * menu); public slots: - /// populate the menu + /// populate the toplevel menu and all children void showing(); private: /// return true if the given submenu is disabled - bool disabled(string const & name); + bool disabled(Menu * menu); /// our owning menubar Menubar::Pimpl * owner_; -- 2.39.2