]> git.lyx.org Git - features.git/commitdiff
First step towards fixing bug 4588: move the ui file reading and the ToolbarBackend...
authorAbdelrazak Younes <younes@lyx.org>
Sat, 24 May 2008 09:28:05 +0000 (09:28 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 24 May 2008 09:28:05 +0000 (09:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24921 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
development/scons/scons_manifest.py
src/LyX.cpp
src/LyX.h
src/Makefile.am
src/ToolbarBackend.cpp [deleted file]
src/ToolbarBackend.h [deleted file]
src/frontends/Application.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/Makefile.am
src/frontends/qt4/ToolbarBackend.cpp [new file with mode: 0644]
src/frontends/qt4/ToolbarBackend.h [new file with mode: 0644]

index 8ac54674f40ce23faff6c006f9842b078dd9af71..2051c1f919e87a1eaf7f002b6774e4fce352b7c7 100644 (file)
@@ -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
 ''')
index d7a205db6d771657be2c8dc13507d42a03351a8d..0131eb95f9113981ce745fcc2ded20f0873bf34f 100644 (file)
@@ -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<string> uifiles;
-       list<string>::const_iterator it  = uifiles.begin();
-       list<string>::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)
 {
index 3d98e42b8edb5100c719d27152f7e0c6e6018969..5a82c9037c10f2c87c4d9e596f086711ac5b1b7a 100644 (file)
--- 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.
index 7bbfb49446667f3ff896d5b96a450cb3a1417922..ef58a1817d98846dce1cf38bafe61eb8fc8e82eb 100644 (file)
@@ -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/ToolbarBackend.cpp b/src/ToolbarBackend.cpp
deleted file mode 100644 (file)
index 419f051..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-/**
- * \file ToolbarBackend.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jean-Marc Lasgouttes
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "ToolbarBackend.h"
-#include "FuncRequest.h"
-#include "Lexer.h"
-#include "LyXAction.h"
-#include "support/lstrings.h"
-
-#include "support/debug.h"
-#include "support/gettext.h"
-
-#include <boost/bind.hpp>
-
-#include <algorithm>
-
-using namespace std;
-using namespace lyx::support;
-
-namespace lyx {
-
-namespace {
-
-class ToolbarNamesEqual
-{
-public:
-       ToolbarNamesEqual(string const & name) : name_(name) {}
-       bool operator()(ToolbarInfo const & tbinfo) const
-       {
-               return tbinfo.name == name_;
-       }
-private:
-       string name_;
-};
-
-} // namespace anon
-
-
-ToolbarBackend toolbarbackend;
-
-
-/////////////////////////////////////////////////////////////////////////
-//
-// ToolbarItem
-//
-/////////////////////////////////////////////////////////////////////////
-
-ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
-       : type_(type), func_(func), label_(label)
-{
-}
-
-
-ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
-       : type_(type), label_(label), name_(name)
-{
-}
-
-
-ToolbarItem::~ToolbarItem()
-{}
-
-
-void ToolbarInfo::add(ToolbarItem const & item)
-{
-       items.push_back(item);
-       items.back().func_.origin = FuncRequest::TOOLBAR;
-}
-
-
-ToolbarInfo & ToolbarInfo::read(Lexer & lex)
-{
-       enum {
-               TO_COMMAND = 1,
-               TO_ENDTOOLBAR,
-               TO_SEPARATOR,
-               TO_LAYOUTS,
-               TO_MINIBUFFER,
-               TO_TABLEINSERT,
-               TO_POPUPMENU,
-               TO_ICONPALETTE,
-       };
-
-       struct LexerKeyword toolTags[] = {
-               { "end", TO_ENDTOOLBAR },
-               { "iconpalette", TO_ICONPALETTE },
-               { "item", TO_COMMAND },
-               { "layouts", TO_LAYOUTS },
-               { "minibuffer", TO_MINIBUFFER },
-               { "popupmenu", TO_POPUPMENU },
-               { "separator", TO_SEPARATOR },
-               { "tableinsert", TO_TABLEINSERT }
-       };
-
-       //consistency check
-       if (compare_ascii_no_case(lex.getString(), "toolbar")) {
-               LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
-                      << lex.getString() << '\'');
-       }
-
-       lex.next(true);
-       name = lex.getString();
-
-       lex.next(true);
-       gui_name = lex.getString();
-
-       // FIXME what to do here?
-       if (!lex) {
-               LYXERR0("ToolbarInfo::read: Malformed toolbar "
-                       "description " <<  lex.getString());
-               return *this;
-       }
-
-       bool quit = false;
-
-       lex.pushTable(toolTags);
-
-       if (lyxerr.debugging(Debug::PARSER))
-               lex.printTable(lyxerr);
-
-       while (lex.isOK() && !quit) {
-               switch (lex.lex()) {
-               case TO_COMMAND:
-                       if (lex.next(true)) {
-                               docstring const tooltip = translateIfPossible(lex.getDocString());
-                               lex.next(true);
-                               string const func_arg = lex.getString();
-                               LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
-                                       << func_arg << '\'');
-
-                               FuncRequest func =
-                                       lyxaction.lookupFunc(func_arg);
-                               add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
-                       }
-                       break;
-
-               case TO_MINIBUFFER:
-                       add(ToolbarItem(ToolbarItem::MINIBUFFER,
-                               FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
-                       break;
-
-               case TO_SEPARATOR:
-                       add(ToolbarItem(ToolbarItem::SEPARATOR,
-                               FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
-                       break;
-
-               case TO_POPUPMENU:
-                       if (lex.next(true)) {
-                               string const name = lex.getString();
-                               lex.next(true);
-                               docstring const label = lex.getDocString();
-                               add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
-                       }
-                       break;
-
-               case TO_ICONPALETTE:
-                       if (lex.next(true)) {
-                               string const name = lex.getString();
-                               lex.next(true);
-                               docstring const label = lex.getDocString();
-                               add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
-                       }
-                       break;
-
-               case TO_LAYOUTS:
-                       add(ToolbarItem(ToolbarItem::LAYOUTS,
-                               FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
-                       break;
-
-               case TO_TABLEINSERT:
-                       if (lex.next(true)) {
-                               docstring const tooltip = lex.getDocString();
-                               add(ToolbarItem(ToolbarItem::TABLEINSERT,
-                                       FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
-                       }
-                       break;
-
-               case TO_ENDTOOLBAR:
-                       quit = true;
-                       break;
-
-               default:
-                       lex.printError("ToolbarInfo::read: "
-                                      "Unknown toolbar tag: `$$Token'");
-                       break;
-               }
-       }
-
-       lex.popTable();
-       return *this;
-}
-
-
-
-/////////////////////////////////////////////////////////////////////////
-//
-// ToolbarBackend
-//
-/////////////////////////////////////////////////////////////////////////
-
-
-ToolbarBackend::ToolbarBackend()
-{
-       fullScreenWindows = 0;
-}
-
-
-void ToolbarBackend::readToolbars(Lexer & lex)
-{
-       enum {
-               TO_TOOLBAR = 1,
-               TO_ENDTOOLBARSET,
-       };
-
-       struct LexerKeyword toolTags[] = {
-               { "end", TO_ENDTOOLBARSET },
-               { "toolbar", TO_TOOLBAR }
-       };
-
-       //consistency check
-       if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
-               LYXERR0("ToolbarBackend::readToolbars: ERROR wrong token:`"
-                      << lex.getString() << '\'');
-       }
-
-       lex.pushTable(toolTags);
-
-       if (lyxerr.debugging(Debug::PARSER))
-               lex.printTable(lyxerr);
-
-       bool quit = false;
-       while (lex.isOK() && !quit) {
-               switch (lex.lex()) {
-               case TO_TOOLBAR: {
-                       ToolbarInfo tbinfo;
-                       tbinfo.read(lex);
-                       toolbars.push_back(tbinfo);
-                       break;
-                       }
-               case TO_ENDTOOLBARSET:
-                       quit = true;
-                       break;
-               default:
-                       lex.printError("ToolbarBackend::readToolbars: "
-                                      "Unknown toolbar tag: `$$Token'");
-                       break;
-               }
-       }
-
-       lex.popTable();
-}
-
-
-void ToolbarBackend::readToolbarSettings(Lexer & lex)
-{
-       //consistency check
-       if (compare_ascii_no_case(lex.getString(), "toolbars")) {
-               LYXERR0("ToolbarBackend::readToolbarSettings: ERROR wrong token:`"
-                      << lex.getString() << '\'');
-       }
-
-       lex.next(true);
-
-       while (lex.isOK()) {
-               string name = lex.getString();
-               lex.next(true);
-
-               if (!compare_ascii_no_case(name, "end"))
-                       return;
-
-               Toolbars::iterator tcit = toolbars.begin();
-               Toolbars::iterator tend = toolbars.end();
-               for (; tcit != tend; ++tcit) {
-                       if (tcit->name == name)
-                               break;
-               }
-
-               if (tcit == tend) {
-                       LYXERR0("ToolbarBackend: undefined toolbar " << name);
-                       return;
-               }
-
-               tcit->flags = static_cast<ToolbarInfo::Flags>(0);
-               string flagstr = lex.getString();
-               lex.next(true);
-               vector<string> flags = getVectorFromString(flagstr);
-
-               vector<string>::const_iterator cit = flags.begin();
-               vector<string>::const_iterator end = flags.end();
-
-               for (; cit != end; ++cit) {
-                       int flag = 0;
-                       if (!compare_ascii_no_case(*cit, "off"))
-                               flag = ToolbarInfo::OFF;
-                       else if (!compare_ascii_no_case(*cit, "on"))
-                               flag = ToolbarInfo::ON;
-                       else if (!compare_ascii_no_case(*cit, "math"))
-                               flag = ToolbarInfo::MATH;
-                       else if (!compare_ascii_no_case(*cit, "table"))
-                               flag = ToolbarInfo::TABLE;
-                       else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
-                               flag = ToolbarInfo::MATHMACROTEMPLATE;
-                       else if (!compare_ascii_no_case(*cit, "review"))
-                               flag = ToolbarInfo::REVIEW;
-                       else if (!compare_ascii_no_case(*cit, "top"))
-                               flag = ToolbarInfo::TOP;
-                       else if (!compare_ascii_no_case(*cit, "bottom"))
-                               flag = ToolbarInfo::BOTTOM;
-                       else if (!compare_ascii_no_case(*cit, "left"))
-                               flag = ToolbarInfo::LEFT;
-                       else if (!compare_ascii_no_case(*cit, "right"))
-                               flag = ToolbarInfo::RIGHT;
-                       else if (!compare_ascii_no_case(*cit, "auto"))
-                               flag = ToolbarInfo::AUTO;
-                       else {
-                               LYXERR(Debug::ANY,
-                                       "ToolbarBackend::readToolbarSettings: unrecognised token:`"
-                                       << *cit << '\'');
-                       }
-                       tcit->flags = static_cast<ToolbarInfo::Flags>(tcit->flags | flag);
-               }
-
-               usedtoolbars.push_back(*tcit);
-       }
-}
-
-
-ToolbarInfo const * ToolbarBackend::getDefinedToolbarInfo(string const & name) const
-{
-       Toolbars::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name));
-       if (it == toolbars.end())
-               return 0;
-       return &(*it);
-}
-
-
-ToolbarInfo * ToolbarBackend::getUsedToolbarInfo(string const &name)
-{
-       Toolbars::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name));
-       if (it == usedtoolbars.end())
-               return 0;
-       return &(*it);
-}
-
-} // namespace lyx
diff --git a/src/ToolbarBackend.h b/src/ToolbarBackend.h
deleted file mode 100644 (file)
index 8845b5d..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-// -*- C++ -*-
-/**
- * \file ToolbarBackend.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jean-Marc Lasgouttes
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef TOOLBAR_BACKEND_H
-#define TOOLBAR_BACKEND_H
-
-#include "FuncRequest.h"
-
-#include <vector>
-
-
-namespace lyx {
-
-
-class Lexer;
-
-class ToolbarItem {
-public:
-       enum Type {
-               /// command/action
-               COMMAND,
-               /// the command buffer
-               MINIBUFFER,
-               /// adds space between buttons in the toolbar
-               SEPARATOR,
-               /// a special combox insead of a button
-               LAYOUTS,
-               /// a special widget to insert tabulars
-               TABLEINSERT,
-               ///
-               POPUPMENU,
-               ///
-               ICONPALETTE
-       };
-
-       ToolbarItem(Type type,
-                FuncRequest const & func,
-                docstring const & label = docstring());
-
-       ToolbarItem(Type type,
-                std::string const & name = std::string(),
-                docstring const & label = docstring());
-
-       ~ToolbarItem();
-
-       /// item type
-       Type type_;
-       /// action
-       FuncRequest func_;
-       /// label/tooltip
-       docstring label_;
-       /// name
-       std::string name_;
-};
-
-
-///
-class ToolbarInfo {
-public:
-       /// toolbar flags
-       enum Flags {
-               ON = 1, //< show
-               OFF = 2, //< do not show
-               MATH = 4, //< show when in math
-               TABLE = 8, //< show when in table
-               TOP = 16, //< show at top
-               BOTTOM = 32, //< show at bottom
-               LEFT = 64, //< show at left
-               RIGHT = 128, //< show at right
-               REVIEW = 256, //< show when change tracking is enabled
-               AUTO = 512,  //< only if AUTO is set, when MATH, TABLE and REVIEW is used
-               MATHMACROTEMPLATE = 1024 //< show in math macro template
-       };
-       /// the toolbar items
-       typedef std::vector<ToolbarItem> Items;
-
-       typedef Items::const_iterator item_iterator;
-
-       explicit ToolbarInfo(std::string const & name = std::string())
-               : name(name) {}
-
-       /// toolbar name
-       std::string name;
-       /// toolbar GUI name
-       std::string gui_name;
-       /// toolbar contents
-       Items items;
-       /// flags
-       Flags flags;
-       /// store flags when coming to fullscreen mode
-       Flags before_fullscreen;
-
-       /// read a toolbar from the file
-       ToolbarInfo & read(Lexer &);
-
-private:
-       /// add toolbar item
-       void add(ToolbarItem const &);
-};
-
-
-///
-class ToolbarBackend {
-public:
-       typedef std::vector<ToolbarInfo> Toolbars;
-
-       ToolbarBackend();
-
-       /// iterator for all toolbars
-       Toolbars::const_iterator begin() const { return usedtoolbars.begin(); }
-
-       Toolbars::const_iterator end() const { return usedtoolbars.end(); }
-
-       Toolbars::iterator begin() { return usedtoolbars.begin(); }
-
-       Toolbars::iterator end() { return usedtoolbars.end(); }
-
-       /// read toolbars from the file
-       void readToolbars(Lexer &);
-
-       /// read ui toolbar settings
-       void readToolbarSettings(Lexer &);
-
-       ///
-       ToolbarInfo const * getDefinedToolbarInfo(std::string const & name) const;
-       ///
-       ToolbarInfo * getUsedToolbarInfo(std::string const & name);
-
-       // FIXME should be deleted when every window has its own toolbar config.
-       /// number of toggleFullScreen calls, i.e. number of FullScreen windows.
-       int fullScreenWindows;
-
-private:
-       /// all the defined toolbars
-       Toolbars toolbars;
-
-       /// toolbars listed
-       Toolbars usedtoolbars;
-};
-
-/// The global instance
-extern ToolbarBackend toolbarbackend;
-
-
-
-} // namespace lyx
-
-#endif // TOOLBAR_BACKEND_H
index 83b57e4efc9bbdf1bfc252ea02c665fca169f2b1..4b2299bbbec96187fae7261548a3d615afa8e6b1 100644 (file)
@@ -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
index e379a9556fa14f78b84a29f11a277578c4ffc131..80f4fe44836f0a23884d8a60b4edf7ef01fc07f5 100644 (file)
@@ -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<string> uifiles;
+       list<string>::const_iterator it  = uifiles.begin();
+       list<string>::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_)
index c6683cc25095b109879c51d2f736850b73d18665..e36934d35de54d9179d251721c5e9a26677192eb 100644 (file)
@@ -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_;
index 594bf54084d32b3a4499478812cc88ea96945193..997c071088b9266331baba177f6c2cda6aacff34 100644 (file)
@@ -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/frontends/qt4/ToolbarBackend.cpp b/src/frontends/qt4/ToolbarBackend.cpp
new file mode 100644 (file)
index 0000000..419f051
--- /dev/null
@@ -0,0 +1,355 @@
+/**
+ * \file ToolbarBackend.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jean-Marc Lasgouttes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "ToolbarBackend.h"
+#include "FuncRequest.h"
+#include "Lexer.h"
+#include "LyXAction.h"
+#include "support/lstrings.h"
+
+#include "support/debug.h"
+#include "support/gettext.h"
+
+#include <boost/bind.hpp>
+
+#include <algorithm>
+
+using namespace std;
+using namespace lyx::support;
+
+namespace lyx {
+
+namespace {
+
+class ToolbarNamesEqual
+{
+public:
+       ToolbarNamesEqual(string const & name) : name_(name) {}
+       bool operator()(ToolbarInfo const & tbinfo) const
+       {
+               return tbinfo.name == name_;
+       }
+private:
+       string name_;
+};
+
+} // namespace anon
+
+
+ToolbarBackend toolbarbackend;
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// ToolbarItem
+//
+/////////////////////////////////////////////////////////////////////////
+
+ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
+       : type_(type), func_(func), label_(label)
+{
+}
+
+
+ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
+       : type_(type), label_(label), name_(name)
+{
+}
+
+
+ToolbarItem::~ToolbarItem()
+{}
+
+
+void ToolbarInfo::add(ToolbarItem const & item)
+{
+       items.push_back(item);
+       items.back().func_.origin = FuncRequest::TOOLBAR;
+}
+
+
+ToolbarInfo & ToolbarInfo::read(Lexer & lex)
+{
+       enum {
+               TO_COMMAND = 1,
+               TO_ENDTOOLBAR,
+               TO_SEPARATOR,
+               TO_LAYOUTS,
+               TO_MINIBUFFER,
+               TO_TABLEINSERT,
+               TO_POPUPMENU,
+               TO_ICONPALETTE,
+       };
+
+       struct LexerKeyword toolTags[] = {
+               { "end", TO_ENDTOOLBAR },
+               { "iconpalette", TO_ICONPALETTE },
+               { "item", TO_COMMAND },
+               { "layouts", TO_LAYOUTS },
+               { "minibuffer", TO_MINIBUFFER },
+               { "popupmenu", TO_POPUPMENU },
+               { "separator", TO_SEPARATOR },
+               { "tableinsert", TO_TABLEINSERT }
+       };
+
+       //consistency check
+       if (compare_ascii_no_case(lex.getString(), "toolbar")) {
+               LYXERR0("ToolbarInfo::read: ERROR wrong token:`"
+                      << lex.getString() << '\'');
+       }
+
+       lex.next(true);
+       name = lex.getString();
+
+       lex.next(true);
+       gui_name = lex.getString();
+
+       // FIXME what to do here?
+       if (!lex) {
+               LYXERR0("ToolbarInfo::read: Malformed toolbar "
+                       "description " <<  lex.getString());
+               return *this;
+       }
+
+       bool quit = false;
+
+       lex.pushTable(toolTags);
+
+       if (lyxerr.debugging(Debug::PARSER))
+               lex.printTable(lyxerr);
+
+       while (lex.isOK() && !quit) {
+               switch (lex.lex()) {
+               case TO_COMMAND:
+                       if (lex.next(true)) {
+                               docstring const tooltip = translateIfPossible(lex.getDocString());
+                               lex.next(true);
+                               string const func_arg = lex.getString();
+                               LYXERR(Debug::PARSER, "ToolbarInfo::read TO_COMMAND func: `"
+                                       << func_arg << '\'');
+
+                               FuncRequest func =
+                                       lyxaction.lookupFunc(func_arg);
+                               add(ToolbarItem(ToolbarItem::COMMAND, func, tooltip));
+                       }
+                       break;
+
+               case TO_MINIBUFFER:
+                       add(ToolbarItem(ToolbarItem::MINIBUFFER,
+                               FuncRequest(FuncCode(ToolbarItem::MINIBUFFER))));
+                       break;
+
+               case TO_SEPARATOR:
+                       add(ToolbarItem(ToolbarItem::SEPARATOR,
+                               FuncRequest(FuncCode(ToolbarItem::SEPARATOR))));
+                       break;
+
+               case TO_POPUPMENU:
+                       if (lex.next(true)) {
+                               string const name = lex.getString();
+                               lex.next(true);
+                               docstring const label = lex.getDocString();
+                               add(ToolbarItem(ToolbarItem::POPUPMENU, name, label));
+                       }
+                       break;
+
+               case TO_ICONPALETTE:
+                       if (lex.next(true)) {
+                               string const name = lex.getString();
+                               lex.next(true);
+                               docstring const label = lex.getDocString();
+                               add(ToolbarItem(ToolbarItem::ICONPALETTE, name, label));
+                       }
+                       break;
+
+               case TO_LAYOUTS:
+                       add(ToolbarItem(ToolbarItem::LAYOUTS,
+                               FuncRequest(FuncCode(ToolbarItem::LAYOUTS))));
+                       break;
+
+               case TO_TABLEINSERT:
+                       if (lex.next(true)) {
+                               docstring const tooltip = lex.getDocString();
+                               add(ToolbarItem(ToolbarItem::TABLEINSERT,
+                                       FuncRequest(FuncCode(ToolbarItem::TABLEINSERT)), tooltip));
+                       }
+                       break;
+
+               case TO_ENDTOOLBAR:
+                       quit = true;
+                       break;
+
+               default:
+                       lex.printError("ToolbarInfo::read: "
+                                      "Unknown toolbar tag: `$$Token'");
+                       break;
+               }
+       }
+
+       lex.popTable();
+       return *this;
+}
+
+
+
+/////////////////////////////////////////////////////////////////////////
+//
+// ToolbarBackend
+//
+/////////////////////////////////////////////////////////////////////////
+
+
+ToolbarBackend::ToolbarBackend()
+{
+       fullScreenWindows = 0;
+}
+
+
+void ToolbarBackend::readToolbars(Lexer & lex)
+{
+       enum {
+               TO_TOOLBAR = 1,
+               TO_ENDTOOLBARSET,
+       };
+
+       struct LexerKeyword toolTags[] = {
+               { "end", TO_ENDTOOLBARSET },
+               { "toolbar", TO_TOOLBAR }
+       };
+
+       //consistency check
+       if (compare_ascii_no_case(lex.getString(), "toolbarset")) {
+               LYXERR0("ToolbarBackend::readToolbars: ERROR wrong token:`"
+                      << lex.getString() << '\'');
+       }
+
+       lex.pushTable(toolTags);
+
+       if (lyxerr.debugging(Debug::PARSER))
+               lex.printTable(lyxerr);
+
+       bool quit = false;
+       while (lex.isOK() && !quit) {
+               switch (lex.lex()) {
+               case TO_TOOLBAR: {
+                       ToolbarInfo tbinfo;
+                       tbinfo.read(lex);
+                       toolbars.push_back(tbinfo);
+                       break;
+                       }
+               case TO_ENDTOOLBARSET:
+                       quit = true;
+                       break;
+               default:
+                       lex.printError("ToolbarBackend::readToolbars: "
+                                      "Unknown toolbar tag: `$$Token'");
+                       break;
+               }
+       }
+
+       lex.popTable();
+}
+
+
+void ToolbarBackend::readToolbarSettings(Lexer & lex)
+{
+       //consistency check
+       if (compare_ascii_no_case(lex.getString(), "toolbars")) {
+               LYXERR0("ToolbarBackend::readToolbarSettings: ERROR wrong token:`"
+                      << lex.getString() << '\'');
+       }
+
+       lex.next(true);
+
+       while (lex.isOK()) {
+               string name = lex.getString();
+               lex.next(true);
+
+               if (!compare_ascii_no_case(name, "end"))
+                       return;
+
+               Toolbars::iterator tcit = toolbars.begin();
+               Toolbars::iterator tend = toolbars.end();
+               for (; tcit != tend; ++tcit) {
+                       if (tcit->name == name)
+                               break;
+               }
+
+               if (tcit == tend) {
+                       LYXERR0("ToolbarBackend: undefined toolbar " << name);
+                       return;
+               }
+
+               tcit->flags = static_cast<ToolbarInfo::Flags>(0);
+               string flagstr = lex.getString();
+               lex.next(true);
+               vector<string> flags = getVectorFromString(flagstr);
+
+               vector<string>::const_iterator cit = flags.begin();
+               vector<string>::const_iterator end = flags.end();
+
+               for (; cit != end; ++cit) {
+                       int flag = 0;
+                       if (!compare_ascii_no_case(*cit, "off"))
+                               flag = ToolbarInfo::OFF;
+                       else if (!compare_ascii_no_case(*cit, "on"))
+                               flag = ToolbarInfo::ON;
+                       else if (!compare_ascii_no_case(*cit, "math"))
+                               flag = ToolbarInfo::MATH;
+                       else if (!compare_ascii_no_case(*cit, "table"))
+                               flag = ToolbarInfo::TABLE;
+                       else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
+                               flag = ToolbarInfo::MATHMACROTEMPLATE;
+                       else if (!compare_ascii_no_case(*cit, "review"))
+                               flag = ToolbarInfo::REVIEW;
+                       else if (!compare_ascii_no_case(*cit, "top"))
+                               flag = ToolbarInfo::TOP;
+                       else if (!compare_ascii_no_case(*cit, "bottom"))
+                               flag = ToolbarInfo::BOTTOM;
+                       else if (!compare_ascii_no_case(*cit, "left"))
+                               flag = ToolbarInfo::LEFT;
+                       else if (!compare_ascii_no_case(*cit, "right"))
+                               flag = ToolbarInfo::RIGHT;
+                       else if (!compare_ascii_no_case(*cit, "auto"))
+                               flag = ToolbarInfo::AUTO;
+                       else {
+                               LYXERR(Debug::ANY,
+                                       "ToolbarBackend::readToolbarSettings: unrecognised token:`"
+                                       << *cit << '\'');
+                       }
+                       tcit->flags = static_cast<ToolbarInfo::Flags>(tcit->flags | flag);
+               }
+
+               usedtoolbars.push_back(*tcit);
+       }
+}
+
+
+ToolbarInfo const * ToolbarBackend::getDefinedToolbarInfo(string const & name) const
+{
+       Toolbars::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name));
+       if (it == toolbars.end())
+               return 0;
+       return &(*it);
+}
+
+
+ToolbarInfo * ToolbarBackend::getUsedToolbarInfo(string const &name)
+{
+       Toolbars::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name));
+       if (it == usedtoolbars.end())
+               return 0;
+       return &(*it);
+}
+
+} // namespace lyx
diff --git a/src/frontends/qt4/ToolbarBackend.h b/src/frontends/qt4/ToolbarBackend.h
new file mode 100644 (file)
index 0000000..8845b5d
--- /dev/null
@@ -0,0 +1,157 @@
+// -*- C++ -*-
+/**
+ * \file ToolbarBackend.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jean-Marc Lasgouttes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef TOOLBAR_BACKEND_H
+#define TOOLBAR_BACKEND_H
+
+#include "FuncRequest.h"
+
+#include <vector>
+
+
+namespace lyx {
+
+
+class Lexer;
+
+class ToolbarItem {
+public:
+       enum Type {
+               /// command/action
+               COMMAND,
+               /// the command buffer
+               MINIBUFFER,
+               /// adds space between buttons in the toolbar
+               SEPARATOR,
+               /// a special combox insead of a button
+               LAYOUTS,
+               /// a special widget to insert tabulars
+               TABLEINSERT,
+               ///
+               POPUPMENU,
+               ///
+               ICONPALETTE
+       };
+
+       ToolbarItem(Type type,
+                FuncRequest const & func,
+                docstring const & label = docstring());
+
+       ToolbarItem(Type type,
+                std::string const & name = std::string(),
+                docstring const & label = docstring());
+
+       ~ToolbarItem();
+
+       /// item type
+       Type type_;
+       /// action
+       FuncRequest func_;
+       /// label/tooltip
+       docstring label_;
+       /// name
+       std::string name_;
+};
+
+
+///
+class ToolbarInfo {
+public:
+       /// toolbar flags
+       enum Flags {
+               ON = 1, //< show
+               OFF = 2, //< do not show
+               MATH = 4, //< show when in math
+               TABLE = 8, //< show when in table
+               TOP = 16, //< show at top
+               BOTTOM = 32, //< show at bottom
+               LEFT = 64, //< show at left
+               RIGHT = 128, //< show at right
+               REVIEW = 256, //< show when change tracking is enabled
+               AUTO = 512,  //< only if AUTO is set, when MATH, TABLE and REVIEW is used
+               MATHMACROTEMPLATE = 1024 //< show in math macro template
+       };
+       /// the toolbar items
+       typedef std::vector<ToolbarItem> Items;
+
+       typedef Items::const_iterator item_iterator;
+
+       explicit ToolbarInfo(std::string const & name = std::string())
+               : name(name) {}
+
+       /// toolbar name
+       std::string name;
+       /// toolbar GUI name
+       std::string gui_name;
+       /// toolbar contents
+       Items items;
+       /// flags
+       Flags flags;
+       /// store flags when coming to fullscreen mode
+       Flags before_fullscreen;
+
+       /// read a toolbar from the file
+       ToolbarInfo & read(Lexer &);
+
+private:
+       /// add toolbar item
+       void add(ToolbarItem const &);
+};
+
+
+///
+class ToolbarBackend {
+public:
+       typedef std::vector<ToolbarInfo> Toolbars;
+
+       ToolbarBackend();
+
+       /// iterator for all toolbars
+       Toolbars::const_iterator begin() const { return usedtoolbars.begin(); }
+
+       Toolbars::const_iterator end() const { return usedtoolbars.end(); }
+
+       Toolbars::iterator begin() { return usedtoolbars.begin(); }
+
+       Toolbars::iterator end() { return usedtoolbars.end(); }
+
+       /// read toolbars from the file
+       void readToolbars(Lexer &);
+
+       /// read ui toolbar settings
+       void readToolbarSettings(Lexer &);
+
+       ///
+       ToolbarInfo const * getDefinedToolbarInfo(std::string const & name) const;
+       ///
+       ToolbarInfo * getUsedToolbarInfo(std::string const & name);
+
+       // FIXME should be deleted when every window has its own toolbar config.
+       /// number of toggleFullScreen calls, i.e. number of FullScreen windows.
+       int fullScreenWindows;
+
+private:
+       /// all the defined toolbars
+       Toolbars toolbars;
+
+       /// toolbars listed
+       Toolbars usedtoolbars;
+};
+
+/// The global instance
+extern ToolbarBackend toolbarbackend;
+
+
+
+} // namespace lyx
+
+#endif // TOOLBAR_BACKEND_H