#include "insets/Inset.h"
#include "insets/InsetCitation.h"
#include "insets/InsetGraphics.h"
+#include "insets/InsetQuotes.h"
#include "support/lassert.h"
#include "support/convert.h"
#include <QProxyStyle>
#endif
-#include "support/shared_ptr.h"
-
#include <algorithm>
+#include <memory>
#include <vector>
using namespace std;
in the InsetCaption context menu. */
SwitchCaptions,
/** Commands to separate environments. */
- EnvironmentSeparators
+ EnvironmentSeparators,
+ /** This is the list of quotation marks available */
+ SwitchQuotes
};
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
QString const & submenu = QString(),
QString const & tooltip = QString(),
bool optional = false)
- : kind_(kind), label_(label), submenuname_(submenu),
- tooltip_(tooltip), optional_(optional)
+ : kind_(kind), label_(label), func_(make_shared<FuncRequest>()),
+ submenuname_(submenu), tooltip_(tooltip), optional_(optional)
{
LATTEST(kind == Submenu || kind == Help || kind == Info);
}
QString const & tooltip = QString(),
bool optional = false,
FuncRequest::Origin origin = FuncRequest::MENU)
- : kind_(kind), label_(label), func_(func),
+ : kind_(kind), label_(label), func_(make_shared<FuncRequest>(func)),
tooltip_(tooltip), optional_(optional)
{
- func_.setOrigin(origin);
+ func_->setOrigin(origin);
}
- // shared_ptr<MenuDefinition> needs this apprently...
- ~MenuItem() {}
-
/// The label of a given menuitem
QString label() const
{
/// The kind of entry
Kind kind() const { return kind_; }
/// the action (if relevant)
- FuncRequest const & func() const { return func_; }
+ shared_ptr<FuncRequest const> func() const { return func_; }
/// the tooltip
QString const & tooltip() const { return tooltip_; }
/// returns true if the entry should be omitted when disabled
return QString();
// Get the keys bound to this action, but keep only the
// first one later
- KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(func_);
+ KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*func_);
if (!bindings.empty())
return toqstr(bindings.begin()->print(KeySequence::ForGui));
LYXERR(Debug::KBMAP, "No binding for "
- << lyxaction.getActionName(func_.action())
- << '(' << func_.argument() << ')');
+ << lyxaction.getActionName(func_->action())
+ << '(' << func_->argument() << ')');
return QString();
}
///
QString label_;
///
- FuncRequest func_;
+ shared_ptr<FuncRequest> func_;// non-null
///
QString submenuname_;
///
///
size_t size() const { return items_.size(); }
///
- MenuItem const & operator[](size_t) const;
- ///
const_iterator begin() const { return items_.begin(); }
///
const_iterator end() const { return items_.end(); }
void expandArguments(BufferView const *, bool switcharg = false);
void expandCaptions(Buffer const * buf, bool switchcap = false);
void expandEnvironmentSeparators(BufferView const *);
+ void expandQuotes(BufferView const *);
///
ItemList items_;
///
switch (i.kind()) {
case MenuItem::Command: {
- FuncStatus status = lyx::getStatus(i.func());
+ FuncStatus status = lyx::getStatus(*i.func());
if (status.unknown() || (!status.enabled() && i.optional()))
break;
items_.push_back(i);
md_switcharguments,
md_captions,
md_switchcaptions,
- md_env_separators
+ md_env_separators,
+ md_switchquotes
};
LexerKeyword menutags[] = {
{ "submenu", md_submenu },
{ "switcharguments", md_switcharguments },
{ "switchcaptions", md_switchcaptions },
+ { "switchquotes", md_switchquotes },
{ "toc", md_toc },
{ "toolbars", md_toolbars },
{ "updateformats", md_updateformats },
add(MenuItem(MenuItem::EnvironmentSeparators));
break;
+ case md_switchquotes:
+ add(MenuItem(MenuItem::SwitchQuotes));
+ break;
+
case md_optsubmenu:
case md_submenu: {
lex.next(true);
}
-MenuItem const & MenuDefinition::operator[](size_type i) const
-{
- return items_[i];
-}
-
-
bool MenuDefinition::hasFunc(FuncRequest const & func) const
{
for (const_iterator it = begin(), et = end(); it != et; ++it)
- if (it->func() == func)
+ if (*it->func() == func)
return true;
return false;
}
const_iterator m = begin();
const_iterator m_end = end();
for (; m != m_end; ++m) {
- if (m->kind() == MenuItem::Command && m->func() == func) {
+ if (m->kind() == MenuItem::Command && *m->func() == func) {
names.push_back(qstring_to_ucs4(m->label()));
return true;
}
if (!buf && kind != MenuItem::ImportFormats)
return;
- typedef vector<Format const *> Formats;
- Formats formats;
+ FormatList formats;
FuncCode action = LFUN_NOACTION;
switch (kind) {
LATTEST(false);
return;
}
- sort(formats.begin(), formats.end(), Format::formatSorter);
bool const view_update = (kind == MenuItem::ViewFormats
|| kind == MenuItem::UpdateFormats);
MenuItem item(MenuItem::Submenu, smenue);
item.setSubmenu(MenuDefinition(smenue));
- Formats::const_iterator fit = formats.begin();
- Formats::const_iterator end = formats.end();
- for (; fit != end ; ++fit) {
- if ((*fit)->dummy())
+ for (Format const * f : formats) {
+ if (f->dummy())
continue;
- docstring lab = from_utf8((*fit)->prettyname());
- docstring const scut = from_utf8((*fit)->shortcut());
+ docstring lab = f->prettyname();
+ docstring const scut = from_utf8(f->shortcut());
docstring const tmplab = lab;
if (!scut.empty())
break;
case MenuItem::ViewFormats:
case MenuItem::UpdateFormats:
- if ((*fit)->name() == buf->params().getDefaultOutputFormat()) {
+ if (f->name() == buf->params().getDefaultOutputFormat()) {
docstring lbl = (kind == MenuItem::ViewFormats
? bformat(_("View [%1$s]|V"), label)
: bformat(_("Update [%1$s]|U"), label));
}
// fall through
case MenuItem::ExportFormats:
- if (!(*fit)->inExportMenu())
+ if (!f->inExportMenu())
continue;
break;
default:
// note that at this point, we know that buf is not null
LATTEST(buf);
item.submenu().addWithStatusCheck(MenuItem(MenuItem::Command,
- toqstr(label), FuncRequest(action, (*fit)->name())));
+ toqstr(label), FuncRequest(action, f->name())));
} else {
if (buf)
addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
- FuncRequest(action, (*fit)->name())));
+ FuncRequest(action, f->name())));
else
add(MenuItem(MenuItem::Command, toqstr(label),
- FuncRequest(action, (*fit)->name())));
+ FuncRequest(action, f->name())));
}
}
if (view_update)
if (!buf)
return;
- vector<docstring> caps;
DocumentClass const & dc = buf->params().documentClass();
- TextClass::InsetLayouts::const_iterator lit = dc.insetLayouts().begin();
- TextClass::InsetLayouts::const_iterator len = dc.insetLayouts().end();
- for (; lit != len; ++lit) {
- if (prefixIs(lit->first, from_ascii("Caption:")))
- caps.push_back(lit->first);
+ vector< pair<docstring, FuncRequest> > caps;
+ for (pair<docstring, InsetLayout> const & il : dc.insetLayouts()) {
+ docstring instype;
+ docstring const type = split(il.first, instype, ':');
+ if (instype == "Caption") {
+ // skip forbidden caption types
+ FuncRequest const cmd = switchcap
+ ? FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype ") + type)
+ : FuncRequest(LFUN_CAPTION_INSERT, type);
+ if (getStatus(cmd).enabled())
+ caps.push_back(make_pair(type, cmd));
+ }
}
if (caps.empty() || (switchcap && caps.size() == 1))
return;
if (caps.size() == 1) {
- docstring dummy;
- docstring const type = split(*caps.begin(), dummy, ':');
- add(MenuItem(MenuItem::Command, qt_("Caption"),
- FuncRequest(LFUN_CAPTION_INSERT, translateIfPossible(type))));
+ add(MenuItem(MenuItem::Command, qt_("Caption"), caps.front().second));
return;
}
MenuDefinition captions;
-
- vector<docstring>::const_iterator cit = caps.begin();
- vector<docstring>::const_iterator end = caps.end();
-
- for (int ii = 1; cit != end; ++cit, ++ii) {
- docstring dummy;
- docstring const type = split(*cit, dummy, ':');
+ for (pair<docstring, FuncRequest> const & cap : caps) {
+ docstring const type = cap.first;
docstring const trtype = translateIfPossible(type);
docstring const cmitem = bformat(_("Caption (%1$s)"), trtype);
- // make menu item optional, otherwise we would also see
- // forbidden caption types
if (switchcap)
- addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cmitem),
- FuncRequest(LFUN_INSET_MODIFY,
- from_ascii("changetype ")
- + type), QString(), true));
+ add(MenuItem(MenuItem::Command, toqstr(cmitem), cap.second));
else
- captions.addWithStatusCheck(MenuItem(MenuItem::Command,
- toqstr(trtype),
- FuncRequest(LFUN_CAPTION_INSERT,
- type), QString(), true));
+ captions.add(MenuItem(MenuItem::Command, toqstr(trtype), cap.second));
}
if (!captions.empty()) {
MenuItem item(MenuItem::Submenu, qt_("Caption"));
}
+void MenuDefinition::expandQuotes(BufferView const * bv)
+{
+ if (!bv)
+ return;
+
+ if (!bv->cursor().inTexted())
+ return;
+
+ Inset const * inset = bv->cursor().nextInset();
+ if (!inset || inset->lyxCode() != QUOTE_CODE) {
+ add(MenuItem(MenuItem::Command,
+ qt_("No Quote in Scope!"),
+ FuncRequest(LFUN_NOACTION)));
+ return;
+ }
+ InsetQuotes const * qinset =
+ static_cast<InsetQuotes const *>(inset);
+
+ map<string, docstring> styles = quoteparams.getTypes();
+ string const qtype = qinset->getType();
+
+ map<string, docstring>::const_iterator qq = styles.begin();
+ map<string, docstring>::const_iterator end = styles.end();
+
+ MenuDefinition eqs;
+ MenuDefinition sqs;
+ MenuDefinition gqs;
+ MenuDefinition pqs;
+ MenuDefinition cqs;
+ MenuDefinition aqs;
+ MenuDefinition qqs;
+ MenuDefinition bqs;
+ MenuDefinition wqs;
+ MenuDefinition fqs;
+ MenuDefinition iqs;
+ MenuDefinition rqs;
+ MenuDefinition xqs;
+ InsetQuotesParams::QuoteStyle globalqs =
+ bv->buffer().masterBuffer()->params().quotes_style;
+ FuncRequest cmd = FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype xld"));
+ docstring desc = bformat(_("%1$stext (dynamic)"),
+ docstring(1, quoteparams.getQuoteChar(globalqs,
+ InsetQuotesParams::PrimaryQuotes,
+ InsetQuotesParams::OpeningQuote)));
+ if (prefixIs(qtype, "x"))
+ add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else
+ xqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ cmd = FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype xls"));
+ desc = bformat(_("%1$stext (dynamic)"),
+ docstring(1, quoteparams.getQuoteChar(globalqs,
+ InsetQuotesParams::SecondaryQuotes,
+ InsetQuotesParams::OpeningQuote)));
+ if (prefixIs(qtype, "x"))
+ add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else
+ xqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ cmd = FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype xrd"));
+ desc = bformat(_("text%1$s (dynamic)"),
+ docstring(1, quoteparams.getQuoteChar(globalqs,
+ InsetQuotesParams::PrimaryQuotes,
+ InsetQuotesParams::ClosingQuote)));
+ if (prefixIs(qtype, "x"))
+ add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else
+ xqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ cmd = FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype xrs"));
+ desc = bformat(_("text%1$s (dynamic)"),
+ docstring(1, quoteparams.getQuoteChar(globalqs,
+ InsetQuotesParams::SecondaryQuotes,
+ InsetQuotesParams::ClosingQuote)));
+ if (prefixIs(qtype, "x"))
+ add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else
+ xqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+
+ for (; qq != end; ++qq) {
+ docstring const style = from_ascii(qq->first);
+ cmd = FuncRequest(LFUN_INSET_MODIFY, from_ascii("changetype ") + style);
+ desc = contains(style, 'l') ?
+ bformat(_("%1$stext"), qq->second) : bformat(_("text%1$s"), qq->second);
+ if (prefixIs(style, qtype[0]))
+ add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'e') && !prefixIs(qtype, "e"))
+ eqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 's') && !prefixIs(qtype, "s"))
+ sqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'g') && !prefixIs(qtype, "g"))
+ gqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'p') && !prefixIs(qtype, "p"))
+ pqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'c') && !prefixIs(qtype, "c"))
+ cqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'a') && !prefixIs(qtype, "a"))
+ aqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'q') && !prefixIs(qtype, "q"))
+ qqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'b') && !prefixIs(qtype, "b"))
+ bqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'w') && !prefixIs(qtype, "w"))
+ wqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'f') && !prefixIs(qtype, "f"))
+ fqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'i') && !prefixIs(qtype, "i"))
+ iqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ else if (prefixIs(style, 'r') && !prefixIs(qtype, "r"))
+ rqs.add(MenuItem(MenuItem::Command, toqstr(desc), cmd));
+ }
+
+ if (!xqs.empty()) {
+ MenuItem item(MenuItem::Submenu, qt_("Dynamic Quotation Marks"));
+ item.setSubmenu(xqs);
+ add(item);
+ }
+ if (!eqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::EnglishQuotes)));
+ item.setSubmenu(eqs);
+ add(item);
+ }
+ if (!sqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::SwedishQuotes)));
+ item.setSubmenu(sqs);
+ add(item);
+ }
+ if (!gqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::GermanQuotes)));
+ item.setSubmenu(gqs);
+ add(item);
+ }
+ if (!pqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::PolishQuotes)));
+ item.setSubmenu(pqs);
+ add(item);
+ }
+ if (!cqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::SwissQuotes)));
+ item.setSubmenu(cqs);
+ add(item);
+ }
+ if (!aqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::DanishQuotes)));
+ item.setSubmenu(aqs);
+ add(item);
+ }
+ if (!qqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::PlainQuotes)));
+ item.setSubmenu(qqs);
+ add(item);
+ }
+ if (!bqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::BritishQuotes)));
+ item.setSubmenu(bqs);
+ add(item);
+ }
+ if (!wqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::SwedishGQuotes)));
+ item.setSubmenu(wqs);
+ add(item);
+ }
+ if (!fqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::FrenchQuotes)));
+ item.setSubmenu(fqs);
+ add(item);
+ }
+ if (!iqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::FrenchINQuotes)));
+ item.setSubmenu(iqs);
+ add(item);
+ }
+ if (!rqs.empty()) {
+ MenuItem item(MenuItem::Submenu,
+ toqstr(quoteparams.getGuiLabel(InsetQuotesParams::RussianQuotes)));
+ item.setSubmenu(rqs);
+ add(item);
+ }
+}
+
+
void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
{
if (!bv)
{
/// populates the menu or one of its submenu
/// This is used as a recursive function
- void populate(QMenu & qMenu, MenuDefinition const & menu);
+ void populate(QMenu * qMenu, MenuDefinition const & menu);
/// Only needed for top level menus.
MenuDefinition * top_level_menu;
return label;
}
-void Menu::Impl::populate(QMenu & qMenu, MenuDefinition const & menu)
+void Menu::Impl::populate(QMenu * qMenu, MenuDefinition const & menu)
{
LYXERR(Debug::GUI, "populating menu " << menu.name());
if (menu.empty()) {
return;
}
LYXERR(Debug::GUI, " ***** menu entries " << menu.size());
- MenuDefinition::const_iterator m = menu.begin();
- MenuDefinition::const_iterator end = menu.end();
- for (; m != end; ++m) {
- if (m->kind() == MenuItem::Separator)
- qMenu.addSeparator();
- else if (m->kind() == MenuItem::Submenu) {
- QMenu * subMenu = qMenu.addMenu(label(*m));
- populate(*subMenu, m->submenu());
+ for (MenuItem const & m : menu)
+ switch (m.kind()) {
+ case MenuItem::Separator:
+ qMenu->addSeparator();
+ break;
+ case MenuItem::Submenu: {
+ QMenu * subMenu = qMenu->addMenu(label(m));
+ populate(subMenu, m.submenu());
subMenu->setEnabled(!subMenu->isEmpty());
- } else {
- // we have a MenuItem::Command
- qMenu.addAction(new Action(QIcon(), label(*m),
- m->func(), m->tooltip(), &qMenu));
+ break;
+ }
+ case MenuItem::Command:
+ default:
+ // FIXME: A previous comment assured that MenuItem::Command was the
+ // only possible case in practice, but this is wrong. It would be
+ // good to document which cases are actually treated here.
+ qMenu->addAction(new Action(m.func(), QIcon(), label(m),
+ m.tooltip(), qMenu));
+ break;
}
- }
}
#if (defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)) && (QT_VERSION >= 0x040600)
QAction::MenuRole role;
};
- static MacMenuEntry entries[] = {
+ static const MacMenuEntry entries[] = {
{LFUN_DIALOG_SHOW, "aboutlyx", "About LyX",
QAction::AboutRole},
{LFUN_DIALOG_SHOW, "prefs", "Preferences",
// add the entries to a QMenu that will eventually be empty
// and therefore invisible.
QMenu * qMenu = qmb->addMenu("special");
- MenuDefinition::const_iterator cit = mac_special_menu_.begin();
- MenuDefinition::const_iterator end = mac_special_menu_.end();
- for (size_t i = 0 ; cit != end ; ++cit, ++i) {
- Action * action = new Action(QIcon(), cit->label(),
- cit->func(), QString(), qMenu);
+ size_t i = 0;
+ for (MenuItem const & m : mac_special_menu_) {
+ Action * action = new Action(m.func(), QIcon(), m.label(),
+ QString(), qMenu);
action->setMenuRole(entries[i].role);
qMenu->addAction(action);
+ ++i;
}
}
tomenu.expandEnvironmentSeparators(bv);
break;
+ case MenuItem::SwitchQuotes:
+ tomenu.expandQuotes(bv);
+ break;
+
case MenuItem::Submenu: {
MenuItem item(*cit);
item.setSubmenu(MenuDefinition(cit->submenuname()));
break;
case MenuItem::Command:
- if (!mac_special_menu_.hasFunc(cit->func()))
+ if (!mac_special_menu_.hasFunc(*cit->func()))
tomenu.addWithStatusCheck(*cit);
}
}
if (qmenu->d->view)
bv = qmenu->d->view->currentBufferView();
d->expand(fromLyxMenu, *qmenu->d->top_level_menu, bv);
- qmenu->d->populate(*qmenu, *qmenu->d->top_level_menu);
+ qmenu->d->populate(qmenu, *qmenu->d->top_level_menu);
}