On Fri, Mar 11, 2016 at 06:17:33PM +0000, Guillaume Munch wrote:

> Le 11/03/2016 18:01, José Matos a écrit :
> >On Friday, March 11, 2016 05:52:46 PM Guillaume Munch wrote:
> >>What about drawing this inset differently when it is alone in its paragraph?
> >
> >I would be happy. :-)
> >
> 
> Or adapt lyx2lyx to convert the old separator into the plain separator
> followed by the parbreak separator on the same paragraph?

Okay, I surrender...

The attached patch introduces a new kind of separator, the latexpar
separator. This is exactly the same as the old parbreak one and the
only difference is the way parbreak and latexpar kinds are represented
on screen. The new latexpar is represented exactly as the old parbreak,
while a parbreak separator is now represented as a double line.

The context menu does not account for latexpar separators and only
"true" separators can be turned each into the other one.

Note that this is a format change and I don't know whether this is
allowed at this stage of development.

Please, test whether there are cases in which the old parbreak is
not turned into the new latexpar kind. This is easy to do, because a
double line should always appear alone in a standard LyX paragraph.

-- 
Enrico
diff --git a/development/FORMAT b/development/FORMAT
index 1d24d92..4d84435 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,16 @@ adjustments are made to tex2lyx and bugs are fixed in 
lyx2lyx.
 
 -----------------------
 
+2016-03-12 Enrico Forestieri <for...@lyx.org>
+       * Format incremented to 507
+         New kind of Separator inset (latexpar). The old parbreak separator
+         used specifically to introduce a LaTeX paragraph break in the output
+         (and thus not as a proper separator) is turned into a latexpar kind.
+         The only difference with the parbreak kind is the representation
+         on screen. The new latexpar kind is represented by the same symbol
+         used previously for the parbreak one, while the latter is now
+         represented as a double line.
+
 2016-01-26 Guillaume Munch <g...@lyx.org>
        * Format incremented to 506
          No new parameters.
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index b2b5731..e7078f1 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -86,7 +86,7 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 
4)),
                    ("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
                    ("2_0", list(range(346,414)), minor_versions("2.0" , 8)),
                    ("2_1", list(range(414,475)), minor_versions("2.1" , 0)),
-                   ("2_2", list(range(475,507)), minor_versions("2.2" , 0))
+                   ("2_2", list(range(475,508)), minor_versions("2.2" , 0))
                   ]
 
 ####################################################################
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index a1f3005..5fbd916 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -304,6 +304,46 @@ def revert_separator(document):
         i = i + 1
 
 
+def convert_parbreak(document):
+    """
+    Convert parbreak separators not specifically used to separate
+    environments to latexpar separators.
+    """
+    parbreakinset = "\\begin_inset Separator parbreak"
+    i = 0
+    while 1:
+        i = find_token(document.body, parbreakinset, i)
+        if i == -1:
+            return
+        lay = get_containing_layout(document.body, i)
+        if lay == False:
+            document.warning("Malformed LyX document: Can't convert separator 
inset at line " + str(i))
+            i += 1
+            continue
+        if lay[0] == "Standard":
+            # Convert only if not alone in the paragraph
+            k1 = find_nonempty_line(document.body, lay[1] + 1, i + 1)
+            k2 = find_nonempty_line(document.body, i + 1, lay[2])
+            if k1 < i or k2 > i or not check_token(document.body[i], 
parbreakinset):
+                document.body[i] = document.body[i].replace("parbreak", 
"latexpar")
+        else:
+            document.body[i] = document.body[i].replace("parbreak", "latexpar")
+        i += 1
+
+
+def revert_parbreak(document):
+    """
+    Revert latexpar separators to parbreak separators.
+    """
+    i = 0
+    while 1:
+        i = find_token(document.body, "\\begin_inset Separator latexpar", i)
+        if i == -1:
+            return
+        document.body[i] = document.body[i].replace("latexpar", "parbreak")
+        i += 1
+
+
 def revert_smash(document):
     " Set amsmath to on if smash commands are used "
 
@@ -2253,10 +2293,12 @@ convert = [
            [503, []],
            [504, [convert_save_props]],
            [505, []],
-           [506, [convert_info_tabular_feature]]
+           [506, [convert_info_tabular_feature]],
+           [507, [convert_parbreak]]
           ]
 
 revert =  [
+           [506, [revert_parbreak]],
            [505, [revert_info_tabular_feature]],
            [504, []],
            [503, [revert_save_props]],
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 1e83905..831c3f6 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -635,9 +635,9 @@ void LyXAction::init()
                { LFUN_NEWLINE_INSERT, "newline-insert", Noop, Edit },
 /*!
  * \var lyx::FuncCode lyx::LFUN_SEPARATOR_INSERT
- * \li Action: Inserts an environment separator or paragraph break.
+ * \li Action: Inserts an environment separator or latex paragraph break.
  * \li Syntax: separator-insert [<ARG>]
- * \li Params: <ARG>: <plain|parbreak> default: plain
+ * \li Params: <ARG>: <plain|parbreak|latexpar> default: plain
  * \li Origin: ef, 2 May 2014
  * \endvar
  */
diff --git a/src/factory.cpp b/src/factory.cpp
index b7320d0..b8d9433 100644
--- a/src/factory.cpp
+++ b/src/factory.cpp
@@ -107,6 +107,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & 
cmd)
                                inp.kind = InsetSeparatorParams::PLAIN;
                        else if (name == "parbreak")
                                inp.kind = InsetSeparatorParams::PARBREAK;
+                       else if (name == "latexpar")
+                               inp.kind = InsetSeparatorParams::LATEXPAR;
                        else {
                                lyxerr << "Wrong argument for LyX function 
'separator-insert'." << endl;
                                break;
diff --git a/src/insets/InsetSeparator.cpp b/src/insets/InsetSeparator.cpp
index b981d2c..a759f1f 100644
--- a/src/insets/InsetSeparator.cpp
+++ b/src/insets/InsetSeparator.cpp
@@ -52,6 +52,9 @@ void InsetSeparatorParams::write(ostream & os) const
        case InsetSeparatorParams::PARBREAK:
                os <<  "parbreak";
                break;
+       case InsetSeparatorParams::LATEXPAR:
+               os <<  "latexpar";
+               break;
        }
 }
 
