Strip old tabular code. More Alert fixes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6627 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-03-29 10:29:38 +00:00
parent 770092ed6b
commit 06242eb145
14 changed files with 44 additions and 513 deletions

View File

@ -564,12 +564,7 @@ bool BufferView::insertInset(Inset * inset, string const & lout)
}
// This is also a buffer property (ale)
// Not so sure about that. a goto Label function can not be buffer local, just
// think how this will work in a multiwindow/buffer environment, all the
// cursors in all the views showing this buffer will move. (Lgb)
// OK, then no cursor action should be allowed in buffer. (ale)
bool BufferView::gotoLabel(string const & label)
void BufferView::gotoLabel(string const & label)
{
for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
it != buffer()->inset_iterator_end(); ++it) {
@ -580,10 +575,9 @@ bool BufferView::gotoLabel(string const & label)
text->setCursor(it.getPar(), it.getPos());
text->selection.cursor = text->cursor;
update(text, BufferView::SELECT);
return true;
return;
}
}
return false;
}

View File

@ -144,7 +144,7 @@ public:
WordLangTuple const nextWord(float & value);
/// move cursor to the named label
bool gotoLabel(string const & label);
void gotoLabel(string const & label);
/// copy the environment type from current paragraph
void copyEnvironment();

View File

@ -1049,8 +1049,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
restorePosition(strToUnsignedInt(ev.argument));
break;
case LFUN_REF_GOTO:
{
case LFUN_REF_GOTO: {
string label = ev.argument;
if (label.empty()) {
InsetRef * inset =
@ -1061,13 +1060,8 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
}
}
if (!label.empty()) {
//bv_->savePosition(0);
if (!bv_->gotoLabel(label))
Alert::alert(_("Error"),
_("Couldn't find this label"),
_("in current document."));
}
if (!label.empty())
bv_->gotoLabel(label);
}
break;

View File

@ -1,3 +1,13 @@
2003-03-29 John Levon <levon@movementarian.org>
* BufferView.C:
* BufferView.h:
* BufferView_pimpl.C: Alert fixes
* Makefile.am:
* tabular.C:
* tabular-old.C: remove unused table compat reading
2003-03-29 John Levon <levon@movementarian.org>
* BufferView.C:

View File

@ -201,7 +201,6 @@ lyx_SOURCES = \
sgml.h \
tabular.C \
tabular.h \
tabular-old.C \
tabular_funcs.C \
tabular_funcs.h \
tex-accent.C \

View File

