Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

CutAndPaste Namespace Reference


Functions

PitPosPair cutSelection (BufferParams const &params, ParagraphList &pars, ParagraphList::iterator startpit, ParagraphList::iterator endpit, int start, int end, lyx::textclass_type tc, bool doclear=false)
PitPosPair eraseSelection (BufferParams const &params, ParagraphList &pars, ParagraphList::iterator startpit, ParagraphList::iterator endpit, int start, int end, bool doclear=false)
bool copySelection (ParagraphList::iterator startpit, ParagraphList::iterator endpit, int start, int end, lyx::textclass_type tc)
std::pair< PitPosPair, ParagraphList::iterator > pasteSelection (Buffer const &buffer, ParagraphList &pars, ParagraphList::iterator pit, int pos, lyx::textclass_type tc, ErrorList &)
std::pair< PitPosPair, ParagraphList::iterator > pasteSelection (Buffer const &buffer, ParagraphList &pars, ParagraphList::iterator pit, int pos, lyx::textclass_type tc, size_t cuts_indexm, ErrorList &)
int nrOfParagraphs ()
int SwitchLayoutsBetweenClasses (lyx::textclass_type c1, lyx::textclass_type c2, ParagraphList &par, ErrorList &)
 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. More...

bool checkPastePossible ()


Function Documentation

bool CutAndPaste::checkPastePossible  
 

Definition at line 420 of file CutAndPaste.C.

Referenced by LyXText::pasteSelection.

00421 {
00422         return !cuts.empty() && !cuts[0].first.empty();
00423 }

bool CutAndPaste::copySelection ParagraphList::iterator    startpit,
ParagraphList::iterator    endpit,
int    start,
int    end,
lyx::textclass_type    tc
 

Definition at line 180 of file CutAndPaste.C.

Referenced by LyXText::copySelection.

00183 {
00184         Assert(0 <= start && start <= startpit->size());
00185         Assert(0 <= end && end <= endpit->size());
00186         Assert(startpit != endpit || start <= end);
00187 
00188         ParagraphList paragraphs;
00189 
00190         // Clone the paragraphs within the selection.
00191         ParagraphList::iterator postend = boost::next(endpit);
00192 
00193         paragraphs.assign(startpit, postend);
00194         for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
00195 
00196         // Cut out the end of the last paragraph.
00197         Paragraph & back = paragraphs.back();
00198         back.erase(end, back.size());
00199 
00200         // Cut out the begin of the first paragraph
00201         Paragraph & front = paragraphs.front();
00202         front.erase(0, start);
00203 
00204         cuts.push(make_pair(paragraphs, tc));
00205 
00206         return true;
00207 }

PitPosPair CutAndPaste::cutSelection BufferParams const &    params,
ParagraphList   pars,
ParagraphList::iterator    startpit,
ParagraphList::iterator    endpit,
int    start,
int    end,
lyx::textclass_type    tc,
bool    doclear = false
 

Definition at line 84 of file CutAndPaste.C.

Referenced by LyXText::cutSelection.

00090 {
00091         copySelection(startpit, endpit, startpos, endpos, tc);
00092         return eraseSelection(params, pars, startpit, endpit, startpos,
00093                               endpos, doclear);
00094 }

PitPosPair CutAndPaste::eraseSelection BufferParams const &    params,
ParagraphList   pars,
ParagraphList::iterator    startpit,
ParagraphList::iterator    endpit,
int    start,
int    end,
bool    doclear = false
 

Definition at line 97 of file CutAndPaste.C.

Referenced by LyXText::cutSelection.

00102 {
00103         if (startpit == pars.end() || (startpos > startpit->size()))
00104                 return PitPosPair(endpit, endpos);
00105 
00106         if (endpit == pars.end() || startpit == endpit) {
00107                 endpos -= startpit->erase(startpos, endpos);
00108                 return PitPosPair(endpit, endpos);
00109         }
00110 
00111         // clear end/begin fragments of the first/last par in selection
00112         bool all_erased = true;
00113 
00114         startpit->erase(startpos, startpit->size());
00115         if (startpit->size() != startpos)
00116                 all_erased = false;
00117 
00118         endpos -= endpit->erase(0, endpos);
00119         if (endpos != 0)
00120                 all_erased = false;
00121 
00122         // Loop through the deleted pars if any, erasing as needed
00123 
00124         ParagraphList::iterator pit = boost::next(startpit);
00125 
00126         while (pit != endpit && pit != pars.end()) {
00127                 ParagraphList::iterator const next = boost::next(pit);
00128                 // "erase" the contents of the par
00129                 pit->erase(0, pit->size());
00130                 if (!pit->size()) {
00131                         // remove the par if it's now empty
00132                         pars.erase(pit);
00133                 } else
00134                         all_erased = false;
00135                 pit = next;
00136         }
00137 
00138 #if 0 // FIXME: why for cut but not copy ?
00139         // the cut selection should begin with standard layout
00140         if (realcut) {
00141                 buf->params().clear();
00142                 buf->bibkey = 0;
00143                 buf->layout(textclasslist[buffer->params.textclass].defaultLayoutName());
00144         }
00145 #endif
00146 
00147         if (boost::next(startpit) == pars.end())
00148                 return PitPosPair(endpit, endpos);
00149 
00150         if (doclear) {
00151                 boost::next(startpit)->stripLeadingSpaces();
00152         }
00153 
00154         // paste the paragraphs again, if possible
00155         if (all_erased &&
00156             (startpit->hasSameLayout(*boost::next(startpit)) ||
00157              boost::next(startpit)->empty())) {
00158                 mergeParagraph(params, pars, startpit);
00159                 // this because endpar gets deleted here!
00160                 endpit = startpit;
00161                 endpos = startpos;
00162         }
00163 
00164         return PitPosPair(endpit, endpos);
00165 
00166 }

