Martin Vermeer wrote:
> On Thu, Mar 31, 2005 at 09:52:57AM +0200, Jean-Marc Lasgouttes wrote:
>> >>>>> "Georg" == Georg Baum
>> >>>>> <[EMAIL PROTECTED]>
>> >>>>> writes:
>>
>> Georg> I thought the reason for using the istringstream was to get rid
>> Georg> of whitespace or other stuff that might be in cmd.argument
>> Georg> after the first word. Is that wrong? And if we get rid of it
>> Georg> here we should get rid of it in all the other insets, too (not
>> Georg> necessarily now)...
>>
>> Then you can use FuncRequest::getArg(1). I am not sure it has the best
>> possible implementation, but at least this is a consistent interface.
I had a closer look, and it turned out that more arguments are only needed
in MathGridInset for append-column etc. cmd.argument can be used directly
at all other places. I did not change MathGridInset to use
FuncRequest::getArg(1) because I wanted to be on the safe side.
> Should we at this point just add a comment to this effect at a strategic
> location, e.g., math_gridinset?
Simply changing the implementation was not more work, so I did that instead
of the comment.
Updated and tested patch attached. Since getStatus and doDispatch should
handle the same lfuns I also implemented the missing doDispatch methods.
This is going in unless I get a no.
Georg
Index: src/mathed/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v
retrieving revision 1.480
diff -u -p -r1.480 ChangeLog
--- src/mathed/ChangeLog 30 Mar 2005 09:05:30 -0000 1.480
+++ src/mathed/ChangeLog 31 Mar 2005 17:16:41 -0000
@@ -1,3 +1,20 @@
+2005-03-31 Georg Baum <[EMAIL PROTECTED]>
+
+ * math_amsarrayinset.[Ch], math_tabularinset.[Ch],
+ math_splitinset.[Ch] (infoize): implement
+ * math_amsarrayinset.[Ch], math_splitinset.[Ch],
+ math_substackinset.[Ch] (doDispatch): implement
+ * math_casesinset.C (getStatus, doDispatch): use cmd.argument directly
+ * math_gridinset.C (getStatus): ditto
+ * math_arrayinset.C (infoize): generalize
+
+2005-03-30 Martin Vermeer <[EMAIL PROTECTED]>
+
+ * math_amsarrayinset.[Ch] (getStatus):
+ * math_splitinset.[Ch] (getStatus):
+ * math_substackinset.[Ch]: suppress output of vertical gridlines
+ where appropriate
+
2005-03-27 Georg Baum <[EMAIL PROTECTED]>
* math_amsarrayinset.[Ch] (validate): new, require amsmath
Index: src/mathed/math_amsarrayinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_amsarrayinset.C,v
retrieving revision 1.26
diff -u -p -r1.26 math_amsarrayinset.C
--- src/mathed/math_amsarrayinset.C 30 Mar 2005 09:05:30 -0000 1.26
+++ src/mathed/math_amsarrayinset.C 31 Mar 2005 17:11:36 -0000
@@ -17,8 +17,19 @@
#include "math_streamstr.h"
#include "math_support.h"
+#include "cursor.h"
+#include "funcrequest.h"
+#include "FuncStatus.h"
+#include "gettext.h"
+#include "undo.h"
+
+#include "support/lstrings.h"
+#include "support/std_ostream.h"
+
+
using std::string;
using std::auto_ptr;
+using lyx::support::bformat;
MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
@@ -90,11 +101,57 @@ void MathAMSArrayInset::draw(PainterInfo
}
+void MathAMSArrayInset::doDispatch(LCursor & cur, FuncRequest & cmd)
+{
+ switch (cmd.action) {
+ case LFUN_TABULAR_FEATURE: {
+ recordUndo(cur);
+ string const s = cmd.argument;
+ if (s == "add-vline-left" || s == "add-vline-right") {
+ cur.undispatched();
+ break;
+ }
+ }
+ default:
+ MathGridInset::doDispatch(cur, cmd);
+ }
+}
+
+
+bool MathAMSArrayInset::getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const
+{
+ switch (cmd.action) {
+ case LFUN_TABULAR_FEATURE: {
+ string const s = cmd.argument;
+ if (s == "add-vline-left" || s == "add-vline-right") {
+ flag.message(bformat(
+ N_("Can't add vertical grid lines in '%1$s'"),
+ name_));
+ flag.enabled(false);
+ return true;
+ }
+ return MathGridInset::getStatus(cur, cmd, flag);
+ }
+ default:
+ return MathGridInset::getStatus(cur, cmd, flag);
+ }
+}
+
+
void MathAMSArrayInset::write(WriteStream & os) const
{
os << "\\begin{" << name_ << '}';
MathGridInset::write(os);
os << "\\end{" << name_ << '}';
+}
+
+
+void MathAMSArrayInset::infoize(std::ostream & os) const
+{
+ string name = name_;
+ name[0] = lyx::support::uppercase(name[0]);
+ os << name << ' ';
}
Index: src/mathed/math_amsarrayinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_amsarrayinset.h,v
retrieving revision 1.19
diff -u -p -r1.19 math_amsarrayinset.h
--- src/mathed/math_amsarrayinset.h 30 Mar 2005 09:05:30 -0000 1.19
+++ src/mathed/math_amsarrayinset.h 31 Mar 2005 17:11:36 -0000
@@ -32,7 +32,14 @@ public:
MathAMSArrayInset const * asAMSArrayInset() const { return this; }
///
+ virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
+ ///
+ bool getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const;
+ ///
void write(WriteStream & os) const;
+ ///
+ void infoize(std::ostream & os) const;
///
void normalize(NormalStream &) const;
///
Index: src/mathed/math_arrayinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_arrayinset.C,v
retrieving revision 1.56
diff -u -p -r1.56 math_arrayinset.C
--- src/mathed/math_arrayinset.C 30 Mar 2005 09:05:30 -0000 1.56
+++ src/mathed/math_arrayinset.C 31 Mar 2005 17:11:36 -0000
@@ -17,6 +17,8 @@
#include "math_mathmlstream.h"
#include "math_streamstr.h"
+#include "support/lstrings.h"
+
#include <iterator>
#include <sstream>
@@ -113,7 +115,9 @@ void MathArrayInset::write(WriteStream &
void MathArrayInset::infoize(std::ostream & os) const
{
- os << "Array";
+ string name = name_;
+ name[0] = lyx::support::uppercase(name[0]);
+ os << name << ' ';
}
Index: src/mathed/math_casesinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_casesinset.C,v
retrieving revision 1.28
diff -u -p -r1.28 math_casesinset.C
--- src/mathed/math_casesinset.C 24 Mar 2005 16:26:15 -0000 1.28
+++ src/mathed/math_casesinset.C 31 Mar 2005 17:11:36 -0000
@@ -24,7 +24,6 @@
#include "support/lstrings.h"
-#include <sstream>
using lyx::support::bformat;
@@ -32,7 +31,6 @@ using std::endl;
using std::max;
using std::min;
using std::swap;
-using std::istringstream;
using std::string;
using std::auto_ptr;
@@ -71,9 +69,7 @@ void MathCasesInset::doDispatch(LCursor
switch (cmd.action) {
case LFUN_TABULAR_FEATURE: {
recordUndo(cur);
- istringstream is(cmd.argument);
- string s;
- is >> s;
+ string const s = cmd.argument;
if (s == "add-vline-left" || s == "add-vline-right") {
cur.undispatched();
break;
@@ -90,9 +86,7 @@ bool MathCasesInset::getStatus(LCursor &
{
switch (cmd.action) {
case LFUN_TABULAR_FEATURE: {
- istringstream is(cmd.argument);
- string s;
- is >> s;
+ string const s = cmd.argument;
if (s == "add-vline-left" || s == "add-vline-right") {
flag.enabled(false);
flag.message(bformat(
diff -u -p -r1.156 math_gridinset.C
--- src/mathed/math_gridinset.C 14 Feb 2005 14:25:17 -0000 1.156
+++ src/mathed/math_gridinset.C 31 Mar 2005 17:11:36 -0000
@@ -1237,9 +1274,7 @@ bool MathGridInset::getStatus(LCursor &
{
switch (cmd.action) {
case LFUN_TABULAR_FEATURE: {
- istringstream is(cmd.argument);
- string s;
- is >> s;
+ string const s = cmd.argument;
if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
flag.enabled(false);
flag.message(N_("Only one row"));
Index: src/mathed/math_splitinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_splitinset.C,v
retrieving revision 1.15
diff -u -p -r1.15 math_splitinset.C
--- src/mathed/math_splitinset.C 23 Nov 2004 23:04:52 -0000 1.15
+++ src/mathed/math_splitinset.C 31 Mar 2005 17:11:37 -0000
@@ -15,7 +15,17 @@
#include "math_mathmlstream.h"
#include "math_streamstr.h"
+#include "cursor.h"
+#include "funcrequest.h"
+#include "FuncStatus.h"
+#include "gettext.h"
+#include "undo.h"
+#include "support/lstrings.h"
+#include "support/std_ostream.h"
+
+
+using lyx::support::bformat;
using std::string;
using std::auto_ptr;
@@ -47,6 +57,44 @@ char MathSplitInset::defaultColAlign(col
}
+void MathSplitInset::doDispatch(LCursor & cur, FuncRequest & cmd)
+{
+ switch (cmd.action) {
+ case LFUN_TABULAR_FEATURE: {
+ recordUndo(cur);
+ string const s = cmd.argument;
+ if (s == "add-vline-left" || s == "add-vline-right") {
+ cur.undispatched();
+ break;
+ }
+ }
+ default:
+ MathGridInset::doDispatch(cur, cmd);
+ }
+}
+
+
+bool MathSplitInset::getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const
+{
+ switch (cmd.action) {
+ case LFUN_TABULAR_FEATURE: {
+ string const s = cmd.argument;
+ if (s == "add-vline-left" || s == "add-vline-right") {
+ flag.message(bformat(
+ N_("Can't add vertical grid lines in '%1$s'"),
+ name_));
+ flag.enabled(false);
+ return true;
+ }
+ return MathGridInset::getStatus(cur, cmd, flag);
+ }
+ default:
+ return MathGridInset::getStatus(cur, cmd, flag);
+ }
+}
+
+
void MathSplitInset::write(WriteStream & ws) const
{
if (ws.fragile())
@@ -56,4 +104,12 @@ void MathSplitInset::write(WriteStream &
if (ws.fragile())
ws << "\\protect";
ws << "\\end{" << name_ << "}\n";
+}
+
+
+void MathSplitInset::infoize(std::ostream & os) const
+{
+ string name = name_;
+ name[0] = lyx::support::uppercase(name[0]);
+ os << name << ' ';
}
Index: src/mathed/math_splitinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_splitinset.h,v
retrieving revision 1.13
diff -u -p -r1.13 math_splitinset.h
--- src/mathed/math_splitinset.h 23 Nov 2004 23:04:52 -0000 1.13
+++ src/mathed/math_splitinset.h 31 Mar 2005 17:11:37 -0000
@@ -19,8 +19,16 @@ class MathSplitInset : public MathGridIn
public:
///
explicit MathSplitInset(std::string const & name);
+
///
+ virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
+ ///
+ bool getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const;
+
void write(WriteStream & os) const;
+ ///
+ void infoize(std::ostream & os) const;
///
int defaultColSpace(col_type) { return 0; }
///
Index: src/mathed/math_substackinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_substackinset.C,v
retrieving revision 1.19
diff -u -p -r1.19 math_substackinset.C
--- src/mathed/math_substackinset.C 30 Mar 2005 09:05:30 -0000 1.19
+++ src/mathed/math_substackinset.C 31 Mar 2005 17:11:37 -0000
@@ -16,6 +16,17 @@
#include "math_mathmlstream.h"
#include "support/std_ostream.h"
+#include "cursor.h"
+#include "funcrequest.h"
+#include "FuncStatus.h"
+#include "gettext.h"
+#include "undo.h"
+
+#include "support/lstrings.h"
+
+
+using lyx::support::bformat;
+using std::string;
using std::auto_ptr;
@@ -45,6 +56,44 @@ void MathSubstackInset::metrics(MetricsI
void MathSubstackInset::draw(PainterInfo & pi, int x, int y) const
{
MathGridInset::draw(pi, x + 1, y);
+}
+
+
+void MathSubstackInset::doDispatch(LCursor & cur, FuncRequest & cmd)
+{
+ switch (cmd.action) {
+ case LFUN_TABULAR_FEATURE: {
+ recordUndo(cur);
+ string const s = cmd.argument;
+ if (s == "add-vline-left" || s == "add-vline-right") {
+ cur.undispatched();
+ break;
+ }
+ }
+ default:
+ MathGridInset::doDispatch(cur, cmd);
+ }
+}
+
+
+bool MathSubstackInset::getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const
+{
+ switch (cmd.action) {
+ case LFUN_TABULAR_FEATURE: {
+ string const name("substack");
+ string const s = cmd.argument;
+ if (s == "add-vline-left" || s == "add-vline-right") {
+ flag.message(bformat(
+ N_("Can't add vertical grid lines in '%1$s'"), name));
+ flag.enabled(false);
+ return true;
+ }
+ return MathGridInset::getStatus(cur, cmd, flag);
+ }
+ default:
+ return MathGridInset::getStatus(cur, cmd, flag);
+ }
}
Index: src/mathed/math_substackinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_substackinset.h,v
retrieving revision 1.15
diff -u -p -r1.15 math_substackinset.h
--- src/mathed/math_substackinset.h 30 Mar 2005 09:05:30 -0000 1.15
+++ src/mathed/math_substackinset.h 31 Mar 2005 17:11:37 -0000
@@ -29,7 +29,10 @@ public:
MathSubstackInset const * asSubstackInset() const { return this; }
///
- void normalize();
+ virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
+ ///
+ bool getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const;
///
void infoize(std::ostream & os) const;
///
Index: src/mathed/math_tabularinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_tabularinset.C,v
retrieving revision 1.13
diff -u -p -r1.13 math_tabularinset.C
--- src/mathed/math_tabularinset.C 23 Nov 2004 23:04:52 -0000 1.13
+++ src/mathed/math_tabularinset.C 31 Mar 2005 17:11:37 -0000
@@ -15,6 +15,9 @@
#include "math_mathmlstream.h"
#include "math_streamstr.h"
+#include "support/lstrings.h"
+#include "support/std_ostream.h"
+
#include <iterator>
@@ -76,6 +79,14 @@ void MathTabularInset::write(WriteStream
os << "\\end{" << name_ << '}';
// adding a \n here is bad if the tabular is the last item
// in an \eqnarray...
+}
+
+
+void MathTabularInset::infoize(std::ostream & os) const
+{
+ string name = name_;
+ name[0] = lyx::support::uppercase(name[0]);
+ os << name << ' ';
}
Index: src/mathed/math_tabularinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_tabularinset.h,v
retrieving revision 1.9
diff -u -p -r1.9 math_tabularinset.h
--- src/mathed/math_tabularinset.h 23 Nov 2004 23:04:52 -0000 1.9
+++ src/mathed/math_tabularinset.h 31 Mar 2005 17:11:37 -0000
@@ -37,6 +37,8 @@ public:
///
void write(WriteStream & os) const;
///
+ void infoize(std::ostream & os) const;
+ ///
void normalize(NormalStream &) const;
///
void maple(MapleStream &) const;