From e13cc7e90df58a893c6cfce955bf23ec60fb22ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 6 Mar 2008 21:50:27 +0000 Subject: [PATCH] start moving MenuBackend to the frontend git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23523 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyX.cpp | 4 ++-- src/Makefile.am | 4 ++-- src/MenuBackend.cpp | 14 +++++++------- src/MenuBackend.h | 4 ++-- src/frontends/Application.h | 12 ++++++++++++ src/frontends/qt4/GuiApplication.cpp | 15 ++++++++++++++- src/frontends/qt4/GuiApplication.h | 2 ++ src/insets/InsetInfo.cpp | 17 +++++++---------- src/insets/InsetInfo.h | 3 ++- 9 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index 56cf176cf1..041b5e3c3d 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -28,13 +28,13 @@ #include "Encoding.h" #include "ErrorList.h" #include "Format.h" +#include "FuncStatus.h" #include "KeyMap.h" #include "Language.h" #include "Lexer.h" #include "LyXAction.h" #include "LyXFunc.h" #include "LyXRC.h" -#include "MenuBackend.h" #include "ModuleList.h" #include "Mover.h" #include "Server.h" @@ -1080,7 +1080,7 @@ bool LyX::readUIFile(string const & name, bool include) break; } case ui_menuset: - theApp()->menuBackend().read(lex); + theApp()->readMenus(lex); break; case ui_toolbarset: diff --git a/src/Makefile.am b/src/Makefile.am index f8b6a2ee52..005acf0209 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,6 +63,8 @@ lyx_SOURCES = \ $(ASPELL) $(PSPELL) $(ISPELL) SpellBase.cpp \ Box.cpp \ Box.h \ + MenuBackend.cpp \ + MenuBackend.h \ Dimension.cpp \ Dimension.h \ PrinterParams.cpp \ @@ -132,7 +134,6 @@ SOURCEFILESCORE = \ LyXFunc.cpp \ LyXRC.cpp \ LyXVC.cpp \ - MenuBackend.cpp \ MetricsInfo.cpp \ ModuleList.cpp \ Mover.cpp \ @@ -234,7 +235,6 @@ HEADERFILESCORE = \ LyX.h \ LyXRC.h \ LyXVC.h \ - MenuBackend.h \ MetricsInfo.h \ ModuleList.h \ Mover.h \ diff --git a/src/MenuBackend.cpp b/src/MenuBackend.cpp index de7172f5d0..4409135c4d 100644 --- a/src/MenuBackend.cpp +++ b/src/MenuBackend.cpp @@ -404,21 +404,21 @@ void Menu::checkShortcuts() const } -bool Menu::searchFunc(FuncRequest & func, stack & names) const +bool Menu::searchMenu(FuncRequest const & func, vector & names) const { const_iterator m = begin(); const_iterator m_end = end(); for (; m != m_end; ++m) { if (m->kind() == MenuItem::Command && m->func() == func) { - names.push(m->label()); + names.push_back(m->label()); return true; - } else if (m->kind() == MenuItem::Submenu) { - names.push(m->label()); + } + if (m->kind() == MenuItem::Submenu) { + names.push_back(m->label()); Menu submenu = theApp()->menuBackend().getMenu(m->submenuname()); - if (submenu.searchFunc(func, names)) + if (submenu.searchMenu(func, names)) return true; - else - names.pop(); + names.pop_back(); } } return false; diff --git a/src/MenuBackend.h b/src/MenuBackend.h index 33e9d57b45..65c2d97398 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -19,7 +19,6 @@ #include #include -#include namespace lyx { @@ -187,7 +186,8 @@ public: // search for func in this menu iteratively, and put menu // names in a stack. - bool searchFunc(FuncRequest & func, std::stack & names) const; + bool searchMenu(FuncRequest const & func, std::vector & names) + const; private: friend class MenuBackend; diff --git a/src/frontends/Application.h b/src/frontends/Application.h index 997d41a5af..ebb98e9aff 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -14,9 +14,12 @@ #include "ColorCode.h" #include "support/strfwd.h" +#include "support/docstring.h" #include +#include + namespace lyx { @@ -25,6 +28,7 @@ class Buffer; class FuncRequest; class FuncStatus; class Inset; +class Lexer; class MenuBackend; struct RGBColor; @@ -211,6 +215,11 @@ public: */ virtual void updateColor(ColorCode col) = 0; + /** + * read and create the menu structure + */ + virtual void readMenus(Lexer & lex) = 0; + /** * add a callback for socket read notification * @param fd socket descriptor (file/socket/etc) @@ -227,6 +236,9 @@ public: /// virtual MenuBackend const & menuBackend() const = 0; virtual MenuBackend & menuBackend() = 0; + + virtual bool searchMenu(FuncRequest const & func, + std::vector & names) const = 0; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 693a396d50..0beb0f7c24 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -29,7 +29,6 @@ #include "Font.h" #include "FuncRequest.h" #include "FuncStatus.h" -#include "support/gettext.h" #include "LyX.h" #include "LyXFunc.h" #include "LyXRC.h" @@ -40,6 +39,7 @@ #include "support/ExceptionMessage.h" #include "support/FileName.h" #include "support/ForkedCalls.h" +#include "support/gettext.h" #include "support/lstrings.h" #include "support/os.h" #include "support/Package.h" @@ -649,6 +649,19 @@ Buffer const * GuiApplication::updateInset(Inset const * inset) const } +void GuiApplication::readMenus(Lexer & lex) +{ + menuBackend().read(lex); +} + + +bool GuiApplication::searchMenu(FuncRequest const & func, + vector & names) const +{ + return menuBackend().getMenubar().searchMenu(func, names); +} + + //////////////////////////////////////////////////////////////////////// // X11 specific stuff goes here... #ifdef Q_WS_X11 diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 29b522b647..5460de3bc8 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -73,8 +73,10 @@ public: virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol); virtual std::string const hexName(ColorCode col); virtual void updateColor(ColorCode col); + virtual void readMenus(Lexer & lex); virtual void registerSocketCallback(int fd, SocketCallback func); void unregisterSocketCallback(int fd); + bool searchMenu(FuncRequest const & func, std::vector & names) const; //@} Menus const & menus() const { return menus_; } diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index dd4afdeafb..910052f5a4 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -11,9 +11,6 @@ #include "InsetInfo.h" -#include -#include - #include "BaseClassList.h" #include "Buffer.h" #include "BufferParams.h" @@ -25,7 +22,6 @@ #include "LyXAction.h" #include "LyXRC.h" #include "Lexer.h" -#include "MenuBackend.h" #include "MetricsInfo.h" #include "ParagraphParameters.h" @@ -38,6 +34,8 @@ #include "support/lstrings.h" #include "support/ExceptionMessage.h" +#include + using namespace std; using namespace lyx::support; @@ -207,15 +205,14 @@ void InsetInfo::updateInfo() break; } case MENU_INFO: { - stack names; + vector names; FuncRequest func = lyxaction.lookupFunc(name_); if (func.action == LFUN_UNKNOWN_ACTION) { setText(_("No menu entry for "), bp.getFont(), false); break; } // iterate through the menubackend to find it - Menu menu = theApp()->menuBackend().getMenubar(); - if (!menu.searchFunc(func, names)) { + if (!theApp()->searchMenu(func, names)) { setText(_("No menu entry for "), bp.getFont(), false); break; } @@ -228,9 +225,9 @@ void InsetInfo::updateInfo() if (i != 0) info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR), Change(Change::UNCHANGED)); - for (i = 0; i < names.top().length(); ++i) - info.insertChar(i, names.top()[i], bp.getFont(), false); - names.pop(); + for (i = 0; i != names.back().length(); ++i) + info.insertChar(i, names.back()[i], bp.getFont(), false); + names.pop_back(); } break; } diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index 9a82e13d72..0b5dfd191e 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -14,8 +14,9 @@ #include "InsetText.h" #include "RenderButton.h" -#include "support/gettext.h" #include "Cursor.h" + +#include "support/gettext.h" #include "support/Translator.h" /* InsetInfo displays shortcuts, lyxrc, package and textclass -- 2.39.2