minimal ERT spacing patch (first patch sent to list plus a couple of fixes)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7134 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-06-07 17:45:43 +00:00
parent 856b10ecaf
commit 13a21fe510
11 changed files with 57 additions and 24 deletions

View File

@ -1,3 +1,14 @@
2003-06-07 John Levon <levon@movementarian.org>
* buffer.C:
* paragraph_funcs.C:
* paragraph_pimpl.C:
* text.C:
* text2.C:
* paragraph.h:
* paragraph.C: allow InsetERT to freely space lines,
and some consolidation of code
2003-06-06 José Matos <jamatos@fep.up.pt>
* buffer.C (makeDocBookFile): fix bug #821

View File

@ -414,7 +414,7 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
for(string::const_iterator cit = str.begin();
cit != str.end(); ++cit) {
if (*cit == '\n') {
if (autobreakrows && (!par->empty() || layout->keepempty)) {
if (autobreakrows && (!par->empty() || par->allowEmpty())) {
breakParagraph(params, paragraphs, par, pos,
layout->isEnvironment());
++par;
@ -425,12 +425,10 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
}
// do not insert consecutive spaces if !free_spacing
} else if ((*cit == ' ' || *cit == '\t') &&
space_inserted && !layout->free_spacing &&
!par->isFreeSpacing())
{
space_inserted && !par->isFreeSpacing()) {
continue;
} else if (*cit == '\t') {
if (!layout->free_spacing && !par->isFreeSpacing()) {
if (!par->isFreeSpacing()) {
// tabs are like spaces here
par->insertChar(pos, ' ', font);
++pos;
@ -1522,7 +1520,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
bool ws;
string str;
boost::tie(ws, str) = sgml::escapeChar(c);
if (ws && !style->free_spacing && !par->isFreeSpacing()) {
if (ws && !par->isFreeSpacing()) {
// in freespacing mode, spaces are
// non-breaking characters
if (desc_on) {// if char is ' ' then...
@ -1907,9 +1905,9 @@ void Buffer::simpleDocBookOnePar(ostream & os,
if (style->pass_thru) {
os << c;
} else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
} else if (par->isFreeSpacing() || c != ' ') {
os << str;
} else if (desc_on ==1) {
} else if (desc_on == 1) {
++char_line_count;
os << "\n</term><listitem><para>";
desc_on = 2;

View File

@ -1,3 +1,8 @@
2003-06-07 John Levon <levon@movementarian.org>
* insetert.C (latex): make a newline mean just that not
a new par
2003-06-07 José Matos <jamatos@fep.up.pt>
* insethfill.[Ch] (linuxdoc, docbook): implement output

View File

@ -346,8 +346,8 @@ int InsetERT::latex(Buffer const *, ostream & os,
}
++par;
if (par != end) {
os << "\n\n";
lines += 2;
os << "\n";
++lines;
}
}

View File

@ -330,8 +330,12 @@ string const InsetGraphics::prepareFile(Buffer const * buf,
string orig_file = params().filename;
string const rel_file = MakeRelPath(orig_file, buf->filePath());
if (!IsFileReadable(rel_file))
if (!IsFileReadable(orig_file)) {
lyxerr[Debug::GRAPHICS]
<< "InsetGraphics::prepareFile\n"
<< "No file '" << orig_file << "' can be found!" << endl;
return rel_file;
}
bool const zipped = zippedFile(orig_file);
@ -521,6 +525,8 @@ int InsetGraphics::latex(Buffer const * buf, ostream & os,
(before + '{' + relative_file + " not found!}" + after);
os << latex_str;
lyxerr[Debug::GRAPHICS] << "InsetGraphics::latex outputting:\n"
<< latex_str << endl;
// Return how many newlines we issued.
return int(lyx::count(latex_str.begin(), latex_str.end(),'\n') + 1);
}

View File

@ -623,7 +623,7 @@ void Paragraph::makeSameLayout(Paragraph const & par)
int Paragraph::stripLeadingSpaces()
{
if (layout()->free_spacing || isFreeSpacing())
if (isFreeSpacing())
return 0;
int i = 0;
@ -1409,6 +1409,9 @@ ParagraphParameters const & Paragraph::params() const
bool Paragraph::isFreeSpacing() const
{
if (layout()->free_spacing)
return true;
// for now we just need this, later should we need this in some
// other way we can always add a function to Inset::() too.
if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
@ -1417,6 +1420,16 @@ bool Paragraph::isFreeSpacing() const
}
bool Paragraph::allowEmpty() const
{
if (layout()->keepempty)
return true;
if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
return false;
}
bool operator==(Paragraph const & lhs, Paragraph const & rhs)
{
#warning FIXME this implementatoin must be completely wrong...

View File

@ -283,9 +283,12 @@ public:
///
int stripLeadingSpaces();
///
/// return true if we allow multiple spaces
bool isFreeSpacing() const;
/// return true if we allow this par to stay empty
bool allowEmpty() const;
///
ParagraphParameters & params();
///

View File

@ -71,7 +71,7 @@ void breakParagraph(BufferParams const & bparams,
tmp->setLabelWidthString(par->params().labelWidthString());
}
bool const isempty = (par->layout()->keepempty && par->empty());
bool const isempty = (par->allowEmpty() && par->empty());
if (!isempty && (par->size() > pos || par->empty() || flag == 2)) {
tmp->layout(par->layout());
@ -937,10 +937,9 @@ int readParToken(Buffer & buf, Paragraph & par, LyXLex & lex, string const & tok
lex.next();
font.setLyXColor(lex.getString());
} else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
LyXLayout_ptr const & layout = par.layout();
// Insets don't make sense in a free-spacing context! ---Kayvan
if (layout->free_spacing || par.isFreeSpacing()) {
if (par.isFreeSpacing()) {
if (token == "\\InsetSpace")
par.insertChar(par.size(), ' ', font, change);
else if (lex.isOK()) {

View File

@ -429,8 +429,7 @@ void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow,
&& getChar(i - 1) != ' '
&& (i < size() - 1)
// same in FreeSpacing mode
&& !style.free_spacing
&& !owner_->isFreeSpacing()
&& !owner_->isFreeSpacing()
// In typewriter mode, we want to avoid
// ! . ? : at the end of a line
&& !(font.family() == LyXFont::TYPEWRITER_FAMILY

View File

@ -1461,10 +1461,9 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
LyXLayout_ptr const & layout = cursor.par()->layout();
// this is only allowed, if the current paragraph is not empty or caption
// and if it has not the keepempty flag aktive
if (cursor.par()->empty()
&& layout->labeltype != LABEL_SENSITIVE
&& !layout->keepempty)
// and if it has not the keepempty flag active
if (cursor.par()->empty() && !cursor.par()->allowEmpty()
&& layout->labeltype != LABEL_SENSITIVE)
return;
setUndo(bv(), Undo::FINISH, cursor.par());
@ -1487,7 +1486,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
// breakParagraph call should return a bool if it inserts the
// paragraph before or behind and we should react on that one
// but we can fix this in 1.3.0 (Jug 20020509)
bool const isempty = (layout->keepempty && cursor.par()->empty());
bool const isempty = (cursor.par()->allowEmpty() && cursor.par()->empty());
::breakParagraph(bv()->buffer()->params, paragraphs, cursor.par(), cursor.pos(),
keep_layout);

View File

@ -2224,7 +2224,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
return false;
// Do not delete empty paragraphs with keepempty set.
if (old_cursor.par()->layout()->keepempty)
if (old_cursor.par()->allowEmpty())
return false;
// only do our magic if we changed paragraph