int CutAndPaste::nrOfParagraphs  
 

Definition at line 375 of file CutAndPaste.C.

Referenced by InsetText::localDispatch.

00376 {
00377         return cuts.empty() ? 0 : cuts[0].first.size();
00378 }

pair< PitPosPair, ParagraphList::iterator > CutAndPaste::pasteSelection Buffer const &    buffer,
ParagraphList   pars,
ParagraphList::iterator    pit,
int    pos,
lyx::textclass_type    tc,
size_t    cuts_indexm,
ErrorList  
 

Definition at line 222 of file CutAndPaste.C.

00227 {
00228         if (!checkPastePossible())
00229                 return make_pair(PitPosPair(pit, pos), pit);
00230 
00231         Assert (pos <= pit->size());
00232 
00233         // Make a copy of the CaP paragraphs.
00234         ParagraphList simple_cut_clone = cuts[cut_index].first;
00235         textclass_type const textclass = cuts[cut_index].second;
00236 
00237         // Now remove all out of the pars which is NOT allowed in the
00238         // new environment and set also another font if that is required.
00239 
00240         // Make sure there is no class difference.
00241         SwitchLayoutsBetweenClasses(textclass, tc, simple_cut_clone,
00242                                     errorlist);
00243 
00244         ParagraphList::iterator tmpbuf = simple_cut_clone.begin();
00245         int depth_delta = pit->params().depth() - tmpbuf->params().depth();
00246 
00247         Paragraph::depth_type max_depth = pit->getMaxDepthAfter();
00248 
00249         for (; tmpbuf != simple_cut_clone.end(); ++tmpbuf) {
00250                 // If we have a negative jump so that the depth would
00251                 // go below 0 depth then we have to redo the delta to
00252                 // this new max depth level so that subsequent
00253                 // paragraphs are aligned correctly to this paragraph
00254                 // at level 0.
00255                 if ((int(tmpbuf->params().depth()) + depth_delta) < 0)
00256                         depth_delta = 0;
00257 
00258                 // Set the right depth so that we are not too deep or shallow.
00259                 tmpbuf->params().depth(tmpbuf->params().depth() + depth_delta);
00260                 if (tmpbuf->params().depth() > max_depth)
00261                         tmpbuf->params().depth(max_depth);
00262 
00263                 // Only set this from the 2nd on as the 2nd depends
00264                 // for maxDepth still on pit.
00265                 if (tmpbuf != simple_cut_clone.begin())
00266                         max_depth = tmpbuf->getMaxDepthAfter();
00267 
00268                 // Set the inset owner of this paragraph.
00269                 tmpbuf->setInsetOwner(pit->inInset());
00270                 for (pos_type i = 0; i < tmpbuf->size(); ++i) {
00271                         if (tmpbuf->getChar(i) == Paragraph::META_INSET) {
00272                                 if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode())) {
00273                                         tmpbuf->erase(i--);
00274                                 }
00275                         } else {
00276                                 LyXFont f1 = tmpbuf->getFont(buffer.params, i, outerFont(pit, pars));
00277                                 LyXFont f2 = f1;
00278                                 if (!pit->checkInsertChar(f1)) {
00279                                         tmpbuf->erase(i--);
00280                                 } else if (f1 != f2) {
00281                                         tmpbuf->setFont(i, f1);
00282                                 }
00283                         }
00284                 }
00285         }
00286 
00287         // Make the buf exactly the same layout than
00288         // the cursor paragraph.
00289         simple_cut_clone.begin()->makeSameLayout(*pit);
00290 
00291         // Prepare the paragraphs and insets for insertion
00292         // A couple of insets store buffer references so need
00293         // updating
00294         ParIterator fpit(simple_cut_clone.begin(), simple_cut_clone);
00295         ParIterator fend(simple_cut_clone.end(), simple_cut_clone);
00296 
00297         for (; fpit != fend; ++fpit) {
00298                 InsetList::iterator lit = fpit->insetlist.begin();
00299                 InsetList::iterator eit = fpit->insetlist.end();
00300 
00301                 for (; lit != eit; ++lit) {
00302                         switch (lit->inset->lyxCode()) {
00303                         case Inset::INCLUDE_CODE: {
00304                                 InsetInclude * ii = static_cast<InsetInclude*>(lit->inset);
00305                                 InsetInclude::Params ip = ii->params();
00306                                 ip.masterFilename_ = buffer.fileName();
00307                                 ii->set(ip);
00308                                 break;
00309                         }
00310 
00311                         case Inset::TABULAR_CODE: {
00312                                 InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
00313                                 it->buffer(const_cast<Buffer*>(&buffer));
00314                                 break;
00315                         }
00316 
00317                         default:
00318                                 break; // nothing
00319                         }
00320                 }
00321         }
00322 
00323         bool paste_the_end = false;
00324 
00325         // Open the paragraph for inserting the buf
00326         // if necessary.
00327         if (pit->size() > pos || boost::next(pit) == pars.end()) {
00328                 breakParagraphConservative(buffer.params,
00329                                            pars, pit, pos);
00330                 paste_the_end = true;
00331         }
00332 
00333         // Set the end for redoing later.
00334         ParagraphList::iterator endpit = boost::next(boost::next(pit));
00335 
00336         // Paste it!
00337 
00338         ParagraphList::iterator past_pit = boost::next(pit);
00339         pars.splice(past_pit, simple_cut_clone);
00340         ParagraphList::iterator last_paste = boost::prior(past_pit);
00341 
00342         // If we only inserted one paragraph.
00343         if (boost::next(pit) == last_paste)
00344                 last_paste = pit;
00345 
00346         mergeParagraph(buffer.params, pars, pit);
00347 
00348         // Store the new cursor position.
00349         pit = last_paste;
00350         pos = last_paste->size();
00351 
00352         // Maybe some pasting.
00353 #warning CHECK! Are we comparing last_paste to the wrong list here? (Lgb)
00354         if (boost::next(last_paste) != pars.end() &&
00355             paste_the_end) {
00356                 if (boost::next(last_paste)->hasSameLayout(*last_paste)) {
00357                         mergeParagraph(buffer.params, pars,
00358                                        last_paste);
00359                 } else if (boost::next(last_paste)->empty()) {
00360                         boost::next(last_paste)->makeSameLayout(*last_paste);
00361                         mergeParagraph(buffer.params, pars,
00362                                        last_paste);
00363                 } else if (last_paste->empty()) {
00364                         last_paste->makeSameLayout(*boost::next(last_paste));
00365                         mergeParagraph(buffer.params, pars,
00366                                        last_paste);
00367                 } else
00368                         boost::next(last_paste)->stripLeadingSpaces();
00369         }
00370 
00371         return make_pair(PitPosPair(pit, pos), endpit);
00372 }

