]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Toolbars.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / Toolbars.cpp
index 33c444d0e5337727efb27e45582ead2ce4da4a84..f395e52a0a65b147859a54b7f698ceb1ad4a34de 100644 (file)
 #include <config.h>
 
 #include "Toolbars.h"
+#include "Converter.h"
+#include "Format.h"
 #include "FuncRequest.h"
 #include "Lexer.h"
 #include "LyXAction.h"
-#include "support/lstrings.h"
+#include "qt_helpers.h"
 
 #include "support/debug.h"
 #include "support/gettext.h"
+#include "support/lstrings.h"
 
 #include <boost/bind.hpp>
 
@@ -30,10 +33,6 @@ using namespace lyx::support;
 namespace lyx {
 namespace frontend {
 
-namespace {
-
-} // namespace anon
-
 
 /////////////////////////////////////////////////////////////////////////
 //
@@ -70,18 +69,28 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
                TO_MINIBUFFER,
                TO_TABLEINSERT,
                TO_POPUPMENU,
+               TO_STICKYPOPUPMENU,
                TO_ICONPALETTE,
+               TO_EXPORTFORMATS,
+               TO_IMPORTFORMATS,
+               TO_UPDATEFORMATS,
+               TO_VIEWFORMATS,
        };
 
        struct LexerKeyword toolTags[] = {
                { "end", TO_ENDTOOLBAR },
+               { "exportformats", TO_EXPORTFORMATS },
                { "iconpalette", TO_ICONPALETTE },
+               { "importformats", TO_IMPORTFORMATS },
                { "item", TO_COMMAND },
                { "layouts", TO_LAYOUTS },
                { "minibuffer", TO_MINIBUFFER },
                { "popupmenu", TO_POPUPMENU },
                { "separator", TO_SEPARATOR },
-               { "tableinsert", TO_TABLEINSERT }
+               { "stickypopupmenu", TO_STICKYPOPUPMENU },
+               { "tableinsert", TO_TABLEINSERT },
+               { "updateformats", TO_UPDATEFORMATS },
+               { "viewformats", TO_VIEWFORMATS },
        };
 
        //consistency check
@@ -94,7 +103,7 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
        name = lex.getString();
 
        lex.next(true);
-       gui_name = lex.getString();
+       gui_name = _(lex.getString());
 
        // FIXME what to do here?
        if (!lex) {
@@ -111,7 +120,8 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
                lex.printTable(lyxerr);
 
        while (lex.isOK() && !quit) {
-               switch (lex.lex()) {
+               int const code = lex.lex();
+               switch (code) {
                case TO_COMMAND:
                        if (lex.next(true)) {
                                docstring const tooltip = translateIfPossible(lex.getDocString());
@@ -145,6 +155,15 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
                        }
                        break;
 
+               case TO_STICKYPOPUPMENU:
+                       if (lex.next(true)) {
+                               string const name = lex.getString();
+                               lex.next(true);
+                               docstring const label = lex.getDocString();
+                               add(ToolbarItem(ToolbarItem::STICKYPOPUPMENU, name, label));
+                       }
+                       break;
+
                case TO_ICONPALETTE:
                        if (lex.next(true)) {
                                string const name = lex.getString();
@@ -171,6 +190,53 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
                        quit = true;
                        break;
 
+               case TO_EXPORTFORMATS:
+               case TO_IMPORTFORMATS:
+               case TO_UPDATEFORMATS:
+               case TO_VIEWFORMATS: {
+                       vector<Format const *> formats = (code == TO_IMPORTFORMATS) ?
+                               theConverters().importableFormats() :
+                               theConverters().exportableFormats(code != TO_EXPORTFORMATS);
+                       sort(formats.begin(), formats.end());
+                       vector<Format const *>::const_iterator fit = formats.begin();
+                       vector<Format const *>::const_iterator end = formats.end();
+                       for (; fit != end ; ++fit) {
+                               if ((*fit)->dummy())
+                                       continue;
+                               if (code != TO_IMPORTFORMATS &&
+                                   !(*fit)->documentFormat())
+                                       continue;
+
+                               docstring const prettyname =
+                                       from_utf8((*fit)->prettyname());
+                               docstring tooltip;
+                               FuncCode lfun = LFUN_NOACTION;
+                               switch (code) {
+                               case TO_EXPORTFORMATS:
+                                       lfun = LFUN_BUFFER_EXPORT;
+                                       tooltip = _("Export %1$s");
+                                       break;
+                               case TO_IMPORTFORMATS:
+                                       lfun = LFUN_BUFFER_IMPORT;
+                                       tooltip = _("Import %1$s");
+                                       break;
+                               case TO_UPDATEFORMATS:
+                                       lfun = LFUN_BUFFER_UPDATE;
+                                       tooltip = _("Update %1$s");
+                                       break;
+                               case TO_VIEWFORMATS:
+                                       lfun = LFUN_BUFFER_VIEW;
+                                       tooltip = _("View %1$s");
+                                       break;
+                               }
+                               FuncRequest func(lfun, (*fit)->name(),
+                                               FuncRequest::TOOLBAR);
+                               add(ToolbarItem(ToolbarItem::COMMAND, func,
+                                               bformat(tooltip, prettyname)));
+                       }
+                       break;
+               }
+
                default:
                        lex.printError("ToolbarInfo::read: "
                                       "Unknown toolbar tag: `$$Token'");
@@ -190,6 +256,12 @@ ToolbarInfo & ToolbarInfo::read(Lexer & lex)
 //
 /////////////////////////////////////////////////////////////////////////
 
+void Toolbars::reset()
+{
+       toolbar_info_.clear();
+       toolbar_visibility_.clear();
+}
+
 
 void Toolbars::readToolbars(Lexer & lex)
 {
@@ -286,6 +358,8 @@ void Toolbars::readToolbarSettings(Lexer & lex)
                                flag = RIGHT;
                        else if (!compare_ascii_no_case(*cit, "auto"))
                                flag = AUTO;
+                       else if (!compare_ascii_no_case(*cit, "samerow"))
+                               flag = SAMEROW;
                        else {
                                LYXERR(Debug::ANY,
                                        "Toolbars::readToolbarSettings: unrecognised token:`"
@@ -298,7 +372,8 @@ void Toolbars::readToolbarSettings(Lexer & lex)
 
                if (visibility >= MATH) {
                        if (ToolbarInfo const * ti = info(name))
-                               const_cast<ToolbarInfo *>(ti)->gui_name += " (auto)";
+                               const_cast<ToolbarInfo *>(ti)->gui_name +=
+                                       " (" + _("auto") + ")";
                }
        }
 }
@@ -323,5 +398,11 @@ int Toolbars::defaultVisibility(std::string const & name) const
 }
 
 
+bool Toolbars::isMainToolbar(std::string const & name) const
+{
+       return toolbar_visibility_.find(name) != toolbar_visibility_.end();
+}
+
+
 } // namespace frontend
 } // namespace lyx