Dear all,

I would like to thank all of the developers and contributors to the LyX
project that have made such a great piece of software. Also, I would
like to compliment the developers on the fine source code which made a
feature that I so desperately needed easy to implement. Which brings me
to my main point.

My Environment choice box started to grow to an unwieldy size as my
custom ".layouts" grew. Many of the styles were sub-levels. For example:
Requirement, Subrequirement, Subsubrequirement, and
Subsubsubrequirement. The same was true for other styles that I had made
like feature, supplement, and use case. As you can see, the environment
choice box was quickly growing. 

I wished for a way to just have "Requirement" in the Environment choice
box and be able to cycle through the levels much like one can do with
the sections, with the tab key. Since this feature didn't exist, I
decided to implement it in a manner generic that I hope will be useful
to the project as a whole. 

I have added a keyword within the "Style" section of a ".layout" file
called "NextStyle" that is implemented with an LyX function called
"layout-next" (action LFUN_LAYOUT_NEXT), and can be bound to a key of
your choosing. This enables the following in the .layout file:

 Style Requirement
        ...
        NextStyle Subrequirement 
        ...
End

Style Subrequirement
        ...
        NextStyle Subsubrequirement 
        ...
End

Style Subsubrequirement
        ...
        NextStyle Subsubsubrequirement 
        ...
End

Style Subsubsubrequirement
        ...
        NextStyle Requirement 
        ...
End

It is my sincere hope that the developers find this useful and decide to
implement it as part of the LyX project. 

Kind regards,
John

I hereby grant permission to license my contributions to LyX under the
Gnu General Public Licence (version two or later):

diff -u -r lyx-2.0.3/src/frontends/qt4/GuiApplication.cpp
lyx-2.0.3-jwc/src/frontends/qt4/GuiApplication.cpp
--- lyx-2.0.3/src/frontends/qt4/GuiApplication.cpp      2011-12-04
11:16:32.000000000 -0500
+++ lyx-2.0.3-jwc/src/frontends/qt4/GuiApplication.cpp  2012-03-30
08:34:42.899226451 -0400
@@ -1031,6 +1031,7 @@
        case LFUN_RECONFIGURE:
        case LFUN_SERVER_GET_FILENAME:
        case LFUN_SERVER_NOTIFY:
+       case LFUN_LAYOUT_NEXT:
                enable = true;
                break;

diff -u -r lyx-2.0.3/src/FuncCode.h lyx-2.0.3-jwc/src/FuncCode.h
--- lyx-2.0.3/src/FuncCode.h    2010-11-23 15:09:08.000000000 -0500
+++ lyx-2.0.3-jwc/src/FuncCode.h        2012-03-29 16:31:21.577230704
-0400
@@ -173,6 +173,7 @@
        LFUN_MARK_OFF,
        LFUN_MARK_ON,
        LFUN_LAYOUT,
+       LFUN_LAYOUT_NEXT,
        // 120
        LFUN_LAYOUT_PARAGRAPH,
        LFUN_DROP_LAYOUTS_CHOICE,       // used in bindings as of
20071228
diff -u -r lyx-2.0.3/src/insets/InsetTabular.cpp
lyx-2.0.3-jwc/src/insets/InsetTabular.cpp
--- lyx-2.0.3/src/insets/InsetTabular.cpp       2012-01-27
16:44:30.000000000 -0500
+++ lyx-2.0.3-jwc/src/insets/InsetTabular.cpp   2012-03-29
19:50:13.123230530 -0400
@@ -3334,6 +3334,7 @@
        bool enabled = true;
        switch (cmd.action()) {
        case LFUN_LAYOUT:
+       case LFUN_LAYOUT_NEXT:
                enabled = !forcePlainLayout();
                break;
        case LFUN_LAYOUT_PARAGRAPH:
diff -u -r lyx-2.0.3/src/Layout.cpp lyx-2.0.3-jwc/src/Layout.cpp
--- lyx-2.0.3/src/Layout.cpp    2012-01-14 10:06:40.000000000 -0500
+++ lyx-2.0.3-jwc/src/Layout.cpp        2012-03-30 08:38:28.627232561
-0400
@@ -45,6 +45,7 @@
        LT_BOTTOMSEP,
        LT_CATEGORY,
        LT_COMMANDDEPTH,
+       LT_NEXTSTYLE,
        LT_COPYSTYLE,
        LT_DEPENDSON,
        LT_OBSOLETEDBY,
@@ -166,6 +167,7 @@
                { "category",       LT_CATEGORY },
                { "commanddepth",   LT_COMMANDDEPTH },
                { "copystyle",      LT_COPYSTYLE },
+               { "nextstyle",      LT_NEXTSTYLE },
                { "dependson",      LT_DEPENDSON },
                { "end",            LT_END },
                { "endlabelstring", LT_ENDLABELSTRING },
@@ -275,6 +277,16 @@
                        break;
                        }

