mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Extend environment-split to an 'outer' split function
This fixes a major beamer UI flaw reported by several users.
This commit is contained in:
parent
9d7f25a4ae
commit
5a3f1a731f
@ -112,6 +112,10 @@ Format 1
|
||||
\bind "M-a Up" "outline-up"
|
||||
\bind "M-a Down" "outline-down"
|
||||
|
||||
|
||||
\bind "M-a Return" "environment-split"
|
||||
\bind "M-a S-Return" "environment-split outer"
|
||||
|
||||
# Obsolete Tastenbelegung: in die persönliche *.bind Datei kopieren und
|
||||
# auskommentieren wenn diese Tastenbelegung gewünscht ist.
|
||||
# \bind "M-a S-quotedbl" "layout Section*" # M-a S-2
|
||||
|
@ -125,6 +125,9 @@ Format 1
|
||||
\bind "M-p Up" "outline-up"
|
||||
\bind "M-p Down" "outline-down"
|
||||
|
||||
\bind "M-p Return" "environment-split"
|
||||
\bind "M-p S-Return" "environment-split outer"
|
||||
|
||||
|
||||
# These are kept for backwards compatibility (only make sense on US keyboard)
|
||||
\bind "M-p S-at" "layout Section*" # M-p S-2
|
||||
|
@ -318,6 +318,8 @@ Menuset
|
||||
Item "Move Paragraph Up|o" "paragraph-move-up"
|
||||
Item "Move Paragraph Down|v" "paragraph-move-down"
|
||||
Separator
|
||||
EnvironmentSeparators
|
||||
Separator
|
||||
OptItem "Promote Section|r" "outline-out"
|
||||
OptItem "Demote Section|m" "outline-in"
|
||||
OptItem "Move Section Down|D" "outline-down"
|
||||
|
@ -133,6 +133,7 @@ Menuset
|
||||
# obvious what the context is for the others)
|
||||
OptItem "Increase List Depth|I" "depth-increment"
|
||||
OptItem "Decrease List Depth|D" "depth-decrement"
|
||||
EnvironmentSeparators
|
||||
OptItem "Dissolve Inset" "inset-dissolve"
|
||||
OptItem "TeX Code Settings...|C" "inset-settings ert"
|
||||
# 'a' shortcut to match Insert entry, shouldn't clash with Table Settings
|
||||
@ -150,7 +151,6 @@ Menuset
|
||||
# This is in the Table submenu instead for now.
|
||||
# OptItem "Table Settings...|a" "inset-settings tabular"
|
||||
OptItem "Table Settings...|a" "layout-tabular"
|
||||
OptItem "Split Environment|l" "environment-split"
|
||||
End
|
||||
|
||||
Menu "edit_paste"
|
||||
|
@ -3682,7 +3682,9 @@ void LyXAction::init()
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_ENVIRONMENT_SPLIT
|
||||
* \li Action: Splits the current environment with a Separator.
|
||||
* \li Syntax: environment-split
|
||||
* \li Syntax: environment-split [outer]
|
||||
* \li Params: outer: If this is given, LyX will split the outermost environment in
|
||||
* the current nesting hierarchy.
|
||||
* \li Origin: spitz, 23 Dec 2012
|
||||
* \endvar
|
||||
*/
|
||||
|
@ -1378,10 +1378,32 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
||||
}
|
||||
|
||||
case LFUN_ENVIRONMENT_SPLIT: {
|
||||
bool const outer = cmd.argument() == "outer";
|
||||
Paragraph const & para = cur.paragraph();
|
||||
docstring const layout = para.layout().name();
|
||||
docstring layout = para.layout().name();
|
||||
depth_type split_depth = cur.paragraph().params().depth();
|
||||
if (outer) {
|
||||
// check if we have an environment in our nesting hierarchy
|
||||
pit_type pit = cur.pit();
|
||||
Paragraph cpar = pars_[pit];
|
||||
while (true) {
|
||||
if (pit == 0 || cpar.params().depth() == 0)
|
||||
break;
|
||||
--pit;
|
||||
cpar = pars_[pit];
|
||||
if (cpar.params().depth() < split_depth
|
||||
&& cpar.layout().isEnvironment()) {
|
||||
layout = cpar.layout().name();
|
||||
split_depth = cpar.params().depth();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cur.pos() > 0)
|
||||
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
|
||||
if (outer) {
|
||||
while (cur.paragraph().params().depth() > split_depth)
|
||||
lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
|
||||
}
|
||||
bool const morecont = cur.lastpos() > cur.pos();
|
||||
lyx::dispatch(FuncRequest(LFUN_LAYOUT, "Separator"));
|
||||
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
|
||||
@ -2892,8 +2914,28 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
break;
|
||||
|
||||
case LFUN_ENVIRONMENT_SPLIT: {
|
||||
if (cur.paragraph().layout().isEnvironment()
|
||||
&& cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))) {
|
||||
if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))) {
|
||||
enable = false;
|
||||
break;
|
||||
}
|
||||
if (cmd.argument() == "outer") {
|
||||
// check if we have an environment in our nesting hierarchy
|
||||
bool res = false;
|
||||
depth_type const current_depth = cur.paragraph().params().depth();
|
||||
pit_type pit = cur.pit();
|
||||
Paragraph cpar = pars_[pit];
|
||||
while (true) {
|
||||
if (pit == 0 || cpar.params().depth() == 0)
|
||||
break;
|
||||
--pit;
|
||||
cpar = pars_[pit];
|
||||
if (cpar.params().depth() < current_depth)
|
||||
res = cpar.layout().isEnvironment();
|
||||
}
|
||||
enable = res;
|
||||
break;
|
||||
}
|
||||
else if (cur.paragraph().layout().isEnvironment()) {
|
||||
enable = true;
|
||||
break;
|
||||
}
|
||||
|
@ -47,10 +47,12 @@
|
||||
#include "LyXRC.h"
|
||||
#include "lyxfind.h"
|
||||
#include "Paragraph.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "ParIterator.h"
|
||||
#include "Session.h"
|
||||
#include "SpellChecker.h"
|
||||
#include "TextClass.h"
|
||||
#include "Text.h"
|
||||
#include "TocBackend.h"
|
||||
#include "Toolbars.h"
|
||||
#include "WordLangTuple.h"
|
||||
@ -185,7 +187,9 @@ public:
|
||||
Captions,
|
||||
/** This is the list of captions available
|
||||
in the InsetCaption context menu. */
|
||||
SwitchCaptions
|
||||
SwitchCaptions,
|
||||
/** Commands to separate environments. */
|
||||
EnvironmentSeparation
|
||||
};
|
||||
|
||||
explicit MenuItem(Kind kind) : kind_(kind), optional_(false) {}
|
||||
@ -363,6 +367,7 @@ public:
|
||||
void expandLanguageSelector(Buffer const * buf);
|
||||
void expandArguments(BufferView const *, bool switcharg = false);
|
||||
void expandCaptions(Buffer const * buf, bool switchcap = false);
|
||||
void expandEnvironmentSeparators(BufferView const *);
|
||||
///
|
||||
ItemList items_;
|
||||
///
|
||||
@ -474,7 +479,8 @@ void MenuDefinition::read(Lexer & lex)
|
||||
md_arguments,
|
||||
md_switcharguments,
|
||||
md_captions,
|
||||
md_switchcaptions
|
||||
md_switchcaptions,
|
||||
md_env_separators
|
||||
};
|
||||
|
||||
LexerKeyword menutags[] = {
|
||||
@ -488,6 +494,7 @@ void MenuDefinition::read(Lexer & lex)
|
||||
{ "documents", md_documents },
|
||||
{ "elements", md_elements },
|
||||
{ "end", md_endmenu },
|
||||
{ "environmentseparators", md_env_separators },
|
||||
{ "exportformats", md_exportformats },
|
||||
{ "floatinsert", md_floatinsert },
|
||||
{ "floatlistinsert", md_floatlistinsert },
|
||||
@ -651,6 +658,10 @@ void MenuDefinition::read(Lexer & lex)
|
||||
add(MenuItem(MenuItem::SwitchCaptions));
|
||||
break;
|
||||
|
||||
case md_env_separators:
|
||||
add(MenuItem(MenuItem::EnvironmentSeparation));
|
||||
break;
|
||||
|
||||
case md_optsubmenu:
|
||||
case md_submenu: {
|
||||
lex.next(true);
|
||||
@ -1649,6 +1660,47 @@ void MenuDefinition::expandCaptions(Buffer const * buf, bool switchcap)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
|
||||
{
|
||||
if (!bv)
|
||||
return;
|
||||
|
||||
Paragraph const par = bv->cursor().paragraph();
|
||||
docstring const curlayout = par.layout().name();
|
||||
docstring outerlayout;
|
||||
depth_type current_depth = par.params().depth();
|
||||
// check if we have an environment in our nesting hierarchy
|
||||
pit_type pit = bv->cursor().pit();
|
||||
Paragraph cpar = bv->buffer().text().getPar(pit);
|
||||
while (true) {
|
||||
if (pit == 0 || cpar.params().depth() == 0)
|
||||
break;
|
||||
--pit;
|
||||
cpar = bv->buffer().text().getPar(pit);
|
||||
if (cpar.params().depth() < current_depth
|
||||
&& cpar.layout().isEnvironment()) {
|
||||
outerlayout = cpar.layout().name();
|
||||
current_depth = cpar.params().depth();
|
||||
}
|
||||
}
|
||||
if (par.layout().isEnvironment()) {
|
||||
docstring const label =
|
||||
bformat(_("Start New Environment (%1$s)"),
|
||||
translateIfPossible(curlayout));
|
||||
add(MenuItem(MenuItem::Command, toqstr(label),
|
||||
FuncRequest(LFUN_ENVIRONMENT_SPLIT)));
|
||||
}
|
||||
if (!outerlayout.empty()) {
|
||||
docstring const label =
|
||||
bformat(_("Start New Parent Environment (%1$s)"),
|
||||
translateIfPossible(outerlayout));
|
||||
add(MenuItem(MenuItem::Command, toqstr(label),
|
||||
FuncRequest(LFUN_ENVIRONMENT_SPLIT,
|
||||
from_ascii("outer"))));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
@ -1793,7 +1845,8 @@ struct Menus::Impl {
|
||||
/** The entries with the following kind are expanded to a
|
||||
sequence of Command MenuItems: Lastfiles, Documents,
|
||||
ViewFormats, ExportFormats, UpdateFormats, Branches,
|
||||
Indices, Arguments, SwitchArguments, Captions, SwitchCaptions
|
||||
Indices, Arguments, SwitchArguments, Captions, SwitchCaptions,
|
||||
EnvironmentSeparation
|
||||
*/
|
||||
void expand(MenuDefinition const & frommenu, MenuDefinition & tomenu,
|
||||
BufferView const *) const;
|
||||
@ -2030,6 +2083,10 @@ void Menus::Impl::expand(MenuDefinition const & frommenu,
|
||||
tomenu.expandCaptions(buf, true);
|
||||
break;
|
||||
|
||||
case MenuItem::EnvironmentSeparation:
|
||||
tomenu.expandEnvironmentSeparators(bv);
|
||||
break;
|
||||
|
||||
case MenuItem::Submenu: {
|
||||
MenuItem item(*cit);
|
||||
item.setSubmenu(MenuDefinition(cit->submenuname()));
|
||||
|
Loading…
Reference in New Issue
Block a user