mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Simplify MenuBackend and menubar interactions.
* GuiMenubar: freed from GuiView and QMenuBar, renamed to 'Menus' * GuiView: just use the standard QMenuBar. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22308 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
cfb1d4027b
commit
722329490b
@ -738,7 +738,6 @@ src_frontends_qt4_header_files = Split('''
|
|||||||
GuiLog.h
|
GuiLog.h
|
||||||
GuiMath.h
|
GuiMath.h
|
||||||
GuiMathMatrix.h
|
GuiMathMatrix.h
|
||||||
GuiMenubar.h
|
|
||||||
GuiNomencl.h
|
GuiNomencl.h
|
||||||
GuiNote.h
|
GuiNote.h
|
||||||
GuiPainter.h
|
GuiPainter.h
|
||||||
@ -771,6 +770,7 @@ src_frontends_qt4_header_files = Split('''
|
|||||||
LaTeXHighlighter.h
|
LaTeXHighlighter.h
|
||||||
LengthCombo.h
|
LengthCombo.h
|
||||||
LyXFileDialog.h
|
LyXFileDialog.h
|
||||||
|
Menus.h
|
||||||
PanelStack.h
|
PanelStack.h
|
||||||
TocModel.h
|
TocModel.h
|
||||||
TocWidget.h
|
TocWidget.h
|
||||||
@ -826,7 +826,6 @@ src_frontends_qt4_files = Split('''
|
|||||||
GuiLog.cpp
|
GuiLog.cpp
|
||||||
GuiMath.cpp
|
GuiMath.cpp
|
||||||
GuiMathMatrix.cpp
|
GuiMathMatrix.cpp
|
||||||
GuiMenubar.cpp
|
|
||||||
GuiNomencl.cpp
|
GuiNomencl.cpp
|
||||||
GuiNote.cpp
|
GuiNote.cpp
|
||||||
GuiPainter.cpp
|
GuiPainter.cpp
|
||||||
@ -859,6 +858,7 @@ src_frontends_qt4_files = Split('''
|
|||||||
LengthCombo.cpp
|
LengthCombo.cpp
|
||||||
LaTeXHighlighter.cpp
|
LaTeXHighlighter.cpp
|
||||||
LyXFileDialog.cpp
|
LyXFileDialog.cpp
|
||||||
|
Menus.h
|
||||||
PanelStack.cpp
|
PanelStack.cpp
|
||||||
TocModel.cpp
|
TocModel.cpp
|
||||||
TocWidget.cpp
|
TocWidget.cpp
|
||||||
|
@ -17,11 +17,10 @@
|
|||||||
#include "GuiFontLoader.h"
|
#include "GuiFontLoader.h"
|
||||||
#include "GuiClipboard.h"
|
#include "GuiClipboard.h"
|
||||||
#include "GuiSelection.h"
|
#include "GuiSelection.h"
|
||||||
|
#include "Menus.h"
|
||||||
|
|
||||||
#include "frontends/Application.h"
|
#include "frontends/Application.h"
|
||||||
|
|
||||||
#include "MenuBackend.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
@ -64,8 +63,8 @@ public:
|
|||||||
virtual Clipboard & clipboard();
|
virtual Clipboard & clipboard();
|
||||||
virtual Selection & selection();
|
virtual Selection & selection();
|
||||||
virtual FontLoader & fontLoader() { return font_loader_; }
|
virtual FontLoader & fontLoader() { return font_loader_; }
|
||||||
MenuBackend const & menuBackend() const { return menu_backend_; }
|
MenuBackend const & menuBackend() const { return menus_; }
|
||||||
MenuBackend & menuBackend() { return menu_backend_; }
|
MenuBackend & menuBackend() { return menus_; }
|
||||||
virtual int exec();
|
virtual int exec();
|
||||||
virtual void exit(int status);
|
virtual void exit(int status);
|
||||||
virtual bool event(QEvent * e);
|
virtual bool event(QEvent * e);
|
||||||
@ -76,6 +75,8 @@ public:
|
|||||||
void unregisterSocketCallback(int fd);
|
void unregisterSocketCallback(int fd);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
Menus const & menus() const { return menus_; }
|
||||||
|
Menus & menus() { return menus_; }
|
||||||
/// Methods inherited from \c QApplication class
|
/// Methods inherited from \c QApplication class
|
||||||
//@{
|
//@{
|
||||||
bool notify(QObject * receiver, QEvent * event);
|
bool notify(QObject * receiver, QEvent * event);
|
||||||
@ -140,7 +141,7 @@ private:
|
|||||||
///
|
///
|
||||||
std::map<int, SocketNotifier *> socket_notifiers_;
|
std::map<int, SocketNotifier *> socket_notifiers_;
|
||||||
///
|
///
|
||||||
MenuBackend menu_backend_;
|
Menus menus_;
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
public:
|
public:
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
#include "GuiApplication.h"
|
#include "GuiApplication.h"
|
||||||
#include "GuiWorkArea.h"
|
#include "GuiWorkArea.h"
|
||||||
#include "GuiKeySymbol.h"
|
#include "GuiKeySymbol.h"
|
||||||
#include "GuiMenubar.h"
|
|
||||||
#include "GuiToolbar.h"
|
#include "GuiToolbar.h"
|
||||||
#include "GuiToolbars.h"
|
#include "GuiToolbars.h"
|
||||||
|
#include "Menus.h"
|
||||||
|
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
@ -165,7 +165,6 @@ struct GuiView::GuiViewPrivate
|
|||||||
delete splitter_;
|
delete splitter_;
|
||||||
delete bg_widget_;
|
delete bg_widget_;
|
||||||
delete stack_widget_;
|
delete stack_widget_;
|
||||||
delete menubar_;
|
|
||||||
delete toolbars_;
|
delete toolbars_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,8 +241,6 @@ public:
|
|||||||
QSplitter * splitter_;
|
QSplitter * splitter_;
|
||||||
QStackedWidget * stack_widget_;
|
QStackedWidget * stack_widget_;
|
||||||
BackgroundWidget * bg_widget_;
|
BackgroundWidget * bg_widget_;
|
||||||
/// view's menubar
|
|
||||||
GuiMenubar * menubar_;
|
|
||||||
/// view's toolbars
|
/// view's toolbars
|
||||||
GuiToolbars * toolbars_;
|
GuiToolbars * toolbars_;
|
||||||
/// The main layout box.
|
/// The main layout box.
|
||||||
@ -280,9 +277,11 @@ public:
|
|||||||
GuiView::GuiView(int id)
|
GuiView::GuiView(int id)
|
||||||
: d(*new GuiViewPrivate), id_(id)
|
: d(*new GuiViewPrivate), id_(id)
|
||||||
{
|
{
|
||||||
// GuiToolbars *must* be initialised before GuiMenubar.
|
// GuiToolbars *must* be initialised before the menu bar.
|
||||||
d.toolbars_ = new GuiToolbars(*this);
|
d.toolbars_ = new GuiToolbars(*this);
|
||||||
d.menubar_ = new GuiMenubar(this);
|
|
||||||
|
// Fill up the menu bar.
|
||||||
|
guiApp->menus().fillMenuBar(this);
|
||||||
|
|
||||||
setCentralWidget(d.stack_widget_);
|
setCentralWidget(d.stack_widget_);
|
||||||
|
|
||||||
@ -1366,7 +1365,7 @@ bool GuiView::dispatch(FuncRequest const & cmd)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_MENU_OPEN:
|
case LFUN_MENU_OPEN:
|
||||||
d.menubar_->openByName(toqstr(cmd.argument()));
|
guiApp->menus().openByName(toqstr(cmd.argument()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_FILE_INSERT:
|
case LFUN_FILE_INSERT:
|
||||||
@ -1596,7 +1595,7 @@ void GuiView::resetDialogs()
|
|||||||
// Make sure that no LFUN uses any LyXView.
|
// Make sure that no LFUN uses any LyXView.
|
||||||
theLyXFunc().setLyXView(0);
|
theLyXFunc().setLyXView(0);
|
||||||
d.toolbars_->init();
|
d.toolbars_->init();
|
||||||
d.menubar_->init();
|
guiApp->menus().fillMenuBar(this);
|
||||||
if (d.layout_)
|
if (d.layout_)
|
||||||
d.layout_->updateContents(true);
|
d.layout_->updateContents(true);
|
||||||
// Now update controls with current buffer.
|
// Now update controls with current buffer.
|
||||||
|
@ -94,7 +94,6 @@ SOURCEFILES = \
|
|||||||
GuiLog.cpp \
|
GuiLog.cpp \
|
||||||
GuiMath.cpp \
|
GuiMath.cpp \
|
||||||
GuiMathMatrix.cpp \
|
GuiMathMatrix.cpp \
|
||||||
GuiMenubar.cpp \
|
|
||||||
GuiNomencl.cpp \
|
GuiNomencl.cpp \
|
||||||
GuiNote.cpp \
|
GuiNote.cpp \
|
||||||
GuiPainter.cpp \
|
GuiPainter.cpp \
|
||||||
@ -127,6 +126,7 @@ SOURCEFILES = \
|
|||||||
LengthCombo.cpp \
|
LengthCombo.cpp \
|
||||||
LyXFileDialog.cpp \
|
LyXFileDialog.cpp \
|
||||||
LaTeXHighlighter.cpp \
|
LaTeXHighlighter.cpp \
|
||||||
|
Menus.cpp \
|
||||||
PanelStack.cpp \
|
PanelStack.cpp \
|
||||||
qt_helpers.cpp \
|
qt_helpers.cpp \
|
||||||
TocModel.cpp \
|
TocModel.cpp \
|
||||||
@ -181,7 +181,6 @@ MOCHEADER = \
|
|||||||
GuiListings.h \
|
GuiListings.h \
|
||||||
GuiLog.h \
|
GuiLog.h \
|
||||||
GuiMathMatrix.h \
|
GuiMathMatrix.h \
|
||||||
GuiMenubar.h \
|
|
||||||
GuiNomencl.h \
|
GuiNomencl.h \
|
||||||
GuiNote.h \
|
GuiNote.h \
|
||||||
GuiParagraph.h \
|
GuiParagraph.h \
|
||||||
@ -212,6 +211,7 @@ MOCHEADER = \
|
|||||||
LengthCombo.h \
|
LengthCombo.h \
|
||||||
LyXFileDialog.h \
|
LyXFileDialog.h \
|
||||||
LaTeXHighlighter.h \
|
LaTeXHighlighter.h \
|
||||||
|
Menus.h \
|
||||||
PanelStack.h \
|
PanelStack.h \
|
||||||
qlkey.h \
|
qlkey.h \
|
||||||
TocModel.h \
|
TocModel.h \
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* \file qt4/GuiMenubar.cpp
|
* \file qt4/Menus.cpp
|
||||||
* This file is part of LyX, the document processor.
|
* This file is part of LyX, the document processor.
|
||||||
* Licence details can be found in the file COPYING.
|
* Licence details can be found in the file COPYING.
|
||||||
*
|
*
|
||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "GuiMenubar.h"
|
#include "Menus.h"
|
||||||
|
|
||||||
#include "Action.h"
|
#include "Action.h"
|
||||||
#include "GuiApplication.h"
|
#include "GuiApplication.h"
|
||||||
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
#include "MenuBackend.h"
|
|
||||||
|
|
||||||
#include "support/debug.h"
|
#include "support/debug.h"
|
||||||
|
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
@ -32,40 +30,30 @@ namespace frontend {
|
|||||||
|
|
||||||
// MacOSX specific stuff is at the end.
|
// MacOSX specific stuff is at the end.
|
||||||
|
|
||||||
GuiMenubar::GuiMenubar(GuiView * view)
|
void Menus::fillMenuBar(GuiView * view)
|
||||||
: owner_(view)
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GuiMenubar::init()
|
|
||||||
{
|
{
|
||||||
// Clear all menubar contents before filling it.
|
// Clear all menubar contents before filling it.
|
||||||
owner_->menuBar()->clear();
|
view->menuBar()->clear();
|
||||||
|
|
||||||
#ifdef Q_WS_MACX
|
#ifdef Q_WS_MACX
|
||||||
// setup special mac specific menu item
|
// setup special mac specific menu item
|
||||||
macxMenuBarInit();
|
macxMenuBarInit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// menu controller
|
LYXERR(Debug::GUI, "populating menu bar" << to_utf8(getMenubar().name()));
|
||||||
MenuBackend & menu_backend = guiApp->menuBackend();
|
|
||||||
LYXERR(Debug::GUI, "populating menu bar" << to_utf8(menu_backend.getMenubar().name()));
|
|
||||||
|
|
||||||
if (menu_backend.getMenubar().size() == 0) {
|
if (getMenubar().size() == 0) {
|
||||||
LYXERR(Debug::GUI, "\tERROR: empty menu bar"
|
LYXERR(Debug::GUI, "\tERROR: empty menu bar"
|
||||||
<< to_utf8(menu_backend.getMenubar().name()));
|
<< to_utf8(getMenubar().name()));
|
||||||
return;
|
return;
|
||||||
// continue;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LYXERR(Debug::GUI, "menu bar entries "
|
LYXERR(Debug::GUI, "menu bar entries "
|
||||||
<< menu_backend.getMenubar().size());
|
<< getMenubar().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu menu;
|
Menu menu;
|
||||||
menu_backend.expand(menu_backend.getMenubar(), menu, owner_->buffer());
|
expand(getMenubar(), menu, view->buffer());
|
||||||
|
|
||||||
Menu::const_iterator m = menu.begin();
|
Menu::const_iterator m = menu.begin();
|
||||||
Menu::const_iterator end = menu.end();
|
Menu::const_iterator end = menu.end();
|
||||||
@ -81,26 +69,24 @@ void GuiMenubar::init()
|
|||||||
<< " is a submenu named " << to_utf8(m->submenuname()));
|
<< " is a submenu named " << to_utf8(m->submenuname()));
|
||||||
|
|
||||||
docstring name = m->submenuname();
|
docstring name = m->submenuname();
|
||||||
if (!menu_backend.hasMenu(name)) {
|
if (!hasMenu(name)) {
|
||||||
LYXERR(Debug::GUI, "\tERROR: " << to_utf8(name)
|
LYXERR(Debug::GUI, "\tERROR: " << to_utf8(name)
|
||||||
<< " submenu has no menu!");
|
<< " submenu has no menu!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu menu;
|
Menu menu;
|
||||||
menu_backend.expand(menu_backend.getMenubar(), menu, owner_->buffer());
|
expand(getMenubar(), menu, view->buffer());
|
||||||
|
|
||||||
GuiPopupMenu * qMenu = new GuiPopupMenu(owner_, *m, true);
|
GuiPopupMenu * qMenu = new GuiPopupMenu(view, *m, true);
|
||||||
owner_->menuBar()->addMenu(qMenu);
|
view->menuBar()->addMenu(qMenu);
|
||||||
|
|
||||||
name_map_[toqstr(name)] = qMenu;
|
name_map_[toqstr(name)] = qMenu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GuiMenubar::~GuiMenubar() {}
|
void Menus::openByName(QString const & name)
|
||||||
|
|
||||||
void GuiMenubar::openByName(QString const & name)
|
|
||||||
{
|
{
|
||||||
if (QMenu * menu = name_map_.value(name))
|
if (QMenu * menu = name_map_.value(name))
|
||||||
menu->exec(QCursor::pos());
|
menu->exec(QCursor::pos());
|
||||||
@ -131,7 +117,7 @@ void GuiMenubar::openByName(QString const & name)
|
|||||||
focus. (JMarc)
|
focus. (JMarc)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void GuiMenubar::macxMenuBarInit()
|
void Menus::macxMenuBarInit(GuiView * view)
|
||||||
{
|
{
|
||||||
/* Since Qt 4.2, the qt/mac menu code has special code for
|
/* Since Qt 4.2, the qt/mac menu code has special code for
|
||||||
specifying the role of a menu entry. However, it does not
|
specifying the role of a menu entry. However, it does not
|
||||||
@ -174,20 +160,19 @@ void GuiMenubar::macxMenuBarInit()
|
|||||||
from_utf8(entries[i].label),
|
from_utf8(entries[i].label),
|
||||||
func));
|
func));
|
||||||
}
|
}
|
||||||
MenuBackend & menu_backend = guiApp->menuBackend();
|
specialMenu(special);
|
||||||
menu_backend.specialMenu(special);
|
|
||||||
|
|
||||||
// add the entries to a QMenu that will eventually be empty
|
// add the entries to a QMenu that will eventually be empty
|
||||||
// and therefore invisible.
|
// and therefore invisible.
|
||||||
QMenu * qMenu = owner_->menuBar()->addMenu("special");
|
QMenu * qMenu = view->menuBar()->addMenu("special");
|
||||||
|
|
||||||
// we do not use 'special' because it is a temporary variable,
|
// we do not use 'special' because it is a temporary variable,
|
||||||
// whereas MenuBackend::specialMenu points to a persistent
|
// whereas MenuBackend::specialMenu points to a persistent
|
||||||
// copy.
|
// copy.
|
||||||
Menu::const_iterator cit = menu_backend.specialMenu().begin();
|
Menu::const_iterator cit = specialMenu().begin();
|
||||||
Menu::const_iterator end = menu_backend.specialMenu().end();
|
Menu::const_iterator end = specialMenu().end();
|
||||||
for (size_t i = 0 ; cit != end ; ++cit, ++i) {
|
for (size_t i = 0 ; cit != end ; ++cit, ++i) {
|
||||||
Action * action = new Action(*owner_, QIcon(),
|
Action * action = new Action(*view, QIcon(),
|
||||||
toqstr(cit->label()),
|
toqstr(cit->label()),
|
||||||
cit->func(), QString());
|
cit->func(), QString());
|
||||||
action->setMenuRole(entries[i].role);
|
action->setMenuRole(entries[i].role);
|
||||||
@ -199,4 +184,4 @@ void GuiMenubar::macxMenuBarInit()
|
|||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
#include "GuiMenubar_moc.cpp"
|
#include "Menus_moc.cpp"
|
@ -1,6 +1,6 @@
|
|||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
/**
|
/**
|
||||||
* \file GuiMenubar.h
|
* \file Menus.h
|
||||||
* This file is part of LyX, the document processor.
|
* This file is part of LyX, the document processor.
|
||||||
* Licence details can be found in the file COPYING.
|
* Licence details can be found in the file COPYING.
|
||||||
*
|
*
|
||||||
@ -10,14 +10,14 @@
|
|||||||
* Full author contact details are available in file CREDITS.
|
* Full author contact details are available in file CREDITS.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef GUIMENUBAR_H
|
#ifndef MENUS_H
|
||||||
#define GUIMENUBAR_H
|
#define MENUS_H
|
||||||
|
|
||||||
|
#include "MenuBackend.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
class QMenuBar;
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
@ -25,32 +25,24 @@ class GuiView;
|
|||||||
class GuiPopupMenu;
|
class GuiPopupMenu;
|
||||||
class GuiView;
|
class GuiView;
|
||||||
|
|
||||||
class GuiMenubar : public QObject
|
class Menus : public QObject, public MenuBackend
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GuiMenubar(GuiView *);
|
Menus() {}
|
||||||
|
|
||||||
~GuiMenubar();
|
|
||||||
|
|
||||||
///
|
///
|
||||||
void init();
|
void fillMenuBar(GuiView * view);
|
||||||
|
|
||||||
/// opens a top-level submenu given its name
|
/// opens a top-level submenu given its name
|
||||||
void openByName(QString const & name);
|
void openByName(QString const & name);
|
||||||
|
|
||||||
/// return the owning view
|
|
||||||
GuiView * view() { return owner_; }
|
|
||||||
|
|
||||||
/// update the state of the menuitems - not needed
|
/// update the state of the menuitems - not needed
|
||||||
void updateView();
|
void updateView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Initialize specific MACOS X menubar
|
/// Initialize specific MACOS X menubar
|
||||||
void macxMenuBarInit();
|
void macxMenuBarInit(GuiView * view);
|
||||||
|
|
||||||
/// owning view
|
|
||||||
GuiView * owner_;
|
|
||||||
|
|
||||||
typedef QHash<QString, GuiPopupMenu *> NameMap;
|
typedef QHash<QString, GuiPopupMenu *> NameMap;
|
||||||
|
|
||||||
@ -61,4 +53,4 @@ private:
|
|||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
#endif // GUIMENUBAR_H
|
#endif // MENUS_H
|
Loading…
Reference in New Issue
Block a user