From 525259940d40d08d3911e8b055f9e3a546267504 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Tue, 6 May 2003 09:34:56 +0000 Subject: [PATCH] Some cleanup, and prepare for new feature. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6937 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 17 +++++- src/CutAndPaste.C | 62 +++++++++++---------- src/CutAndPaste.h | 33 ++++++----- src/frontends/controllers/ChangeLog | 5 ++ src/frontends/controllers/ControlDocument.C | 5 +- src/support/ChangeLog | 6 +- src/support/limited_stack.h | 28 +++++----- 7 files changed, 93 insertions(+), 63 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 5a76c667b1..966e8d8d4d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,10 +1,23 @@ +2003-05-06 Lars Gullik Bjønnes + + * 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 * text2.C: don't cast wrap inset to float 2003-05-05 André Pönitz - * 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 * BufferView.h: diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 2e77087eb3..53167debc2 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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 @@ -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 > 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 CutAndPaste::pasteSelection(ParagraphList & pars, ParagraphList::iterator pit, int pos, textclass_type tc) +{ + return pasteSelection(pars, pit, pos, tc, 0); +} + +pair +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(); } diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index dbb7a297bb..860703ef94 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -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 +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(); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 38ae48d7d3..625a811144 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2003-05-06 Lars Gullik Bjønnes + + * ControlDocument.C (classApply): adjust call to + SwitchLayoutsBetweenClasses. + 2003-04-25 Lars Gullik Bjønnes * ControlDocument.C (setLanguage): call updateDocLang when not diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index 18461bf408..dd23125bab 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -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; diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 3fa01a88db..66008b983b 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,7 @@ +2003-05-06 Lars Gullik Bjønnes + + * limited_stack.h: Change some comments, simplify a couple of + class functions. 2003-02-21 André Pönitz @@ -32,7 +36,7 @@ 2003-02-25 Alfredo Braunstein * forkedcontr.C (timer): remove bogus continue - + 2003-02-25 Alfredo Braunstein * forkedcallqueue.[Ch]: added diff --git a/src/support/limited_stack.h b/src/support/limited_stack.h index fa05691ce5..f56d0c3ca6 100644 --- a/src/support/limited_stack.h +++ b/src/support/limited_stack.h @@ -15,7 +15,7 @@ #include /** - * 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 class limited_stack; -- 2.39.2