]> git.lyx.org Git - lyx.git/commitdiff
* optional old-style editing mode for macros with a parameter list.
authorStefan Schimanski <sts@lyx.org>
Fri, 25 Jan 2008 22:02:38 +0000 (22:02 +0000)
committerStefan Schimanski <sts@lyx.org>
Fri, 25 Jan 2008 22:02:38 +0000 (22:02 +0000)
* combobox in the preferences dialog to choose the macro editing mode of choice.

The reason for the three choices (inline box, inline without box,
list) is that it seems that there are at least these three groups of
people, and each of them is very strong about their opinion what that
the best mode is. So here there are all of them, pick your favourite.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22670 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXFunc.cpp
src/LyXRC.cpp
src/LyXRC.h
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/ui/PrefUi.ui
src/mathed/MathMacro.cpp
src/mathed/MathMacro.h

index 6505661e7d3b93c9f6e120bad4c4b1b83e14f21f..ef90163f34f802c962c544e95eff2b3a472c8d8d 100644 (file)
@@ -2210,6 +2210,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS:
        case LyXRC::RC_LANGUAGE_PACKAGE:
        case LyXRC::RC_LANGUAGE_USE_BABEL:
+       case LyXRC::RC_MACRO_EDIT_STYLE:
        case LyXRC::RC_MAKE_BACKUP:
        case LyXRC::RC_MARK_FOREIGN_LANGUAGE:
        case LyXRC::RC_NUMLASTFILES:
@@ -2254,7 +2255,6 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_SERVERPIPE:
        case LyXRC::RC_SET_COLOR:
        case LyXRC::RC_SHOW_BANNER:
-       case LyXRC::RC_SHOW_MACRO_LABEL:
        case LyXRC::RC_SPELL_COMMAND:
        case LyXRC::RC_TEMPDIRPATH:
        case LyXRC::RC_TEMPLATEPATH:
