#include <algorithm>
+using lyx::char_type;
+using lyx::docstring;
+using lyx::support::compare_no_case;
using lyx::support::compare_ascii_no_case;
using lyx::support::contains;
-using lyx::support::MakeDisplayPath;
+using lyx::support::makeDisplayPath;
using lyx::support::token;
using boost::bind;
class MenuNamesEqual : public std::unary_function<Menu, bool> {
public:
- MenuNamesEqual(string const & name)
+ MenuNamesEqual(docstring const & name)
: name_(name) {}
bool operator()(Menu const & menu) const
{
return menu.name() == name_;
}
private:
- string name_;
+ docstring name_;
};
} // namespace anon
{}
-MenuItem::MenuItem(Kind kind, string const & label,
- string const & submenu, bool optional)
+MenuItem::MenuItem(Kind kind, docstring const & label,
+ docstring const & submenu, bool optional)
: kind_(kind), label_(label),
submenuname_(submenu), optional_(optional)
{
}
-MenuItem::MenuItem(Kind kind, string const & label,
+MenuItem::MenuItem(Kind kind, docstring const & label,
FuncRequest const & func, bool optional)
: kind_(kind), label_(label), func_(func), optional_(optional)
{
}
-string const MenuItem::label() const
+docstring const MenuItem::label() const
{
- return token(label_, '|', 0);
+ return token(label_, char_type('|'), 0);
}
-string const MenuItem::shortcut() const
+docstring const MenuItem::shortcut() const
{
- return token(label_, '|', 1);
+ return token(label_, char_type('|'), 1);
}
-string const MenuItem::binding() const
+docstring const MenuItem::binding() const
{
if (kind_ != Command)
- return string();
+ return docstring();
// Get the keys bound to this action, but keep only the
// first one later
kb_keymap::Bindings bindings = toplevel_keymap->findbindings(func_);
if (bindings.size()) {
- return bindings.begin()->print();
+ return lyx::from_utf8(bindings.begin()->print());
} else {
lyxerr[Debug::KBMAP]
<< "No binding for "
<< lyxaction.getActionName(func_.action)
- << '(' << func_.argument << ')' << endl;
- return string();
+ << '(' << lyx::to_utf8(func_.argument()) << ')' << endl;
+ return docstring();
}
}
// fallback to md_item
case md_item: {
lex.next(true);
- string const name = _(lex.getString());
+ docstring const name = _(lex.getString());
lex.next(true);
string const command = lex.getString();
FuncRequest func = lyxaction.lookupFunc(command);
// fallback to md_submenu
case md_submenu: {
lex.next(true);
- string const mlabel = _(lex.getString());
+ docstring const mlabel = _(lex.getString());
lex.next(true);
- string const mname = lex.getString();
+ docstring const mname = lyx::from_utf8(lex.getString());
add(MenuItem(MenuItem::Submenu, mlabel, mname,
optional));
optional = false;
// This is a quadratic algorithm, but we do not care because
// menus are short enough
for (const_iterator it1 = begin(); it1 != end(); ++it1) {
- string shortcut = it1->shortcut();
+ docstring shortcut = it1->shortcut();
if (shortcut.empty())
continue;
if (!contains(it1->label(), shortcut))
lyxerr << "Menu warning: menu entry \""
- << it1->label()
+ << lyx::to_utf8(it1->label())
<< "\" does not contain shortcut `"
- << shortcut << "'." << endl;
+ << lyx::to_utf8(shortcut) << "'." << endl;
for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
- if (!compare_ascii_no_case(it2->shortcut(), shortcut)) {
+ if (!compare_no_case(it2->shortcut(), shortcut)) {
lyxerr << "Menu warning: menu entries "
- << '"' << it1->fulllabel()
- << "\" and \"" << it2->fulllabel()
+ << '"' << lyx::to_utf8(it1->fulllabel())
+ << "\" and \"" << lyx::to_utf8(it2->fulllabel())
<< "\" share the same shortcut."
<< endl;
}
}
-void MenuBackend::specialMenu(string const &name)
+void MenuBackend::specialMenu(docstring const &name)
{
if (hasMenu(name))
specialmenu_ = &getMenu(name);
int ii = 1;
for (; lfit != lf.end() && ii < 10; ++lfit, ++ii) {
- string const label = convert<string>(ii) + ". "
- + MakeDisplayPath((*lfit), 30)
- + '|' + convert<string>(ii);
+ docstring const label = convert<docstring>(ii) + lyx::from_ascii(". ")
+ + makeDisplayPath((*lfit), 30)
+ + char_type('|') + convert<docstring>(ii);
tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))), view);
}
}
Strings::const_iterator docit = names.begin();
Strings::const_iterator end = names.end();
for (; docit != end; ++docit, ++ii) {
- string label = MakeDisplayPath(*docit, 20);
+ docstring label = makeDisplayPath(*docit, 20);
if (ii < 10)
- label = convert<string>(ii) + ". " + label + '|' + convert<string>(ii);
- tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_SWITCHBUFFER, *docit)), view);
+ label = convert<docstring>(ii) + lyx::from_ascii(". ") + label + char_type('|') + convert<docstring>(ii);
+ tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BUFFER_SWITCH, *docit)), view);
}
}
switch (kind) {
case MenuItem::ImportFormats:
formats = Importer::GetImportableFormats();
- action = LFUN_IMPORT;
+ action = LFUN_BUFFER_IMPORT;
break;
case MenuItem::ViewFormats:
- formats = Exporter::GetExportableFormats(*view->buffer(), true);
- action = LFUN_PREVIEW;
+ formats = Exporter::getExportableFormats(*view->buffer(), true);
+ action = LFUN_BUFFER_VIEW;
break;
case MenuItem::UpdateFormats:
- formats = Exporter::GetExportableFormats(*view->buffer(), true);
- action = LFUN_UPDATE;
+ formats = Exporter::getExportableFormats(*view->buffer(), true);
+ action = LFUN_BUFFER_UPDATE;
break;
default:
- formats = Exporter::GetExportableFormats(*view->buffer(), false);
- action = LFUN_EXPORT;
+ formats = Exporter::getExportableFormats(*view->buffer(), false);
+ action = LFUN_BUFFER_EXPORT;
}
sort(formats.begin(), formats.end(), compare_format());
for (; fit != end ; ++fit) {
if ((*fit)->dummy())
continue;
- string label = (*fit)->prettyname();
- // we need to hide the default graphic export formats
- // from the external menu, because we need them only
- // for the internal lyx-view and external latex run
- if (label == "EPS" || label == "XPM" || label == "PNG")
- continue;
+ docstring label = lyx::from_utf8((*fit)->prettyname());
- if (kind == MenuItem::ImportFormats) {
+ switch (kind) {
+ case MenuItem::ImportFormats:
if ((*fit)->name() == "text")
label = _("Plain Text as Lines");
else if ((*fit)->name() == "textparagraph")
label = _("Plain Text as Paragraphs");
- label += "...";
- } else if (kind == MenuItem::ExportFormats) {
- // exporting to LyX does not make sense
- // FIXME: Introduce noexport flag
- if ((*fit)->name() == "lyx")
+ label += lyx::from_ascii("...");
+ break;
+ case MenuItem::ViewFormats:
+ case MenuItem::ExportFormats:
+ case MenuItem::UpdateFormats:
+ if (!(*fit)->documentFormat())
continue;
+ break;
+ default:
+ BOOST_ASSERT(false);
+ break;
}
if (!(*fit)->shortcut().empty())
- label += '|' + (*fit)->shortcut();
+ label += char_type('|') + lyx::from_utf8((*fit)->shortcut());
tomenu.add(MenuItem(MenuItem::Command, label,
FuncRequest(action, (*fit)->name())),
FloatList::const_iterator end = floats.end();
for (; cit != end; ++cit) {
// normal float
- string const label = _(cit->second.name());
+ docstring const label = _(cit->second.name());
tomenu.add(MenuItem(MenuItem::Command, label,
- FuncRequest(LFUN_INSET_FLOAT,
+ FuncRequest(LFUN_FLOAT_INSERT,
cit->second.type())),
view);
}
CharStyles::iterator cit = charstyles.begin();
CharStyles::iterator end = charstyles.end();
for (; cit != end; ++cit) {
- string const label = cit->name;
+ docstring const label = lyx::from_utf8(cit->name);
tomenu.add(MenuItem(MenuItem::Command, label,
- FuncRequest(LFUN_INSERT_CHARSTYLE,
+ FuncRequest(LFUN_CHARSTYLE_INSERT,
cit->name)), view);
}
}
// check whether depth is smaller than the smallest depth in toc.
int min_depth = 1000;
for (lyx::toc::Toc::size_type i = from; i < to; ++i)
- min_depth = std::min(min_depth, toc_list[i].depth);
+ min_depth = std::min(min_depth, toc_list[i].depth());
if (min_depth > depth)
depth = min_depth;
if (to - from <= max_number_of_items) {
for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
- string label(4 * max(0, toc_list[i].depth - depth),' ');
- label += limit_string_length(toc_list[i].str);
- if (toc_list[i].depth == depth
+ docstring label(4 * max(0, toc_list[i].depth() - depth), char_type(' '));
+ label += lyx::from_utf8(limit_string_length(toc_list[i].str()));
+ if (toc_list[i].depth() == depth
&& shortcut_count < 9) {
- if (label.find(convert<string>(shortcut_count + 1)) != string::npos)
- label += '|' + convert<string>(++shortcut_count);
+ if (label.find(convert<docstring>(shortcut_count + 1)) != docstring::npos)
+ label += char_type('|') + convert<docstring>(++shortcut_count);
}
tomenu.add(MenuItem(MenuItem::Command, label,
FuncRequest(toc_list[i].action())));
while (pos < to) {
lyx::toc::Toc::size_type new_pos = pos + 1;
while (new_pos < to &&
- toc_list[new_pos].depth > depth)
+ toc_list[new_pos].depth() > depth)
++new_pos;
- string label(4 * max(0, toc_list[pos].depth - depth), ' ');
- label += limit_string_length(toc_list[pos].str);
- if (toc_list[pos].depth == depth &&
+ docstring label(4 * max(0, toc_list[pos].depth() - depth), ' ');
+ label += lyx::from_utf8(limit_string_length(toc_list[pos].str()));
+ if (toc_list[pos].depth() == depth &&
shortcut_count < 9) {
- if (label.find(convert<string>(shortcut_count + 1)) != string::npos)
- label += '|' + convert<string>(++shortcut_count);
+ if (label.find(convert<docstring>(shortcut_count + 1)) != docstring::npos)
+ label += char_type('|') + convert<docstring>(++shortcut_count);
}
if (new_pos == pos + 1) {
tomenu.add(MenuItem(MenuItem::Command,
}
FloatList const & floatlist = buf->params().getLyXTextClass().floats();
- lyx::toc::TocList toc_list = lyx::toc::getTocList(*buf);
+ lyx::toc::TocList const & toc_list = lyx::toc::getTocList(*buf);
lyx::toc::TocList::const_iterator cit = toc_list.begin();
lyx::toc::TocList::const_iterator end = toc_list.end();
for (; cit != end; ++cit) {
lyx::toc::Toc::const_iterator ccit = cit->second.begin();
lyx::toc::Toc::const_iterator eend = cit->second.end();
for (; ccit != eend; ++ccit) {
- string const label = limit_string_length(ccit->str);
+ docstring const label = lyx::from_utf8(limit_string_length(ccit->str()));
menu->add(MenuItem(MenuItem::Command,
label,
FuncRequest(ccit->action())));
vector<string>::const_iterator end = sel.end();
for (unsigned int index = 0; cit != end; ++cit, ++index) {
- tomenu.add(MenuItem(MenuItem::Command, *cit,
+ tomenu.add(MenuItem(MenuItem::Command, lyx::from_utf8(*cit),
FuncRequest(LFUN_PASTE, convert<string>(index))));
}
}
BranchList::const_iterator end = params.branchlist().end();
for (int ii = 1; cit != end; ++cit, ++ii) {
- string label = cit->getBranch();
+ docstring label = lyx::from_utf8(cit->getBranch());
if (ii < 10)
- label = convert<string>(ii) + ". " + label + "|" + convert<string>(ii);
+ label = convert<docstring>(ii) + lyx::from_ascii(". ") + label + char_type('|') + convert<docstring>(ii);
tomenu.add(MenuItem(MenuItem::Command, label,
- FuncRequest(LFUN_INSERT_BRANCH,
+ FuncRequest(LFUN_BRANCH_INSERT,
cit->getBranch())), view);
}
}
break;
case md_menu: {
lex.next(true);
- string const name = lex.getString();
+ docstring const name = lyx::from_utf8(lex.getString());
if (hasMenu(name)) {
getMenu(name).read(lex);
} else {
}
-bool MenuBackend::hasMenu(string const & name) const
+bool MenuBackend::hasMenu(docstring const & name) const
{
return find_if(begin(), end(), MenuNamesEqual(name)) != end();
}
-Menu const & MenuBackend::getMenu(string const & name) const
+Menu const & MenuBackend::getMenu(docstring const & name) const
{
const_iterator cit = find_if(begin(), end(), MenuNamesEqual(name));
if (cit == end())
- lyxerr << "No submenu named " << name << endl;
+ lyxerr << "No submenu named " << lyx::to_utf8(name) << endl;
BOOST_ASSERT(cit != end());
return (*cit);
}
-Menu & MenuBackend::getMenu(string const & name)
+Menu & MenuBackend::getMenu(docstring const & name)
{
iterator it = find_if(begin(), end(), MenuNamesEqual(name));
if (it == end())
- lyxerr << "No submenu named " << name << endl;
+ lyxerr << "No submenu named " << lyx::to_utf8(name) << endl;
BOOST_ASSERT(it != end());
return (*it);
}