@ -292,7 +292,7 @@ int Buffer::readHeader(LyXLex & lex)
if (unknown[0] != '\\') {
unknownClass(unknown);
} else {
++unknown_tokens;
++unknown_tokens;
}
}
}
@ -812,9 +812,6 @@ string const Buffer::asciiParagraph(Paragraph const & par,
/* noindent ? */
/* what about the alignment */
// } else {
// lyxerr << "Should this ever happen?" << endl;
// }
// linelen <= 0 is special and means we don't have paragraph breaks

View File

@ -1,3 +1,7 @@
2003-03-29 John Levon <levon@movementarian.org>
* insettabular.C: Alert fix
2003-03-28 John Levon <levon@movementarian.org>
* insetfloat.C: reset label on INSET_MODIFY

View File

@ -1982,9 +1982,11 @@ void InsetTabular::tabularFeatures(BufferView * bv,
case LyXTabular::MULTICOLUMN:
{
if (sel_row_start != sel_row_end) {
Alert::alert(_("Impossible operation!"),
_("Multicolumns can only be horizontally."),
_("Sorry."));
#ifdef WITH_WARNINGS
#warning Need I say it ? This is horrible.
#endif
Alert::error(_("Error setting multicolumn"),
_("You cannot set multicolumn vertically."));
return;
}
// just multicol for one Single Cell

View File

@ -42,10 +42,13 @@ int LyXReplace(BufferView * bv,
// CutSelection cannot cut a single space, so we have to stop
// in order to avoid endless loop :-(
if (searchstr.length() == 0
|| (searchstr.length() == 1 && searchstr[0] == ' '))
{
Alert::alert(_("Sorry!"), _("You cannot replace a single space, "
"nor an empty character."));
|| (searchstr.length() == 1 && searchstr[0] == ' ')) {
#ifdef WITH_WARNINGS
#warning BLECH. If we have an LFUN for replace, we can fix this bogosity
#endif
Alert::error(_("Cannot replace"),
_("You cannot replace a single space or "
"an empty character."));
return 0;
}

View File

@ -71,7 +71,7 @@ public:
// Reads LyX textclass definitions according to textclass config file
bool LyXTextClassList::Read ()
bool LyXTextClassList::Read()
{
LyXLex lex(0, 0);
string real_file = LibFileSearch("", "textclass.lst");
@ -82,10 +82,6 @@ bool LyXTextClassList::Read ()
lyxerr << "LyXTextClassList::Read: unable to find "
"textclass file `" << MakeDisplayPath(real_file, 1000)
<< "'. Exiting." << endl;
Alert::alert(_("LyX wasn't able to find its layout descriptions!"),
_("Check that the file \"textclass.lst\""),
_("is installed correctly. Sorry, has to exit :-("));
return false;
// This causes LyX to end... Not a desirable behaviour. Lgb
// What do you propose? That the user gets a file dialog
@ -142,9 +138,6 @@ bool LyXTextClassList::Read ()
if (classlist_.empty()) {
lyxerr << "LyXTextClassList::Read: no textclasses found!"
<< endl;
Alert::alert(_("LyX wasn't able to find any layout description!"),
_("Check the contents of the file \"textclass.lst\""),
_("Sorry, has to exit :-("));
return false;
}
// Ok everything loaded ok, now sort the list.

View File

@ -105,9 +105,9 @@ void LyXVC::registrer()
// there must be a file to save
if (!IsFileReadable(filename)) {
Alert::alert(_("File not saved"),
_("You must save the file"),
_("before it can be registered."));
Alert::error(_("Document not saved"),
_("You must save the document "
"before it can be registered."));
return;
}
@ -145,8 +145,6 @@ void LyXVC::registrer()
if (!tmp.first || tmp.second.empty()) {
// should we insist on checking tmp.second.empty()?
lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
Alert::alert(_("Info"),
_("This document has NOT been registered."));
return;
}

View File

@ -1,254 +0,0 @@
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2000-2001 The LyX Team.
*
* @author: Jürgen Vigna
*
* ======================================================
*/
#include <config.h>
#include "tabular.h"
#include "buffer.h"
#include "debug.h"
#include "support/lstrings.h"
#include "support/textutils.h"
using std::abs;
using std::istream;
using std::getline;
using std::endl;
#ifndef CXX_GLOBAL_CSTD
using std::strlen;
#endif
namespace {
bool getTokenValue(string const & str, char const * token, string & ret)
{
size_t token_length = strlen(token);
string::size_type pos = str.find(token);
if (pos == string::npos || pos + token_length + 1 >= str.length()
|| str[pos + token_length] != '=')
return false;
ret.erase();
pos += token_length + 1;
char ch = str[pos];
if ((ch != '"') && (ch != '\'')) { // only read till next space
ret += ch;
ch = ' ';
}
while ((pos < str.length() - 1) && (str[++pos] != ch))
ret += str[pos];
return true;
}
bool getTokenValue(string const & str, char const * token, int & num)
{
string::size_type pos = str.find(token);
char ch = str[pos + strlen(token)];
if ((pos == string::npos) || (ch != '='))
return false;
string ret;
pos += strlen(token) + 1;
ch = str[pos];
if ((ch != '"') && (ch != '\'')) { // only read till next space
if (!IsDigit(ch))
return false;
ret += ch;
}
++pos;
while ((pos < str.length() - 1) && IsDigit(str[pos]))
ret += str[pos++];
num = strToInt(ret);
return true;
}
bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
{
int tmp;
bool const ret = getTokenValue(str, token, tmp);
num = static_cast<LyXAlignment>(tmp);
return ret;
}
bool getTokenValue(string const & str, char const * token,
LyXTabular::VAlignment & num)
{
int tmp;
bool const ret = getTokenValue(str, token, tmp);
num = static_cast<LyXTabular::VAlignment>(tmp);
return ret;
}
bool getTokenValue(string const & str, char const * token,
LyXTabular::BoxType & num)
{
int tmp;
bool ret = getTokenValue(str, token, tmp);
num = static_cast<LyXTabular::BoxType>(tmp);
return ret;
}
bool getTokenValue(string const & str, char const * token, bool & flag)
{
string::size_type pos = str.find(token);
char ch = str[pos + strlen(token)];
if ((pos == string::npos) || (ch != '='))
return false;
string ret;
pos += strlen(token) + 1;
ch = str[pos];
if ((ch != '"') && (ch != '\'')) { // only read till next space
if (!IsDigit(ch))
return false;
ret += ch;
}
++pos;
while ((pos < str.length() - 1) && IsDigit(str[pos]))
ret += str[pos++];
flag = strToInt(ret);
return true;
}
bool getTokenValue(string const & str, const char * token, LyXLength & len)
{
string tmp;
if (!getTokenValue(str, token, tmp))
return false;
return isValidLength(tmp, &len);
}
inline
void l_getline(istream & is, string & str)
{
#ifdef WITH_WARNINGS
//#warning old l_getline
#endif
getline(is, str);
while (str.empty())
getline(is, str);
}
} // namespace anon
void LyXTabular::ReadOld(Buffer const * buf, istream & is,
LyXLex & lex, string const & l)
{
string line(l);
int rows_arg;
int columns_arg;
if (!getTokenValue(line, "rows", rows_arg))
return;
if (!getTokenValue(line, "columns", columns_arg))
return;
Init(buf->params, rows_arg, columns_arg);
l_getline(is, line);
if (!prefixIs(line, "<Features ")) {
lyxerr << "Wrong tabular format (expected <Feture ...> got"
<< line << ')' << endl;
return;
}
getTokenValue(line, "islongtable", is_long_tabular);
int hrow;
int fhrow;
int frow;
int lfrow;
getTokenValue(line, "endhead", hrow);
getTokenValue(line, "endfirsthead", fhrow);
getTokenValue(line, "endfoot", frow);
getTokenValue(line, "endlastfoot", lfrow);
setHeaderFooterRows(abs(hrow), abs(fhrow), abs(frow), abs(lfrow));
for (int i = 0; i < rows_; ++i) {
l_getline(is, line);
if (!prefixIs(line, "<Row ")) {
lyxerr << "Wrong tabular format (expected <Row ...> got"
<< line << ')' << endl;
return;
}
getTokenValue(line, "topline", row_info[i].top_line);
getTokenValue(line, "bottomline", row_info[i].bottom_line);
getTokenValue(line, "newpage", row_info[i].newpage);
for (int j = 0; j < columns_; ++j) {
l_getline(is,line);
if (!prefixIs(line,"<Column")) {
lyxerr << "Wrong tabular format (expected <Column ...> got"
<< line << ')' << endl;
return;
}
if (!i) {
getTokenValue(line, "alignment", column_info[j].alignment);
getTokenValue(line, "valignment", column_info[j].valignment);
getTokenValue(line, "leftline", column_info[j].left_line);
getTokenValue(line, "rightline", column_info[j].right_line);
getTokenValue(line, "width", column_info[j].p_width);
getTokenValue(line, "special", column_info[j].align_special);
}
l_getline(is, line);
if (!prefixIs(line, "<Cell")) {
lyxerr << "Wrong tabular format (expected <Cell ...> got"
<< line << ')' << endl;
return;
}
getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
getTokenValue(line, "alignment", cell_info[i][j].alignment);
getTokenValue(line, "valignment", cell_info[i][j].valignment);
getTokenValue(line, "topline", cell_info[i][j].top_line);
getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
getTokenValue(line, "leftline", cell_info[i][j].left_line);
getTokenValue(line, "rightline", cell_info[i][j].right_line);
getTokenValue(line, "rotate", cell_info[i][j].rotate);
getTokenValue(line, "usebox", cell_info[i][j].usebox);
getTokenValue(line, "width", cell_info[i][j].p_width);
getTokenValue(line, "special", cell_info[i][j].align_special);
l_getline(is, line);
if (prefixIs(line, "\\begin_inset")) {
cell_info[i][j].inset.read(buf, lex);
l_getline(is, line);
}
if (line != "</Cell>") {
lyxerr << "Wrong tabular format (expected </Cell> got"
<< line << ')' << endl;
return;
}
l_getline(is, line);
if (line != "</Column>") {
lyxerr << "Wrong tabular format (expected </Column> got"
<< line << ')' << endl;
return;
}
}
l_getline(is, line);
if (line != "</Row>") {
lyxerr << "Wrong tabular format (expected </Row> got"
<< line << ')' << endl;
return;
}
}
while (line != "</LyXTabular>") {
l_getline(is, line);
}
set_row_column_number_info();
}

View File

@ -1102,17 +1102,15 @@ void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
l_getline(is, line);
if (!prefixIs(line, "<lyxtabular ")
&& !prefixIs(line, "<LyXTabular ")) {
OldFormatRead(buf->params, lex, line);
lyx::Assert(false);
return;
}
int version;
if (!getTokenValue(line, "version", version))
return;
if (version == 1)
ReadOld(buf, is, lex, line);
else if (version >= 2)
ReadNew(buf, is, lex, line, version);
lyx::Assert(version >= 2);
read(buf, is, lex, line, version);
}
void LyXTabular::setHeaderFooterRows(int hr, int fhr, int fr, int lfr)
@ -1192,8 +1190,8 @@ void LyXTabular::setHeaderFooterRows(int hr, int fhr, int fr, int lfr)
}
}
void LyXTabular::ReadNew(Buffer const * buf, istream & is,
LyXLex & lex, string const & l, int const version)
void LyXTabular::read(Buffer const * buf, istream & is,
LyXLex & lex, string const & l, int const version)
{
string line(l);
int rows_arg;
@ -1314,209 +1312,6 @@ void LyXTabular::ReadNew(Buffer const * buf, istream & is,
}
void LyXTabular::OldFormatRead(BufferParams const & bp,
LyXLex & lex, string const & fl)
{
int version;
int i;
int j;
int rows_arg = 0;
int columns_arg = 0;
int is_long_tabular_arg = false;
int rotate_arg = false;
int a = -1;
int b = -1;
int c = -1;
int d = -1;
int e = 0;
int f = 0;
int g = 0;
istream & is = lex.getStream();
string s(fl);
if (s.length() > 8)
version = lyx::atoi(s.substr(8, string::npos));
else
version = 1;
vector<int> cont_row_info;
if (version < 5) {
lyxerr << "Tabular format < 5 is not supported anymore\n"
"Get an older version of LyX (< 1.1.x) for conversion!"
<< endl;
Alert::alert(_("Warning:"),
_("Tabular format < 5 is not supported anymore\n"),
_("Get an older version of LyX (< 1.1.x) for conversion!"));
if (version > 2) {
is >> rows_arg >> columns_arg >> is_long_tabular_arg
>> rotate_arg >> a >> b >> c >> d;
} else
is >> rows_arg >> columns_arg;
Init(bp, rows_arg, columns_arg);
cont_row_info = vector<int>(rows_arg);
SetLongTabular(is_long_tabular_arg);
SetRotateTabular(rotate_arg);
string tmp;
for (i = 0; i < rows_; ++i) {
getline(is, tmp);
cont_row_info[i] = false;
}
for (i = 0; i < columns_; ++i) {
getline(is, tmp);
}
for (i = 0; i < rows_; ++i) {
for (j = 0; j < columns_; ++j) {
getline(is, tmp);
}
}
} else {
is >> rows_arg >> columns_arg >> is_long_tabular_arg
>> rotate_arg >> a >> b >> c >> d;
Init(bp, rows_arg, columns_arg);
cont_row_info = vector<int>(rows_arg);
SetLongTabular(is_long_tabular_arg);
SetRotateTabular(rotate_arg);
setHeaderFooterRows(a+1, b+1 , c+1, d+1);
for (i = 0; i < rows_; ++i) {
a = b = c = d = e = f = g = 0;
is >> a >> b >> c >> d;
row_info[i].top_line = a;
row_info[i].bottom_line = b;
cont_row_info[i] = c;
row_info[i].newpage = d;
}
for (i = 0; i < columns_; ++i) {
string s1;
string s2;
is >> a >> b >> c;
#if 1
char ch; // skip '"'
is >> ch;
#else
// ignore is buggy but we will use it later (Lgb)
is.ignore(); // skip '"'
#endif
getline(is, s1, '"');
#if 1
is >> ch; // skip '"'
#else
// ignore is buggy but we will use it later (Lgb)
is.ignore(); // skip '"'
#endif
getline(is, s2, '"');
column_info[i].alignment = static_cast<LyXAlignment>(a);
column_info[i].left_line = b;
column_info[i].right_line = c;
column_info[i].p_width = LyXLength(s1);
column_info[i].align_special = s2;
}
for (i = 0; i < rows_; ++i) {
for (j = 0; j < columns_; ++j) {
string s1;
string s2;
is >> a >> b >> c >> d >> e >> f >> g;
#if 1
char ch;
is >> ch; // skip '"'
#else
// ignore is buggy but we will use it later (Lgb)
is.ignore(); // skip '"'
#endif
getline(is, s1, '"');
#if 1
is >> ch; // skip '"'
#else
// ignore is buggy but we will use it later (Lgb)
is.ignore(); // skip '"'
#endif
getline(is, s2, '"');
cell_info[i][j].multicolumn = static_cast<char>(a);
cell_info[i][j].alignment = static_cast<LyXAlignment>(b);
cell_info[i][j].top_line = static_cast<char>(c);
cell_info[i][j].bottom_line = static_cast<char>(d);
cell_info[i][j].left_line = column_info[j].left_line;
cell_info[i][j].right_line = column_info[j].right_line;
cell_info[i][j].rotate = static_cast<bool>(f);
cell_info[i][j].usebox = static_cast<BoxType>(g);
cell_info[i][j].align_special = s1;
cell_info[i][j].p_width = LyXLength(s2);
}
}
}
set_row_column_number_info(true);
string tmptok;
Paragraph::depth_type depth = 0;
ParagraphList parlist;
ParagraphList::iterator pit = parlist.begin();
while (lex.isOK()) {
lex.nextToken();
string const token = lex.getString();
if (token.empty())
continue;
if (token == "\\layout"
|| token == "\\end_float" // this should not exist anymore
|| token == "\\end_inset" // as it is substituted by this
|| token == "\\end_deeper")
{
lex.pushToken(token);
break;
}
if (token == "\\the_end") {
lex.pushToken(token);
break;
}
owner_->bufferOwner()->readParagraph(lex, token, parlist, pit, depth);
}
Paragraph * par = &(*parlist.begin());
// now we have the par we should fill the insets with this!
int cell = 0;
InsetText * inset = GetCellInset(cell);
int row;
for (int i = 0; i < par->size(); ++i) {
if (par->isNewline(i)) {
++cell;
if (cell > numberofcells) {
lyxerr << "Some error in reading old table format occured!" <<
endl << "Terminating when reading cell[" << cell << "]!" <<
endl;
delete par;
return;
}
row = row_of_cell(cell);
if (cont_row_info[row]) {
DeleteRow(row);
cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
while (!IsFirstCellInRow(--cell));
} else {
inset = GetCellInset(cell);
continue;
}
inset = GetCellInset(cell);
row = row_of_cell(cell);
if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
{
// insert a space instead
par->erase(i);
par->insertChar(i, ' ');
}
}
par->copyIntoMinibuffer(*owner_->bufferOwner(), i);
inset->paragraph()->insertFromMinibuffer(inset->paragraph()->size());
}
delete par;
Reinit();
}
bool LyXTabular::IsMultiColumn(int cell, bool real) const
{
return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&

View File

@ -290,8 +290,6 @@ public:
///
void Read(Buffer const *, LyXLex &);
///
void OldFormatRead(BufferParams const &, LyXLex &, string const &);
///
int latex(Buffer const *, std::ostream &, bool, bool) const;
///
int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
@ -483,11 +481,9 @@ private:
typedef std::vector<columnstruct> column_vector;
///
void ReadNew(Buffer const * buf, std::istream & is,
LyXLex & lex, string const & l, int const version);
void read(Buffer const * buf, std::istream & is,
LyXLex & lex, string const & l, int const version);
///
void ReadOld(Buffer const * buf, std::istream & is,
LyXLex & lex, string const & l);
///
int rows_;
///