#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 <boost/bind.hpp>
+#include "support/lstrings.h"
#include <algorithm>
namespace lyx {
namespace frontend {
-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
-
/////////////////////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////////////////////
-ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & label)
- : type_(type), func_(func), label_(label)
+ToolbarItem::ToolbarItem(Type type, FuncRequest const & func,
+ docstring const & label)
+ : type_(type), func_(make_shared<FuncRequest>(func)), label_(label)
{
}
-ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
- : type_(type), label_(label), name_(name)
+ToolbarItem::ToolbarItem(Type type, string const & name,
+ docstring const & label)
+ : type_(type), func_(make_shared<FuncRequest>()), label_(label), name_(name)
{
}
-ToolbarItem::~ToolbarItem()
-{}
-
-
void ToolbarInfo::add(ToolbarItem const & item)
{
items.push_back(item);
- items.back().func_.origin = FuncRequest::TOOLBAR;
+ items.back().func_->setOrigin(FuncRequest::TOOLBAR);
}
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
name = lex.getString();
lex.next(true);
- gui_name = lex.getString();
+ gui_name = _(lex.getString());
// FIXME what to do here?
if (!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());
}
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();
quit = true;
break;
+ case TO_EXPORTFORMATS:
+ case TO_IMPORTFORMATS:
+ case TO_UPDATEFORMATS:
+ case TO_VIEWFORMATS: {
+ FormatList formats = (code == TO_IMPORTFORMATS) ?
+ theConverters().importableFormats() :
+ theConverters().exportableFormats(true);
+ sort(formats.begin(), formats.end());
+ for (Format const * f : formats) {
+ if (f->dummy())
+ continue;
+ if (code != TO_IMPORTFORMATS &&
+ !f->documentFormat())
+ continue;
+
+ docstring const prettyname = f->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, f->name(),
+ FuncRequest::TOOLBAR);
+ add(ToolbarItem(ToolbarItem::COMMAND, func,
+ bformat(tooltip, prettyname)));
+ }
+ break;
+ }
+
default:
lex.printError("ToolbarInfo::read: "
"Unknown toolbar tag: `$$Token'");
//
/////////////////////////////////////////////////////////////////////////
-
-Toolbars::Toolbars()
+void Toolbars::reset()
{
- fullScreenWindows = 0;
+ toolbar_info_.clear();
+ toolbar_visibility_.clear();
}
{
enum {
TO_TOOLBAR = 1,
- TO_ENDTOOLBARSET,
+ TO_ENDTOOLBARSET
};
struct LexerKeyword toolTags[] = {
case TO_TOOLBAR: {
ToolbarInfo tbinfo;
tbinfo.read(lex);
- toolbars.push_back(tbinfo);
+ toolbar_info_.push_back(tbinfo);
break;
}
case TO_ENDTOOLBARSET:
if (!compare_ascii_no_case(name, "end"))
return;
- Infos::iterator tcit = toolbars.begin();
- Infos::iterator tend = toolbars.end();
- for (; tcit != tend; ++tcit) {
- if (tcit->name == name)
- break;
- }
-
- if (tcit == tend) {
- LYXERR0("Toolbars: undefined toolbar " << name);
- return;
- }
-
- tcit->flags = static_cast<ToolbarInfo::Flags>(0);
+ int visibility = 0;
string flagstr = lex.getString();
lex.next(true);
vector<string> flags = getVectorFromString(flagstr);
vector<string>::const_iterator end = flags.end();
for (; cit != end; ++cit) {
- int flag = 0;
+ Visibility flag = ON;
if (!compare_ascii_no_case(*cit, "off"))
- flag = ToolbarInfo::OFF;
+ flag = OFF;
else if (!compare_ascii_no_case(*cit, "on"))
- flag = ToolbarInfo::ON;
+ flag = ON;
else if (!compare_ascii_no_case(*cit, "math"))
- flag = ToolbarInfo::MATH;
+ flag = MATH;
else if (!compare_ascii_no_case(*cit, "table"))
- flag = ToolbarInfo::TABLE;
+ flag = TABLE;
else if (!compare_ascii_no_case(*cit, "mathmacrotemplate"))
- flag = ToolbarInfo::MATHMACROTEMPLATE;
+ flag = MATHMACROTEMPLATE;
else if (!compare_ascii_no_case(*cit, "review"))
- flag = ToolbarInfo::REVIEW;
+ flag = REVIEW;
+ else if (!compare_ascii_no_case(*cit, "minibuffer"))
+ flag = MINIBUFFER;
else if (!compare_ascii_no_case(*cit, "top"))
- flag = ToolbarInfo::TOP;
+ flag = TOP;
else if (!compare_ascii_no_case(*cit, "bottom"))
- flag = ToolbarInfo::BOTTOM;
+ flag = BOTTOM;
else if (!compare_ascii_no_case(*cit, "left"))
- flag = ToolbarInfo::LEFT;
+ flag = LEFT;
else if (!compare_ascii_no_case(*cit, "right"))
- flag = ToolbarInfo::RIGHT;
+ flag = RIGHT;
else if (!compare_ascii_no_case(*cit, "auto"))
- flag = ToolbarInfo::AUTO;
+ flag = AUTO;
+ else if (!compare_ascii_no_case(*cit, "samerow"))
+ flag = SAMEROW;
+ else if (!compare_ascii_no_case(*cit, "ipa"))
+ flag = IPA;
else {
LYXERR(Debug::ANY,
"Toolbars::readToolbarSettings: unrecognised token:`"
<< *cit << '\'');
+ continue;
}
- tcit->flags = static_cast<ToolbarInfo::Flags>(tcit->flags | flag);
+ visibility |= flag;
}
+ toolbar_visibility_[name] = visibility;
- usedtoolbars.push_back(*tcit);
+ if (visibility & ALLOWAUTO) {
+ if (ToolbarInfo const * ti = info(name))
+ const_cast<ToolbarInfo *>(ti)->gui_name +=
+ " (" + _("auto") + ")";
+ }
}
}
-ToolbarInfo const * Toolbars::getDefinedToolbarInfo(string const & name) const
+ToolbarInfo const * Toolbars::info(std::string const & name) const
+{
+ Infos::const_iterator end = toolbar_info_.end();
+ for (Infos::const_iterator it = toolbar_info_.begin(); it != end; ++it)
+ if (it->name == name)
+ return &(*it);
+ return 0;
+}
+
+
+int Toolbars::defaultVisibility(std::string const & name) const
{
- Infos::const_iterator it = find_if(toolbars.begin(), toolbars.end(), ToolbarNamesEqual(name));
- if (it == toolbars.end())
- return 0;
- return &(*it);
+ map<string, int>::const_iterator it = toolbar_visibility_.find(name);
+ if (it != toolbar_visibility_.end())
+ return it->second;
+ return OFF | BOTTOM;
}
-ToolbarInfo * Toolbars::getUsedToolbarInfo(string const &name)
+bool Toolbars::isMainToolbar(std::string const & name) const
{
- Infos::iterator it = find_if(usedtoolbars.begin(), usedtoolbars.end(), ToolbarNamesEqual(name));
- if (it == usedtoolbars.end())
- return 0;
- return &(*it);
+ return toolbar_visibility_.find(name) != toolbar_visibility_.end();
}
+
} // namespace frontend
} // namespace lyx