Jean-Marc Lasgouttes wrote:
> Frankly, inserting special characters is a nightmare to me.

ooonly for yoooouuur
bjutifuuul eyyyyes
sun never seeets
through coooding niiiights :)

pavel
diff --git a/development/FORMAT b/development/FORMAT
index afcd41c..3d5b603 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,10 @@ adjustments are made to tex2lyx and bugs are fixed in 
lyx2lyx.
 
 -----------------------
 
+2011-07-02 Pavel Sanda <sa...@lyx.org>
+       * Format incremented to 414 (rXXXX)
+         New InsetSpace param \textvisiblespace
+
 2011-02-15 Richard Heck <rgh...@comcast.net>
        * Format incremented to 413 (r37682)
          New buffer param \html_css_as_file to control whether
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index 505cfb7..db3dc0b 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -25,11 +25,15 @@ import sys, os
 
 # Uncomment only what you need to import, please.
 
+from parser_tools import find_token, find_end_of_inset
+
 #from parser_tools import find_token, find_end_of, find_tokens, \
   #find_token_exact, find_end_of_inset, find_end_of_layout, \
   #find_token_backwards, is_in_inset, get_value, get_quoted_value, \
   #del_token, check_token, get_option_value
-  
+
+from lyx2lyx_tools import put_cmd_in_ert
+
 #from lyx2lyx_tools import add_to_preamble, insert_to_preamble, \
 #  put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \
 #  revert_font_attrs, hex2ratio, str2bool
@@ -53,6 +57,16 @@ import sys, os
 ###
 ###############################################################################
 
+def revert_visible_space(document):
+    "Revert InsetSpace visible into its ERT counterpart"
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset space 
\\textvisiblespace{}", i)
+        if i == -1:
+            return
+        end = find_end_of_inset(document.body, i)
+        subst = put_cmd_in_ert("\\textvisiblespace{}")
+        document.body[i:end + 1] = subst
 
 
 ##
@@ -60,10 +74,10 @@ import sys, os
 #
 
 supported_versions = ["2.1.0","2.1"]