index 96e0dac284e635b774ffcecaaab1857b0c6546bc..a0d1c6d1ae00c00e74b91b064e1265528c628117 100644 (file)
@@ -137,7 +137,7 @@ keyword_item lyxrcTags[] = {
        { "\\serverpipe", LyXRC::RC_SERVERPIPE },
        { "\\set_color", LyXRC::RC_SET_COLOR },
        { "\\show_banner", LyXRC::RC_SHOW_BANNER },
-       { "\\show_macro_label", LyXRC::RC_SHOW_MACRO_LABEL },
+       { "\\macro_edit_style", LyXRC::RC_MACRO_EDIT_STYLE },
        { "\\sort_layouts", LyXRC::RC_SORT_LAYOUTS },
        { "\\spell_command", LyXRC::RC_SPELL_COMMAND },
        { "\\tempdir_path", LyXRC::RC_TEMPDIRPATH },
@@ -261,7 +261,7 @@ void LyXRC::setDefaults() {
        tex_allows_spaces = false;
        date_insert_format = "%x";
        cursor_follows_scrollbar = false;
-       show_macro_label = true;
+       macro_edit_style = MACRO_EDIT_INLINE_BOX;
        dialogs_iconify_with_main = false;
        label_init_length = 3;
        preview = PREVIEW_OFF;
@@ -839,9 +839,13 @@ int LyXRC::read(Lexer & lexrc)
                        }
                        break;
 
-               case RC_SHOW_MACRO_LABEL:
+               case RC_MACRO_EDIT_STYLE:
                        if (lexrc.next()) {
-                               show_macro_label = lexrc.getBool();
+                               switch (lexrc.getInteger()) {
+                               case 0: macro_edit_style = MACRO_EDIT_INLINE_BOX; break;
+                               case 1: macro_edit_style = MACRO_EDIT_INLINE; break;
+                               case 2: macro_edit_style = MACRO_EDIT_LIST; break;
+                               }
                        }
                        break;
 
@@ -1582,12 +1586,16 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                if (tag != RC_LAST)
                        break;
-       case RC_SHOW_MACRO_LABEL:
+       case RC_MACRO_EDIT_STYLE:
                if (ignore_system_lyxrc ||
-                   show_macro_label
-                   != system_lyxrc.show_macro_label) {
-                       os << "\\show_macro_label "
-                          << convert<string>(show_macro_label) << '\n';
+                   macro_edit_style
+                   != system_lyxrc.macro_edit_style) {
+                       os << "\\macro_edit_style ";
+                       switch (macro_edit_style) {
+                       case MACRO_EDIT_INLINE_BOX: os << "0\n"; break;
+                       case MACRO_EDIT_INLINE: os << "1\n"; break;
+                       case MACRO_EDIT_LIST: os << "2\n"; break;
+                       }
                }
                if (tag != RC_LAST)
                        break;
index bc2a25ec93245f44b3af03c178910d3b31236594..5d8ed983ee23c01124c725a74881a43ac8cfabfb 100644 (file)
@@ -83,6 +83,7 @@ public:
                RC_SORT_LAYOUTS,
                RC_USELASTFILEPOS,
                RC_LOADSESSION,
+               RC_MACRO_EDIT_STYLE,
                RC_MAKE_BACKUP,
                RC_MARK_FOREIGN_LANGUAGE,
                RC_NUMLASTFILES,
@@ -124,7 +125,6 @@ public:
                RC_SERVERPIPE,
                RC_SET_COLOR,
                RC_SHOW_BANNER,
-               RC_SHOW_MACRO_LABEL,
                RC_SPELL_COMMAND,
                RC_TEMPDIRPATH,
                RC_TEMPLATEPATH,
@@ -342,7 +342,13 @@ public:
        ///
        bool cursor_follows_scrollbar;
        ///
-       bool show_macro_label;
+       enum MacroEditStyle {
+               MACRO_EDIT_INLINE_BOX = 0,
+               MACRO_EDIT_INLINE,
+               MACRO_EDIT_LIST
+       };
+       ///
+       MacroEditStyle macro_edit_style;
        ///
        bool dialogs_iconify_with_main;
        ///
index e8315e2a31a592a204ac99104c3fec1089ff2372..ee5c28ab3870d261f7e5eb93f3c3f01005132e49 100644 (file)
@@ -1621,7 +1621,7 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
                this, SIGNAL(changed()));
        connect(sortEnvironmentsCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
-       connect(showMacroLabelCB, SIGNAL(clicked()),
+       connect(macroEditStyleCO, SIGNAL(activated(int)),
                this, SIGNAL(changed()));
        connect(autoSaveSB, SIGNAL(valueChanged(int)),
                this, SIGNAL(changed()));
@@ -1645,7 +1645,11 @@ void PrefUserInterface::apply(LyXRC & rc) const
        rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
        rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
        rc.sort_layouts = sortEnvironmentsCB->isChecked();
-       rc.show_macro_label = showMacroLabelCB->isChecked();
+       switch (macroEditStyleCO->currentIndex()) {
+               case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
+               case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
+               case 2: rc.macro_edit_style = LyXRC::MACRO_EDIT_LIST;   break;
+       }
        rc.autosave = autoSaveSB->value() * 60;
        rc.make_backup = autoSaveCB->isChecked();
        rc.num_lastfiles = lastfilesSB->value();
@@ -1662,7 +1666,7 @@ void PrefUserInterface::update(LyXRC const & rc)
        allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
        cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
        sortEnvironmentsCB->setChecked(rc.sort_layouts);
-       showMacroLabelCB->setChecked(rc.show_macro_label);
+       macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
        // convert to minutes
        int mins(rc.autosave / 60);
        if (rc.autosave && !mins)
index 7749f37db88005747e6b016269444dd3300534fc..614eb8bcea2bc15d08183f4d5fb86d6dd65adfe5 100644 (file)
@@ -215,10 +215,22 @@ p, li { white-space: pre-wrap; }
        </widget>
       </item>
       <item row="2" column="0" >
-       <widget class="QCheckBox" name="showMacroLabelCB" >
-        <property name="text" >
-         <string>Show a box with the macro name around Math Macros</string>
-        </property>
+       <widget class="QComboBox" name="macroEditStyleCO" >
+        <item>
+         <property name="text" >
+          <string>Edit Math Macros inline with a box around</string>
+         </property>
+        </item>
+        <item>
+         <property name="text" >
+          <string>Edit Math Macros inline with the name in the status bar</string>
+         </property>
+        </item>
+        <item>
+         <property name="text" >
+          <string>Edit Math Macros with a parameter list (like in LyX &lt; 1.6)</string>
+         </property>
+        </item>
        </widget>
       </item>
      </layout>
@@ -325,15 +337,15 @@ p, li { white-space: pre-wrap; }
   <tabstop>uiFileED</tabstop>
   <tabstop>uiFilePB</tabstop>
   <tabstop>tooltipCB</tabstop>
-  <tabstop>allowGeometrySessionCB</tabstop>
   <tabstop>restoreCursorCB</tabstop>
+  <tabstop>allowGeometrySessionCB</tabstop>
   <tabstop>loadSessionCB</tabstop>
   <tabstop>autoSaveCB</tabstop>
   <tabstop>autoSaveSB</tabstop>
   <tabstop>lastfilesSB</tabstop>
   <tabstop>cursorFollowsCB</tabstop>
   <tabstop>sortEnvironmentsCB</tabstop>
-  <tabstop>showMacroLabelCB</tabstop>
+  <tabstop>macroEditStyleCO</tabstop>
   <tabstop>pixmapCacheCB</tabstop>
  </tabstops>
  <includes>
index 0d9c0e904a125b7c54628c8687449d119796153f..c43fcd48984e92ad8404811da2c9efc3b84b7093 100644 (file)
@@ -186,6 +186,46 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
                dim.asc = max(bsdim.ascent(), dim.ascent());
                dim.des = max(bsdim.descent(), dim.descent());
                metricsMarkers(dim);
+       } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST 
+                  && editing_[mi.base.bv]) {
+               // Macro will be edited in a old-style list mode here:
+
+               BOOST_ASSERT(macro_ != 0);
+               Dimension fontDim;
+               FontInfo labelFont = sane_font;
+               math_font_max_dim(labelFont, fontDim.asc, fontDim.des);
+               
+               // get dimension of components of list view
+               Dimension nameDim;
+               nameDim.wid = mathed_string_width(mi.base.font, from_ascii("Macro \\") + name() + ": ");
+               nameDim.asc = fontDim.asc;
+               nameDim.des = fontDim.des;
+
+               Dimension argDim;
+               argDim.wid = mathed_string_width(labelFont, from_ascii("#9: "));
+               argDim.asc = fontDim.asc;
+               argDim.des = fontDim.des;
+               
+               Dimension defDim;
+               definition_.metrics(mi, defDim);
+               
+               // add them up
+               dim.wid = nameDim.wid + defDim.wid;
+               dim.asc = max(nameDim.asc, defDim.asc);
+               dim.des = max(nameDim.des, defDim.des);
+               
+               for (idx_type i = 0; i < nargs(); ++i) {
+                       Dimension cdim;
+                       cell(i).metrics(mi, cdim);
+                       dim.des += max(argDim.height(), cdim.height()) + 1;
+                       dim.wid = max(dim.wid, argDim.wid + cdim.wid);
+               }
+               
+               // make space for box and markers, 2 pixels
+               dim.asc += 1;
+               dim.des += 1;
+               dim.wid += 2;
+               metricsMarkers2(dim);
        } else {
                BOOST_ASSERT(macro_ != 0);
 
@@ -199,7 +239,8 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
                macro_->unlock();
 
                // calculate dimension with label while editing
-               if (lyxrc.show_macro_label && editing_[mi.base.bv]) {
+               if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX 
+                   && editing_[mi.base.bv]) {
                        FontInfo font = mi.base.font;
                        augmentFont(font, from_ascii("lyxtex"));
                        Dimension namedim;
@@ -213,6 +254,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
                        dim.asc += 1 + namedim.height() + 1;
                        dim.des += 2;
                }
+        
        }
 }
 