+               case LT_NEXTSTYLE: {     // initialize with a known
style
+                       docstring style;
+                       lex >> style;
+                       style = subst(style, '_', ' ');
+
+                       docstring const tmpname = style;
+                       this->next_style_ = tmpname;
+                       break;
+                       }
+
                case LT_OBSOLETEDBY: {   // replace with a known style
                        docstring style;
                        lex >> style;
diff -u -r lyx-2.0.3/src/Layout.h lyx-2.0.3-jwc/src/Layout.h
--- lyx-2.0.3/src/Layout.h      2011-10-30 18:40:03.000000000 -0400
+++ lyx-2.0.3-jwc/src/Layout.h  2012-03-29 11:28:37.392228561 -0400
@@ -80,6 +80,10 @@
        ///
        docstring const & obsoleted_by() const { return obsoleted_by_; }
        ///
+       void setNextStyle(docstring const & n) { next_style_ = n; }
+       ///
+       docstring const & next_style() const { return next_style_; }
+       ///
        docstring const & depends_on() const { return depends_on_; }
        ///
        std::string const & latexname() const { return latexname_; }
@@ -290,6 +294,10 @@
        */
        docstring obsoleted_by_;

+       /** Name of an layout that is advanced by user keyboard
+       */
+       docstring next_style_;
+
        /** Name of an layout which preamble must come before this one
            This is used when the preamble snippet uses macros defined
in
            another preamble
diff -u -r lyx-2.0.3/src/LyXAction.cpp lyx-2.0.3-jwc/src/LyXAction.cpp
--- lyx-2.0.3/src/LyXAction.cpp 2011-12-15 17:06:04.000000000 -0500
+++ lyx-2.0.3-jwc/src/LyXAction.cpp     2012-03-29 17:46:08.416226152
-0400
@@ -1449,6 +1449,14 @@
  */
                { LFUN_LAYOUT, "layout", Noop, Layout },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_LAYOUT_NEXT
+ * \li Action: Sets the layout (that is, environment) for the current
paragraph.
+ * \li Syntax: layout <LAYOUT>
+ * \li Params: <LAYOUT>: the layout to use
+ * \endvar
+ */
+               { LFUN_LAYOUT_NEXT, "layout-next", Noop, Layout },
+/*!
  * \var lyx::FuncCode lyx::LFUN_LAYOUT_PARAGRAPH
  * \li Action: Launches the paragraph settings dialog.
  * \li Syntax: layout-paragraph
diff -u -r lyx-2.0.3/src/Text3.cpp lyx-2.0.3-jwc/src/Text3.cpp
--- lyx-2.0.3/src/Text3.cpp     2012-01-21 12:16:56.000000000 -0500
+++ lyx-2.0.3-jwc/src/Text3.cpp 2012-03-30 08:53:02.144231145 -0400
@@ -1252,8 +1252,9 @@
                cur.message(cur.paragraph().layout().name());
                break;

+       case LFUN_LAYOUT_NEXT:
        case LFUN_LAYOUT: {
-               docstring layout = cmd.argument();
+               docstring layout = (act == LFUN_LAYOUT) ? cmd.argument()
: cur.paragraph().layout().next_style();
                LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " <<
to_utf8(layout));

                Paragraph const & para = cur.paragraph();
@@ -2679,6 +2680,7 @@
                break;

        case LFUN_LAYOUT:
+       case LFUN_LAYOUT_NEXT:
                enable = !cur.inset().forcePlainLayout();
                break;

Reply via email to