more fixes and updates

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@292 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 1999-11-05 06:02:34 +00:00
parent dfe1bc44b4
commit 65e9b99a59
17 changed files with 489 additions and 191 deletions

View File

@ -1,3 +1,27 @@
1999-11-05 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/bufferlist.C: use a vector to store the buffers in. This is
an internal change and should not affect any other thing.
* src/BufferView.C (waitForX): use XSync instead of the lengthy
stuff in waitForX.
* src/text.C (Fill): fix potential bug, one off bug.
1999-11-04 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/Makefile.am (lyx_main.o): add more files it depends on.
* src/lyx_cb.C (addNewlineAndDepth): parameters in wrong order.
* src/support/lyxstring.C: use size_t for the reference count,
size, reserved memory and xtra.
(internal_compare): new private member function. Now the compare
functions should work for std::strings that have embedded '\0'
characters.
(compare): all compare functions rewritten to use
internal_compare.
1999-11-03 Lars Gullik Bjønnes <larsbj@lyx.org> 1999-11-03 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/support/lyxstring.C (compare): pass c_str() * src/support/lyxstring.C (compare): pass c_str()

View File

@ -9,26 +9,17 @@
# #
# This is all the files that contains internationalization strings. # This is all the files that contains internationalization strings.
src/BufferView.C
src/Chktex.C
src/FontLoader.C
src/LaTeX.C
src/LaTeXLog.C
src/Literate.C
src/LyXAction.C
src/LyXSendto.C
src/LyXView.C
src/PaperLayout.C
src/ParagraphExtra.C
src/TableLayout.C
src/buffer.C src/buffer.C
src/bufferlist.C src/bufferlist.C
src/BufferView.C
src/bullet_forms.C src/bullet_forms.C
src/bullet_forms_cb.C src/bullet_forms_cb.C
src/Chktex.C
src/combox.C src/combox.C
src/credits.C src/credits.C
src/credits_form.C src/credits_form.C
src/filedlg.C src/filedlg.C
src/FontLoader.C
src/form1.C src/form1.C
src/gettext.h src/gettext.h
src/insets/figinset.C src/insets/figinset.C
@ -49,21 +40,27 @@ src/insets/inseturl.C
src/insets/lyxinset.h src/insets/lyxinset.h
src/intl.C src/intl.C
src/kbmap.C src/kbmap.C
src/LaTeX.C
src/LaTeXLog.C
src/latexoptions.C src/latexoptions.C
src/layout.C src/layout.C
src/layout_forms.C src/layout_forms.C
src/Literate.C
src/LyXAction.C
src/lyx.C src/lyx.C
src/lyx_cb.C src/lyx_cb.C
src/lyxfont.C
src/lyxfr0.C
src/lyxfr1.C
src/lyxfunc.C
src/lyx_gui.C src/lyx_gui.C
src/lyx_gui_misc.C src/lyx_gui_misc.C
src/lyx_main.C src/lyx_main.C
src/lyx_sendfax.C src/lyx_sendfax.C
src/lyx_sendfax_main.C src/lyx_sendfax_main.C
src/lyxfont.C src/LyXSendto.C
src/lyxfr0.C
src/lyxfr1.C
src/lyxfunc.C
src/lyxvc.C src/lyxvc.C
src/LyXView.C
src/mathed/formula.C src/mathed/formula.C
src/mathed/formula.h src/mathed/formula.h
src/mathed/formulamacro.C src/mathed/formulamacro.C
@ -72,12 +69,15 @@ src/mathed/math_panel.C
src/menus.C src/menus.C
src/minibuffer.C src/minibuffer.C
src/minibuffer.h src/minibuffer.h
src/PaperLayout.C
src/paragraph.C src/paragraph.C
src/ParagraphExtra.C
src/print_form.C src/print_form.C
src/sp_form.C
src/spellchecker.C src/spellchecker.C
src/sp_form.C
src/support/filetools.C src/support/filetools.C
src/support/lyxlib.h src/support/lyxlib.h
src/support/path.h src/support/path.h
src/text.C src/TableLayout.C
src/text2.C src/text2.C
src/text.C

View File

@ -520,6 +520,7 @@ void BufferView::UpCB(FL_OBJECT * ob, long)
static static
void waitForX() void waitForX()
{ {
#if 0
static Window w = 0; static Window w = 0;
static Atom a = 0; static Atom a = 0;
if (!a) if (!a)
@ -539,6 +540,8 @@ void waitForX()
XChangeProperty(fl_display, w, a, a, 8, XChangeProperty(fl_display, w, a, a, 8,
PropModeAppend, reinterpret_cast<unsigned char*>(""), 0); PropModeAppend, reinterpret_cast<unsigned char*>(""), 0);
XWindowEvent(fl_display, w, PropertyChangeMask, &ev); XWindowEvent(fl_display, w, PropertyChangeMask, &ev);
#endif
XSync(fl_get_display(), 0);
} }

View File

@ -173,7 +173,10 @@ lyx_SOURCES = \
vspace.C \ vspace.C \
vspace.h vspace.h
lyx_main.o: lyx_main.C lyx_main.h config.h version.h debug.h gettext.h lyx_main.o: lyx_main.C lyx_main.h config.h version.h debug.h gettext.h \
lyx_gui.h lyx_gui_misc.h lyxrc.h support/path.h support/filetools.h \
bufferlist.h debug.h support/FileInfo.h lastfiles.h intl.h \
lyxserver.h layout.h gettext.h
$(CXXCOMPILE) -DLYX_DIR=\"$(LYX_DIR)\" -DTOP_SRCDIR=\"$(top_srcdir)\" \ $(CXXCOMPILE) -DLYX_DIR=\"$(LYX_DIR)\" -DTOP_SRCDIR=\"$(top_srcdir)\" \
-DLYX_NAME=\"$(PACKAGE)\" -c $(top_srcdir)/src/lyx_main.C -DLYX_NAME=\"$(PACKAGE)\" -c $(top_srcdir)/src/lyx_main.C

View File

