some important changes to FIX_DOUBLE_SPCE still not completely correct (please help out.) Some external functions called from wrappers. use MODERN_STL_STREAMS in lyxsum.C

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@423 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2000-01-17 21:01:30 +00:00
parent 722d679779
commit c36aa67f7b
21 changed files with 288 additions and 142 deletions

View File

@ -1,3 +1,26 @@
2000-01-14 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/support/date.C: new file
* src/support/chdir.C: new file
* src/support/getUserName.C: new file
* src/support/getcwd.C: new file
* src/support/abort.C: new file
* src/support/kill.C: new file
* src/support/lyxlib.h: moved all the functions in this file
insede struct lyx. Added also kill and abort to this struct. This
is a way to avoid the "kill is not defined in <csignal>", we make
C++ wrappers for functions that are not ANSI C or ANSI C++.
* src/support/lyxsum.C (sum): use #ifdef MODERN_STL_STREAMS
instead of #if __GLIBCPP__. Since lyxsum is now put inside struct
lyx it has been renamed to sum.
2000-01-14 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr> 2000-01-14 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/text.C: add using directives for std::min and std::max. * src/text.C: add using directives for std::min and std::max.

View File

@ -35,7 +35,7 @@ void DepTable::insert(string const & fi,
if (deplist.find(f) == deplist.end()) { if (deplist.find(f) == deplist.end()) {
if (upd) { if (upd) {
one = two; one = two;
two = lyxsum(f.c_str()); two = lyx::sum(f.c_str());
} }
deplist[f] = make_pair(one, two); deplist[f] = make_pair(one, two);
} }
@ -48,7 +48,7 @@ void DepTable::update()
itr != deplist.end(); itr != deplist.end();
++itr) { ++itr) {
unsigned long one = (*itr).second.second; unsigned long one = (*itr).second.second;
unsigned long two = lyxsum((*itr).first.c_str()); unsigned long two = lyx::sum((*itr).first.c_str());
(*itr).second = make_pair(one, two); (*itr).second = make_pair(one, two);
if (lyxerr.debugging()) { if (lyxerr.debugging()) {
lyxerr << "update: " << (*itr).first << " " lyxerr << "update: " << (*itr).first << " "

View File

@ -1588,7 +1588,7 @@ void Buffer::makeLaTeXFile(string const & fname,
// first paragraph of the document. (Asger) // first paragraph of the document. (Asger)
texrow.start(paragraph, 0); texrow.start(paragraph, 0);
string userName(getUserName()); string userName(lyx::getUserName());
string LFile; string LFile;
if (!only_body && nice) { if (!only_body && nice) {
@ -2146,9 +2146,9 @@ void Buffer::makeLinuxDocFile(string const & fname, int column)
<< params.preamble << " \n]>\n\n"; << params.preamble << " \n]>\n\n";
} }
string userName(getUserName()); string userName(lyx::getUserName());
ofs << "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 " ofs << "<!-- LinuxDoc file was created by LyX 1.0 (C) 1995-1999 "
<< "by <" << userName << "> " << date() << " -->\n"; << "by <" << userName << "> " << lyx::date() << " -->\n";
if(params.options.empty()) if(params.options.empty())
sgmlOpenTag(ofs, 0, top_element); sgmlOpenTag(ofs, 0, top_element);

View File

@ -57,6 +57,7 @@ using std::ifstream;
#include "gettext.h" #include "gettext.h"
#include "lyx_gui_misc.h" // CancelCloseBoxCB #include "lyx_gui_misc.h" // CancelCloseBoxCB
#include "support/FileInfo.h" #include "support/FileInfo.h"
#include "support/lyxlib.h"
extern BufferView * current_view; extern BufferView * current_view;
#if 0 #if 0
@ -260,7 +261,7 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
lyxerr << "Killing gs " lyxerr << "Killing gs "
<< p->gspid << endl; << p->gspid << endl;
} }
kill(p->gspid, SIGHUP); lyx::kill(p->gspid, SIGHUP);
sprintf(tmp, "%s/~lyxgs%d.ps", sprintf(tmp, "%s/~lyxgs%d.ps",
system_tempdir.c_str(), system_tempdir.c_str(),
@ -275,7 +276,7 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
lyxerr << "Killing gs " lyxerr << "Killing gs "
<< p->gspid << endl; << p->gspid << endl;
} }
kill(p->gspid, SIGHUP); lyx::kill(p->gspid, SIGHUP);
sprintf(tmp, "%s/~lyxgs%d.ps", sprintf(tmp, "%s/~lyxgs%d.ps",
system_tempdir.c_str(), system_tempdir.c_str(),
@ -472,7 +473,7 @@ static void freefigdata(figdata * tmpdata)
chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh); chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
// kill ghostscript and unlink it's files // kill ghostscript and unlink it's files
tmpdata->gspid = -1; tmpdata->gspid = -1;
kill(pid, SIGKILL); lyx::kill(pid, SIGKILL);
sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid); sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
unlink(buf); unlink(buf);
} }

