Automate the setting of the ascii only flag.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33328 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2010-02-04 23:03:48 +00:00
parent 2a69d4e4f8
commit d652a84f4b
3 changed files with 22 additions and 12 deletions

View File

@ -65,15 +65,12 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const
void CommandInset::write(WriteStream & os) const
{
ModeSpecifier specifier(os, currentMode(), lockedMode());
ModeSpecifier specifier(os, currentMode(), lockedMode(), asciiOnly());
MathEnsurer ensurer(os, needs_math_mode_);
bool const ascii = os.asciiOnly();
os.asciiOnly(asciiOnly());
os << '\\' << name_;
if (cell(1).size())
os << '[' << cell(1) << ']';
os << '{' << cell(0) << '}';
os.asciiOnly(ascii);
}

View File

@ -278,7 +278,8 @@ bool ensureMath(WriteStream & os, bool needs_math_mode, bool macro)
}
int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked)
int ensureMode(WriteStream & os, InsetMath::mode_type mode,
bool locked, bool ascii)
{
bool textmode = mode == InsetMath::TEXT_MODE;
if (os.latex() && textmode && os.pendingBrace()) {
@ -287,10 +288,12 @@ int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked)
os.pendingSpace(false);
os.textMode(true);
}
int oldmodes = os.textMode() ? 1 : 0;
int oldmodes = os.textMode() ? 0x01 : 0;
os.textMode(textmode);
oldmodes |= os.lockedMode() ? 2 : 0;
oldmodes |= os.lockedMode() ? 0x02 : 0;
os.lockedMode(locked);
oldmodes |= os.asciiOnly() ? 0x04 : 0;
os.asciiOnly(ascii);
return oldmodes;
}

View File

@ -127,7 +127,7 @@ WriteStream & operator<<(WriteStream &, unsigned int);
bool ensureMath(WriteStream & os, bool needs_math_mode = true, bool macro = false);
/// ensure the requested mode, possibly by closing \ensuremath
int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked);
int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked, bool ascii);
/**
@ -191,6 +191,8 @@ private:
* the mode needs being temporarily switched when a command would not work
* in the current mode. As there are cases where this switching is to be
* avoided, the optional third parameter can be used to lock the mode.
* When the mode is locked, the optional fourth parameter specifies whether
* strings are to be output by using a suitable ascii representation.
*
* Example 1:
*
@ -204,6 +206,13 @@ private:
*
* Sets the current mode to text mode and disallows mode switching.
*
* Example 3:
*
* ModeSpecifier specifier(os, TEXT_MODE, true, true);
*
* Sets the current mode to text mode, disallows mode switching, and outputs
* strings as ascii only.
*
* At the end of specifier's scope the mode is reset to its previous value.
*/
class ModeSpecifier
@ -211,13 +220,14 @@ class ModeSpecifier
public:
///
explicit ModeSpecifier(WriteStream & os, InsetMath::mode_type mode,
bool locked = false)
: os_(os), oldmodes_(ensureMode(os, mode, locked)) {}
bool locked = false, bool ascii = false)
: os_(os), oldmodes_(ensureMode(os, mode, locked, ascii)) {}
///
~ModeSpecifier()
{
os_.textMode(oldmodes_ & 1);
os_.lockedMode(oldmodes_ & 2);
os_.textMode(oldmodes_ & 0x01);
os_.lockedMode(oldmodes_ & 0x02);
os_.asciiOnly(oldmodes_ & 0x04);
}
private:
///