2003-05-06 09:34:56 +00:00
|
|
|
|
/* \file CutAndPaste.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-06-28 01:23:11 +00:00
|
|
|
|
* \author Juergen Vigna
|
2003-05-06 09:34:56 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-06-28 01:23:11 +00:00
|
|
|
|
* \author Alfredo Braunstein
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-05-06 09:34:56 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
|
*/
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "CutAndPaste.h"
|
2000-06-08 23:16:16 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "buffer.h"
|
2003-05-20 16:51:31 +00:00
|
|
|
|
#include "errorlist.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2002-03-05 10:53:46 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2002-03-15 15:28:25 +00:00
|
|
|
|
#include "lyxtext.h"
|
2000-06-08 23:16:16 +00:00
|
|
|
|
#include "lyxcursor.h"
|
2001-12-07 18:40:24 +00:00
|
|
|
|
#include "iterators.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "lyxtextclasslist.h"
|
2002-08-12 08:16:01 +00:00
|
|
|
|
#include "undo_funcs.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include "gettext.h"
|
2002-08-20 19:41:13 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#include "debug.h"
|
2003-06-03 15:10:14 +00:00
|
|
|
|
#include "insets/insetinclude.h"
|
|
|
|
|
#include "insets/insettabular.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2003-04-30 10:32:01 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2003-05-06 09:34:56 +00:00
|
|
|
|
#include "support/limited_stack.h"
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
using std::endl;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
using std::pair;
|
2003-05-01 12:53:22 +00:00
|
|
|
|
using std::make_pair;
|
|
|
|
|
using std::for_each;
|
2003-06-17 15:33:49 +00:00
|
|
|
|
using std::vector;
|
2003-05-01 12:53:22 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
using namespace lyx::support;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
using lyx::pos_type;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
using lyx::textclass_type;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
|
|
|
|
|
|
typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
|
2000-04-19 01:42:55 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
|
CutStack cuts(10);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
|
|
|
|
|
|
std::vector<string>
|
2003-06-17 15:33:49 +00:00
|
|
|
|
CutAndPaste::availableSelections(Buffer const & buffer)
|
|
|
|
|
{
|
|
|
|
|
vector<string> selList;
|
|
|
|
|
|
|
|
|
|
CutStack::const_iterator cit = cuts.begin();
|
|
|
|
|
CutStack::const_iterator end = cuts.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
2003-06-19 13:55:31 +00:00
|
|
|
|
// we do not use cit-> here because gcc 2.9x does not
|
|
|
|
|
// like it (JMarc)
|
|
|
|
|
ParagraphList const & pars = (*cit).first;
|
2003-06-18 13:53:11 +00:00
|
|
|
|
string asciiSel;
|
|
|
|
|
ParagraphList::const_iterator pit = pars.begin();
|
|
|
|
|
ParagraphList::const_iterator pend = pars.end();
|
|
|
|
|
for (; pit != pend; ++pit) {
|
|
|
|
|
asciiSel += pit->asString(&buffer, false);
|
|
|
|
|
if (asciiSel.size() > 25) {
|
|
|
|
|
asciiSel.replace(22, string::npos, "...");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selList.push_back(asciiSel);
|
2003-06-17 15:33:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return selList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-10 14:39:45 +00:00
|
|
|
|
PitPosPair CutAndPaste::cutSelection(BufferParams const & params,
|
|
|
|
|
ParagraphList & pars,
|
2003-05-01 12:53:22 +00:00
|
|
|
|
ParagraphList::iterator startpit,
|
2003-04-29 09:40:49 +00:00
|
|
|
|
ParagraphList::iterator endpit,
|
2003-05-01 12:53:22 +00:00
|
|
|
|
int startpos, int endpos,
|
2003-04-29 09:40:49 +00:00
|
|
|
|
textclass_type tc, bool doclear)
|
2001-04-17 13:48:09 +00:00
|
|
|
|
{
|
2003-04-30 10:32:01 +00:00
|
|
|
|
copySelection(startpit, endpit, startpos, endpos, tc);
|
2003-06-10 14:39:45 +00:00
|
|
|
|
return eraseSelection(params, pars, startpit, endpit, startpos,
|
2003-04-29 09:40:49 +00:00
|
|
|
|
endpos, doclear);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
2003-06-10 14:39:45 +00:00
|
|
|
|
PitPosPair CutAndPaste::eraseSelection(BufferParams const & params,
|
|
|
|
|
ParagraphList & pars,
|
2003-05-01 12:53:22 +00:00
|
|
|
|
ParagraphList::iterator startpit,
|
2003-04-29 09:40:49 +00:00
|
|
|
|
ParagraphList::iterator endpit,
|
|
|
|
|
int startpos, int endpos, bool doclear)
|
|
|
|
|
{
|
|
|
|
|
if (startpit == pars.end() || (startpos > startpit->size()))
|
2003-04-30 10:32:01 +00:00
|
|
|
|
return PitPosPair(endpit, endpos);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
if (endpit == pars.end() || startpit == endpit) {
|
|
|
|
|
endpos -= startpit->erase(startpos, endpos);
|
2003-04-30 10:32:01 +00:00
|
|
|
|
return PitPosPair(endpit, endpos);
|
2003-04-29 09:40:49 +00:00
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// clear end/begin fragments of the first/last par in selection
|
2003-04-29 09:40:49 +00:00
|
|
|
|
bool all_erased = true;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
startpit->erase(startpos, startpit->size());
|
|
|
|
|
if (startpit->size() != startpos)
|
|
|
|
|
all_erased = false;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
endpos -= endpit->erase(0, endpos);
|
|
|
|
|
if (endpos != 0)
|
|
|
|
|
all_erased = false;
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
// Loop through the deleted pars if any, erasing as needed
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
ParagraphList::iterator pit = boost::next(startpit);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
while (pit != endpit && pit != pars.end()) {
|
|
|
|
|
ParagraphList::iterator const next = boost::next(pit);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// "erase" the contents of the par
|
2003-04-29 09:40:49 +00:00
|
|
|
|
pit->erase(0, pit->size());
|
|
|
|
|
if (!pit->size()) {
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// remove the par if it's now empty
|
2003-04-29 09:40:49 +00:00
|
|
|
|
pars.erase(pit);
|
|
|
|
|
} else
|
|
|
|
|
all_erased = false;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
pit = next;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
#if 0 // FIXME: why for cut but not copy ?
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// the cut selection should begin with standard layout
|
|
|
|
|
if (realcut) {
|
|
|
|
|
buf->params().clear();
|
|
|
|
|
buf->bibkey = 0;
|
|
|
|
|
buf->layout(textclasslist[buffer->params.textclass].defaultLayoutName());
|
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
#endif
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-29 09:40:49 +00:00
|
|
|
|
if (boost::next(startpit) == pars.end())
|
2003-04-30 10:32:01 +00:00
|
|
|
|
return PitPosPair(endpit, endpos);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (doclear) {
|
2003-04-29 09:40:49 +00:00
|
|
|
|
boost::next(startpit)->stripLeadingSpaces();
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
2002-03-05 23:02:37 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// paste the paragraphs again, if possible
|
2003-05-01 12:53:22 +00:00
|
|
|
|
if (all_erased &&
|
2003-04-29 10:56:15 +00:00
|
|
|
|
(startpit->hasSameLayout(*boost::next(startpit)) ||
|
2003-04-29 09:40:49 +00:00
|
|
|
|
boost::next(startpit)->empty())) {
|
2003-06-10 14:39:45 +00:00
|
|
|
|
mergeParagraph(params, pars, startpit);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// this because endpar gets deleted here!
|
2003-04-29 09:40:49 +00:00
|
|
|
|
endpit = startpit;
|
|
|
|
|
endpos = startpos;
|
2000-05-22 11:08:25 +00:00
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
2003-04-30 10:32:01 +00:00
|
|
|
|
return PitPosPair(endpit, endpos);
|
2003-04-29 09:40:49 +00:00
|
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-05-01 12:53:22 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct resetOwnerAndChanges {
|
|
|
|
|
void operator()(Paragraph & p) {
|
|
|
|
|
p.cleanChanges();
|
|
|
|
|
p.setInsetOwner(0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
|
2003-04-30 10:32:01 +00:00
|
|
|
|
ParagraphList::iterator endpit,
|
2003-03-06 21:01:04 +00:00
|
|
|
|
int start, int end, textclass_type tc)
|
2001-04-17 13:48:09 +00:00
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
|
Assert(0 <= start && start <= startpit->size());
|
|
|
|
|
Assert(0 <= end && end <= endpit->size());
|
|
|
|
|
Assert(startpit != endpit || start <= end);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-05-06 09:34:56 +00:00
|
|
|
|
ParagraphList paragraphs;
|
2003-05-01 12:53:22 +00:00
|
|
|
|
|
|
|
|
|
// Clone the paragraphs within the selection.
|
2003-04-30 10:32:01 +00:00
|
|
|
|
ParagraphList::iterator postend = boost::next(endpit);
|
2003-05-01 12:53:22 +00:00
|
|
|
|
|
|
|
|
|
paragraphs.assign(startpit, postend);
|
|
|
|
|
for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-30 10:32:01 +00:00
|
|
|
|
// Cut out the end of the last paragraph.
|
|
|
|
|
Paragraph & back = paragraphs.back();
|
2003-05-01 12:53:22 +00:00
|
|
|
|
back.erase(end, back.size());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-30 10:32:01 +00:00
|
|
|
|
// Cut out the begin of the first paragraph
|
|
|
|
|
Paragraph & front = paragraphs.front();
|
2003-05-01 12:53:22 +00:00
|
|
|
|
front.erase(0, start);
|
|
|
|
|
|
2003-05-06 09:34:56 +00:00
|
|
|
|
cuts.push(make_pair(paragraphs, tc));
|
|
|
|
|
|
2001-04-17 13:48:09 +00:00
|
|
|
|
return true;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2003-04-30 10:32:01 +00:00
|
|
|
|
pair<PitPosPair, ParagraphList::iterator>
|
2003-06-10 14:39:45 +00:00
|
|
|
|
CutAndPaste::pasteSelection(Buffer const & buffer,
|
|
|
|
|
ParagraphList & pars,
|
2003-04-30 10:32:01 +00:00
|
|
|
|
ParagraphList::iterator pit, int pos,
|
2003-05-20 16:51:31 +00:00
|
|
|
|
textclass_type tc,
|
|
|
|
|
ErrorList & errorlist)
|
2003-05-06 09:34:56 +00:00
|
|
|
|
{
|
2003-06-10 14:39:45 +00:00
|
|
|
|
return pasteSelection(buffer, pars, pit, pos, tc, 0, errorlist);
|
2003-05-06 09:34:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
|
|
2003-05-06 09:34:56 +00:00
|
|
|
|
pair<PitPosPair, ParagraphList::iterator>
|
2003-06-10 14:39:45 +00:00
|
|
|
|
CutAndPaste::pasteSelection(Buffer const & buffer,
|
|
|
|
|
ParagraphList & pars,
|
2003-05-06 09:34:56 +00:00
|
|
|
|
ParagraphList::iterator pit, int pos,
|
2003-05-20 16:51:31 +00:00
|
|
|
|
textclass_type tc, size_t cut_index,
|
|
|
|
|
ErrorList & errorlist)
|
2001-04-17 13:48:09 +00:00
|
|
|
|
{
|
2003-03-06 21:01:04 +00:00
|
|
|
|
if (!checkPastePossible())
|
2003-05-01 12:53:22 +00:00
|
|
|
|
return make_pair(PitPosPair(pit, pos), pit);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
Assert (pos <= pit->size());
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-05-01 15:43:58 +00:00
|
|
|
|
// Make a copy of the CaP paragraphs.
|
2003-05-06 09:34:56 +00:00
|
|
|
|
ParagraphList simple_cut_clone = cuts[cut_index].first;
|
|
|
|
|
textclass_type const textclass = cuts[cut_index].second;
|
2003-05-01 13:12:43 +00:00
|
|
|
|
|
2003-05-01 15:43:58 +00:00
|
|
|
|
// Now remove all out of the pars which is NOT allowed in the
|
2003-05-01 13:12:43 +00:00
|
|
|
|
// new environment and set also another font if that is required.
|
2003-05-01 15:43:58 +00:00
|
|
|
|
|
2003-05-06 09:34:56 +00:00
|
|
|
|
// Make sure there is no class difference.
|
2003-05-21 21:20:50 +00:00
|
|
|
|
SwitchLayoutsBetweenClasses(textclass, tc, simple_cut_clone,
|
2003-05-20 16:51:31 +00:00
|
|
|
|
errorlist);
|
2003-05-06 09:34:56 +00:00
|
|
|
|
|
2003-05-01 13:22:07 +00:00
|
|
|
|
ParagraphList::iterator tmpbuf = simple_cut_clone.begin();
|
2003-04-30 10:32:01 +00:00
|
|
|
|
int depth_delta = pit->params().depth() - tmpbuf->params().depth();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-04-30 10:32:01 +00:00
|
|
|
|
Paragraph::depth_type max_depth = pit->getMaxDepthAfter();
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-05-01 13:22:07 +00:00
|
|
|
|
for (; tmpbuf != simple_cut_clone.end(); ++tmpbuf) {
|
2003-03-08 15:58:28 +00:00
|
|
|
|
// If we have a negative jump so that the depth would
|
|
|
|
|
// go below 0 depth then we have to redo the delta to
|
|
|
|
|
// this new max depth level so that subsequent
|
|
|
|
|
// paragraphs are aligned correctly to this paragraph
|
|
|
|
|
// at level 0.
|
|
|
|
|
if ((int(tmpbuf->params().depth()) + depth_delta) < 0)
|
|
|
|
|
depth_delta = 0;
|
2003-05-01 15:43:58 +00:00
|
|
|
|
|
2003-05-01 14:45:04 +00:00
|
|
|
|
// Set the right depth so that we are not too deep or shallow.
|
2003-03-08 15:58:28 +00:00
|
|
|
|
tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
|
|
|
|
|
if (tmpbuf->params().depth() > max_depth)
|
|
|
|
|
tmpbuf->params().depth(max_depth);
|
2003-05-01 13:12:43 +00:00
|
|
|
|
|
|
|
|
|
// Only set this from the 2nd on as the 2nd depends
|
|
|
|
|
// for maxDepth still on pit.
|
2003-05-01 15:43:58 +00:00
|
|
|
|
if (tmpbuf != simple_cut_clone.begin())
|
2003-03-08 15:58:28 +00:00
|
|
|
|
max_depth = tmpbuf->getMaxDepthAfter();
|
2003-05-01 13:12:43 +00:00
|
|
|
|
|
|
|
|
|
// Set the inset owner of this paragraph.
|
2003-04-30 10:32:01 +00:00
|
|
|
|
tmpbuf->setInsetOwner(pit->inInset());
|
2003-03-08 15:58:28 +00:00
|
|
|
|
for (pos_type i = 0; i < tmpbuf->size(); ++i) {
|
|
|
|
|
if (tmpbuf->getChar(i) == Paragraph::META_INSET) {
|
2003-04-30 10:32:01 +00:00
|
|
|
|
if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode())) {
|
2003-03-08 15:58:28 +00:00
|
|
|
|
tmpbuf->erase(i--);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2003-06-10 14:39:45 +00:00
|
|
|
|
LyXFont f1 = tmpbuf->getFont(buffer.params, i, outerFont(pit, pars));
|
2003-03-08 15:58:28 +00:00
|
|
|
|
LyXFont f2 = f1;
|
2003-04-30 10:32:01 +00:00
|
|
|
|
if (!pit->checkInsertChar(f1)) {
|
2003-03-08 15:58:28 +00:00
|
|
|
|
tmpbuf->erase(i--);
|
|
|
|
|
} else if (f1 != f2) {
|
|
|
|
|
tmpbuf->setFont(i, f1);
|
2001-12-05 15:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-17 13:48:09 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-05-01 13:12:43 +00:00
|
|
|
|
// Make the buf exactly the same layout than
|
|
|
|
|
// the cursor paragraph.
|
2003-05-01 13:22:07 +00:00
|
|
|
|
simple_cut_clone.begin()->makeSameLayout(*pit);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
|
// Prepare the paragraphs and insets for insertion
|
|
|
|
|
// A couple of insets store buffer references so need
|
|
|
|
|
// updating
|
|
|
|
|
ParIterator fpit(simple_cut_clone.begin(), simple_cut_clone);
|
|
|
|
|
ParIterator fend(simple_cut_clone.end(), simple_cut_clone);
|
|
|
|
|
|
|
|
|
|
for (; fpit != fend; ++fpit) {
|
|
|
|
|
InsetList::iterator lit = fpit->insetlist.begin();
|
|
|
|
|
InsetList::iterator eit = fpit->insetlist.end();
|
|
|
|
|
|
|
|
|
|
for (; lit != eit; ++lit) {
|
|
|
|
|
switch (lit->inset->lyxCode()) {
|
|
|
|
|
case Inset::INCLUDE_CODE: {
|
|
|
|
|
InsetInclude * ii = static_cast<InsetInclude*>(lit->inset);
|
|
|
|
|
InsetInclude::Params ip = ii->params();
|
2003-06-10 14:39:45 +00:00
|
|
|
|
ip.masterFilename_ = buffer.fileName();
|
2003-06-03 15:10:14 +00:00
|
|
|
|
ii->set(ip);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-06-10 14:39:45 +00:00
|
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
|
case Inset::TABULAR_CODE: {
|
|
|
|
|
InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
|
2003-06-10 14:39:45 +00:00
|
|
|
|
it->buffer(const_cast<Buffer*>(&buffer));
|
2003-06-03 15:10:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-06-10 14:39:45 +00:00
|
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
|
default:
|
|
|
|
|
break; // nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-08 15:58:28 +00:00
|
|
|
|
bool paste_the_end = false;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-05-01 13:12:43 +00:00
|
|
|
|
// Open the paragraph for inserting the buf
|
|
|
|
|
// if necessary.
|
2003-05-01 15:43:58 +00:00
|
|
|
|
if (pit->size() > pos || boost::next(pit) == pars.end()) {
|
2003-06-10 14:39:45 +00:00
|
|
|
|
breakParagraphConservative(buffer.params,
|
2003-05-01 13:04:16 +00:00
|
|
|
|
pars, pit, pos);
|
2003-03-08 15:58:28 +00:00
|
|
|
|
paste_the_end = true;
|
|
|
|
|
}
|
2003-05-01 13:22:07 +00:00
|
|
|
|
|
2003-05-01 13:12:43 +00:00
|
|
|
|
// Set the end for redoing later.
|
2003-04-30 10:32:01 +00:00
|
|
|
|
ParagraphList::iterator endpit = boost::next(boost::next(pit));
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-05-01 13:12:43 +00:00
|
|
|
|
// Paste it!
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-05-01 14:45:04 +00:00
|
|
|
|
ParagraphList::iterator past_pit = boost::next(pit);
|
2003-05-01 22:37:02 +00:00
|
|
|
|
pars.splice(past_pit, simple_cut_clone);
|
2003-05-01 14:45:04 +00:00
|
|
|
|
ParagraphList::iterator last_paste = boost::prior(past_pit);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-05-01 14:45:04 +00:00
|
|
|
|
// If we only inserted one paragraph.
|
|
|
|
|
if (boost::next(pit) == last_paste)
|
|
|
|
|
last_paste = pit;
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-06-10 14:39:45 +00:00
|
|
|
|
mergeParagraph(buffer.params, pars, pit);
|
2003-05-01 15:43:58 +00:00
|
|
|
|
|
2003-05-01 13:12:43 +00:00
|
|
|
|
// Store the new cursor position.
|
2003-05-01 14:45:04 +00:00
|
|
|
|
pit = last_paste;
|
|
|
|
|
pos = last_paste->size();
|
|
|
|
|
|
2003-05-01 13:12:43 +00:00
|
|
|
|
// Maybe some pasting.
|
2003-05-01 15:43:58 +00:00
|
|
|
|
#warning CHECK! Are we comparing last_paste to the wrong list here? (Lgb)
|
2003-05-01 22:37:02 +00:00
|
|
|
|
if (boost::next(last_paste) != pars.end() &&
|
2003-05-01 14:45:04 +00:00
|
|
|
|
paste_the_end) {
|
|
|
|
|
if (boost::next(last_paste)->hasSameLayout(*last_paste)) {
|
2003-06-10 14:39:45 +00:00
|
|
|
|
mergeParagraph(buffer.params, pars,
|
2003-05-01 14:45:04 +00:00
|
|
|
|
last_paste);
|
|
|
|
|
} else if (boost::next(last_paste)->empty()) {
|
|
|
|
|
boost::next(last_paste)->makeSameLayout(*last_paste);
|
2003-06-10 14:39:45 +00:00
|
|
|
|
mergeParagraph(buffer.params, pars,
|
2003-05-01 14:45:04 +00:00
|
|
|
|
last_paste);
|
|
|
|
|
} else if (last_paste->empty()) {
|
|
|
|
|
last_paste->makeSameLayout(*boost::next(last_paste));
|
2003-06-10 14:39:45 +00:00
|
|
|
|
mergeParagraph(buffer.params, pars,
|
2003-05-01 14:45:04 +00:00
|
|
|
|
last_paste);
|
2003-03-08 15:58:28 +00:00
|
|
|
|
} else
|
2003-05-01 14:45:04 +00:00
|
|
|
|
boost::next(last_paste)->stripLeadingSpaces();
|
2003-03-08 15:58:28 +00:00
|
|
|
|
}
|
2003-03-17 16:25:00 +00:00
|
|
|
|
|
2003-05-01 12:53:22 +00:00
|
|
|
|
return make_pair(PitPosPair(pit, pos), endpit);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2003-05-06 09:34:56 +00:00
|
|
|
|
return cuts.empty() ? 0 : cuts[0].first.size();
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2001-11-29 17:12:21 +00:00
|
|
|
|
int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
|
2001-12-15 14:34:17 +00:00
|
|
|
|
textclass_type c2,
|
2003-05-20 16:51:31 +00:00
|
|
|
|
ParagraphList & pars,
|
|
|
|
|
ErrorList & errorlist)
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
|
Assert(!pars.empty());
|
2003-05-06 09:34:56 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
int ret = 0;
|
2003-05-01 15:43:58 +00:00
|
|
|
|
if (c1 == c2)
|
2001-04-03 08:34:52 +00:00
|
|
|
|
return ret;
|
2001-12-07 18:40:24 +00:00
|
|
|
|
|
2002-04-24 21:45:29 +00:00
|
|
|
|
LyXTextClass const & tclass1 = textclasslist[c1];
|
|
|
|
|
LyXTextClass const & tclass2 = textclasslist[c2];
|
2003-05-21 21:20:50 +00:00
|
|
|
|
ParIterator end = ParIterator(pars.end(), pars);
|
|
|
|
|
for (ParIterator it = ParIterator(pars.begin(), pars); it != end; ++it) {
|
2003-06-12 11:09:55 +00:00
|
|
|
|
string const name = it->layout()->name();
|
2002-04-24 21:45:29 +00:00
|
|
|
|
bool hasLayout = tclass2.hasLayout(name);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-12-01 21:10:37 +00:00
|
|
|
|
if (hasLayout)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
it->layout(tclass2[name]);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
else
|
2003-06-12 11:09:55 +00:00
|
|
|
|
it->layout(tclass2.defaultLayout());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-04-24 21:45:29 +00:00
|
|
|
|
if (!hasLayout && name != tclass1.defaultLayoutName()) {
|
2001-04-03 08:34:52 +00:00
|
|
|
|
++ret;
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string const s = bformat(
|
|
|
|
|
_("Layout had to be changed from\n%1$s to %2$s\n"
|
|
|
|
|
"because of class conversion from\n%3$s to %4$s"),
|
2003-06-12 11:09:55 +00:00
|
|
|
|
name, it->layout()->name(), tclass1.name(), tclass2.name());
|
2003-05-06 09:34:56 +00:00
|
|
|
|
// To warn the user that something had to be done.
|
2003-05-21 21:20:50 +00:00
|
|
|
|
errorlist.push_back(ErrorItem("Changed Layout", s,
|
2003-06-12 11:09:55 +00:00
|
|
|
|
it->id(), 0,
|
|
|
|
|
it->size()));
|
2001-04-03 08:34:52 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2003-03-06 21:01:04 +00:00
|
|
|
|
bool CutAndPaste::checkPastePossible()
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2003-05-06 09:34:56 +00:00
|
|
|
|
return !cuts.empty() && !cuts[0].first.empty();
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|