View File

@ -156,7 +156,7 @@ extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev)
XGetErrorText(display, xeev->error_code, etxt, 512); XGetErrorText(display, xeev->error_code, etxt, 512);
lyxerr << etxt << endl; lyxerr << etxt << endl;
// By doing an abort we get a nice backtrace. (hopefully) // By doing an abort we get a nice backtrace. (hopefully)
abort(); lyx::abort();
return 0; // Solaris CC wants us to return something return 0; // Solaris CC wants us to return something
} }

View File

@ -615,6 +615,6 @@ void error_handler(int err_sig)
lyxerr << "Bye." << endl; lyxerr << "Bye." << endl;
if(err_sig!= SIGHUP && (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV)) if(err_sig!= SIGHUP && (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV))
abort(); lyx::abort();
exit(0); exit(0);
} }

View File

@ -2,6 +2,8 @@
#ifndef LASSERT_H #ifndef LASSERT_H
#define LASSERT_H #define LASSERT_H
#include "support/lyxlib.h"
//namespace LyX { //namespace LyX {
#ifdef ENABLE_ASSERTIONS #ifdef ENABLE_ASSERTIONS
@ -11,7 +13,7 @@ template<class A> inline void Assert(A assertion)
{ {
//if (!assertion) throw X(); //if (!assertion) throw X();
if (!assertion) { if (!assertion) {
abort(); lyx::abort();
} }
} }
@ -24,7 +26,7 @@ template<class A> inline void Assert(A * ptr)
template<> inline void Assert(void const * ptr) template<> inline void Assert(void const * ptr)
{ {
if (!ptr) { if (!ptr) {
abort(); lyx::abort();
} }
} }
#endif /* HAVE_PARTIAL_SPECIALIZATION */ #endif /* HAVE_PARTIAL_SPECIALIZATION */

View File

@ -23,9 +23,15 @@ libsupport_la_SOURCES = \
LRegex.h \ LRegex.h \
LSubstring.C \ LSubstring.C \
LSubstring.h \ LSubstring.h \
abort.C \
block.h \ block.h \
chdir.C \
date.C \
filetools.C \ filetools.C \
filetools.h \ filetools.h \
getUserName.C \
getcwd.C \
kill.C \
lstrings.C \ lstrings.C \
lstrings.h \ lstrings.h \
lyxlib.h \ lyxlib.h \

10
src/support/abort.C Normal file
View File

@ -0,0 +1,10 @@
#include <config.h>
#include <stdlib.h>
#include "support/lyxlib.h"
void lyx::abort()
{
::abort();
}

14
src/support/chdir.C Normal file
View File

@ -0,0 +1,14 @@
#include <config.h>
#include <unistd.h>
#include "support/lyxlib.h"
int lyx::chdir(char const * name)
{
#ifndef __EMX__
return ::chdir(name);
#else
return ::_chdir2(name);
#endif
}