-convert = [#[414, []]
+convert = [[414, []]
           ]
 
-revert =  [#[413, []]
+revert =  [[413, [revert_visible_space]]
           ]
 
 
diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index ab38d32..3279a8c 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -201,6 +201,7 @@ Menuset
        Menu "context-space"
                Item "Interword Space|w" "inset-modify space \space{}"
                Item "Protected Space|o" "inset-modify space ~"
+               Item "Visible Space|a" "inset-modify space \textvisiblespace{}"
                Item "Thin Space|T" "inset-modify space \thinspace{}"
                Item "Negative Thin Space|N" "inset-modify space 
\negthinspace{}"
                Item "Half Quad Space (Enskip)|k" "inset-modify space \enskip{}"
diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index 88d84d2..57dc3db 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -392,6 +392,7 @@ Menuset
                Separator
                Item "Protected Space|P" "space-insert protected"
                Item "Interword Space|w" "space-insert normal"
+               Item "Visible Space|i" "space-insert visible"
                Item "Thin Space|T" "space-insert thin"
                Item "Horizontal Space...|o" "dialog-show-new-inset space"
                Item "Horizontal Line...|L" "dialog-show-new-inset line"
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 7d85e3a..d0aa3e6 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -127,7 +127,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 413; // rgh: html_css_as_file
+int const LYX_FORMAT = 414; //ps : simsalabum
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index f9ee2f8..9f4bd81 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -475,8 +475,8 @@ void LyXAction::init()
  * \var lyx::FuncCode lyx::LFUN_SPACE_INSERT
  * \li Action: Inserts one of horizontal space insets.
  * \li Syntax: space-insert <NAME> [<LEN>]
- * \li Params: <NAME>: normal, protected, thin, quad, qquad, enspace, enskip,
-                       negthinspace, hfill, hfill*, dotfill, hrulefill, hspace,
+ * \li Params: <NAME>: normal, protected, visible, thin, quad, qquad, enspace,
+                       enskip, negthinspace, hfill, hfill*, dotfill, 
hrulefill, hspace,
                        hspace* \n
                <LEN>: length for custom spaces (hspace, hspace* for protected)
  * \li Origin: JSpitzm, 20 May 2003, Mar 17 2008
diff --git a/src/factory.cpp b/src/factory.cpp
index bdae9a0..686d23f 100644
--- a/src/factory.cpp
+++ b/src/factory.cpp
@@ -382,6 +382,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & 
cmd)
                                isp.kind = InsetSpaceParams::NORMAL;
                        else if (name == "protected")
                                isp.kind = InsetSpaceParams::PROTECTED;
+                       else if (name == "visible")
+                               isp.kind = InsetSpaceParams::VISIBLE;
                        else if (name == "thin")
                                isp.kind = InsetSpaceParams::THIN;
                        else if (isp.math && name == "med")
diff --git a/src/frontends/qt4/GuiHSpace.cpp b/src/frontends/qt4/GuiHSpace.cpp
index a896c1e..e4141bc 100644
--- a/src/frontends/qt4/GuiHSpace.cpp
+++ b/src/frontends/qt4/GuiHSpace.cpp
@@ -61,6 +61,7 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
                spacingCO->addItem(qt_("Double Quad (2 em)"));
                spacingCO->addItem(qt_("Horizontal Fill"));
                spacingCO->addItem(qt_("Custom"));
+               spacingCO->addItem(qt_("Visible Space"));
        }
 
        connect(spacingCO, SIGNAL(highlighted(QString)),
@@ -96,7 +97,8 @@ void GuiHSpace::changedSlot()
 void GuiHSpace::enableWidgets()
 {
        int const selection = spacingCO->currentIndex();
-       bool const custom = (selection == spacingCO->count() - 1);
+       bool const custom = (math_mode_ && selection == 9) ||
+               (!math_mode_ && selection == 7);
        valueLE->setEnabled(custom);
        unitCO->setEnabled(custom);
        if (math_mode_) {
@@ -130,6 +132,10 @@ void GuiHSpace::paramsToDialog(Inset const * inset)
                        item = 0;
                        protect = !params.math;
                        break;
+               case InsetSpaceParams::VISIBLE:
+                       item = 8;
+                       protect = true;
+                       break;
                case InsetSpaceParams::THIN:
                        item = params.math ? 0 : 1;
                        break;
@@ -312,6 +318,9 @@ docstring GuiHSpace::dialogToParams() const
                                params.kind = InsetSpaceParams::CUSTOM;
                        params.length = GlueLength(widgetsToLength(valueLE, 
unitCO));
                        break;
+               case 8:
+                       params.kind = InsetSpaceParams::VISIBLE;
+                       break;
        }
        return from_ascii(InsetSpace::params2string(params));
 }
diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp
index 6e7c94d..d589b97 100644
--- a/src/insets/InsetSpace.cpp
+++ b/src/insets/InsetSpace.cpp
@@ -70,6 +70,9 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) 
const
        case InsetSpaceParams::PROTECTED:
                message = _("Protected Space");
                break;
+       case InsetSpaceParams::VISIBLE:
+               message = _("Visible Space");
+               break;
        case InsetSpaceParams::THIN:
                message = _("Thin Space");
                break;
@@ -215,6 +218,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) 
const
                        dim.wid = fm.width(char_type('M')) / 2;
                        break;
                case InsetSpaceParams::PROTECTED:
+               case InsetSpaceParams::VISIBLE:
                case InsetSpaceParams::NORMAL:
                        dim.wid = fm.width(char_type(' '));
                        break;
@@ -349,7 +353,8 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
        xp[0] = x;
        yp[0] = y - max(h / 4, 1);
        if (params_.kind == InsetSpaceParams::NORMAL ||
-           params_.kind == InsetSpaceParams::PROTECTED) {
+           params_.kind == InsetSpaceParams::PROTECTED ||
+           params_.kind == InsetSpaceParams::VISIBLE) {
                xp[1] = x;     yp[1] = y;
                xp[2] = x + w; yp[2] = y;
        } else {
@@ -359,15 +364,18 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) 
const
        xp[3] = x + w;
        yp[3] = y - max(h / 4, 1);
 
