On Fri, Mar 24, 2006 at 10:38:24AM +0200, Martin Vermeer wrote: > On Fri, Mar 24, 2006 at 04:55:21AM +0200, Martin Vermeer wrote: > > ... > > > Ah. So we have to add a forceDefaultParagraphs = true definition... > > No, not enough. In ERT, we intercept LFUN_PASTE in the dispatch routine > and reset the pasted paragraphs (these come from doInsertInset). > > The same problem exists for Note and Box. But there it isn't so > obnoxious as one could imagine wanting to put multiple paragraphs with > nonstandard layouts into one. For charstyle it makes no sense.
Came up with the attached patch. It adds a method to CutAndPaste for resetting the paragraph styles in the cut buffer 0. For this, there is now special code in insetert.C's dispatch of Paste, which I partly removed according to the FIXME there. (There is font-related code that has to stay.) Now the insertion of an inset "around" a selection tests whether the inset wants to force default paragraphs, and resets the cut buffer to that before inserting. This avoids adding special dispatch/paste code to every inset of that type, i.e., ERT, tabular, charstyle (new), and box. Does this look like a sane approach? - Martin
Index: CutAndPaste.C =================================================================== --- CutAndPaste.C (revision 13467) +++ CutAndPaste.C (working copy) @@ -614,6 +614,22 @@ void pasteParagraphList(LCursor & cur, P } +void resetParagraphStyles(LyXTextClass const & textclass, size_t sel_index) +{ + ParagraphList & plist = const_cast<ParagraphList &>(theCuts[sel_index].first); + ParagraphList::const_iterator const beg = plist.begin(); + ParagraphList::const_iterator const end = plist.end(); + ParagraphList::const_iterator it = beg; + for (; it != end; ++it) { + LyXLayout_ptr const & p = textclass.defaultLayout(); + lyx::pit_type pit = std::distance(beg, it); + plist[pit].layout(p); + plist[pit].setBeginOfBody(); + plist[pit].params().clear(); + } +} + + void pasteSelection(LCursor & cur, size_t sel_index) { // this does not make sense, if there is nothing to paste Index: CutAndPaste.h =================================================================== --- CutAndPaste.h (revision 13467) +++ CutAndPaste.h (working copy) @@ -60,7 +60,8 @@ void pasteSelection(LCursor & cur, size_ /// void pasteParagraphList(LCursor & cur, ParagraphList const & parlist, textclass_type textclass); - +/// +void resetParagraphStyles(LyXTextClass const & textclass, size_t); /** Needed to switch between different classes. This works * for a list of paragraphs beginning with the specified par. Index: text3.C =================================================================== --- text3.C (revision 13467) +++ text3.C (working copy) @@ -74,6 +74,7 @@ using lyx::cap::copySelection; using lyx::cap::cutSelection; using lyx::cap::pasteSelection; using lyx::cap::replaceSelection; +using lyx::cap::resetParagraphStyles; using lyx::support::isStrUnsignedInt; using lyx::support::token; @@ -268,8 +269,14 @@ bool doInsertInset(LCursor & cur, LyXTex if (edit) inset->edit(cur, true); - if (gotsel && pastesel) + if (gotsel && pastesel) { + // Reset paragraph style on cut buffer 0: + if (inset->forceDefaultParagraphs(cur.idx())) { + resetParagraphStyles(cur.buffer().params() + .getLyXTextClass(), 0); + } cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE)); + } return true; } Index: insets/insetert.C =================================================================== --- insets/insetert.C (revision 13467) +++ insets/insetert.C (working copy) @@ -249,14 +249,10 @@ void InsetERT::doDispatch(LCursor & cur, ParagraphList::iterator const end = paragraphs().end(); for (ParagraphList::iterator par = paragraphs().begin(); par != end; ++par) { - par->layout(layout); - // in case par had a manual label - par->setBeginOfBody(); pos_type const siz = par->size(); for (pos_type i = 0; i < siz; ++i) { par->setFont(i, font); } - par->params().clear(); } break; }
pgpph4SStVS4E.pgp
Description: PGP signature