Some cleanup, and prepare for new feature.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6937 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-05-06 09:34:56 +00:00
parent ebdfad1c62
commit 525259940d
7 changed files with 93 additions and 63 deletions

View File

@ -1,10 +1,23 @@
2003-05-06 Lars Gullik Bjønnes <larsbj@gullik.net>
* CutAndPaste.h: Update file header.
* CutAndPaste.C: Update file header.
Store the parts cut out of the Document in a limited_stack.
(copySelection): adjust
(pasteSelection): new function, takes the index in the limited stack.
(nrOfParagraphs): adjust
(SwitchLayoutsBetweenClasses): Change to take a ParagraphList&,
simplify error inset insertion.
(checkPastePossible): adjust
2003-05-06 John Levon <levon@movementarian.org>
* text2.C: don't cast wrap inset to float
2003-05-05 André Pönitz <poenitz@gmx.net>
* iterator.C:
* iterator.C:
* undo_funcs.C: use getParagraphs() instead of getFirstParagraph()
* buffer.[Ch]: new function hasParWithId() to help to get rid of a
@ -19,7 +32,7 @@
* lyxtextclass.h:
* lyxtextclasslist.C: Handle new textclass.lst format; new method
isTeXClassAvailable()
2003-05-03 John Levon <levon@movementarian.org>
* BufferView.h:

View File

@ -1,11 +1,12 @@
/* This file is part of
* ======================================================
/* \file CutAndPaste.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* LyX, The Document Processor
* \author Jurgen Vigna
* \author Lars Gullik Bjønnes
*
* Copyright 1995-2001 The LyX Team.
*
* ====================================================== */
* Full author contact details are available in file CREDITS
*/
#include <config.h>
@ -27,6 +28,7 @@
#include "support/BoostFormat.h"
#include "support/LAssert.h"
#include "support/limited_stack.h"
using std::endl;
using std::pair;
@ -59,9 +61,7 @@ extern BufferView * current_view;
namespace {
// FIXME: stupid name
ParagraphList paragraphs;
textclass_type textclass = 0;
limited_stack<pair<ParagraphList, textclass_type> > cuts(10);
} // namespace anon
@ -172,7 +172,7 @@ bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
lyx::Assert(0 <= end && end <= endpit->size());
lyx::Assert(startpit != endpit || start <= end);
textclass = tc;
ParagraphList paragraphs;
// Clone the paragraphs within the selection.
ParagraphList::iterator postend = boost::next(endpit);
@ -188,6 +188,8 @@ bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
Paragraph & front = paragraphs.front();
front.erase(0, start);
cuts.push(make_pair(paragraphs, tc));
return true;
}
@ -196,6 +198,14 @@ pair<PitPosPair, ParagraphList::iterator>
CutAndPaste::pasteSelection(ParagraphList & pars,
ParagraphList::iterator pit, int pos,
textclass_type tc)
{
return pasteSelection(pars, pit, pos, tc, 0);
}
pair<PitPosPair, ParagraphList::iterator>
CutAndPaste::pasteSelection(ParagraphList & pars,
ParagraphList::iterator pit, int pos,
textclass_type tc, size_t cut_index)
{
if (!checkPastePossible())
return make_pair(PitPosPair(pit, pos), pit);
@ -203,19 +213,18 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
lyx::Assert (pos <= pit->size());
// Make a copy of the CaP paragraphs.
ParagraphList simple_cut_clone = paragraphs;
ParagraphList simple_cut_clone = cuts[cut_index].first;
textclass_type const textclass = cuts[cut_index].second;
// Now remove all out of the pars which is NOT allowed in the
// new environment and set also another font if that is required.
// Make sure there is no class difference.
SwitchLayoutsBetweenClasses(textclass, tc, simple_cut_clone);
ParagraphList::iterator tmpbuf = simple_cut_clone.begin();
int depth_delta = pit->params().depth() - tmpbuf->params().depth();
// Make sure there is no class difference.
#warning current_view used here
SwitchLayoutsBetweenClasses(textclass, tc, &*tmpbuf,
current_view->buffer()->params);
Paragraph::depth_type max_depth = pit->getMaxDepthAfter();
for (; tmpbuf != simple_cut_clone.end(); ++tmpbuf) {
@ -314,16 +323,17 @@ CutAndPaste::pasteSelection(ParagraphList & pars,
int CutAndPaste::nrOfParagraphs()
{
return paragraphs.size();
return cuts.empty() ? 0 : cuts[0].first.size();
}
int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
textclass_type c2,
Paragraph * par,
BufferParams const & /*bparams*/)
ParagraphList & pars)
{
lyx::Assert(par);
lyx::Assert(!pars.empty());
Paragraph * par = &*pars.begin();
int ret = 0;
if (c1 == c2)
@ -363,15 +373,9 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
+ tclass1.name() + _(" to ")
+ tclass2.name();
#endif
freezeUndo();
// To warn the user that something had to be done.
InsetError * new_inset = new InsetError(s);
LyXText * txt = current_view->getLyXText();
LyXCursor cur = txt->cursor;
txt->setCursorIntern(par, 0);
txt->insertInset(new_inset);
txt->fullRebreak();
txt->setCursorIntern(cur.par(), cur.pos());
unFreezeUndo();
par->insertInset(0, new_inset);
}
}
return ret;
@ -380,5 +384,5 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1,
bool CutAndPaste::checkPastePossible()
{
return !paragraphs.empty();
return !cuts.empty() && !cuts[0].first.empty();
}

