]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
simplify GuiToc / TocWidget interaction. Much can still be simplified...
[lyx.git] / src / mathed / InsetMathHull.cpp
index 967843c48c8b07c75ab99f7eea277406c1bc360c..976b4865cf2f28a88186fded7b75e0f03fa18697 100644 (file)
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "Cursor.h"
-#include "debug.h"
+#include "support/debug.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
-#include "gettext.h"
+#include "support/gettext.h"
 #include "LyXRC.h"
 #include "OutputParams.h"
 #include "sgml.h"
 
 #include "frontends/Painter.h"
 
-#include "support/lyxlib.h"
 #include "support/lstrings.h"
 
 #include <sstream>
 
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
 using cap::grabAndEraseSelection;
-using support::bformat;
-using support::subst;
-
-using std::endl;
-using std::max;
-using std::ostream;
-using std::istringstream;
-using std::ostringstream;
-using std::swap;
-using std::vector;
-
 
 namespace {
 
@@ -241,6 +231,8 @@ char InsetMathHull::defaultColAlign(col_type col)
 {
        if (type_ == hullEqnArray)
                return "rcl"[col];
+       if (type_ == hullGather)
+               return 'c';
        if (type_ >= hullAlign)
                return "rl"[col & 1];
        return 'c';
@@ -960,7 +952,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func)
        iss >> dlang >> extra;
        if (extra.empty())
                extra = from_ascii("noextra");
-       std::string const lang = to_ascii(dlang);
+       string const lang = to_ascii(dlang);
 
        // FIXME: temporarily disabled
        //if (cur.selection()) {
@@ -1035,6 +1027,8 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_FINISHED_BACKWARD:
        case LFUN_FINISHED_FORWARD:
+       case LFUN_FINISHED_RIGHT:
+       case LFUN_FINISHED_LEFT:
                //lyxerr << "action: " << cmd.action << endl;
                InsetMathGrid::doDispatch(cur, cmd);
                notifyCursorLeaves(cur);
@@ -1045,7 +1039,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
                // just swallow this
                break;
 
-       case LFUN_BREAK_LINE:
+       case LFUN_NEW_LINE:
                // some magic for the common case
                if (type_ == hullSimple || type_ == hullEquation) {
                        cur.recordUndoInset();
@@ -1058,30 +1052,28 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
                InsetMathGrid::doDispatch(cur, cmd);
                break;
 
-       case LFUN_MATH_NUMBER:
+       case LFUN_MATH_NUMBER_TOGGLE: {
                //lyxerr << "toggling all numbers" << endl;
-               if (display()) {
-                       cur.recordUndoInset();
-                       bool old = numberedType();
-                       if (type_ == hullMultline)
-                               numbered(nrows() - 1, !old);
-                       else
-                               for (row_type row = 0; row < nrows(); ++row)
-                                       numbered(row, !old);
-
-                       cur.message(old ? _("No number") : _("Number"));
-               }
+               cur.recordUndoInset();
+               bool old = numberedType();
+               if (type_ == hullMultline)
+                       numbered(nrows() - 1, !old);
+               else
+                       for (row_type row = 0; row < nrows(); ++row)
+                               numbered(row, !old);
+               
+               cur.message(old ? _("No number") : _("Number"));
                break;
+       }
 
-       case LFUN_MATH_NONUMBER:
-               if (display()) {
-                       cur.recordUndoInset();
-                       row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
-                       bool old = numbered(r);
-                       cur.message(old ? _("No number") : _("Number"));
-                       numbered(r, !old);
-               }
+       case LFUN_MATH_NUMBER_LINE_TOGGLE: {
+               cur.recordUndoInset();
+               row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
+               bool old = numbered(r);
+               cur.message(old ? _("No number") : _("Number"));
+               numbered(r, !old);
                break;
+       }
 
        case LFUN_LABEL_INSERT: {
                cur.recordUndoInset();
@@ -1094,7 +1086,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
 
                InsetCommandParams p(LABEL_CODE);
                p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
-               std::string const data = InsetCommandMailer::params2string("label", p);
+               string const data = InsetCommandMailer::params2string("label", p);
 
                if (cmd.argument().empty())
                        cur.bv().showDialog("label", data);
@@ -1107,14 +1099,14 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_INSERT: {
                //lyxerr << "arg: " << to_utf8(cmd.argument()) << endl;
-               std::string const name = cmd.getArg(0);
+               string const name = cmd.getArg(0);
                if (name == "label") {
                        InsetCommandParams p(LABEL_CODE);
                        InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), p);
                        docstring str = p["name"];
                        cur.recordUndoInset();
                        row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
-                       str = support::trim(str);
+                       str = trim(str);
                        if (!str.empty())
                                numbered(r, true);
                        docstring old = label(r);
@@ -1146,6 +1138,10 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                if (cur.pos() > cur.lastpos())
                        cur.pos() = cur.lastpos();
+               
+               // FIXME: find some more clever handling of the selection,
+               // i.e. preserve it.
+               cur.clearSelection();
                //cur.dispatched(FINISHED);
                break;
        }
@@ -1172,19 +1168,31 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
        switch (cmd.action) {
        case LFUN_FINISHED_BACKWARD:
        case LFUN_FINISHED_FORWARD:
+       case LFUN_FINISHED_RIGHT:
+       case LFUN_FINISHED_LEFT:
        case LFUN_UP:
        case LFUN_DOWN:
-               status.enabled(true);
-               return true;
-       case LFUN_BREAK_LINE:
-       case LFUN_MATH_NUMBER:
-       case LFUN_MATH_NONUMBER:
+       case LFUN_NEW_LINE:
        case LFUN_MATH_EXTERN:
        case LFUN_MATH_MUTATE:
        case LFUN_MATH_DISPLAY:
                // we handle these
                status.enabled(true);
                return true;
+       case LFUN_MATH_NUMBER_TOGGLE:
+               // FIXME: what is the right test, this or the one of
+               // LABEL_INSERT?
+               status.enabled(display());
+               status.setOnOff(numberedType());
+               return true;
+       case LFUN_MATH_NUMBER_LINE_TOGGLE: {
+               // FIXME: what is the right test, this or the one of
+               // LABEL_INSERT?
+               status.enabled(display());
+               row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
+               status.setOnOff(numbered(r));
+               return true;
+       }
        case LFUN_LABEL_INSERT:
                status.enabled(type_ != hullSimple);
                return true;
@@ -1196,7 +1204,7 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
                return InsetMathGrid::getStatus(cur, cmd, status);
        case LFUN_TABULAR_FEATURE: {
                istringstream is(to_utf8(cmd.argument()));
-               std::string s;
+               string s;
                is >> s;
                if (!rowChangeOK()
                    && (s == "append-row"
@@ -1306,10 +1314,12 @@ void InsetMathHull::handleFont2(Cursor & cur, docstring const & arg)
 }
 
 
-void InsetMathHull::edit(Cursor & cur, bool front)
+void InsetMathHull::edit(Cursor & cur, bool front, EntryDirection entry_from)
 {
        cur.push(*this);
-       front ? idxFirst(cur) : idxLast(cur);
+       bool enter_front = (entry_from == Inset::ENTRY_DIRECTION_LEFT || 
+               (entry_from == Inset::ENTRY_DIRECTION_IGNORE && front));
+       enter_front ? idxFirst(cur) : idxLast(cur);
        // The inset formula dimension is not necessarily the same as the
        // one of the instant preview image, so we have to indicate to the
        // BufferView that a metrics update is needed.
@@ -1409,7 +1419,7 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
 #endif
 
 
-void InsetMathHull::write(Buffer const &, std::ostream & os) const
+void InsetMathHull::write(Buffer const &, ostream & os) const
 {
        odocstringstream oss;
        WriteStream wi(oss, false, false);