From 145585dc189203d37dd9eb78e071f8cc2959f82c Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sat, 24 May 2008 09:28:05 +0000 Subject: [PATCH] First step towards fixing bug 4588: move the ui file reading and the ToolbarBackend to the frontend. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24921 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 4 +- src/LyX.cpp | 99 -------------------- src/LyX.h | 2 - src/Makefile.am | 2 - src/frontends/Application.h | 5 - src/frontends/qt4/GuiApplication.cpp | 101 +++++++++++++++++++++ src/frontends/qt4/GuiApplication.h | 3 + src/frontends/qt4/Makefile.am | 4 +- src/{ => frontends/qt4}/ToolbarBackend.cpp | 0 src/{ => frontends/qt4}/ToolbarBackend.h | 0 10 files changed, 109 insertions(+), 111 deletions(-) rename src/{ => frontends/qt4}/ToolbarBackend.cpp (100%) rename src/{ => frontends/qt4}/ToolbarBackend.h (100%) diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 8ac54674f4..2051c1f919 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -115,7 +115,6 @@ src_header_files = Split(''' TextMetrics.h Thesaurus.h TocBackend.h - ToolbarBackend.h Trans.h Undo.h VCBackend.h @@ -210,7 +209,6 @@ src_pre_files = Split(''' TextClass.cpp TextMetrics.cpp TocBackend.cpp - ToolbarBackend.cpp Trans.cpp Undo.cpp VCBackend.cpp @@ -762,6 +760,7 @@ src_frontends_qt4_header_files = Split(''' PanelStack.h TocModel.h TocWidget.h + ToolbarBackend.h Validator.h qt_helpers.h qt_i18n.h @@ -852,6 +851,7 @@ src_frontends_qt4_files = Split(''' PanelStack.cpp TocModel.cpp TocWidget.cpp + ToolbarBackend.cpp Validator.cpp qt_helpers.cpp ''') diff --git a/src/LyX.cpp b/src/LyX.cpp index d7a205db6d..0131eb95f9 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -40,7 +40,6 @@ #include "Server.h" #include "ServerSocket.h" #include "Session.h" -#include "ToolbarBackend.h" #include "frontends/alert.h" #include "frontends/Application.h" @@ -827,10 +826,6 @@ bool LyX::init() pimpl_->lyxfunc_.initKeySequences(&pimpl_->toplevel_keymap_); - // Read menus - if (use_gui && !readUIFile(lyxrc.ui_file)) - return false; - if (lyxerr.debugging(Debug::LYXRC)) lyxrc.print(); @@ -971,100 +966,6 @@ bool LyX::readRcFile(string const & name) return true; } - -// Read the ui file `name' -bool LyX::readUIFile(string const & name, bool include) -{ - enum { - ui_menuset = 1, - ui_toolbars, - ui_toolbarset, - ui_include, - ui_last - }; - - LexerKeyword uitags[] = { - { "include", ui_include }, - { "menuset", ui_menuset }, - { "toolbars", ui_toolbars }, - { "toolbarset", ui_toolbarset } - }; - - // Ensure that a file is read only once (prevents include loops) - static list uifiles; - list::const_iterator it = uifiles.begin(); - list::const_iterator end = uifiles.end(); - it = find(it, end, name); - if (it != end) { - LYXERR(Debug::INIT, "UI file '" << name << "' has been read already. " - << "Is this an include loop?"); - return false; - } - - LYXERR(Debug::INIT, "About to read " << name << "..."); - - - FileName ui_path; - if (include) { - ui_path = libFileSearch("ui", name, "inc"); - if (ui_path.empty()) - ui_path = libFileSearch("ui", - changeExtension(name, "inc")); - } - else - ui_path = libFileSearch("ui", name, "ui"); - - if (ui_path.empty()) { - LYXERR(Debug::INIT, "Could not find " << name); - showFileError(name); - return false; - } - - uifiles.push_back(name); - - LYXERR(Debug::INIT, "Found " << name << " in " << ui_path); - Lexer lex(uitags); - lex.setFile(ui_path); - if (!lex.isOK()) { - lyxerr << "Unable to set LyXLeX for ui file: " << ui_path - << endl; - } - - if (lyxerr.debugging(Debug::PARSER)) - lex.printTable(lyxerr); - - while (lex.isOK()) { - switch (lex.lex()) { - case ui_include: { - lex.next(true); - string const file = lex.getString(); - if (!readUIFile(file, true)) - return false; - break; - } - case ui_menuset: - theApp()->readMenus(lex); - break; - - case ui_toolbarset: - toolbarbackend.readToolbars(lex); - break; - - case ui_toolbars: - toolbarbackend.readToolbarSettings(lex); - break; - - default: - if (!rtrim(lex.getString()).empty()) - lex.printError("LyX::ReadUIFile: " - "Unknown menu tag: `$$Token'"); - break; - } - } - return true; -} - - // Read the languages file `name' bool LyX::readLanguagesFile(string const & name) { diff --git a/src/LyX.h b/src/LyX.h index 3d98e42b8e..5a82c9037c 100644 --- a/src/LyX.h +++ b/src/LyX.h @@ -136,8 +136,6 @@ private: bool queryUserLyXDir(bool explicit_userdir); /// read lyxrc/preferences bool readRcFile(std::string const & name); - /// read the given ui (menu/toolbar) file - bool readUIFile(std::string const & name, bool include = false); /// read the given languages file bool readLanguagesFile(std::string const & name); /// read the encodings. diff --git a/src/Makefile.am b/src/Makefile.am index 7bbfb49446..ef58a1817d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -164,7 +164,6 @@ SOURCEFILESCORE = \ TextClass.cpp \ TextMetrics.cpp \ TocBackend.cpp \ - ToolbarBackend.cpp \ Trans.cpp \ Undo.cpp \ VCBackend.cpp \ @@ -264,7 +263,6 @@ HEADERFILESCORE = \ TextClass.h \ TextMetrics.h \ TocBackend.h \ - ToolbarBackend.h \ Trans.h \ Undo.h \ update_flags.h \ diff --git a/src/frontends/Application.h b/src/frontends/Application.h index 83b57e4efc..4b2299bbbe 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -208,11 +208,6 @@ public: * passing Color_white returns "ffffff". */ virtual std::string const hexName(ColorCode col) = 0; - - /** - * read and create the menu structure - */ - virtual void readMenus(Lexer & lex) = 0; /** * add a callback for socket read notification diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index e379a9556f..80f4fe4483 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -22,6 +22,7 @@ #include "GuiView.h" #include "Menus.h" #include "qt_helpers.h" +#include "ToolbarBackend.h" #include "frontends/alert.h" #include "frontends/Application.h" @@ -36,6 +37,7 @@ #include "FuncRequest.h" #include "FuncStatus.h" #include "Language.h" +#include "Lexer.h" #include "LyX.h" #include "LyXFunc.h" #include "LyXRC.h" @@ -749,6 +751,11 @@ void GuiApplication::exit(int status) void GuiApplication::execBatchCommands() { + // Read menus + if (!readUIFile(lyxrc.ui_file)) + // Gives some error box here. + return; + // init the global menubar on Mac. This must be done after the session // was recovered to know the "last files". if (d->global_menubar_) @@ -1041,6 +1048,100 @@ bool GuiApplication::searchMenu(FuncRequest const & func, } +bool GuiApplication::readUIFile(string const & name, bool include) +{ + enum { + ui_menuset = 1, + ui_toolbars, + ui_toolbarset, + ui_include, + ui_last + }; + + LexerKeyword uitags[] = { + { "include", ui_include }, + { "menuset", ui_menuset }, + { "toolbars", ui_toolbars }, + { "toolbarset", ui_toolbarset } + }; + + // Ensure that a file is read only once (prevents include loops) + static list uifiles; + list::const_iterator it = uifiles.begin(); + list::const_iterator end = uifiles.end(); + it = find(it, end, name); + if (it != end) { + LYXERR(Debug::INIT, "UI file '" << name << "' has been read already. " + << "Is this an include loop?"); + return false; + } + + LYXERR(Debug::INIT, "About to read " << name << "..."); + + + FileName ui_path; + if (include) { + ui_path = libFileSearch("ui", toqstr(name), "inc"); + if (ui_path.empty()) + ui_path = libFileSearch("ui", + changeExtension(toqstr(name), "inc")); + } + else + ui_path = libFileSearch("ui", toqstr(name), "ui"); + + if (ui_path.empty()) { + LYXERR(Debug::INIT, "Could not find " << name); + Alert::warning(_("Could not find UI defintion file"), + bformat(_("Error while reading the configuration file\n%1$s.\n" + "Please check your installation."), from_utf8(name))); + return false; + } + + uifiles.push_back(name); + + LYXERR(Debug::INIT, "Found " << name << " in " << ui_path); + Lexer lex(uitags); + lex.setFile(ui_path); + if (!lex.isOK()) { + lyxerr << "Unable to set LyXLeX for ui file: " << ui_path + << endl; + } + + if (lyxerr.debugging(Debug::PARSER)) + lex.printTable(lyxerr); + + while (lex.isOK()) { + switch (lex.lex()) { + case ui_include: { + lex.next(true); + string const file = lex.getString(); + if (!readUIFile(file, true)) + return false; + break; + } + case ui_menuset: + readMenus(lex); + break; + + case ui_toolbarset: + toolbarbackend.readToolbars(lex); + break; + + case ui_toolbars: + toolbarbackend.readToolbarSettings(lex); + break; + + default: + if (!rtrim(lex.getString()).empty()) + lex.printError("LyX::ReadUIFile: " + "Unknown menu tag: `$$Token'"); + break; + } + } + return true; +} + + void GuiApplication::onLastWindowClosed() { if (d->global_menubar_) diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index c6683cc250..e36934d35d 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -127,6 +127,9 @@ private Q_SLOTS: private: /// bool closeAllViews(); + /// read the given ui (menu/toolbar) file + bool readUIFile(std::string const & name, bool include = false); + /// This LyXView is the one receiving Clipboard and Selection /// events GuiView * current_view_; diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 594bf54084..997c071088 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -132,6 +132,7 @@ SOURCEFILES = \ qt_helpers.cpp \ TocModel.cpp \ TocWidget.cpp \ + ToolbarBackend.cpp \ Validator.cpp NOMOCHEADER = \ @@ -151,7 +152,8 @@ NOMOCHEADER = \ GuiToolbars.h \ LaTeXHighlighter.h \ qt_i18n.h \ - qt_helpers.h + qt_helpers.h \ + ToolbarBackend.h MOCHEADER = \ Action.h \ diff --git a/src/ToolbarBackend.cpp b/src/frontends/qt4/ToolbarBackend.cpp similarity index 100% rename from src/ToolbarBackend.cpp rename to src/frontends/qt4/ToolbarBackend.cpp diff --git a/src/ToolbarBackend.h b/src/frontends/qt4/ToolbarBackend.h similarity index 100% rename from src/ToolbarBackend.h rename to src/frontends/qt4/ToolbarBackend.h -- 2.39.2