+       Color col = Color_special;
        if (params_.kind == InsetSpaceParams::PROTECTED ||
            params_.kind == InsetSpaceParams::ENSPACE ||
            params_.kind == InsetSpaceParams::NEGTHIN ||
            params_.kind == InsetSpaceParams::NEGMEDIUM ||
            params_.kind == InsetSpaceParams::NEGTHICK ||
            params_.kind == InsetSpaceParams::CUSTOM_PROTECTED)
-               pi.pain.lines(xp, yp, 4, Color_latex);
-       else
-               pi.pain.lines(xp, yp, 4, Color_special);
+               col = Color_latex;
+       else if (params_.kind == InsetSpaceParams::VISIBLE)
+               col =  Color_foreground;
+
+       pi.pain.lines(xp, yp, 4, col);
 }
 
 
@@ -381,6 +389,9 @@ void InsetSpaceParams::write(ostream & os) const
        case InsetSpaceParams::PROTECTED:
                os <<  "~";
                break;
+       case InsetSpaceParams::VISIBLE:
+               os <<  "\\textvisiblespace{}";
+               break;
        case InsetSpaceParams::THIN:
                os <<  "\\thinspace{}";
                break;
@@ -459,6 +470,8 @@ void InsetSpaceParams::read(Lexer & lex)
                kind = InsetSpaceParams::NORMAL;
        else if (command == "~")
                kind = InsetSpaceParams::PROTECTED;
+       else if (command == "\\textvisiblespace{}")
+               kind = InsetSpaceParams::VISIBLE;
        else if (command == "\\thinspace{}")
                kind = InsetSpaceParams::THIN;
        else if (math && command == "\\medspace{}")
@@ -535,6 +548,9 @@ void InsetSpace::latex(otexstream & os, OutputParams const 
& runparams) const
                else
                        os << (runparams.free_spacing ? ' ' : '~');
                break;
+       case InsetSpaceParams::VISIBLE:
+               os << (runparams.free_spacing ? " " : "\\textvisiblespace{}");
+               break;
        case InsetSpaceParams::THIN:
                os << (runparams.free_spacing ? " " : "\\,");
                break;
@@ -646,8 +662,13 @@ int InsetSpace::docbook(odocstream & os, OutputParams 
const &) const
        case InsetSpaceParams::ENSKIP:
                os << " ";
                break;
+       // FIXME For spaces and dashes look here:
+       // http://oreilly.com/catalog/docbook/book2/iso-pub.html
        case InsetSpaceParams::PROTECTED:
+       // FIXME &blank; ?
+       case InsetSpaceParams::VISIBLE:
        case InsetSpaceParams::ENSPACE:
+       // FIXME &thinsp; ?
        case InsetSpaceParams::THIN:
        case InsetSpaceParams::MEDIUM:
        case InsetSpaceParams::THICK:
@@ -705,6 +726,10 @@ docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams 
const &) const
        case InsetSpaceParams::NEGTHICK:
                output ="&nbsp;";
                break;
+       // no XHTML entity, only unicode code for space character exists
+       case InsetSpaceParams::VISIBLE:
+               output ="&#x2423;";
+               break;
        case InsetSpaceParams::HFILL:
        case InsetSpaceParams::HFILL_PROTECTED:
        case InsetSpaceParams::DOTFILL:
diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h
index 5496e3c..753e3bf 100644
--- a/src/insets/InsetSpace.h
+++ b/src/insets/InsetSpace.h
@@ -30,6 +30,8 @@ struct InsetSpaceParams {
                NORMAL,
                /// Protected (no break) space ('~')
                PROTECTED,
+               /// Visible ("open box") space ('\textvisiblespace')
+               VISIBLE,
                /// Thin space ('\,')
                THIN,
                /// Medium space ('\:')

Reply via email to