mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
several menu improvements. JMarc, I get a crash in expand when I'm
trying to disable a submenu label ... Still need to implement the "special" menu items git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4739 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4ef66c42fc
commit
63ae707688
@ -1,3 +1,8 @@
|
||||
2002-07-22 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* Menubar_pimpl.h:
|
||||
* Menubar_pimpl.C: implement check/disable, submenus
|
||||
|
||||
2002-07-22 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* Toolbar_pimpl.h:
|
||||
|
@ -38,6 +38,28 @@ using std::max;
|
||||
using std::min;
|
||||
using std::for_each;
|
||||
|
||||
namespace {
|
||||
|
||||
string const getLabel(MenuItem const & mi)
|
||||
{
|
||||
string const shortcut = mi.shortcut();
|
||||
string label = mi.label();
|
||||
|
||||
label = subst(label, "&", "&&");
|
||||
|
||||
if (shortcut.empty())
|
||||
return label;
|
||||
|
||||
string::size_type pos = label.find(shortcut);
|
||||
if (pos == string::npos)
|
||||
return label;
|
||||
label.insert(pos, "&");
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef vector<int>::size_type size_type;
|
||||
|
||||
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
|
||||
@ -57,37 +79,96 @@ Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe)
|
||||
|
||||
void Menubar::Pimpl::makeMenu(QMenuData * parent, MenuItem const & menu)
|
||||
{
|
||||
// FIXME: leak
|
||||
// FIXME: does this leak or not ?
|
||||
QPopupMenu * pm = new QPopupMenu();
|
||||
parent->insertItem(menu.label().c_str(), pm);
|
||||
int const parentid = parent->insertItem(getLabel(menu).c_str(), pm);
|
||||
|
||||
Menu md;
|
||||
menubackend_.getMenu(menu.submenu()).expand(md, 0);
|
||||
Menu::const_iterator m = md.begin();
|
||||
Menu::const_iterator end = md.end();
|
||||
for (; m != end; ++m) {
|
||||
// FIXME: handle the special stuff here
|
||||
if (m->kind() == MenuItem::Separator) {
|
||||
pm->insertSeparator();
|
||||
} else if (m->kind() == MenuItem::Submenu) {
|
||||
makeMenu(pm, *m);
|
||||
} else {
|
||||
pm->insertItem(m->label().c_str(), m->action());
|
||||
}
|
||||
pm->insertItem(getLabel(*m).c_str(), m->action());
|
||||
MenuItemInfo const info(pm, m->action(), m);
|
||||
items_[m->label()] = info;
|
||||
updateItem(info);
|
||||
}
|
||||
}
|
||||
|
||||
MenuItemInfo const info(parent, parentid, &menu);
|
||||
items_[menu.label()] = info;
|
||||
updateSubmenu(info);
|
||||
}
|
||||
|
||||
|
||||
// FIXME: this is probably buggy with respect to enabling
|
||||
// two-level submenus
|
||||
void Menubar::Pimpl::updateSubmenu(MenuItemInfo const & i)
|
||||
{
|
||||
bool enable = true;
|
||||
#if 0
|
||||
bool enable = false;
|
||||
Menu md;
|
||||
// FIXME FIXME SEGFAULTS
|
||||
menubackend_.getMenu(i.item_->submenu()).expand(md, 0);
|
||||
Menu::const_iterator m = md.begin();
|
||||
Menu::const_iterator end = md.end();
|
||||
for (; m != end; ++m) {
|
||||
if (m->action() > 0) {
|
||||
FuncStatus const status =
|
||||
owner_->getLyXFunc()->getStatus(m->action());
|
||||
if (!status.disabled())
|
||||
enable = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
i.parent_->setItemEnabled(i.id_, enable);
|
||||
}
|
||||
|
||||
|
||||
void Menubar::Pimpl::updateItem(MenuItemInfo const & i)
|
||||
{
|
||||
if (i.item_->kind() == MenuItem::Submenu) {
|
||||
updateSubmenu(i);
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME
|
||||
if (i.id_ < 0)
|
||||
return;
|
||||
|
||||
FuncStatus const status = owner_->getLyXFunc()->getStatus(i.id_);
|
||||
i.parent_->setItemEnabled(i.id_, !status.disabled());
|
||||
i.parent_->setItemChecked(i.id_, status.onoff(true));
|
||||
}
|
||||
|
||||
|
||||
void Menubar::Pimpl::update()
|
||||
{
|
||||
// FIXME: handle special stuff to be updated.
|
||||
|
||||
ItemMap::const_iterator cit = items_.begin();
|
||||
ItemMap::const_iterator end = items_.end();
|
||||
|
||||
for (; cit != end; ++cit)
|
||||
updateItem(cit->second);
|
||||
}
|
||||
|
||||
|
||||
void Menubar::Pimpl::openByName(string const & name)
|
||||
{
|
||||
lyxerr << "Menubar::Pimpl::openByName: menu " << name << endl;
|
||||
|
||||
#if 0
|
||||
if (menubackend_->getMenu(current_menu_name_).hasSubmenu(name)) {
|
||||
for (ButtonList::const_iterator cit = buttonlist_.begin();
|
||||
cit != buttonlist_.end(); ++cit) {
|
||||
if ((*cit)->item_->submenu() == name) {
|
||||
MenuCallback((*cit)->obj_, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ItemMap::iterator it = items_.find(name);
|
||||
|
||||
if (it == items_.end())
|
||||
lyxerr << "NOT FOUND " << name << endl;
|
||||
|
||||
// FIXME
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -25,7 +24,6 @@
|
||||
#include "LString.h"
|
||||
#include "frontends/Menubar.h"
|
||||
#include "commandtags.h"
|
||||
//#include "MenuBackend.h"
|
||||
|
||||
class LyXView;
|
||||
class QtView;
|
||||
@ -34,22 +32,56 @@ class Menu;
|
||||
class MenuItem;
|
||||
class MenuBackend;
|
||||
|
||||
struct Menubar::Pimpl {
|
||||
public:
|
||||
///
|
||||
Pimpl(LyXView *, MenuBackend const &);
|
||||
/// Opens a top-level submenu given its name
|
||||
void openByName(string const &);
|
||||
|
||||
/// update the state of the menuitems
|
||||
void update() {}
|
||||
|
||||
private:
|
||||
void makeMenu(QMenuData * parent, MenuItem const & menu);
|
||||
/// stored state for menu items
|
||||
struct MenuItemInfo {
|
||||
// I REALLY hate this stupid requirement of std::map
|
||||
MenuItemInfo::MenuItemInfo()
|
||||
: parent_(0), id_(0), item_(0) {};
|
||||
|
||||
QtView * owner_;
|
||||
|
||||
MenuBackend const & menubackend_;
|
||||
MenuItemInfo::MenuItemInfo(QMenuData * p, int id, MenuItem const * item)
|
||||
: parent_(p), id_(id), item_(item) {};
|
||||
|
||||
/// menu containing item
|
||||
QMenuData * parent_;
|
||||
|
||||
/// id in containing menu
|
||||
int id_;
|
||||
|
||||
/// LyX info for item
|
||||
MenuItem const * item_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct Menubar::Pimpl {
|
||||
public:
|
||||
Pimpl(LyXView *, MenuBackend const &);
|
||||
|
||||
/// opens a top-level submenu given its name
|
||||
void openByName(string const &);
|
||||
|
||||
/// update the state of the menuitems
|
||||
void update();
|
||||
|
||||
private:
|
||||
/// create a menu
|
||||
void makeMenu(QMenuData * parent, MenuItem const & menu);
|
||||
|
||||
/// special handling updating a submenu label
|
||||
void updateSubmenu(MenuItemInfo const & i);
|
||||
|
||||
/// update an individual item, returns true if enabled
|
||||
void updateItem(MenuItemInfo const & i);
|
||||
|
||||
/// owning view
|
||||
QtView * owner_;
|
||||
|
||||
/// menu controller
|
||||
MenuBackend const & menubackend_;
|
||||
|
||||
typedef std::map<string, MenuItemInfo> ItemMap;
|
||||
|
||||
/// menu items
|
||||
ItemMap items_;
|
||||
};
|
||||
|
||||
#endif // MENUBAR_PIMPL_H
|
||||
|
@ -53,6 +53,9 @@ QtView::QtView(unsigned int width, unsigned int height)
|
||||
|
||||
qApp->setMainWidget(this);
|
||||
|
||||
bufferview_.reset(new BufferView(this, 0, 0, width, height));
|
||||
::current_view = bufferview_.get();
|
||||
|
||||
menubar_.reset(new Menubar(this, menubackend));
|
||||
|
||||
connect(menuBar(), SIGNAL(activated(int)),
|
||||
@ -63,9 +66,6 @@ QtView::QtView(unsigned int width, unsigned int height)
|
||||
|
||||
statusBar()->setSizeGripEnabled(false);
|
||||
|
||||
bufferview_.reset(new BufferView(this, 0, 0, width, height));
|
||||
::current_view = bufferview_.get();
|
||||
|
||||
view_state_changed.connect(boost::bind(&QtView::update_view_state, this));
|
||||
connect(&idle_timer_, SIGNAL(timeout()), this, SLOT(update_view_state_qt()));
|
||||
|
||||
|
@ -15,15 +15,12 @@ lyx_gui (qt)
|
||||
|
||||
Menubar_pimpl
|
||||
|
||||
- remove menubar-switching as discussed
|
||||
- implement menu key shortcuts
|
||||
- implement on/off switches in menus, enable/disable
|
||||
- parse the submenus (*)
|
||||
- fix disabling submenu labels when appropriate
|
||||
- implement dynamic menus (may need serious backend changes) (*)(*)
|
||||
- dynamic last files
|
||||
- import/export/view/update
|
||||
- navigate
|
||||
- remove openByName
|
||||
- implement openByName
|
||||
|
||||
QAbout
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user