]> git.lyx.org Git - features.git/commitdiff
Further inset configurability, moving charstyle stuff to collapsable
authorMartin Vermeer <martin.vermeer@hut.fi>
Sat, 18 Aug 2007 23:26:07 +0000 (23:26 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Sat, 18 Aug 2007 23:26:07 +0000 (23:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19640 a592a061-630c-0410-9148-cb99ea01b6c8

development/FORMAT
lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_1_6.py
src/Buffer.cpp
src/insets/InsetCharStyle.cpp
src/insets/InsetCharStyle.h
src/insets/InsetCollapsable.cpp
src/insets/InsetNote.cpp

index 9fc543bd1502014f20b1a3937249c7ccd47f0431..ff7c2b5e334be3c6c4285a163402416d658a4c00 100644 (file)
@@ -1,6 +1,11 @@
 LyX file-format changes
 -----------------------
 
+2007-08-17 Martin Vermeer
+
+       * format incremented to 280: the show_label parameter
+         is depreciated in favour of (Collapsable) status.
+
 2007-08-17 Martin Vermeer
 
        * format incremented to 279: CharStyle names are now
index e7993b6bedf2b1b458c25afeafa8c8a88b96fe54..69ca80e2a08d49af74af0f337af0554220de1b6c 100644 (file)
@@ -78,7 +78,7 @@ format_relation = [("0_06",    [200], generate_minor_versions("0.6" , 4)),
                    ("1_3",     [221], generate_minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), generate_minor_versions("1.4" , 5)),
                    ("1_5", range(246,277), generate_minor_versions("1.5" , 1)),
-                   ("1_6", range(277,280), generate_minor_versions("1.6" , 0))]
+                   ("1_6", range(277,281), generate_minor_versions("1.6" , 0))]
 
 
 def formats_list():
index 4061ec27e065f3d44892a2ce3c51c7c670be5698..ebfdad2938509c195cf072e7982531aa3b808a2b 100644 (file)
@@ -105,6 +105,45 @@ def revert_long_charstyle_names(document):
         i += 1
 
 
+def axe_show_label(document):
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CharStyle", i)
+        if i == -1:
+            return
+        if document.body[i + 1].find("show_label") != -1:
+            if document.body[i + 1].find("true") != -1:
+                document.body[i + 1] = "status open"
+                del document.body[ i + 2]
+            else:
+                if document.body[i + 1].find("false") != -1:
+                    document.body[i + 1] = "status collapsed"
+                    del document.body[ i + 2]
+                else:
+                    document.warning("Malformed LyX document: show_label neither false nor true.")
+        else:
+            document.warning("Malformed LyX document: show_label missing in CharStyle.")
+            
+       i += 1
+
+
+def revert_show_label(document):
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CharStyle", i)
+        if i == -1:
+            return
+        if document.body[i + 1].find("status open") != -1:
+            document.body.insert(i + 1, "show_label true")
+        else:
+            if document.body[i + 1].find("status collapsed") != -1:
+                document.body.insert(i + 1, "show_label false")
+            else:
+                document.warning("Malformed LyX document: no legal status line in CharStyle.")
+        i += 1
+
+
+
 ##
 # Conversion hub
 #
@@ -113,10 +152,12 @@ supported_versions = ["1.6.0","1.6"]
 convert = [
            [277, [fix_wrong_tables]],
            [278, [close_begin_deeper]],
-           [279, [long_charstyle_names]]
+           [279, [long_charstyle_names]],
+           [280, [axe_show_label]]
           ]
 
 revert =  [
+           [279, [revert_show_label]],
            [278, [revert_long_charstyle_names]],
            [277, []],
            [276, []]
index 2b0286a16ca699385143186f1bf335da1a6e0348..f13798bd27e1f09de509833437e08dc00cbf4ec6 100644 (file)
@@ -137,7 +137,7 @@ namespace fs = boost::filesystem;
 
 namespace {
 
-int const LYX_FORMAT = 279;
+int const LYX_FORMAT = 280;
 
 } // namespace anon
 
index 77d5fd8af62e2436449ade8f4255be64bbb3ff8a..effe8269acb93d26def2c9cc89bffa4c2fb1042f 100644 (file)
@@ -50,13 +50,11 @@ using std::ostringstream;
 
 
 void InsetCharStyle::init()
-{
-       setDrawFrame(false);
-}
+{}
 
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
-       : InsetCollapsable(bp)
+       : InsetCollapsable(bp, Collapsed)
 {
        params_.type = s;
        setUndefined();
@@ -66,7 +64,7 @@ InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
                                CharStyles::iterator cs)
-       : InsetCollapsable(bp)
+       : InsetCollapsable(bp, Collapsed)
 {
        params_.type = cs->name;
        setDefined(cs);
@@ -101,7 +99,6 @@ void InsetCharStyle::setUndefined()
        params_.font = Font(Font::ALL_INHERIT);
        params_.labelfont = Font(Font::ALL_INHERIT);
        params_.labelfont.setColor(Color::error);
-       params_.show_label = true;
 }
 
 
@@ -112,7 +109,6 @@ void InsetCharStyle::setDefined(CharStyles::iterator cs)
        params_.latexparam = cs->latexparam;
        params_.font = cs->font;
        params_.labelfont = cs->labelfont;
-       params_.show_label = true;
 }
 
 
