mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 05:55:34 +00:00
Context menu for InsetArgument
This commit is contained in:
parent
7a05aeb4ec
commit
9914f21bce
@ -155,6 +155,13 @@ Menuset
|
|||||||
OptItem "Settings...|S" "inset-settings"
|
OptItem "Settings...|S" "inset-settings"
|
||||||
End
|
End
|
||||||
|
|
||||||
|
#
|
||||||
|
# InsetArgument context menu
|
||||||
|
#
|
||||||
|
Menu "context-argument"
|
||||||
|
SwitchArguments
|
||||||
|
End
|
||||||
|
|
||||||
#
|
#
|
||||||
# InsetBox context menu
|
# InsetBox context menu
|
||||||
#
|
#
|
||||||
|
@ -176,7 +176,10 @@ public:
|
|||||||
LanguageSelector,
|
LanguageSelector,
|
||||||
/** This is the list of arguments available
|
/** This is the list of arguments available
|
||||||
for insertion into the current layout. */
|
for insertion into the current layout. */
|
||||||
Arguments
|
Arguments,
|
||||||
|
/** This is the list of arguments available
|
||||||
|
for in the InsetArgument context menu. */
|
||||||
|
SwitchArguments
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
||||||
@ -352,7 +355,7 @@ public:
|
|||||||
void expandGraphicsGroups(BufferView const *);
|
void expandGraphicsGroups(BufferView const *);
|
||||||
void expandSpellingSuggestions(BufferView const *);
|
void expandSpellingSuggestions(BufferView const *);
|
||||||
void expandLanguageSelector(Buffer const * buf);
|
void expandLanguageSelector(Buffer const * buf);
|
||||||
void expandArguments(BufferView const *);
|
void expandArguments(BufferView const *, bool switcharg = false);
|
||||||
///
|
///
|
||||||
ItemList items_;
|
ItemList items_;
|
||||||
///
|
///
|
||||||
@ -461,7 +464,8 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
md_graphicsgroups,
|
md_graphicsgroups,
|
||||||
md_spellingsuggestions,
|
md_spellingsuggestions,
|
||||||
md_languageselector,
|
md_languageselector,
|
||||||
md_arguments
|
md_arguments,
|
||||||
|
md_switcharguments
|
||||||
};
|
};
|
||||||
|
|
||||||
LexerKeyword menutags[] = {
|
LexerKeyword menutags[] = {
|
||||||
@ -492,6 +496,7 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
{ "separator", md_separator },
|
{ "separator", md_separator },
|
||||||
{ "spellingsuggestions", md_spellingsuggestions },
|
{ "spellingsuggestions", md_spellingsuggestions },
|
||||||
{ "submenu", md_submenu },
|
{ "submenu", md_submenu },
|
||||||
|
{ "switcharguments", md_switcharguments },
|
||||||
{ "toc", md_toc },
|
{ "toc", md_toc },
|
||||||
{ "toolbars", md_toolbars },
|
{ "toolbars", md_toolbars },
|
||||||
{ "updateformats", md_updateformats },
|
{ "updateformats", md_updateformats },
|
||||||
@ -627,6 +632,10 @@ void MenuDefinition::read(Lexer & lex)
|
|||||||
add(MenuItem(MenuItem::Arguments));
|
add(MenuItem(MenuItem::Arguments));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case md_switcharguments:
|
||||||
|
add(MenuItem(MenuItem::SwitchArguments));
|
||||||
|
break;
|
||||||
|
|
||||||
case md_optsubmenu:
|
case md_optsubmenu:
|
||||||
optional = true;
|
optional = true;
|
||||||
// fallback to md_submenu
|
// fallback to md_submenu
|
||||||
@ -1539,7 +1548,7 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MenuDefinition::expandArguments(BufferView const * bv)
|
void MenuDefinition::expandArguments(BufferView const * bv, bool switcharg)
|
||||||
{
|
{
|
||||||
if (!bv)
|
if (!bv)
|
||||||
return;
|
return;
|
||||||
@ -1550,7 +1559,7 @@ void MenuDefinition::expandArguments(BufferView const * bv)
|
|||||||
args = inset->getLayout().latexargs();
|
args = inset->getLayout().latexargs();
|
||||||
else
|
else
|
||||||
args = bv->cursor().paragraph().layout().latexargs();
|
args = bv->cursor().paragraph().layout().latexargs();
|
||||||
if (args.empty())
|
if (args.empty() || (switcharg && args.size() == 1))
|
||||||
return;
|
return;
|
||||||
Layout::LaTeXArgMap::const_iterator lait = args.begin();
|
Layout::LaTeXArgMap::const_iterator lait = args.begin();
|
||||||
Layout::LaTeXArgMap::const_iterator const laend = args.end();
|
Layout::LaTeXArgMap::const_iterator const laend = args.end();
|
||||||
@ -1559,6 +1568,12 @@ void MenuDefinition::expandArguments(BufferView const * bv)
|
|||||||
QString item = toqstr(translateIfPossible(arg.labelstring));
|
QString item = toqstr(translateIfPossible(arg.labelstring));
|
||||||
if (!arg.shortcut.empty())
|
if (!arg.shortcut.empty())
|
||||||
item += "|" + toqstr(arg.shortcut);
|
item += "|" + toqstr(arg.shortcut);
|
||||||
|
if (switcharg)
|
||||||
|
add(MenuItem(MenuItem::Command, item,
|
||||||
|
FuncRequest(LFUN_INSET_MODIFY,
|
||||||
|
from_ascii("changetype ")
|
||||||
|
+ convert<docstring>((*lait).first))));
|
||||||
|
else
|
||||||
add(MenuItem(MenuItem::Command, item,
|
add(MenuItem(MenuItem::Command, item,
|
||||||
FuncRequest(LFUN_ARGUMENT_INSERT,
|
FuncRequest(LFUN_ARGUMENT_INSERT,
|
||||||
convert<docstring>((*lait).first))));
|
convert<docstring>((*lait).first))));
|
||||||
@ -1709,7 +1724,7 @@ struct Menus::Impl {
|
|||||||
/** The entries with the following kind are expanded to a
|
/** The entries with the following kind are expanded to a
|
||||||
sequence of Command MenuItems: Lastfiles, Documents,
|
sequence of Command MenuItems: Lastfiles, Documents,
|
||||||
ViewFormats, ExportFormats, UpdateFormats, Branches,
|
ViewFormats, ExportFormats, UpdateFormats, Branches,
|
||||||
Indices, Arguments
|
Indices, Arguments, SwitchArguments
|
||||||
*/
|
*/
|
||||||
void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
|
void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
|
||||||
BufferView const *) const;
|
BufferView const *) const;
|
||||||
@ -1931,7 +1946,11 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MenuItem::Arguments:
|
case MenuItem::Arguments:
|
||||||
tomenu.expandArguments(bv);
|
tomenu.expandArguments(bv, false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MenuItem::SwitchArguments:
|
||||||
|
tomenu.expandArguments(bv, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MenuItem::Submenu: {
|
case MenuItem::Submenu: {
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
#include "InsetArgument.h"
|
#include "InsetArgument.h"
|
||||||
|
|
||||||
|
#include "Cursor.h"
|
||||||
|
#include "FuncStatus.h"
|
||||||
|
#include "FuncRequest.h"
|
||||||
#include "InsetList.h"
|
#include "InsetList.h"
|
||||||
#include "Layout.h"
|
#include "Layout.h"
|
||||||
#include "Lexer.h"
|
#include "Lexer.h"
|
||||||
@ -114,6 +117,86 @@ docstring InsetArgument::toolTip(BufferView const & bv, int, int) const
|
|||||||
return toolTipText(tooltip_ + from_ascii(":\n"));
|
return toolTipText(tooltip_ + from_ascii(":\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InsetArgument::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||||
|
{
|
||||||
|
switch (cmd.action()) {
|
||||||
|
|
||||||
|
case LFUN_INSET_MODIFY: {
|
||||||
|
string const first_arg = cmd.getArg(0);
|
||||||
|
bool const change_type = first_arg == "changetype";
|
||||||
|
if (!change_type) {
|
||||||
|
// not for us
|
||||||
|
// this will not be handled higher up
|
||||||
|
cur.undispatched();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cur.recordUndoInset(ATOMIC_UNDO, this);
|
||||||
|
name_ = cmd.getArg(1);
|
||||||
|
cur.forceBufferUpdate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
InsetCollapsable::doDispatch(cur, cmd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool InsetArgument::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||||
|
FuncStatus & flag) const
|
||||||
|
{
|
||||||
|
switch (cmd.action()) {
|
||||||
|
|
||||||
|
case LFUN_INSET_MODIFY: {
|
||||||
|
string const first_arg = cmd.getArg(0);
|
||||||
|
if (first_arg == "changetype") {
|
||||||
|
string const type = cmd.getArg(1);
|
||||||
|
flag.setOnOff(type == name_);
|
||||||
|
if (type == name_) {
|
||||||
|
flag.setEnabled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Layout::LaTeXArgMap args;
|
||||||
|
bool const insetlayout = &cur.inset() && cur.paragraph().layout().latexargs().empty();
|
||||||
|
if (insetlayout)
|
||||||
|
args = cur.inset().getLayout().latexargs();
|
||||||
|
else
|
||||||
|
args = cur.paragraph().layout().latexargs();
|
||||||
|
Layout::LaTeXArgMap::const_iterator const lait =
|
||||||
|
args.find(convert<unsigned int>(type));
|
||||||
|
if (lait != args.end()) {
|
||||||
|
flag.setEnabled(true);
|
||||||
|
InsetList::const_iterator it = cur.paragraph().insetList().begin();
|
||||||
|
InsetList::const_iterator end = cur.paragraph().insetList().end();
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
if (it->inset->lyxCode() == ARG_CODE) {
|
||||||
|
InsetArgument const * ins =
|
||||||
|
static_cast<InsetArgument const *>(it->inset);
|
||||||
|
if (ins->name() == type) {
|
||||||
|
// we have this already
|
||||||
|
flag.setEnabled(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
flag.setEnabled(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string InsetArgument::contextMenuName() const
|
||||||
|
{
|
||||||
|
return "context-argument";
|
||||||
|
}
|
||||||
|
|
||||||
void InsetArgument::latexArgument(otexstream & os,
|
void InsetArgument::latexArgument(otexstream & os,
|
||||||
OutputParams const & runparams, docstring const & ldelim,
|
OutputParams const & runparams, docstring const & ldelim,
|
||||||
docstring const & rdelim) const
|
docstring const & rdelim) const
|
||||||
|
@ -60,6 +60,8 @@ public:
|
|||||||
void read(Lexer & lex);
|
void read(Lexer & lex);
|
||||||
///
|
///
|
||||||
bool neverIndent() const { return true; }
|
bool neverIndent() const { return true; }
|
||||||
|
///
|
||||||
|
std::string contextMenuName() const;
|
||||||
//@}
|
//@}
|
||||||
/// \name Public functions inherited from InsetCollapsable class
|
/// \name Public functions inherited from InsetCollapsable class
|
||||||
//@{
|
//@{
|
||||||
@ -81,6 +83,10 @@ protected:
|
|||||||
/// \name Protected functions inherited from Inset class
|
/// \name Protected functions inherited from Inset class
|
||||||
//@{
|
//@{
|
||||||
///
|
///
|
||||||
|
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
|
||||||
|
///
|
||||||
|
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||||
|
///
|
||||||
Inset * clone() const { return new InsetArgument(*this); }
|
Inset * clone() const { return new InsetArgument(*this); }
|
||||||
//@}
|
//@}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user