14
src/support/date.C Normal file
View File

@ -0,0 +1,14 @@
#include <config.h>
#include <time.h>
#include "support/lyxlib.h"
char * lyx::date()
{
time_t tid;
if ((tid = ::time(0)) == static_cast<time_t>(-1))
return 0;
else
return ::ctime(&tid);
}

15
src/support/getUserName.C Normal file
View File

@ -0,0 +1,15 @@
#include <config.h>
#include "support/lyxlib.h"
#include "support/filetools.h"
#include "gettext.h"
string lyx::getUserName()
{
string userName(GetEnv("LOGNAME"));
if (userName.empty())
userName = GetEnv("USER");
if (userName.empty())
userName = _("unknown");
return userName;
}

14
src/support/getcwd.C Normal file
View File

@ -0,0 +1,14 @@
#include <config.h>
#include <unistd.h>
#include "support/lyxlib.h"
char * lyx::getcwd(char * buffer, size_t size)
{
#ifndef __EMX__
return ::getcwd(buffer, size);
#else
return ::_getcwd2(buffer, size);
#endif
}

11
src/support/kill.C Normal file
View File

@ -0,0 +1,11 @@
#include <config.h>
#include <sys/types.h>
#include <signal.h>
#include "lyxlib.h"
int lyx::kill(pid_t pid, int sig)
{
return ::kill(pid, sig);
}

View File

@ -10,36 +10,36 @@
#include <cstring> #include <cstring>
#include "LAssert.h" //#include "LAssert.h"
//#warning verify this please. Lgb //#warning verify this please. Lgb
/// ///
template<class T> //template<class T>
size_t lstrlen(T const * t) //size_t lstrlen(T const * t)
{ //{
Assert(t); // we don't want null pointers // Assert(t); // we don't want null pointers
size_t count = 0; // size_t count = 0;
T const * r = t; // T const * r = t;
while(*r != 0) ++r, ++count; // while(*r != 0) ++r, ++count;
return count; // return count;
} //}
//#warning verify this please. Lgb //#Warning verify this please. Lgb
/// ///
template<class T> //template<class T>
T * lstrchr(T const * t, int c) //T * lstrchr(T const * t, int c)
{ //{
Assert(t); // we don't want null pointers // Assert(t); // we don't want null pointers
T * r = const_cast<T*>(t); // T * r = const_cast<T*>(t);
while(*r != 0) { // while(*r != 0) {
if (*r == c) // if (*r == c)
return r; // return r;
else // else
++r; // ++r;
} // }
return 0; // return 0;
} //}
#include <cctype> #include <cctype>
#include "LString.h" #include "LString.h"

View File

@ -12,56 +12,27 @@
#ifndef LYX_LIB_H #ifndef LYX_LIB_H
#define LYX_LIB_H #define LYX_LIB_H
#include <ctime>
#include <unistd.h>
#include "LString.h" #include "LString.h"
#include "gettext.h"
#include "support/filetools.h"
/// generates an checksum
unsigned long lyxsum(char const * file);
/// returns a date string
inline char * date()
{
time_t tid;
if ((tid= time(0)) == static_cast<time_t>(-1))
return 0;
else
return ctime(&tid);
}
// Where can I put this? I found the occurence of the same code // Where can I put this? I found the occurence of the same code
// three/four times. Don't you think it better to use a macro definition // three/four times. Don't you think it better to use a macro definition
// (an inlined member of some class)? // (an inlined member of some class)?
///
inline string getUserName()
{
string userName(GetEnv("LOGNAME"));
if (userName.empty())
userName = GetEnv("USER");
if (userName.empty())
userName = _("unknown");
return userName;
}
// This should have been a namespace // This should have been a namespace
struct lyx { struct lyx {
static char * getcwd(char * buffer, size_t size) { ///
#ifndef __EMX__ static char * getcwd(char * buffer, size_t size);
return ::getcwd(buffer, size); ///
#else static int chdir(char const * name);
return ::_getcwd2(buffer, size); /// generates an checksum
#endif static unsigned long sum(char const * file);
}; /// returns a date string
static int chdir(char const * name) { static char * date();
#ifndef __EMX__ ///
return ::chdir(name); static string getUserName();
#else ///
return ::_chdir2(name); static int kill(int pid, int sig);
#endif ///
}; static void abort();
}; };
#endif #endif