pair< PitPosPair, ParagraphList::iterator > CutAndPaste::pasteSelection Buffer const &    buffer,
ParagraphList   pars,
ParagraphList::iterator    pit,
int    pos,
lyx::textclass_type    tc,
ErrorList  
 

Definition at line 211 of file CutAndPaste.C.

Referenced by LyXText::pasteSelection.

00216 {
00217         return pasteSelection(buffer, pars, pit, pos, tc, 0, errorlist);
00218 }

int CutAndPaste::SwitchLayoutsBetweenClasses lyx::textclass_type    c1,
lyx::textclass_type    c2,
ParagraphList   par,
ErrorList  
 

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.

Definition at line 381 of file CutAndPaste.C.

Referenced by ControlDocument::classApply.

00385 {
00386         Assert(!pars.empty());
00387 
00388         int ret = 0;
00389         if (c1 == c2)
00390                 return ret;
00391 
00392         LyXTextClass const & tclass1 = textclasslist[c1];
00393         LyXTextClass const & tclass2 = textclasslist[c2];
00394         ParIterator end = ParIterator(pars.end(), pars);
00395         for (ParIterator it = ParIterator(pars.begin(), pars); it != end; ++it) {
00396                 string const name = it->layout()->name();
00397                 bool hasLayout = tclass2.hasLayout(name);
00398 
00399                 if (hasLayout)
00400                         it->layout(tclass2[name]);
00401                 else
00402                         it->layout(tclass2.defaultLayout());
00403 
00404                 if (!hasLayout && name != tclass1.defaultLayoutName()) {
00405                         ++ret;
00406                         string const s = bformat(
00407                                 _("Layout had to be changed from\n%1$s to %2$s\n"
00408                                 "because of class conversion from\n%3$s to %4$s"),
00409                          name, it->layout()->name(), tclass1.name(), tclass2.name());
00410                         // To warn the user that something had to be done.
00411                         errorlist.push_back(ErrorItem("Changed Layout", s,
00412                                                       it->id(), 0,
00413                                                       it->size()));
00414                 }
00415         }
00416         return ret;
00417 }


Generated on Fri Jul 18 01:19:06 2003 for lyx by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002