@@ -145,7 +141,7 @@ bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
        mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
        InsetText::metrics(mi, dim);
        mi.base.font = tmpfont;
-       if (params_.show_label) {
+       if (status() == Open) {
                // consider width of the inset label
                Font font(params_.labelfont);
                font.realize(Font(Font::ALL_SANE));
@@ -168,9 +164,13 @@ bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.des += TEXT_TO_INSET_OFFSET;
        dim.wid += 2 * TEXT_TO_INSET_OFFSET;
        mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
-       if (params_.show_label)
+       if (status() == Open)
                dim.des += ascent();
-       bool const changed = dim_ != dim;
+       else {
+               dim.des -= 3;
+               dim.asc -= 3;
+       }
+       bool const changed =  dim_ != dim;
        dim_ = dim;
        return changed;
 }
@@ -184,12 +184,14 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
        getDrawFont(pi.base.font);
        // I don't understand why the above .reduce and .realize aren't
        //needed, or even wanted, here. It just works. -- MV 10.04.2005
-       InsetText::draw(pi, x + TEXT_TO_INSET_OFFSET, y);
+       InsetCollapsable::draw(pi, x, y);
        pi.base.font = tmpfont;
 
        int desc = InsetText::descent();
-       if (params_.show_label)
+       if (status() == Open)
                desc -= ascent();
+       else
+               desc -= 3;
 
        pi.pain.line(x, y + desc - 4, x, y + desc, params_.labelfont.color());
        pi.pain.line(x, y + desc, x + dim_.wid - 3, y + desc,
@@ -198,7 +200,7 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
                params_.labelfont.color());
 
        // the name of the charstyle. Can be toggled.
-       if (params_.show_label) {
+       if (status() == Open) {
                Font font(params_.labelfont);
                font.realize(Font(Font::ALL_SANE));
                font.decSize();
@@ -218,10 +220,11 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
                        s, font, Color::none, Color::none);
        }
 
-       // a visual clue when the cursor is inside the inset
+       // a visual cue when the cursor is inside the inset
        Cursor & cur = pi.base.bv->cursor();
        if (cur.isInside(this)) {
                y -= ascent();
+               y += 3;
                pi.pain.line(x, y + 4, x, y, params_.labelfont.color());
                pi.pain.line(x + 4, y, x, y, params_.labelfont.color());
                pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
@@ -244,18 +247,24 @@ void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_MOUSE_RELEASE:
                        if (cmd.button() == mouse_button::button3)
-                               params_.show_label = !params_.show_label;
+                               if (status() == Open)
+                                       setStatus(cur, Collapsed);
+                               else
+                                       setStatus(cur, Open);
                        else
                                InsetCollapsable::doDispatch(cur, cmd);
                        break;
 
        case LFUN_INSET_TOGGLE:
                if (cmd.argument() == "open")
-                       params_.show_label = true;
+                       setStatus(cur, Open);
                else if (cmd.argument() == "close")
-                       params_.show_label = false;
+                       setStatus(cur, Collapsed);
                else if (cmd.argument() == "toggle" || cmd.argument().empty())
-                       params_.show_label = !params_.show_label;
+                       if (status() == Open)
+                               setStatus(cur, Collapsed);
+                       else
+                               setStatus(cur, Open);
                else // if assign or anything else
                        cur.undispatched();
                cur.dispatched();
@@ -351,7 +360,6 @@ void InsetCharStyle::validate(LaTeXFeatures & features) const
 void InsetCharStyleParams::write(ostream & os) const
 {
        os << "CharStyle " << type << "\n";
-       os << "show_label " << convert<string>(show_label) << "\n";
 }
 
 
@@ -366,11 +374,7 @@ void InsetCharStyleParams::read(Lexer & lex)
                        type = lex.getString();
                }
 
-               else if (token == "show_label") {
-                       lex.next();
-                       show_label = lex.getBool();
-               }
-
+               // This is handled in Collapsable
                else if (token == "status") {
                        lex.pushToken(token);
                        break;
index 61a2f0c69a14b637fd5957df9346522334b0bcc0..91040e4d8637e7ad1df695ad49c3586069a3c625 100644 (file)
@@ -38,8 +38,6 @@ public:
        Font font;
        ///
        Font labelfont;
-       ///
-       bool show_label;
 };
 
 
index 48079092064ead8e65ca7b61c7d5154afe1a8502..23b7414b19bf1dbde985e9e0aa7b51165a9108eb 100644 (file)
@@ -228,43 +228,47 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
        const int xx = x + TEXT_TO_INSET_OFFSET;
 
-       if (decoration() == Minimalistic)  {
-               InsetText::draw(pi, xx, y);
-       } else {
-               Dimension dimc = dimensionCollapsed();
-               int const top  = y - ascent() + TEXT_TO_INSET_OFFSET;
+       // Draw button first -- top, left or only
+       Dimension dimc = dimensionCollapsed();
+       int const top  = y - ascent() + TEXT_TO_INSET_OFFSET;
+       if (decoration() == Classic) {
                button_dim.x1 = xx + 0;
                button_dim.x2 = xx + dimc.width();
                button_dim.y1 = top;
                button_dim.y2 = top + dimc.height();
 
                pi.pain.buttonText(xx, top + dimc.asc, label, layout_.labelfont, mouse_hover_);
+       }
 
-               int textx, texty;
-               switch (geometry()) {
-               case LeftButton:
-                       textx = xx + dimc.width();
-                       texty = top + textdim_.asc;
-                       InsetText::draw(pi, textx, texty);
-                       break;
-               case TopButton:
-                       textx = xx;
-                       texty = top + dimc.height() + textdim_.asc;
-                       InsetText::draw(pi, textx, texty);
-                       break;
-               case ButtonOnly:
-                       break;
-               case NoButton:
-                       textx = xx;
-                       texty = top + textdim_.asc;
-                       InsetText::draw(pi, textx, texty);
-                       break;
-               case SubLabel:
-               case Corners:
-                       // FIXME add handling of SubLabel, Corners
-                       // still in CharStyle
-                       break;
-               }
+       int textx, texty;
+       switch (geometry()) {
+       case LeftButton:
+               textx = xx + dimc.width();
+               texty = top + textdim_.asc;
+               InsetText::draw(pi, textx, texty);
+               break;
+       case TopButton:
+               textx = xx;
+               texty = top + dimc.height() + textdim_.asc;
+               InsetText::draw(pi, textx, texty);
+               break;
+       case ButtonOnly:
+               break;
+       case NoButton:
+               textx = xx;
+               texty = y + textdim_.asc;
+               InsetText::draw(pi, textx, texty);
+               break;
+       case SubLabel:
+       case Corners:
+               // FIXME add handling of SubLabel, Corners
+               // still in CharStyle
+               textx = xx;
+               texty = y + textdim_.asc;
+               const_cast<InsetCollapsable *>(this)->setDrawFrame(false);
+               InsetText::draw(pi, textx, texty);
+               const_cast<InsetCollapsable *>(this)->setDrawFrame(true);
+               break;
        }
        setPosCache(pi, x, y);
 }
index 7e408255f7b38fe3ea16f7916d84351eda594823..73b4c7d179e1c57085c75de0127e10b4e74eab73 100644 (file)
@@ -184,6 +184,7 @@ void InsetNote::setButtonLabel()
 {
        docstring const label = notetranslator_loc().find(params_.type);
        setLabel(label);
+       // isn't this an identity? - MV
        setLabelFont(layout_.labelfont);
 }