2000-04-10 14:29:05 +00:00
|
|
|
|
/* This file is part of
|
|
|
|
|
* ======================================================
|
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
|
*
|
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "CutAndPaste.h"
|
2000-06-08 23:16:16 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "buffer.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "lyxparagraph.h"
|
|
|
|
|
#include "insets/inseterror.h"
|
|
|
|
|
#include "lyx_gui_misc.h"
|
2000-06-08 23:16:16 +00:00
|
|
|
|
#include "lyxcursor.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
using std::pair;
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
extern BufferView * current_view;
|
|
|
|
|
|
2000-04-19 01:42:55 +00:00
|
|
|
|
// J<>rgen, note that this means that you cannot currently have a list
|
|
|
|
|
// of selections cut/copied. So IMHO later we should have a
|
|
|
|
|
// list/vector/deque that we could store
|
|
|
|
|
// struct selection_item {
|
|
|
|
|
// LyXParagraph * buf;
|
|
|
|
|
// LyXTextClassList::size_type textclass;
|
|
|
|
|
// };
|
|
|
|
|
// in and some method of choosing beween them (based on the first few chars
|
|
|
|
|
// in the selection probably.) This would be a nice feature and quite
|
|
|
|
|
// easy to implement. (Lgb)
|
2000-04-20 13:48:34 +00:00
|
|
|
|
//
|
|
|
|
|
// Sure but I just cleaned up this code for now with the same functionality
|
|
|
|
|
// as before. I also want to add a XClipboard function so that we can copy
|
|
|
|
|
// text from LyX to some other X-application in the form of ASCII or in the
|
|
|
|
|
// form of LaTeX (or Docbook depending on the document-class!). Think how nice
|
|
|
|
|
// it could be to select a math-inset do a "Copy to X-Clipboard as LaTeX" and
|
|
|
|
|
// then do a middle mouse button click in the application you want and have
|
|
|
|
|
// the whole formula there in LaTeX-Code. (Jug)
|
2000-04-19 01:42:55 +00:00
|
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
|
static LyXParagraph * buf = 0;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
static LyXTextClassList::size_type textclass = 0;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// for now here this should be in another Cut&Paste Class!
|
2000-04-19 01:42:55 +00:00
|
|
|
|
// J<>rgen, I moved this out of CutAndPaste since it does not operate on any
|
|
|
|
|
// member of the CutAndPaste class and in addition it was private.
|
|
|
|
|
// Perhaps it even should take a parameter? (Lgb)
|
|
|
|
|
static
|
|
|
|
|
void DeleteBuffer()
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2000-04-20 13:48:34 +00:00
|
|
|
|
if (!buf)
|
|
|
|
|
return;
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2000-04-20 13:48:34 +00:00
|
|
|
|
LyXParagraph * tmppar;
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2000-04-20 13:48:34 +00:00
|
|
|
|
while (buf) {
|
|
|
|
|
tmppar = buf;
|
|
|
|
|
buf = buf->next;
|
|
|
|
|
delete tmppar;
|
|
|
|
|
}
|
|
|
|
|
buf = 0;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
|
|
|
|
bool CutAndPaste::cutSelection(LyXParagraph * startpar, LyXParagraph ** endpar,
|
2000-04-10 14:29:05 +00:00
|
|
|
|
int start, int & end, char tc, bool doclear)
|
|
|
|
|
{
|
|
|
|
|
if (!startpar || (start > startpar->Last()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
DeleteBuffer();
|
|
|
|
|
|
|
|
|
|
textclass = tc;
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
if (!(*endpar) ||
|
|
|
|
|
#ifndef NEW_INSETS
|
|
|
|
|
(startpar->ParFromPos(start) ==
|
|
|
|
|
(*endpar)->ParFromPos(end))
|
|
|
|
|
#else
|
|
|
|
|
(startpar == (*endpar))
|
|
|
|
|
#endif
|
2000-11-04 10:00:12 +00:00
|
|
|
|
) {
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// only within one paragraph
|
|
|
|
|
buf = new LyXParagraph;
|
|
|
|
|
LyXParagraph::size_type i = start;
|
|
|
|
|
if (end > startpar->Last())
|
|
|
|
|
end = startpar->Last();
|
|
|
|
|
for (; i < end; ++i) {
|
2000-12-07 15:30:53 +00:00
|
|
|
|
startpar->CopyIntoMinibuffer(*current_view->buffer(), start);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
startpar->Erase(start);
|
|
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
|
buf->InsertFromMinibuffer(buf->Last());
|
|
|
|
|
}
|
2000-09-19 13:50:47 +00:00
|
|
|
|
end = start-1;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
} else {
|
|
|
|
|
// more than one paragraph
|
2000-06-08 23:16:16 +00:00
|
|
|
|
(*endpar)->BreakParagraphConservative(current_view->buffer()->params,
|
|
|
|
|
end);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
*endpar = (*endpar)->Next();
|
|
|
|
|
end = 0;
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
startpar->BreakParagraphConservative(current_view->buffer()->params,
|
|
|
|
|
start);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// store the selection
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
buf = startpar->ParFromPos(start)->next;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#else
|
|
|
|
|
buf = startpar->next;
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
buf->previous = 0;
|
|
|
|
|
(*endpar)->previous->next = 0;
|
|
|
|
|
|
|
|
|
|
// cut the selection
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
startpar->ParFromPos(start)->next = (*endpar);
|
|
|
|
|
|
|
|
|
|
(*endpar)->previous = startpar->ParFromPos(start);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#else
|
|
|
|
|
startpar->next = (*endpar);
|
|
|
|
|
|
|
|
|
|
(*endpar)->previous = startpar;
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// care about footnotes
|
|
|
|
|
if (buf->footnoteflag) {
|
|
|
|
|
LyXParagraph * tmppar = buf;
|
|
|
|
|
while (tmppar){
|
|
|
|
|
tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE;
|
|
|
|
|
tmppar = tmppar->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// the cut selection should begin with standard layout
|
|
|
|
|
buf->Clear();
|
|
|
|
|
|
|
|
|
|
// paste the paragraphs again, if possible
|
|
|
|
|
if (doclear)
|
2000-05-26 16:13:01 +00:00
|
|
|
|
startpar->Next()->StripLeadingSpaces(textclass);
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
|
|
|
|
if (startpar->FirstPhysicalPar()->HasSameLayout(startpar->Next()) ||
|
|
|
|
|
#else
|
|
|
|
|
if (startpar->HasSameLayout(startpar->Next()) ||
|
|
|
|
|
#endif
|
2000-05-22 11:08:25 +00:00
|
|
|
|
!startpar->Next()->Last()) {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-06-08 23:16:16 +00:00
|
|
|
|
startpar->ParFromPos(start)->PasteParagraph(current_view->buffer()->params);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#else
|
|
|
|
|
startpar->PasteParagraph(current_view->buffer()->params);
|
|
|
|
|
#endif
|
2000-05-22 11:08:25 +00:00
|
|
|
|
(*endpar) = startpar; // this because endpar gets deleted here!
|
|
|
|
|
}
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
|
|
|
|
bool CutAndPaste::copySelection(LyXParagraph * startpar, LyXParagraph * endpar,
|
2000-04-10 14:29:05 +00:00
|
|
|
|
int start, int end, char tc)
|
|
|
|
|
{
|
|
|
|
|
if (!startpar || (start > startpar->Last()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
DeleteBuffer();
|
|
|
|
|
|
|
|
|
|
textclass = tc;
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
if (!(endpar) ||
|
|
|
|
|
#ifndef NEW_INSETS
|
|
|
|
|
(startpar->ParFromPos(start) ==
|
|
|
|
|
(endpar)->ParFromPos(end))
|
|
|
|
|
#else
|
|
|
|
|
(startpar == endpar)
|
|
|
|
|
#endif
|
2000-11-04 10:00:12 +00:00
|
|
|
|
) {
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// only within one paragraph
|
|
|
|
|
buf = new LyXParagraph;
|
|
|
|
|
LyXParagraph::size_type i = start;
|
|
|
|
|
if (end > startpar->Last())
|
|
|
|
|
end = startpar->Last();
|
|
|
|
|
for (; i < end; ++i) {
|
2000-12-07 15:30:53 +00:00
|
|
|
|
startpar->CopyIntoMinibuffer(*current_view->buffer(), i);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
buf->InsertFromMinibuffer(buf->Last());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// copy more than one paragraph
|
|
|
|
|
// clone the paragraphs within the selection
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
|
|
|
|
LyXParagraph * tmppar = startpar->ParFromPos(start);
|
|
|
|
|
#else
|
|
|
|
|
LyXParagraph * tmppar = startpar;
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
buf = tmppar->Clone();
|
2000-07-24 21:49:58 +00:00
|
|
|
|
LyXParagraph * tmppar2 = buf;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
while (
|
|
|
|
|
#ifndef NEW_INSETS
|
|
|
|
|
tmppar != endpar->ParFromPos(end)
|
|
|
|
|
#else
|
|
|
|
|
tmppar != endpar
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
&& tmppar->next) {
|
|
|
|
|
tmppar = tmppar->next;
|
|
|
|
|
tmppar2->next = tmppar->Clone();
|
|
|
|
|
tmppar2->next->previous = tmppar2;
|
|
|
|
|
tmppar2 = tmppar2->next;
|
|
|
|
|
}
|
|
|
|
|
tmppar2->next = 0;
|
|
|
|
|
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// care about footnotes
|
|
|
|
|
if (buf->footnoteflag) {
|
|
|
|
|
tmppar = buf;
|
2000-04-11 22:55:29 +00:00
|
|
|
|
while (tmppar) {
|
2000-04-10 14:29:05 +00:00
|
|
|
|
tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE;
|
|
|
|
|
tmppar = tmppar->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// the buf paragraph is too big
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
LyXParagraph::size_type tmpi2 = startpar->PositionInParFromPos(start);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#else
|
|
|
|
|
LyXParagraph::size_type tmpi2 = start;
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
for (; tmpi2; --tmpi2)
|
|
|
|
|
buf->Erase(0);
|
|
|
|
|
|
|
|
|
|
// now tmppar 2 is too big, delete all after end
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
tmpi2 = endpar->PositionInParFromPos(end);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#else
|
|
|
|
|
tmpi2 = end;
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
while (tmppar2->size() > tmpi2) {
|
|
|
|
|
tmppar2->Erase(tmppar2->size() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
|
|
|
|
bool CutAndPaste::pasteSelection(LyXParagraph ** par, LyXParagraph ** endpar,
|
|
|
|
|
int & pos, char tc)
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (!checkPastePossible(*par, pos))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (pos > (*par)->Last())
|
|
|
|
|
pos = (*par)->Last();
|
|
|
|
|
|
|
|
|
|
LyXParagraph * tmpbuf;
|
|
|
|
|
LyXParagraph * tmppar = *par;
|
|
|
|
|
int tmppos = pos;
|
|
|
|
|
|
|
|
|
|
// There are two cases: cutbuffer only one paragraph or many
|
|
|
|
|
if (!buf->next) {
|
|
|
|
|
// only within a paragraph
|
|
|
|
|
tmpbuf = buf->Clone();
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// Some provisions should be done here for checking
|
|
|
|
|
// if we are inserting at the beginning of a
|
|
|
|
|
// paragraph. If there are a space at the beginning
|
|
|
|
|
// of the text to insert and we are inserting at
|
|
|
|
|
// the beginning of the paragraph the space should
|
|
|
|
|
// be removed.
|
|
|
|
|
while (buf->size()) {
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// This is an attempt to fix the
|
|
|
|
|
// "never insert a space at the
|
|
|
|
|
// beginning of a paragraph" problem.
|
|
|
|
|
if (!tmppos && buf->IsLineSeparator(0)) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
buf->Erase(0);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
} else {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
buf->CutIntoMinibuffer(current_view->buffer()->params, 0);
|
|
|
|
|
buf->Erase(0);
|
|
|
|
|
if (tmppar->InsertFromMinibuffer(tmppos))
|
|
|
|
|
++tmppos;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete buf;
|
|
|
|
|
buf = tmpbuf;
|
|
|
|
|
*endpar = tmppar->Next();
|
|
|
|
|
pos = tmppos;
|
|
|
|
|
} else {
|
|
|
|
|
// many paragraphs
|
|
|
|
|
|
|
|
|
|
// make a copy of the simple cut_buffer
|
|
|
|
|
tmpbuf = buf;
|
|
|
|
|
LyXParagraph * simple_cut_clone = tmpbuf->Clone();
|
|
|
|
|
LyXParagraph * tmpbuf2 = simple_cut_clone;
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
if ((*par)->footnoteflag){
|
|
|
|
|
tmpbuf->footnoteflag = (*par)->footnoteflag;
|
|
|
|
|
tmpbuf->footnotekind = (*par)->footnotekind;
|
|
|
|
|
}
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
while (tmpbuf->next) {
|
|
|
|
|
tmpbuf = tmpbuf->next;
|
|
|
|
|
tmpbuf2->next = tmpbuf->Clone();
|
|
|
|
|
tmpbuf2->next->previous = tmpbuf2;
|
|
|
|
|
tmpbuf2 = tmpbuf2->next;
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
if ((*par)->footnoteflag){
|
|
|
|
|
tmpbuf->footnoteflag = (*par)->footnoteflag;
|
|
|
|
|
tmpbuf->footnotekind = (*par)->footnotekind;
|
|
|
|
|
}
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make sure there is no class difference
|
|
|
|
|
SwitchLayoutsBetweenClasses(textclass, tc, buf);
|
|
|
|
|
|
|
|
|
|
// make the buf exactly the same layout than
|
|
|
|
|
// the cursor paragraph
|
|
|
|
|
buf->MakeSameLayout(*par);
|
|
|
|
|
|
|
|
|
|
// find the end of the buffer
|
|
|
|
|
LyXParagraph * lastbuffer = buf;
|
|
|
|
|
while (lastbuffer->Next())
|
|
|
|
|
lastbuffer = lastbuffer->Next();
|
|
|
|
|
|
|
|
|
|
bool paste_the_end = false;
|
|
|
|
|
|
|
|
|
|
// open the paragraph for inserting the buf
|
|
|
|
|
// if necessary
|
|
|
|
|
if (((*par)->Last() > pos) || !(*par)->Next()) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
(*par)->BreakParagraphConservative(current_view->buffer()->params,
|
|
|
|
|
pos);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
paste_the_end = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set the end for redoing later
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
*endpar = (*par)->ParFromPos(pos)->next->Next();
|
|
|
|
|
|
|
|
|
|
// paste it!
|
|
|
|
|
lastbuffer->ParFromPos(lastbuffer->Last())->next =
|
|
|
|
|
(*par)->ParFromPos(pos)->next;
|
|
|
|
|
(*par)->ParFromPos(pos)->next->previous =
|
|
|
|
|
lastbuffer->ParFromPos(lastbuffer->Last());
|
|
|
|
|
|
|
|
|
|
(*par)->ParFromPos(pos)->next = buf;
|
|
|
|
|
buf->previous = (*par)->ParFromPos(pos);
|
|
|
|
|
|
|
|
|
|
if ((*par)->ParFromPos(pos)->Next() == lastbuffer)
|
|
|
|
|
lastbuffer = *par;
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
(*par)->ParFromPos(pos)->PasteParagraph(current_view->buffer()->params);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#else
|
|
|
|
|
*endpar = (*par)->next->Next();
|
|
|
|
|
|
|
|
|
|
// paste it!
|
|
|
|
|
lastbuffer->next = (*par)->next;
|
|
|
|
|
(*par)->next->previous = lastbuffer;
|
|
|
|
|
|
|
|
|
|
(*par)->next = buf;
|
|
|
|
|
buf->previous = (*par);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
if ((*par)->Next() == lastbuffer)
|
|
|
|
|
lastbuffer = *par;
|
|
|
|
|
|
|
|
|
|
(*par)->PasteParagraph(current_view->buffer()->params);
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// store the new cursor position
|
2000-04-27 09:05:04 +00:00
|
|
|
|
*par = lastbuffer;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
pos = lastbuffer->Last();
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// maybe some pasting
|
|
|
|
|
if (lastbuffer->Next() && paste_the_end) {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
if (lastbuffer->Next()->HasSameLayout(lastbuffer)) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(current_view->buffer()->params);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
} else if (!lastbuffer->Next()->Last()) {
|
|
|
|
|
lastbuffer->Next()->MakeSameLayout(lastbuffer);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(current_view->buffer()->params);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
} else if (!lastbuffer->Last()) {
|
|
|
|
|
lastbuffer->MakeSameLayout(lastbuffer->next);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(current_view->buffer()->params);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
#else
|
|
|
|
|
if (lastbuffer->Next()->HasSameLayout(lastbuffer)) {
|
|
|
|
|
lastbuffer->PasteParagraph(current_view->buffer()->params);
|
|
|
|
|
} else if (!lastbuffer->Next()->Last()) {
|
|
|
|
|
lastbuffer->Next()->MakeSameLayout(lastbuffer);
|
|
|
|
|
lastbuffer->PasteParagraph(current_view->buffer()->params);
|
|
|
|
|
} else if (!lastbuffer->Last()) {
|
|
|
|
|
lastbuffer->MakeSameLayout(lastbuffer->next);
|
|
|
|
|
lastbuffer->PasteParagraph(current_view->buffer()->params);
|
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
} else
|
2000-05-26 16:13:01 +00:00
|
|
|
|
lastbuffer->Next()->StripLeadingSpaces(tc);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
// restore the simple cut buffer
|
|
|
|
|
buf = simple_cut_clone;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
int CutAndPaste::nrOfParagraphs()
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2000-04-11 22:55:29 +00:00
|
|
|
|
if (!buf) return 0;
|
|
|
|
|
|
|
|
|
|
int n = 1;
|
2000-04-19 01:42:55 +00:00
|
|
|
|
LyXParagraph * tmppar = buf;
|
2000-04-11 22:55:29 +00:00
|
|
|
|
while(tmppar->next) {
|
|
|
|
|
++n;
|
|
|
|
|
tmppar = tmppar->next;
|
|
|
|
|
}
|
|
|
|
|
return n;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
|
int CutAndPaste::SwitchLayoutsBetweenClasses(LyXTextClassList::size_type c1,
|
|
|
|
|
LyXTextClassList::size_type c2,
|
|
|
|
|
LyXParagraph * par)
|
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
|
|
|
|
if (!par || c1 == c2)
|
|
|
|
|
return ret;
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
par = par->FirstPhysicalPar();
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
while (par) {
|
|
|
|
|
string name = textclasslist.NameOfLayout(c1, par->layout);
|
|
|
|
|
int lay = 0;
|
|
|
|
|
pair<bool, LyXTextClass::LayoutList::size_type> pp =
|
|
|
|
|
textclasslist.NumberOfLayout(c2, name);
|
|
|
|
|
if (pp.first) {
|
|
|
|
|
lay = pp.second;
|
|
|
|
|
} else { // layout not found
|
|
|
|
|
// use default layout "Standard" (0)
|
|
|
|
|
lay = 0;
|
|
|
|
|
}
|
|
|
|
|
par->layout = lay;
|
|
|
|
|
|
|
|
|
|
if (name != textclasslist.NameOfLayout(c2, par->layout)) {
|
|
|
|
|
++ret;
|
2000-05-26 16:13:01 +00:00
|
|
|
|
string s = _("Layout had to be changed from\n")
|
|
|
|
|
+ name + _(" to ")
|
|
|
|
|
+ textclasslist.NameOfLayout(c2, par->layout)
|
|
|
|
|
+ _("\nbecause of class conversion from\n")
|
|
|
|
|
+ textclasslist.NameOfClass(c1) + _(" to ")
|
|
|
|
|
+ textclasslist.NameOfClass(c2);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
InsetError * new_inset = new InsetError(s);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
par->InsertInset(0, new_inset);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
par = par->next;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
bool CutAndPaste::checkPastePossible(LyXParagraph * par, int)
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2000-04-11 22:55:29 +00:00
|
|
|
|
if (!buf) return false;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-07-19 17:16:27 +00:00
|
|
|
|
#ifndef NEW_INSETS
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// be carefull with footnotes in footnotes
|
|
|
|
|
if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
|
|
|
|
|
// check whether the cut_buffer includes a footnote
|
2000-07-19 17:16:27 +00:00
|
|
|
|
LyXParagraph * tmppar = buf;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
while (tmppar && tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE)
|
|
|
|
|
tmppar = tmppar->next;
|
|
|
|
|
|
|
|
|
|
if (tmppar) {
|
|
|
|
|
WriteAlert(_("Impossible operation"),
|
|
|
|
|
_("Can't paste float into float!"),
|
|
|
|
|
_("Sorry."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
#endif
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|