@@ -65,6 +68,8 @@ void InsetSeparatorParams::read(Lexer & lex)
                kind = InsetSeparatorParams::PLAIN;
        else if (token == "parbreak")
                kind = InsetSeparatorParams::PARBREAK;
+       else if (token == "latexpar")
+               kind = InsetSeparatorParams::LATEXPAR;
        else
                lex.printError("Unknown kind: `$$Token'");
 }
@@ -139,6 +144,7 @@ void InsetSeparator::latex(otexstream & os, OutputParams 
const &) const
                                os << breakln << "%\n";
                                break;
                        case InsetSeparatorParams::PARBREAK:
+                       case InsetSeparatorParams::LATEXPAR:
                                os << breakln << "\n";
                                break;
                        default:
@@ -177,7 +183,7 @@ void InsetSeparator::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.asc = fm.maxAscent();
        dim.des = fm.maxDescent();
        dim.wid = fm.width('n');
-       if (params_.kind == InsetSeparatorParams::PLAIN)
+       if (params_.kind != InsetSeparatorParams::LATEXPAR)
                dim.wid *= 8;
 }
 
@@ -194,7 +200,7 @@ void InsetSeparator::draw(PainterInfo & pi, int x, int y) 
const
        int xp[7];
        int yp[7];
 
-       if (params_.kind == InsetSeparatorParams::PLAIN) {
+       if (params_.kind != InsetSeparatorParams::LATEXPAR) {
                yp[0] = int(y - 0.500 * asc * 0.75);
                yp[1] = yp[0];
 
@@ -202,6 +208,12 @@ void InsetSeparator::draw(PainterInfo & pi, int x, int y) 
const
                xp[1] = int(x + wid * 8);
 
                pi.pain.lines(xp, yp, 2, ColorName());
+
+               if (params_.kind == InsetSeparatorParams::PARBREAK) {
+                       yp[0] += 0.25 * asc * 0.75;
+                       yp[1] = yp[0];
+                       pi.pain.lines(xp, yp, 2, ColorName());
+               }
        } else {
                yp[0] = int(y - 0.500 * asc * 0.5);
                yp[1] = int(y - 0.250 * asc * 0.5);
@@ -266,6 +278,9 @@ void InsetSeparator::draw(PainterInfo & pi, int x, int y) 
const
 
 string InsetSeparator::contextMenuName() const
 {
+       if (params_.kind == InsetSeparatorParams::LATEXPAR)
+               return string();
+
        return "context-separator";
 }
 
diff --git a/src/insets/InsetSeparator.h b/src/insets/InsetSeparator.h
index 2049c22..66a0c55 100644
--- a/src/insets/InsetSeparator.h
+++ b/src/insets/InsetSeparator.h
@@ -22,10 +22,9 @@ class InsetSeparatorParams
 public:
        /// The different kinds of separators we support
        enum Kind {
-               ///
                PLAIN,
-               ///
-               PARBREAK
+               PARBREAK,
+               LATEXPAR
        };
        ///
        InsetSeparatorParams() : kind(PLAIN) {}
diff --git a/src/version.h b/src/version.h
index 9a37739..d7dc3ea 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 506 // guillaume munch: convert "inset-modify tabular"
-#define LYX_FORMAT_TEX2LYX 506
+#define LYX_FORMAT_LYX 507 // forenr: convert parbreak to latexpar
+#define LYX_FORMAT_TEX2LYX 507
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to