View File

@ -1,12 +1,13 @@
// -*- C++ -*-
/* This file is part of
* ======================================================
/* \file CutAndPaste.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* LyX, The Document Processor
* \author Jurgen Vigna
* \author Lars Gullik Bjønnes
*
* Copyright 1995-2001 the LyX Team.
*
* ====================================================== */
* Full author contact details are available in file CREDITS
*/
#ifndef CUTANDPASTE_H
#define CUTANDPASTE_H
@ -22,17 +23,17 @@ class LyXTextClass;
namespace CutAndPaste {
///
PitPosPair cutSelection(ParagraphList & pars,
ParagraphList::iterator startpit,
ParagraphList::iterator startpit,
ParagraphList::iterator endpit,
int start, int end, lyx::textclass_type tc,
bool doclear = false);
///
PitPosPair eraseSelection(ParagraphList & pars,
ParagraphList::iterator startpit,
ParagraphList::iterator startpit,
ParagraphList::iterator endpit,
int start, int end, bool doclear = false);
///
bool copySelection(ParagraphList::iterator startpit,
bool copySelection(ParagraphList::iterator startpit,
ParagraphList::iterator endpit,
int start, int end, lyx::textclass_type tc);
///
@ -41,17 +42,23 @@ pasteSelection(ParagraphList & pars,
ParagraphList::iterator pit, int pos,
lyx::textclass_type tc);
///
std::pair<PitPosPair, ParagraphList::iterator>
pasteSelection(ParagraphList & pars,
ParagraphList::iterator pit, int pos,
lyx::textclass_type tc,
size_t cuts_index);
///
int nrOfParagraphs();
/** needed to switch between different classes this works
/** Needed to switch between different classes this works
for a list of paragraphs beginning with the specified par
return value is the number of wrong conversions
return value is the number of wrong conversions.
*/
int SwitchLayoutsBetweenClasses(lyx::textclass_type c1,
lyx::textclass_type c2,
Paragraph * par,
BufferParams const & bparams);
ParagraphList & par);
///
bool checkPastePossible();

View File

@ -1,3 +1,8 @@
2003-05-06 Lars Gullik Bjønnes <larsbj@gullik.net>
* ControlDocument.C (classApply): adjust call to
SwitchLayoutsBetweenClasses.
2003-04-25 Lars Gullik Bjønnes <larsbj@gullik.net>
* ControlDocument.C (setLanguage): call updateDocLang when not

View File

@ -96,7 +96,7 @@ void ControlDocument::setLanguage()
Language const * newL = bp_->language;
if (oldL != newL) {
if (oldL->RightToLeft() == newL->RightToLeft()
&& !lv_.buffer()->isMultiLingual())
lv_.buffer()->changeLanguage(oldL, newL);
@ -123,8 +123,7 @@ void ControlDocument::classApply()
lv_.message(_("Converting document to new document class..."));
int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
old_class, new_class,
&*(lv_.buffer()->paragraphs.begin()),
lv_.buffer()->params);
lv_.buffer()->paragraphs);
if (!ret)
return;

View File

@ -1,3 +1,7 @@
2003-05-06 Lars Gullik Bjønnes <larsbj@gullik.net>
* limited_stack.h: Change some comments, simplify a couple of
class functions.
2003-02-21 André Pönitz <poenitz@gmx.net>
@ -32,7 +36,7 @@
2003-02-25 Alfredo Braunstein <abraunst@libero.it>
* forkedcontr.C (timer): remove bogus continue
2003-02-25 Alfredo Braunstein <abraunst@libero.it>
* forkedcallqueue.[Ch]: added

View File

@ -15,7 +15,7 @@
#include <deque>
/**
* limited_stack - a stack of limited size
* limited_stack - A stack of limited size.
*
* Like a normal stack, but elements falling out
* of the bottom are destructed.
@ -32,29 +32,27 @@ public:
limit_ = limit;
}
/// return the top element
/// Return the top element.
value_type top() {
return c_.front();
}
/// pop and throw away the top element
/// Pop and throw away the top element.
void pop() {
c_.pop_front();
}
/// return true if the stack is empty
/// Return true if the stack is empty.
bool empty() const {
return c_.size() == 0;
return c_.empty();
}
/// clear all elements, deleting them
/// Clear all elements, deleting them.
void clear() {
while (!c_.empty()) {
c_.pop_back();
}
c_.clear();
}
/// push an item on to the stack, deleting the
/// Push an item on to the stack, deleting the
/// bottom item on overflow.
void push(value_type const & v) {
c_.push_front(v);
@ -63,23 +61,23 @@ public:
}
}
/// direct read access to intermediate elements
/// Direct read access to intermediate elements.
T const & operator[](size_type pos) const {
return c_[pos];
}
/// read access to used size
/// Read access to used size.
size_type size() const {
return c_.size();
}
private:
/// internal contents
/// Internal contents.
container_type c_;
/// the maximum number elements stored
/// The maximum number elements stored.
size_type limit_;
};
// make pointer type an error.
// Make pointer type an error.
template <typename T>
class limited_stack<T*>;