View File

@ -3,7 +3,7 @@
* *
* LyX, The Document Processor * LyX, The Document Processor
* *
* The function lyxsum is taken from GNU textutill-1.22 * The function lyx::sum is taken from GNU textutill-1.22
* and is there part of the program chsum. The chsum program * and is there part of the program chsum. The chsum program
* is written by Q. Frank Xia, qx@math.columbia.edu. * is written by Q. Frank Xia, qx@math.columbia.edu.
* *
@ -14,12 +14,14 @@
#include <config.h> #include <config.h>
#ifdef __GLIBCPP__ #ifdef MODERN_STL_STREAMS
#include <fstream> #include <fstream>
#else #else
#include <cstdio> #include <cstdio>
#endif #endif
#include "support/lyxlib.h"
/* Number of bytes to read at once. */ /* Number of bytes to read at once. */
#define BUFLEN (1 << 16) #define BUFLEN (1 << 16)
@ -84,12 +86,12 @@ static unsigned long const crctab[256] =
Return crc if successful, 0 if an error occurs. */ Return crc if successful, 0 if an error occurs. */
unsigned long unsigned long
lyxsum (char const * file) lyx::sum (char const * file)
{ {
unsigned long crc = 0; unsigned long crc = 0;
long length = 0; long length = 0;
long bytes_read; long bytes_read;
#if __GLIBCPP__ #ifdef MODERN_STL_STREAMS
char buf[BUFLEN]; char buf[BUFLEN];
ifstream ifs(file); ifstream ifs(file);
if (!ifs) { if (!ifs) {
@ -98,7 +100,6 @@ lyxsum (char const * file)
while ((bytes_read = ifs.readsome(buf, BUFLEN)) > 0) { while ((bytes_read = ifs.readsome(buf, BUFLEN)) > 0) {
unsigned char * cp = reinterpret_cast<unsigned char*>(buf); unsigned char * cp = reinterpret_cast<unsigned char*>(buf);
length += bytes_read; length += bytes_read;
while (bytes_read--) while (bytes_read--)
crc = (crc << 8) ^ crctab[((crc >> 24) ^ *(cp++)) & 0xFF]; crc = (crc << 8) ^ crctab[((crc >> 24) ^ *(cp++)) & 0xFF];

View File

@ -14,6 +14,7 @@
#include "syscall.h" #include "syscall.h"
#include "syscontr.h" #include "syscontr.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/lyxlib.h"
Systemcalls::Systemcalls() { Systemcalls::Systemcalls() {
pid = 0; // No child yet pid = 0; // No child yet
@ -33,7 +34,7 @@ Systemcalls::~Systemcalls() {
#if 0 #if 0
// If the child is alive, we have to brutally kill it // If the child is alive, we have to brutally kill it
if (getpid() != 0) { if (getpid() != 0) {
::kill(getpid(), SIGKILL); lyx::kill(getpid(), SIGKILL);
} }
#endif #endif
} }
@ -77,7 +78,7 @@ void Systemcalls::kill(int /*tolerance*/) {
lyxerr << "LyX: Can't kill non-existing process." << endl; lyxerr << "LyX: Can't kill non-existing process." << endl;
return; return;
} }
int ret = ::kill(getpid(), SIGHUP); int ret = lyx::kill(getpid(), SIGHUP);
bool wait_for_death = true; bool wait_for_death = true;
if (ret != 0) { if (ret != 0) {
if (errno == ESRCH) { if (errno == ESRCH) {

View File

@ -4,7 +4,7 @@
* LyX, The Document Processor * LyX, The Document Processor
* *
* Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team. * Copyright (C) 1995-2000 The LyX Team.
* *
* ====================================================== */ * ====================================================== */

View File

@ -5,7 +5,7 @@
* LyX, The Document Processor * LyX, The Document Processor
* *
* Copyright 1995 Matthias Ettrich * Copyright 1995 Matthias Ettrich
* Copyright 1995-1998 The LyX Team * Copyright 1995-2000 The LyX Team
* *
* ====================================================== */ * ====================================================== */

View File

@ -1746,7 +1746,7 @@ void LyXText::InsertInset(Inset *inset)
} }
/* this is for the simple cut and paste mechanism */ // this is for the simple cut and paste mechanism
static LyXParagraph * simple_cut_buffer = 0; static LyXParagraph * simple_cut_buffer = 0;
static char simple_cut_buffer_textclass = 0; static char simple_cut_buffer_textclass = 0;
@ -1832,7 +1832,7 @@ void LyXText::CutSelection(bool doclear)
.par->ParFromPos(sel_start_cursor.pos)->previous, .par->ParFromPos(sel_start_cursor.pos)->previous,
undoendpar); undoendpar);
// delete the simple_cut_buffer // clear the simple_cut_buffer
DeleteSimpleCutBuffer(); DeleteSimpleCutBuffer();
// set the textclass // set the textclass
@ -1867,7 +1867,18 @@ void LyXText::CutSelection(bool doclear)
- cut across footnotes and paragraph - cut across footnotes and paragraph
My simplistic tests show that the idea are basically sound but My simplistic tests show that the idea are basically sound but
there are some items to fix up...we only need to find them there are some items to fix up...we only need to find them
first. (Lgb) first.
As do redo Asger's example above (with | beeing the cursor in the
result after cutting.):
Example: "This is our text."
Using " our " as selection, cutting will give "This is|text.".
Using "our" as selection, cutting will give "This is | text.".
Using " our" as selection, cutting will give "This is| text.".
Using "our " as selection, cutting will give "This is |text.".
(Lgb)
*/ */
#ifndef FIX_DOUBLE_SPACE #ifndef FIX_DOUBLE_SPACE
@ -1908,27 +1919,31 @@ void LyXText::CutSelection(bool doclear)
} }
simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last()); simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last());
} }
#ifdef FIX_DOUBLE_SPACES #ifndef FIX_DOUBLE_SPACE
// check for double spaces // check for double spaces
if (sel_start_cursor.pos && if (sel_start_cursor.pos &&
sel_start_cursor.par->Last() > sel_start_cursor.pos && sel_start_cursor.par->Last() > sel_start_cursor.pos
sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1) && && sel_start_cursor.par
sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) { ->IsLineSeparator(sel_start_cursor.pos - 1)
&& sel_start_cursor.par
->IsLineSeparator(sel_start_cursor.pos)) {
sel_start_cursor.par->Erase(sel_start_cursor.pos); sel_start_cursor.par->Erase(sel_start_cursor.pos);
} }
if (space_wrapped) if (space_wrapped)
simple_cut_buffer->InsertChar(i - sel_start_cursor.pos, ' '); simple_cut_buffer->InsertChar(i - sel_start_cursor.pos,
' ');
#endif #endif
endpar = sel_end_cursor.par->Next(); endpar = sel_end_cursor.par->Next();
} } else {
else {
// cut more than one paragraph // cut more than one paragraph
sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos); sel_end_cursor.par
->BreakParagraphConservative(sel_end_cursor.pos);
#ifndef FIX_DOUBLE_SPACE #ifndef FIX_DOUBLE_SPACE
// insert a space at the end if there was one // insert a space at the end if there was one
if (space_wrapped) if (space_wrapped)
sel_end_cursor.par->InsertChar(sel_end_cursor.par->Last(), ' '); sel_end_cursor.par
->InsertChar(sel_end_cursor.par->Last(), ' ');
#endif #endif
sel_end_cursor.par = sel_end_cursor.par->Next(); sel_end_cursor.par = sel_end_cursor.par->Next();
sel_end_cursor.pos = 0; sel_end_cursor.pos = 0;
@ -1938,14 +1953,18 @@ void LyXText::CutSelection(bool doclear)
#ifndef FIX_DOUBLE_SPACE #ifndef FIX_DOUBLE_SPACE
// please break behind a space, if there is one. // please break behind a space, if there is one.
// The space should be copied too // The space should be copied too
if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) if (sel_start_cursor.par
->IsLineSeparator(sel_start_cursor.pos))
sel_start_cursor.pos++; sel_start_cursor.pos++;
#endif
sel_start_cursor.par sel_start_cursor.par
->BreakParagraphConservative(sel_start_cursor.pos); ->BreakParagraphConservative(sel_start_cursor.pos);
#ifndef FIX_DOUBLE_SPACE
if (!sel_start_cursor.pos if (!sel_start_cursor.pos
|| sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1) || sel_start_cursor.par
|| sel_start_cursor.par->IsNewline(sel_start_cursor.pos - 1)) { ->IsLineSeparator(sel_start_cursor.pos - 1)
|| sel_start_cursor.par
->IsNewline(sel_start_cursor.pos - 1)) {
sel_start_cursor.par->Next()->InsertChar(0, ' '); sel_start_cursor.par->Next()->InsertChar(0, ' ');
} }
#endif #endif
@ -1988,11 +2007,13 @@ void LyXText::CutSelection(bool doclear)
!sel_start_cursor.par->Next()->Last()) !sel_start_cursor.par->Next()->Last())
sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->PasteParagraph(); sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->PasteParagraph();
#ifdef FIX_DOUBLE_SPACE #ifndef FIX_DOUBLE_SPACE
// maybe a forgotten blank // maybe a forgotten blank
if (sel_start_cursor.pos if (sel_start_cursor.pos
&& sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos) && sel_start_cursor.par
&& sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1)) { ->IsLineSeparator(sel_start_cursor.pos)
&& sel_start_cursor.par
->IsLineSeparator(sel_start_cursor.pos - 1)) {
sel_start_cursor.par->Erase(sel_start_cursor.pos); sel_start_cursor.par->Erase(sel_start_cursor.pos);
} }
#endif #endif
@ -2027,9 +2048,11 @@ void LyXText::CopySelection()
|| sel_end_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) { || sel_end_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
tmppar = sel_start_cursor.par; tmppar = sel_start_cursor.par;
while (tmppar != sel_end_cursor.par) { while (tmppar != sel_end_cursor.par) {
if (tmppar->footnoteflag != sel_end_cursor.par->footnoteflag){ if (tmppar->footnoteflag !=
sel_end_cursor.par->footnoteflag) {
WriteAlert(_("Impossible operation"), WriteAlert(_("Impossible operation"),
_("Don't know what to do with half floats."), _("Don't know what to do"
" with half floats."),
_("sorry.")); _("sorry."));
return; return;
} }
@ -2186,25 +2209,56 @@ void LyXText::PasteSelection()
else else
table_too_small = true; table_too_small = true;
} else { } else {
#ifdef FIX_DOUBLE_SPACE
// This is an attempt to fix the
// "never insert a space at the
// beginning of a paragraph" problem.
if (tmpcursor.pos == 0
&& simple_cut_buffer->IsLineSeparator(0)) {
simple_cut_buffer->Erase(0);
} else {
simple_cut_buffer->CutIntoMinibuffer(0); simple_cut_buffer->CutIntoMinibuffer(0);
simple_cut_buffer->Erase(0); simple_cut_buffer->Erase(0);
tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos); tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos);
tmpcursor.pos++; tmpcursor.pos++;
} }
#else
simple_cut_buffer->CutIntoMinibuffer(0);
simple_cut_buffer->Erase(0);
tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos);
tmpcursor.pos++;
#endif
}
} }
} else { } else {
/* table stuff -- end */ /* table stuff -- end */
// Some provisions should be done here for checking if we // Some provisions should be done here for checking
// are inserting at the beginning of a paragraph. If there // if we are inserting at the beginning of a
// are a space at the beginning of the text to insert and we are // paragraph. If there are a space at the beginning
// inserting at the beginning of the paragraph the space should // of the text to insert and we are inserting at
// the beginning of the paragraph the space should
// be removed. // be removed.
while (simple_cut_buffer->text.size()) { while (simple_cut_buffer->text.size()) {
#ifdef FIX_DOUBLE_SPACE
// This is an attempt to fix the
// "never insert a space at the
// beginning of a paragraph" problem.
if (tmpcursor.pos == 0
&& simple_cut_buffer->IsLineSeparator(0)) {
simple_cut_buffer->Erase(0);
} else {
simple_cut_buffer->CutIntoMinibuffer(0); simple_cut_buffer->CutIntoMinibuffer(0);
simple_cut_buffer->Erase(0); simple_cut_buffer->Erase(0);
tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos); tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos);
tmpcursor.pos++; tmpcursor.pos++;
} }
#else
simple_cut_buffer->CutIntoMinibuffer(0);
simple_cut_buffer->Erase(0);
tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos);
tmpcursor.pos++;
#endif
}
} }
delete simple_cut_buffer; delete simple_cut_buffer;
simple_cut_buffer = tmppar; simple_cut_buffer = tmppar;
@ -2246,10 +2300,16 @@ void LyXText::PasteSelection()
lastbuffer = lastbuffer->Next(); lastbuffer = lastbuffer->Next();
// find the physical end of the buffer // find the physical end of the buffer
#ifdef WITH_WARNINGS
#warning Explain this please.
#endif
#if 0
// Can someone explain to be why this is done a second time?
// (Lgb)
lastbuffer = simple_cut_buffer; lastbuffer = simple_cut_buffer;
while (lastbuffer->Next()) while (lastbuffer->Next())
lastbuffer = lastbuffer->Next(); lastbuffer = lastbuffer->Next();
#endif
#ifndef FIX_DOUBLE_SPACE #ifndef FIX_DOUBLE_SPACE
// Please break behind a space, if there is one. The space // Please break behind a space, if there is one. The space
// should be copied too. // should be copied too.
@ -2279,11 +2339,14 @@ void LyXText::PasteSelection()
endpar = cursor.par->ParFromPos(cursor.pos)->next->Next(); endpar = cursor.par->ParFromPos(cursor.pos)->next->Next();
// paste it! // paste it!
lastbuffer->ParFromPos(lastbuffer->Last())->next = cursor.par->ParFromPos(cursor.pos)->next; lastbuffer->ParFromPos(lastbuffer->Last())->next =
cursor.par->ParFromPos(cursor.pos)->next->previous = lastbuffer->ParFromPos(lastbuffer->Last()); cursor.par->ParFromPos(cursor.pos)->next;
cursor.par->ParFromPos(cursor.pos)->next->previous =
lastbuffer->ParFromPos(lastbuffer->Last());
cursor.par->ParFromPos(cursor.pos)->next = simple_cut_buffer; cursor.par->ParFromPos(cursor.pos)->next = simple_cut_buffer;
simple_cut_buffer->previous = cursor.par->ParFromPos(cursor.pos); simple_cut_buffer->previous =
cursor.par->ParFromPos(cursor.pos);
if (cursor.par->ParFromPos(cursor.pos)->Next() == lastbuffer) if (cursor.par->ParFromPos(cursor.pos)->Next() == lastbuffer)
lastbuffer = cursor.par; lastbuffer = cursor.par;
@ -2334,8 +2397,8 @@ void LyXText::PasteSelection()
#endif #endif
lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(); lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph();
} } else
else lastbuffer->Next()->ClearParagraph(); lastbuffer->Next()->ClearParagraph();
} }
// restore the simple cut buffer // restore the simple cut buffer