@@ -272,6 +314,10 @@ void MathMacro::updateRepresentation(Cursor const * bvCur)
                
                // expanding macro with the values
                macro_->expand(values, expanded_.cell(0));
+
+               // get definition for list edit mode
+               docstring const & display = macro_->display();
+               asArray(display.empty() ? macro_->definition() : display, definition_);
        }
 }
 
@@ -297,12 +343,68 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                x += mathed_string_width(pi2.base.font, from_ascii("\\")) + 1;
                cell(0).draw(pi2, x, y);
                drawMarkers(pi2, expx, expy);
+       } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
+                  && editing_[pi.base.bv]) {
+               // Macro will be edited in a old-style list mode here:
+               
+               CoordCache & coords = pi.base.bv->coordCache();
+               FontInfo const & labelFont = sane_font;
+               
+               // markers and box needs two pixels
+               x += 2;
+               
+               // get maximal font height
+               Dimension fontDim;
+               math_font_max_dim(pi.base.font, fontDim.asc, fontDim.des);
+               
+               // draw label
+               docstring label = from_ascii("Macro \\") + name() + from_ascii(": ");
+               pi.pain.text(x, y, label, labelFont);
+               x += mathed_string_width(labelFont, label);
+
+               // draw definition
+               definition_.draw(pi, x, y);
+               Dimension defDim
+               = coords.arrays().dim(&definition_);
+               y += max(fontDim.des, defDim.des);
+                               
+               // draw parameters
+               docstring str = from_ascii("#9");
+               int strw1 = mathed_string_width(labelFont, from_ascii("#9"));
+               int strw2 = mathed_string_width(labelFont, from_ascii(": "));
+               
+               for (idx_type i = 0; i < nargs(); ++i) {
+                       // position of label
+                       Dimension cdim
+                       = coords.arrays().dim(&cell(i));
+                       x = expx + 2;
+                       y += max(fontDim.asc, cdim.asc) + 1;
+                       
+                       // draw label
+                       str[1] = '1' + i;
+                       pi.pain.text(x, y, str, labelFont);
+                       x += strw1;
+                       pi.pain.text(x, y, from_ascii(":"), labelFont);
+                       x += strw2;
+                       
+                       // draw paramter
+                       cell(i).draw(pi, x, y);
+                       
+                       // next line
+                       y += max(fontDim.des, cdim.des);
+               }
+               
+               pi.pain.rectangle(expx + 1, expy - dim.asc + 1, dim.wid - 3, 
+                                 dim.height() - 2, Color_mathmacroframe);
+               drawMarkers2(pi, expx, expy);
        } else {
+               bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX;
+               
                // warm up cells
                for (size_t i = 0; i < nargs(); ++i)
                        cell(i).setXY(*pi.base.bv, x, y);
 
-               if (lyxrc.show_macro_label && editing_[pi.base.bv]) {
+               if (drawBox && editing_[pi.base.bv]) {
                        // draw header and rectangle around
                        FontInfo font = pi.base.font;
                        augmentFont(font, from_ascii("lyxtex"));
@@ -321,13 +423,13 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                        expanded_.cell(0).draw(pi, expx, expy);
                        pi.pain.leaveMonochromeMode();
 
-                       if (lyxrc.show_macro_label)
+                       if (drawBox)
                                pi.pain.rectangle(x, y - dim.asc, dim.wid, 
                                                  dim.height(), Color_mathmacroframe);
                } else
                        expanded_.cell(0).draw(pi, expx, expy);
 
-               if (!lyxrc.show_macro_label)
+               if (!drawBox)
                        drawMarkers(pi, x, y);
        }
 
index 276cbdb21f222fda328bce6d05e45f3524e537e8..1296aa140b07a00c42b1f7375366e3c94267d150 100644 (file)
@@ -155,6 +155,8 @@ private:
        DisplayMode displayMode_;
        /// expanded macro with ArgumentProxies
        InsetMathSqrt expanded_;
+       /// editing look of macro
+       MathData definition_;
        /// number of arguments that were really attached
        size_t attachedArgsNum_;
        /// optional argument attached? (only in DISPLAY_NORMAL mode)