@ -159,7 +159,7 @@ bool Buffer::saveParamsAsDefaults()
// Use the current buffer's parameters as default // Use the current buffer's parameters as default
defaults.params.Copy(params); defaults.params.Copy(params);
// add an empty paragraph. Is this enough? // add an empty paragraph. Is this enough?
defaults.paragraph = new LyXParagraph(); defaults.paragraph = new LyXParagraph;
return defaults.writeFile(defaults.filename,false); return defaults.writeFile(defaults.filename,false);
} }
@ -258,7 +258,7 @@ bool Buffer::insertLyXFile(string const & filen)
// if par = 0 normal behavior // if par = 0 normal behavior
// else insert behavior // else insert behavior
// Returns false if "\the_end" is not read for formats >= 2.13. (Asger) // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par) bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph * par)
{ {
string tmptok; string tmptok;
Inset * inset = 0; Inset * inset = 0;
@ -277,7 +277,10 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
string pretoken; string pretoken;
if(!par) { if(!par) {
par = new LyXParagraph(); par = new LyXParagraph;
#ifdef NEW_TEXT
par->text.reserve(500);
#endif
} else { } else {
text->BreakParagraph(); text->BreakParagraph();
return_par = text->FirstParagraph(); return_par = text->FirstParagraph();
@ -326,8 +329,15 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
} else if (token == "\\layout") { } else if (token == "\\layout") {
if (!return_par) if (!return_par)
return_par = par; return_par = par;
else else {
#ifdef NEW_TEXT
par->text.resize(par->text.size());
#endif
par = new LyXParagraph(par); par = new LyXParagraph(par);
#ifdef NEW_TEXT
par->text.reserve(500);
#endif
}
pos = 0; pos = 0;
lex.EatLine(); lex.EatLine();
string layoutname = lex.GetString(); string layoutname = lex.GetString();
@ -354,8 +364,15 @@ bool Buffer::readLyXformat2(LyXLex &lex, LyXParagraph *par)
} else if (token == "\\end_float") { } else if (token == "\\end_float") {
if (!return_par) if (!return_par)
return_par = par; return_par = par;
else else {
#ifdef NEW_TEXT
par->text.resize(par->text.size());
#endif
par = new LyXParagraph(par); par = new LyXParagraph(par);
#ifdef NEW_TEXT
par->text.reserve(500);
#endif
}
footnotekind = LyXParagraph::FOOTNOTE; footnotekind = LyXParagraph::FOOTNOTE;
footnoteflag = LyXParagraph::NO_FOOTNOTE; footnoteflag = LyXParagraph::NO_FOOTNOTE;
pos = 0; pos = 0;

View File

@ -33,8 +33,8 @@
#include "lyx_cb.h" #include "lyx_cb.h"
#include "gettext.h" #include "gettext.h"
extern BufferView *current_view; extern BufferView * current_view;
extern MiniBuffer *minibuffer; extern MiniBuffer * minibuffer;
extern void SmallUpdate(signed char); extern void SmallUpdate(signed char);
extern void BeforeChange(); extern void BeforeChange();
extern int RunLinuxDoc(int, string const &); extern int RunLinuxDoc(int, string const &);
@ -43,15 +43,17 @@ extern int RunLinuxDoc(int, string const &);
// Class BufferStorage // Class BufferStorage
// //
#ifndef NEW_STORE
BufferStorage::BufferStorage() BufferStorage::BufferStorage()
{ {
// Initialize the buffer array // Initialize the buffer array
for (int i=NUMBER_OF_BUFFERS-1; i >=0; i--) { for (int i=NUMBER_OF_BUFFERS-1; i >=0; i--) {
buffer[i] = 0; buffer[i] = 0;
} }
} }
#endif
#ifndef NEW_STORE
bool BufferStorage::isEmpty() bool BufferStorage::isEmpty()
{ {
for (int i=NUMBER_OF_BUFFERS-1; i >=0; i--) { for (int i=NUMBER_OF_BUFFERS-1; i >=0; i--) {
@ -59,23 +61,43 @@ bool BufferStorage::isEmpty()
} }
return true; return true;
} }
#endif
void BufferStorage::release(Buffer * buf)
void BufferStorage::release(Buffer* buf)
{ {
int i=0; #ifdef NEW_STORE
for (i=0; i<NUMBER_OF_BUFFERS; i++) for(Container::iterator it = container.begin();
it != container.end(); ++it) {
if ((*it) == buf) {
Buffer * tmpbuf = (*it);
container.erase(it);
delete tmpbuf;
break;
}
}
#else
int i = 0;
for (i = 0; i < NUMBER_OF_BUFFERS; i++)
if (buffer[i] == buf) break; if (buffer[i] == buf) break;
Buffer *tmpbuf = buffer[i]; Buffer * tmpbuf = buffer[i];
buffer[i] = 0; buffer[i] = 0;
delete tmpbuf; delete tmpbuf;
#endif
} }
Buffer* BufferStorage::newBuffer(string const &s, Buffer * BufferStorage::newBuffer(string const & s,
LyXRC *lyxrc, LyXRC * lyxrc,
bool ronly) bool ronly)
{ {
#ifdef NEW_STORE
Buffer * tmpbuf = new Buffer(s, lyxrc, ronly);
tmpbuf->params.useClassDefaults();
lyxerr.debug() << "Assigning to buffer "
<< container.size() + 1 << endl;
container.push_back(tmpbuf);
return tmpbuf;
#else
int i=0; int i=0;
while (i < NUMBER_OF_BUFFERS - 1 while (i < NUMBER_OF_BUFFERS - 1
&& buffer[i]) i++; && buffer[i]) i++;
@ -83,19 +105,21 @@ Buffer* BufferStorage::newBuffer(string const &s,
buffer[i]->params.useClassDefaults(); buffer[i]->params.useClassDefaults();
lyxerr.debug() << "Assigning to buffer " << i << endl; lyxerr.debug() << "Assigning to buffer " << i << endl;
return buffer[i]; return buffer[i];
#endif
} }
#ifndef NEW_STORE
// //
// Class BufferStrorage_Iter // Class BufferStrorage_Iter
// //
Buffer* BufferStorage_Iter::operator() () Buffer * BufferStorage_Iter::operator() ()
{ {
int i=0; int i = 0;
for (i=index; i < BufferStorage::NUMBER_OF_BUFFERS; i++) { for (i = index; i < BufferStorage::NUMBER_OF_BUFFERS; i++) {
if (cs->buffer[i]) { if (cs->buffer[i]) {
index = i+1; index = i + 1;
return cs->buffer[i]; return cs->buffer[i];
} }
} }
@ -103,19 +127,20 @@ Buffer* BufferStorage_Iter::operator() ()
} }
Buffer* BufferStorage_Iter::operator[] (int a) Buffer * BufferStorage_Iter::operator[] (int a)
{ {
// a is >=1 // a is >=1
if (a<=0) return 0; if (a <= 0) return 0;
int i=0; int i = 0;
while (a--) { while (a--) {
while(!cs->buffer[i++]); while(!cs->buffer[i++]);
} }
if (i-1 < BufferStorage::NUMBER_OF_BUFFERS) if (i - 1 < BufferStorage::NUMBER_OF_BUFFERS)
return cs->buffer[i-1]; return cs->buffer[i - 1];
return 0; return 0;
} }
#endif
// //
@ -127,26 +152,43 @@ BufferList::BufferList()
} }
BufferList::~BufferList() bool BufferList::empty()
{ {
// I am sure something should be done here too. return bstore.empty();
} }
bool BufferList::isEmpty() extern void MenuWrite(Buffer *);
{
return bstore.isEmpty();
}
extern void MenuWrite(Buffer*);
bool BufferList::QwriteAll() bool BufferList::QwriteAll()
{ {
bool askMoreConfirmation = false; bool askMoreConfirmation = false;
string unsaved; string unsaved;
#ifdef NEW_STORE
for(BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
if (!(*it)->isLyxClean()) {
switch(AskConfirmation(_("Changes in document:"),
MakeDisplayPath((*it)->filename,
50),
_("Save document?"))) {
case 1: // Yes
MenuWrite((*it));
break;
case 2: // No
askMoreConfirmation = true;
unsaved += MakeDisplayPath((*it)->filename,50);
unsaved += "\n";
break;
case 3: // Cancel
return false;
}
}
}
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer * b = 0;
while ((b=biter())) { while ((b = biter())) {
if (!b->isLyxClean()) { if (!b->isLyxClean()) {
switch(AskConfirmation(_("Changes in document:"), switch(AskConfirmation(_("Changes in document:"),
MakeDisplayPath(b->filename,50), MakeDisplayPath(b->filename,50),
@ -164,6 +206,7 @@ bool BufferList::QwriteAll()
} }
} }
} }
#endif
if (askMoreConfirmation && if (askMoreConfirmation &&
lyxrc->exit_confirmation && lyxrc->exit_confirmation &&
!AskQuestion(_("Some documents were not saved:"), !AskQuestion(_("Some documents were not saved:"),
@ -176,7 +219,7 @@ bool BufferList::QwriteAll()
// Should probably be moved to somewhere else: BufferView? LyXView? // Should probably be moved to somewhere else: BufferView? LyXView?
bool BufferList::write(Buffer *buf, bool makeBackup) bool BufferList::write(Buffer * buf, bool makeBackup)
{ {
minibuffer->Set(_("Saving document"), minibuffer->Set(_("Saving document"),
MakeDisplayPath(buf->filename),"..."); MakeDisplayPath(buf->filename),"...");
@ -283,27 +326,39 @@ bool BufferList::write(Buffer *buf, bool makeBackup)
void BufferList::closeAll() void BufferList::closeAll()
{ {
_state = BufferList::CLOSING; _state = BufferList::CLOSING;
#ifdef NEW_STORE
while (!bstore.empty()) {
close(bstore.front());
}
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer * b = 0;
while ((b=biter())) { while ((b = biter())) {
close(b); close(b);
} }
#endif
_state = BufferList::OK; _state = BufferList::OK;
} }
void BufferList::resize() void BufferList::resize()
{ {
#ifdef NEW_STORE
for(BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
(*it)->resize();
}
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer * b = 0;
while ((b=biter())) { while ((b = biter())) {
b->resize(); b->resize();
} }
#endif
} }
bool BufferList::close(Buffer *buf) bool BufferList::close(Buffer * buf)
{ {
buf->InsetUnlock(); buf->InsetUnlock();
@ -337,38 +392,67 @@ void BufferList::makePup(int pup)
in the same way as for lastfiles.[hC] in the same way as for lastfiles.[hC]
*/ */
{ {
int ant=0; int ant = 0;
BufferStorage_Iter biter(bstore); #ifdef NEW_STORE
Buffer *b=0; for(BufferStorage::iterator it = bstore.begin();
while ((b=biter())) { it != bstore.end(); ++it) {
string relbuf = MakeDisplayPath(b->filename,30); string relbuf = MakeDisplayPath((*it)->filename, 30);
fl_addtopup(pup, relbuf.c_str()); fl_addtopup(pup, relbuf.c_str());
ant++; ++ant;
} }
#else
BufferStorage_Iter biter(bstore);
Buffer * b = 0;
while ((b = biter())) {
string relbuf = MakeDisplayPath(b->filename, 30);
fl_addtopup(pup, relbuf.c_str());
++ant;
}
#endif
if (ant == 0) fl_addtopup(pup,_("No Documents Open!%t")); if (ant == 0) fl_addtopup(pup,_("No Documents Open!%t"));
} }
Buffer* BufferList::first() Buffer * BufferList::first()
{ {
#ifdef NEW_STORE
if (bstore.empty()) return 0;
return bstore.front();
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
return biter(); return biter();
#endif
} }
Buffer* BufferList::getBuffer(int choice) Buffer * BufferList::getBuffer(int choice)
{ {
#ifdef NEW_STORE
if (choice >= bstore.size()) return 0;
return bstore[choice];
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer * b = 0;
b = biter[choice]; b = biter[choice];
// Be careful, this could be 0. // Be careful, this could be 0.
return b; return b;
#endif
} }
void BufferList::updateInset(Inset *inset, bool mark_dirty) void BufferList::updateInset(Inset * inset, bool mark_dirty)
{ {
#ifdef NEW_STORE
for (BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
if ((*it)->text && (*it)->text->UpdateInset(inset)) {
if (mark_dirty)
(*it)->markDirty();
break;
}
}
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer *b=0;
while ((b=biter())) { while ((b=biter())) {
@ -378,11 +462,23 @@ void BufferList::updateInset(Inset *inset, bool mark_dirty)
break; break;
} }
} }
#endif
} }
int BufferList::unlockInset(UpdatableInset *inset) int BufferList::unlockInset(UpdatableInset * inset)
{ {
#ifdef NEW_STORE
if (!inset) return 1;
for(BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
if ((*it)->the_locking_inset == inset) {
(*it)->InsetUnlock();
return 0;
}
}
return 1;
#else
if (!inset) return 1; if (!inset) return 1;
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
@ -394,11 +490,27 @@ int BufferList::unlockInset(UpdatableInset *inset)
} }
} }
return 1; return 1;
#endif
} }
void BufferList::updateIncludedTeXfiles(string const & mastertmpdir) void BufferList::updateIncludedTeXfiles(string const & mastertmpdir)
{ {
#ifdef NEW_STORE
for(BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
if (!(*it)->isDepClean(mastertmpdir)) {
string writefile = mastertmpdir;
writefile += '/';
writefile += ChangeExtension((*it)->getFileName(),
".tex", true);
(*it)->makeLaTeXFile(writefile, mastertmpdir,
false, true);
(*it)->markDepClean(mastertmpdir);
}
}
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer *b=0;
while ((b=biter())) { while ((b=biter())) {
@ -410,17 +522,64 @@ void BufferList::updateIncludedTeXfiles(string const & mastertmpdir)
b->markDepClean(mastertmpdir); b->markDepClean(mastertmpdir);
} }
} }
#endif
} }
void BufferList::emergencyWriteAll() void BufferList::emergencyWriteAll()
{ {
BufferStorage_Iter biter(bstore); #ifdef NEW_STORE
Buffer *b=0; for (BufferStorage::iterator it = bstore.begin();
while ((b=biter())) { it != bstore.end(); ++it) {
if (!b->isLyxClean()) { if (!(*it)->isLyxClean()) {
bool madeit=false; bool madeit=false;
lyxerr <<_("lyx: Attempting to save"
" document ")
<< (*it)->filename
<< _(" as...") << endl;
for (int i = 0; i < 3 && !madeit; ++i) {
string s;
// We try to save three places:
// 1) Same place as document.
// 2) In HOME directory.
// 3) In "/tmp" directory.
if (i == 0) {
s = (*it)->filename;
} else if (i == 1) {
s = AddName(GetEnvPath("HOME"),
(*it)->filename);
} else { // MakeAbsPath to prepend the current drive letter on OS/2
s = AddName(MakeAbsPath("/tmp/"),
(*it)->filename);
}
s += ".emergency";
lyxerr << " " << i + 1 << ") " << s << endl;
if ((*it)->writeFile(s,true)) {
(*it)->markLyxClean();
lyxerr << _(" Save seems successful. "
"Phew.") << endl;
madeit = true;
} else if (i != 2) {
lyxerr << _(" Save failed! Trying...")
<< endl;
} else {
lyxerr << _(" Save failed! Bummer. Document is lost.") << endl;
}
}
}
}
#else
BufferStorage_Iter biter(bstore);
Buffer * b = 0;
while ((b = biter())) {
if (!b->isLyxClean()) {
bool madeit = false;
lyxerr <<_("lyx: Attempting to save" lyxerr <<_("lyx: Attempting to save"
" document ") " document ")
<< b->filename << b->filename
@ -433,9 +592,9 @@ void BufferList::emergencyWriteAll()
// 1) Same place as document. // 1) Same place as document.
// 2) In HOME directory. // 2) In HOME directory.
// 3) In "/tmp" directory. // 3) In "/tmp" directory.
if (i==0) { if (i == 0) {
s = b->filename; s = b->filename;
} else if (i==1) { } else if (i == 1) {
s = AddName(GetEnvPath("HOME"), s = AddName(GetEnvPath("HOME"),
b->filename); b->filename);
} else { // MakeAbsPath to prepend the current drive letter on OS/2 } else { // MakeAbsPath to prepend the current drive letter on OS/2
@ -444,7 +603,7 @@ void BufferList::emergencyWriteAll()
} }
s += ".emergency"; s += ".emergency";
lyxerr << " " << i+1 << ") " << s << endl; lyxerr << " " << i + 1 << ") " << s << endl;
if (b->writeFile(s,true)) { if (b->writeFile(s,true)) {
b->markLyxClean(); b->markLyxClean();
@ -459,12 +618,13 @@ void BufferList::emergencyWriteAll()
} }
} }
} }
#endif
} }
Buffer* BufferList::readFile(string const & s, bool ronly) Buffer* BufferList::readFile(string const & s, bool ronly)
{ {
Buffer *b = bstore.newBuffer(s, lyxrc, ronly); Buffer * b = bstore.newBuffer(s, lyxrc, ronly);
string ts = s; string ts = s;
string e = OnlyPath(s); string e = OnlyPath(s);
@ -533,32 +693,50 @@ Buffer* BufferList::readFile(string const & s, bool ronly)
bool BufferList::exists(string const & s) bool BufferList::exists(string const & s)
{ {
#ifdef NEW_STORE
for (BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
if ((*it)->filename == s)
return true;
}
return false;
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer * b = 0;
while ((b=biter())) { while ((b = biter())) {
if (b->filename == s) if (b->filename == s)
return true; return true;
} }
return false; return false;
#endif
} }
Buffer* BufferList::getBuffer(string const &s) Buffer * BufferList::getBuffer(string const & s)
{ {
#ifdef NEW_STORE
for(BufferStorage::iterator it = bstore.begin();
it != bstore.end(); ++it) {
if ((*it)->filename == s)
return (*it);
}
return 0;
#else
BufferStorage_Iter biter(bstore); BufferStorage_Iter biter(bstore);
Buffer *b=0; Buffer * b = 0;
while ((b=biter())) { while ((b = biter())) {
if (b->filename ==s) if (b->filename == s)
return b; return b;
} }
return 0; return 0;
#endif
} }
Buffer* BufferList::newFile(string const & name, string tname) Buffer * BufferList::newFile(string const & name, string tname)
{ {
/* get a free buffer */ /* get a free buffer */
Buffer *b = bstore.newBuffer(name, lyxrc); Buffer * b = bstore.newBuffer(name, lyxrc);
// use defaults.lyx as a default template if it exists. // use defaults.lyx as a default template if it exists.
if (tname.empty()) { if (tname.empty()) {
@ -577,11 +755,17 @@ Buffer* BufferList::newFile(string const & name, string tname)
WriteAlert(_("Error!"),_("Unable to open template"), WriteAlert(_("Error!"),_("Unable to open template"),
MakeDisplayPath(tname)); MakeDisplayPath(tname));
// no template, start with empty buffer // no template, start with empty buffer
b->paragraph = new LyXParagraph(); b->paragraph = new LyXParagraph;
#ifdef NEW_TEXT
b->paragraph->text.reserve(500);
#endif
} }
} }
else { // start with empty buffer else { // start with empty buffer
b->paragraph = new LyXParagraph(); b->paragraph = new LyXParagraph;
#ifdef NEW_TEXT
b->paragraph->text.reserve(500);
#endif
} }
b->markDirty(); b->markDirty();
@ -591,7 +775,7 @@ Buffer* BufferList::newFile(string const & name, string tname)
} }
Buffer* BufferList::loadLyXFile(string const & filename, bool tolastfiles) Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles)
{ {
// make sure our path is absolute // make sure our path is absolute
string s = MakeAbsPath(filename); string s = MakeAbsPath(filename);
@ -632,7 +816,7 @@ Buffer* BufferList::loadLyXFile(string const & filename, bool tolastfiles)
return getBuffer(s); return getBuffer(s);
} }
} }
Buffer *b=0; Buffer * b = 0;
bool ro = false; bool ro = false;
switch (IsFileWriteable(s)) { switch (IsFileWriteable(s)) {
case 0: case 0:
@ -641,7 +825,7 @@ Buffer* BufferList::loadLyXFile(string const & filename, bool tolastfiles)
ro = true; ro = true;
// Fall through // Fall through
case 1: case 1:
b=readFile(s, ro); b = readFile(s, ro);
if (b) { if (b) {
b->lyxvc.file_found_hook(s); b->lyxvc.file_found_hook(s);
} }

View File

@ -21,6 +21,8 @@
#include "buffer.h" #include "buffer.h"
#include "debug.h" #include "debug.h"
#define NEW_STORE 1
/** A class to hold all the buffers in a structure /** A class to hold all the buffers in a structure
The point of this class is to hide from bufferlist what kind The point of this class is to hide from bufferlist what kind
of structure the buffers are stored in. Should be no concern for of structure the buffers are stored in. Should be no concern for
@ -30,15 +32,41 @@
gave me an "internal gcc error". gave me an "internal gcc error".
*/ */
class BufferStorage { class BufferStorage {
#ifdef NEW_STORE
public:
///
typedef vector<Buffer *> Container;
///
typedef Container::iterator iterator;
///
bool empty() const { return container.empty(); }
///
void release(Buffer * buf);
///
Buffer * newBuffer(string const & s, LyXRC *, bool = false);
///
Container::iterator begin() { return container.begin(); }
///
Container::iterator end() { return container.end(); }
///
Buffer * front() { return container.front(); }
///
Buffer * operator[](int c) { return container[c]; }
///
int size() const { return container.size(); }
private:
///
Container container;
#else
public: public:
/// ///
BufferStorage(); BufferStorage();
/// ///
bool isEmpty(); bool empty();
/// ///
void release(Buffer* buf); void release(Buffer * buf);
/// ///
Buffer* newBuffer(string const &s, LyXRC *, bool =false); Buffer* newBuffer(string const & s, LyXRC *, bool =false);
private: private:
enum { enum {
/** The max number of buffers there are possible to have /** The max number of buffers there are possible to have
@ -54,8 +82,11 @@ private:
Buffer *buffer[NUMBER_OF_BUFFERS]; Buffer *buffer[NUMBER_OF_BUFFERS];
/// ///
friend class BufferStorage_Iter; friend class BufferStorage_Iter;
#endif
}; };
#ifndef NEW_STORE
/// An Iterator class for BufferStorage /// An Iterator class for BufferStorage
class BufferStorage_Iter { class BufferStorage_Iter {
public: public:
@ -72,7 +103,7 @@ private:
/// ///
unsigned char index; unsigned char index;
}; };
#endif
/** The class governing all the open buffers /** The class governing all the open buffers
@ -85,9 +116,6 @@ public:
/// ///
BufferList(); BufferList();
///
~BufferList();
/// state info /// state info
enum list_state { enum list_state {
/// ///
@ -104,11 +132,11 @@ public:
true), the file name will not be added to the last opened true), the file name will not be added to the last opened
files list files list
*/ */
Buffer* loadLyXFile(string const & filename, Buffer * loadLyXFile(string const & filename,
bool tolastfiles = true); bool tolastfiles = true);
/// ///
bool isEmpty(); bool empty();
/// Saves buffer. Returns false if unsuccesful. /// Saves buffer. Returns false if unsuccesful.
bool write(Buffer *, bool makeBackup = true); bool write(Buffer *, bool makeBackup = true);
@ -123,24 +151,20 @@ public:
void resize(); void resize();
/// Read a file into a buffer readonly or not. /// Read a file into a buffer readonly or not.
Buffer* readFile(string const &, bool ro); Buffer * readFile(string const &, bool ro);
/// Make a new file (buffer) using a template /// Make a new file (buffer) using a template
Buffer* newFile(string const &, string); Buffer * newFile(string const &, string);
/** This one must be moved to some other place. /** This one must be moved to some other place.
*/ */
void makePup(int); void makePup(int);
///** Later with multiple frames this should not be here. ///
// */ void updateInset(Inset *, bool = true);
//Buffer* switchBuffer(Buffer *from, int);
/// ///
void updateInset(Inset*, bool = true); int unlockInset(UpdatableInset *);
///
int unlockInset(UpdatableInset*);
/// ///
void updateIncludedTeXfiles(string const &); void updateIncludedTeXfiles(string const &);
@ -154,15 +178,15 @@ public:
bool close(Buffer *); bool close(Buffer *);
/// ///
Buffer* first(); Buffer * first();
/// returns true if the buffer exists already /// returns true if the buffer exists already
bool exists(string const &); bool exists(string const &);
/// returns a pointer to the buffer with the given name. /// returns a pointer to the buffer with the given name.
Buffer* getBuffer(string const &); Buffer * getBuffer(string const &);
/// returns a pointer to the buffer with the given number. /// returns a pointer to the buffer with the given number.
Buffer* getBuffer(int); Buffer * getBuffer(int);
private: private:
/// ///

View File

@ -1108,7 +1108,10 @@ void InsertAsciiFile(string const & f, bool asParagraph)
return; return;
} }
tmppar = new LyXParagraph(); tmppar = new LyXParagraph;
#ifdef NEW_TEXT
tmppar->text.reserve(500);
#endif
tmppar->readSimpleWholeFile(myfile); tmppar->readSimpleWholeFile(myfile);
// set the end of the string // set the end of the string
@ -4067,10 +4070,10 @@ void UpdateInsetUpdateList()
// way to do this (and the cleanest for now). This function just inserts // way to do this (and the cleanest for now). This function just inserts
// a newline in the string and the inserts 'depth'-spaces so that the // a newline in the string and the inserts 'depth'-spaces so that the
// code is indented in the right way!!! // code is indented in the right way!!!
void addNewlineAndDepth(string &file, int const depth) void addNewlineAndDepth(string & file, int const depth)
{ {
file += '\n'; file += '\n';
file.append(' ', depth); file.append(depth, ' ');
} }

View File

@ -148,7 +148,7 @@ extern "C" int LyX_XErrHandler(Display *display, XErrorEvent *xeev)
{ {
//#warning Please see if you can trigger this! //#warning Please see if you can trigger this!
// emergency save // emergency save
if (!bufferlist.isEmpty()) if (!bufferlist.empty())
bufferlist.emergencyWriteAll(); bufferlist.emergencyWriteAll();
// Get the reason for the crash. // Get the reason for the crash.

View File

@ -2826,7 +2826,7 @@ void LyXFunc::reloadBuffer()
void LyXFunc::CloseBuffer() void LyXFunc::CloseBuffer()
{ {
if (bufferlist.close(owner->currentBuffer()) && !quitting) { if (bufferlist.close(owner->currentBuffer()) && !quitting) {
if (bufferlist.isEmpty()) { if (bufferlist.empty()) {
// need this otherwise SEGV may occur while trying to // need this otherwise SEGV may occur while trying to
// set variables that don't exist // set variables that don't exist
// since there's no current buffer // since there's no current buffer

View File

@ -17,15 +17,17 @@
#endif #endif
#define NEW_TEXT 1 #define NEW_TEXT 1
#define NEW_TABLE 1 //#define NEW_TABLE 1
#ifdef NEW_TABLE #ifdef NEW_TABLE
#include <list> #include <list>
#endif #endif
#ifdef NEW_TEXT #ifdef NEW_TEXT
//#include <vector> #include <vector>
#include <deque> //#include <deque>
//#define __STD_STUFF 1
//#include <rope.h>
#endif #endif
#include "definitions.h" #include "definitions.h"
@ -142,7 +144,11 @@ public:
#ifdef NEW_TEXT #ifdef NEW_TEXT
/// ///
typedef deque<char> TextContainer; typedef char value_type;
///
typedef vector<value_type> TextContainer;
//typedef deque<char> TextContainer;
//typedef rope<char> TextContainer;
typedef int size_type; typedef int size_type;
/// ///
TextContainer text; TextContainer text;

View File

@ -1573,7 +1573,11 @@ void Menus::ShowBufferMenu(FL_OBJECT * ob, long)
// set the pseudo menu-button back // set the pseudo menu-button back
fl_set_object_boxtype(ob, FL_FLAT_BOX); fl_set_object_boxtype(ob, FL_FLAT_BOX);
fl_redraw_object(ob); fl_redraw_object(ob);
#ifdef NEW_STORE
if (choice > 0) men->handleBufferMenu(choice - 1);
#else
if (choice > 0) men->handleBufferMenu(choice); if (choice > 0) men->handleBufferMenu(choice);
#endif
fl_freepup(BufferMenu); fl_freepup(BufferMenu);
} }

View File

@ -697,6 +697,7 @@ void LyXParagraph::Erase(int pos)
#endif #endif
#ifdef NEW_TEXT #ifdef NEW_TEXT
text.erase(text.begin() + pos); text.erase(text.begin() + pos);
//text.erase(pos, 1);
#else #else
// Shift rest of text // Shift rest of text
for (int i = pos; i < last - 1; i++) { for (int i = pos; i < last - 1; i++) {
@ -847,6 +848,7 @@ void LyXParagraph::InsertChar(int pos, char c)
return; return;
} }
text.insert(text.begin() + pos, c); text.insert(text.begin() + pos, c);
//text.insert(pos, c);
#else #else
/* > because last is the next unused position, and you can /* > because last is the next unused position, and you can
* use it if you want */ * use it if you want */
@ -1872,6 +1874,7 @@ void LyXParagraph::BreakParagraph(int pos, int flag)
#ifdef NEW_TEXT #ifdef NEW_TEXT
pos_end = pos_first + par->text.size() - 1; pos_end = pos_first + par->text.size() - 1;
tmp->text.reserve(pos_end - pos);
#else #else
pos_end = pos_first + par->last - 1; pos_end = pos_first + par->last - 1;
/* make sure there is enough memory for the now larger /* make sure there is enough memory for the now larger
@ -1888,7 +1891,9 @@ void LyXParagraph::BreakParagraph(int pos, int flag)
for (i = pos_end; i >= pos; i--) for (i = pos_end; i >= pos; i--)
par->Erase(i - pos_first); par->Erase(i - pos_first);
#ifndef NEW_TEXT #ifdef NEW_TEXT
par->text.resize(par->text.size());
#else
/* free memory of the now shorter paragraph*/ /* free memory of the now shorter paragraph*/
par->FitSize(); par->FitSize();
#endif #endif
@ -1961,7 +1966,7 @@ LyXParagraph * LyXParagraph::FirstSelfrowPar()
LyXParagraph * LyXParagraph::Clone() LyXParagraph * LyXParagraph::Clone()
{ {
/* create a new paragraph */ /* create a new paragraph */
LyXParagraph * result = new LyXParagraph(); LyXParagraph * result = new LyXParagraph;
result->MakeSameLayout(this); result->MakeSameLayout(this);
@ -1983,6 +1988,7 @@ LyXParagraph * LyXParagraph::Clone()
/* copy everything behind the break-position to the new paragraph */ /* copy everything behind the break-position to the new paragraph */
#ifdef NEW_TEXT #ifdef NEW_TEXT
result->text.reserve(size());
for (size_type i = 0; i < size(); i++) { for (size_type i = 0; i < size(); i++) {
CopyIntoMinibuffer(i); CopyIntoMinibuffer(i);
result->InsertFromMinibuffer(i); result->InsertFromMinibuffer(i);
@ -2070,7 +2076,9 @@ void LyXParagraph::BreakParagraphConservative(int pos)
InsertFromMinibuffer will enlarge the memory (it uses InsertFromMinibuffer will enlarge the memory (it uses
InsertChar of course). But doing it by hand InsertChar of course). But doing it by hand
is MUCH faster! (only one time, not thousend times!!) */ is MUCH faster! (only one time, not thousend times!!) */
#ifndef NEW_TEXT #ifdef NEW_TEXT
tmp->text.reserve(pos_end - pos);
#else
tmp->Enlarge(0, pos_end - pos); tmp->Enlarge(0, pos_end - pos);
#endif #endif
for (i = pos; i <= pos_end; i++) { for (i = pos; i <= pos_end; i++) {
@ -2080,7 +2088,9 @@ void LyXParagraph::BreakParagraphConservative(int pos)
} }
for (i = pos_end; i >= pos; i--) for (i = pos_end; i >= pos; i--)
par->Erase(i - pos_first); par->Erase(i - pos_first);
#ifndef NEW_TEXT #ifdef NEW_TEXT
par->text.resize(par->text.size());
#else
/* free memory of the now shorter paragraph*/ /* free memory of the now shorter paragraph*/
par->FitSize(); par->FitSize();
#endif #endif

View File

@ -49,14 +49,13 @@ using std::min;
struct lyxstring::Srep { struct lyxstring::Srep {
/// ///
static lyxstring::size_type const xtra = static size_t const xtra = static_cast<size_t>(8);
static_cast<lyxstring::size_type>(8);
/// size /// size
lyxstring::size_type sz; size_t sz;
/// Reference count /// Reference count
unsigned short ref; size_t ref;
/// The total amount of data reserved for this representaion /// The total amount of data reserved for this representaion
lyxstring::size_type res; size_t res;
/// Data. At least 1 char for trailing null. /// Data. At least 1 char for trailing null.
lyxstring::value_type * s; lyxstring::value_type * s;
@ -344,16 +343,13 @@ void lyxstringInvariant::helper() const
// test every last little thing we *know* should be true. // test every last little thing we *know* should be true.
// I may have missed a test or two, so feel free to fill // I may have missed a test or two, so feel free to fill
// in the gaps. ARRae. // in the gaps. ARRae.
// NOTE: Don't put TestlyxstringInvariant() in any of the
// lyxstring methods used below otherwise you'll get an
// infinite recursion and a crash.
Assert(object); Assert(object);
Assert(object->rep); Assert(object->rep);
Assert(object->rep->s); // s is never 0 Assert(object->rep->s); // s is never 0
Assert(object->rep->res); // always some space allocated Assert(object->rep->res); // always some space allocated
Assert(object->size() <= object->rep->res); Assert(object->rep->sz <= object->rep->res);
Assert(object->rep->ref >= 1); // its in use so it must be referenced Assert(object->rep->ref >= 1); // its in use so it must be referenced
Assert(object->rep->ref < (1 << 8*sizeof(object->rep->ref)) - 1); Assert(object->rep->ref < static_cast<size_t>(1 << (8 * sizeof(object->rep->ref) - 1)));
// if it does ever == then we should be generating a new copy // if it does ever == then we should be generating a new copy
// and starting again. (Is char always 8-bits?) // and starting again. (Is char always 8-bits?)
} }
@ -367,7 +363,8 @@ void lyxstringInvariant::helper() const
// Constructors and Deconstructors. // Constructors and Deconstructors.
/////////////////////////////////////// ///////////////////////////////////////
lyxstring::size_type const lyxstring::npos = static_cast<lyxstring::size_type>(-1); lyxstring::size_type const lyxstring::npos =
static_cast<lyxstring::size_type>(-1);
lyxstring::lyxstring() lyxstring::lyxstring()
{ {
@ -983,7 +980,8 @@ lyxstring::size_type lyxstring::rfind(value_type const * ptr, size_type i,
} }
lyxstring::size_type lyxstring::rfind(value_type const * ptr, size_type i) const lyxstring::size_type lyxstring::rfind(value_type const * ptr,
size_type i) const
{ {
Assert(ptr); Assert(ptr);
TestlyxstringInvariant(this); TestlyxstringInvariant(this);
@ -1123,7 +1121,7 @@ lyxstring::size_type lyxstring::find_last_of(value_type c, size_type i) const
lyxstring::size_type lyxstring::find_first_not_of(lyxstring const & a, lyxstring::size_type lyxstring::find_first_not_of(lyxstring const & a,
size_type i) const size_type i) const
{ {
TestlyxstringInvariant(this); TestlyxstringInvariant(this);
@ -1412,49 +1410,11 @@ lyxstring::size_type lyxstring::copy(value_type * buf, size_type len,
//////////////////// ////////////////////
// Compare funcs should be verified. // Compare funcs should be verified.
// Should we try to make them work with '\0' value_types?
// An STL string can usually contain '\0' value_types.
int lyxstring::compare(lyxstring const & str) const int lyxstring::internal_compare(size_type pos, size_type n,
value_type const * s,
size_type slen, size_type n2) const
{ {
TestlyxstringInvariant(this);
return compare(0, rep->sz, str.c_str(), str.rep->sz);
}
int lyxstring::compare(value_type const * s) const
{
Assert(s);
TestlyxstringInvariant(this);
return compare(0, rep->sz, s, (!s) ? 0 : strlen(s));
}
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str) const
{
TestlyxstringInvariant(this);
return compare(pos, n, str.c_str(), str.rep->sz);
}
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str,
size_type pos2, size_type n2) const
{
TestlyxstringInvariant(this);
return compare(pos, n, str.c_str() + pos2, n2);
}
int lyxstring::compare(size_type pos, size_type n, value_type const * s,
size_type n2) const
{
Assert(s && (pos < rep->sz || pos == 0));
TestlyxstringInvariant(this);
if ((rep->sz == 0 || n == 0) && (!*s || n2 == 0)) return 0; if ((rep->sz == 0 || n == 0) && (!*s || n2 == 0)) return 0;
if (!*s) return 1; if (!*s) return 1;
// since n > n2, min(n,n2) == 0, c == 0 (stops segfault also) // since n > n2, min(n,n2) == 0, c == 0 (stops segfault also)
@ -1462,7 +1422,7 @@ int lyxstring::compare(size_type pos, size_type n, value_type const * s,
// remember that n can very well be a lot larger than rep->sz // remember that n can very well be a lot larger than rep->sz
// so we have to ensure that n is no larger than rep->sz // so we have to ensure that n is no larger than rep->sz
n = min(n, rep->sz); n = min(n, rep->sz);
n2 = min(n2, strlen(s)); n2 = min(n2, slen);
if (n == n2) if (n == n2)
return memcmp(&(rep->s[pos]), s, n); return memcmp(&(rep->s[pos]), s, n);
int c = memcmp(&(rep->s[pos]), s, min(n,n2)); int c = memcmp(&(rep->s[pos]), s, min(n,n2));
@ -1474,6 +1434,52 @@ int lyxstring::compare(size_type pos, size_type n, value_type const * s,
} }
int lyxstring::compare(lyxstring const & str) const
{
TestlyxstringInvariant(this);
return internal_compare(0, rep->sz, str.rep->s,
str.rep->sz, str.rep->sz);
}
int lyxstring::compare(value_type const * s) const
{
Assert(s);
TestlyxstringInvariant(this);
int n = (!s) ? 0 : strlen(s);
return internal_compare(0, rep->sz, s, n, n);
}
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str) const
{
Assert(pos < rep->sz || pos == 0);
TestlyxstringInvariant(this);
return internal_compare(pos, n, str.rep->s, str.rep->sz, str.rep->sz);
}
int lyxstring::compare(size_type pos, size_type n, lyxstring const & str,
size_type pos2, size_type n2) const
{
Assert(pos < rep->sz || pos == 0);
Assert(pos2 < str.rep->sz || pos2 == 0);
TestlyxstringInvariant(this);
return internal_compare(pos, n,
str.rep->s + pos2,
str.rep->sz - pos2, n2);
}
int lyxstring::compare(size_type pos, size_type n, value_type const * s,
size_type n2) const
{
Assert(s && (pos < rep->sz || pos == 0));
TestlyxstringInvariant(this);
return internal_compare(pos, n, s, (!s) ? 0 : strlen(s), n2);
}
///////////////// /////////////////
// Substrings // Substrings
///////////////// /////////////////

View File

@ -533,7 +533,12 @@ private:
//lyxstring & operator=(int); //lyxstring & operator=(int);
// //
//lyxstring & operator+=(int); //lyxstring & operator+=(int);
/// Compare this with s. works with embedded '\0' chars also.
int internal_compare(size_type pos, size_type n,
value_type const * s,
size_type slen, size_type n2) const;
/// Forward declaration of the string representation /// Forward declaration of the string representation
struct Srep; struct Srep;
// DEC cxx requires this. // DEC cxx requires this.

View File

@ -854,7 +854,7 @@ int LyXText::Fill(Row * row, int paperwidth)
LyXParagraph::size_type main_body = LyXParagraph::size_type main_body =
BeginningOfMainBody(row->par); BeginningOfMainBody(row->par);
LyXParagraph::size_type i = row->pos; LyXParagraph::size_type i = row->pos;
while (i < last) { while (i <= last) {
#else #else
int main_body = BeginningOfMainBody(row->par); int main_body = BeginningOfMainBody(row->par);
int i = row->pos; int i = row->pos;

View File

@ -1898,8 +1898,9 @@ This is not implemented yet.
if (sel_start_cursor.par->ParFromPos(sel_start_cursor.pos) if (sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)
== sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) { == sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) {
/* only within one paragraph */ /* only within one paragraph */
simple_cut_buffer = new LyXParagraph(); simple_cut_buffer = new LyXParagraph;
#ifdef NEW_TEXT #ifdef NEW_TEXT
simple_cut_buffer->text.reserve(500);
LyXParagraph::size_type i = LyXParagraph::size_type i =
sel_start_cursor.pos; sel_start_cursor.pos;
#else #else
@ -2072,6 +2073,9 @@ void LyXText::CopySelection()
== sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) { == sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) {
/* only within one paragraph */ /* only within one paragraph */
simple_cut_buffer = new LyXParagraph; simple_cut_buffer = new LyXParagraph;
#if NEW_TEXT
simple_cut_buffer->text.reserve(500);
#endif
for (i = sel_start_cursor.pos; i < sel_end_cursor.pos; ++i){ for (i = sel_start_cursor.pos; i < sel_end_cursor.pos; ++i){
sel_start_cursor.par->CopyIntoMinibuffer(i); sel_start_cursor.par->CopyIntoMinibuffer(i);
simple_cut_buffer->InsertFromMinibuffer(i - sel_start_cursor.pos); simple_cut_buffer->InsertFromMinibuffer(i - sel_start_cursor.pos);
@ -2390,8 +2394,8 @@ bool LyXText::IsStringInText(LyXParagraph * par, int pos, char const * str)
if (par) { if (par) {
int i = 0; int i = 0;
while (pos + i < par->Last() && str[i] && while (pos + i < par->Last() && str[i] &&
str[i]==par->GetChar(pos+i)) { str[i] == par->GetChar(pos + i)) {
i++; ++i;
} }
if (!str[i]) if (!str[i])
return true; return true;
@ -3427,7 +3431,9 @@ bool LyXText::TextHandleUndo(Undo * undo){ // returns false if no undo possible
if (undo->kind == Undo::EDIT){ if (undo->kind == Undo::EDIT){
tmppar2->text = tmppar->text; tmppar2->text = tmppar->text;
#ifdef NEW_TEXT #ifdef NEW_TEXT
tmppar->text.clear(); //tmppar->text.clear();
tmppar->text.erase(tmppar->text.begin(),
tmppar->text.end());
#else #else
tmppar->text = 0; tmppar->text = 0;
#endif #endif
@ -3598,7 +3604,9 @@ Undo * LyXText::CreateUndo(Undo::undo_kind kind, LyXParagraph * before,
// a memory optimization: Just store the layout information when only edit // a memory optimization: Just store the layout information when only edit
if (kind == Undo::EDIT){ if (kind == Undo::EDIT){
#ifdef NEW_TEXT #ifdef NEW_TEXT
tmppar2->text.clear(); //tmppar2->text.clear();
tmppar2->text.erase(tmppar2->text.begin(),
tmppar2->text.end());
#else #else
if (tmppar2->text) if (tmppar2->text)
delete[] tmppar2->text; delete[] tmppar2->text;
@ -3615,7 +3623,8 @@ Undo * LyXText::CreateUndo(Undo::undo_kind kind, LyXParagraph * before,
// a memory optimization: Just store the layout information when only edit // a memory optimization: Just store the layout information when only edit
if (kind == Undo::EDIT){ if (kind == Undo::EDIT){
#ifdef NEW_TEXT #ifdef NEW_TEXT
tmppar2->next->text.clear(); //tmppar2->next->text.clear();
tmppar2->next->text.erase(tmppar2->next->text.begin(), tmppar2->next->text.end());
#else #else
if (tmppar2->next->text) if (tmppar2->next->text)
delete[] tmppar2->next->text; delete[] tmppar2->next->text;