]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
the spellcheck cleanup
[lyx.git] / src / BufferView_pimpl.C
index 4be3119c9521c33e71280bcbfba15f2b7e8bc914..93b49159fe9775986ec819ab1233c8076758e89a 100644 (file)
@@ -23,7 +23,9 @@
 #include "buffer_funcs.h"
 #include "bufferlist.h"
 #include "bufferparams.h"
+#include "cursor.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "factory.h"
 #include "FloatList.h"
 #include "funcrequest.h"
@@ -40,8 +42,7 @@
 #include "paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
-#include "TextCache.h"
-#include "undo_funcs.h"
+#include "undo.h"
 #include "vspace.h"
 
 #include "insets/insetfloatlist.h"
@@ -91,6 +92,7 @@ using lyx::support::system_lyxdir;
 using std::endl;
 using std::make_pair;
 using std::min;
+using std::string;
 
 
 extern BufferList bufferlist;
@@ -253,7 +255,7 @@ bool BufferView::Pimpl::loadLyXFile(string const & filename, bool tolastfiles)
        bv_->showErrorList(_("Parse"));
 
        if (tolastfiles)
-               lastfiles->newFile(b->fileName());
+               LyX::ref().lastfiles().newFile(b->fileName());
 
        return true;
 }
@@ -295,14 +297,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                            << b << ')' << endl;
        if (buffer_) {
                disconnectBuffer();
-               // Put the old text into the TextCache, but
-               // only if the buffer is still loaded.
-               // Also set the owner of the test to 0
-               //              bv_->text->owner(0);
-               textcache.add(buffer_, workarea().workWidth(), bv_->text);
-               if (lyxerr.debugging())
-                       textcache.show(lyxerr, "BufferView::buffer");
-
+               delete bv_->text;
                bv_->text = 0;
        }
 
@@ -337,13 +332,6 @@ void BufferView::Pimpl::buffer(Buffer * b)
        } else {
                lyxerr[Debug::INFO] << "  No Buffer!" << endl;
                owner_->getDialogs().hideBufferDependent();
-
-               // Also remove all remaining text's from the testcache.
-               // (there should not be any!) (if there is any it is a
-               // bug!)
-               if (lyxerr.debugging())
-                       textcache.show(lyxerr, "buffer delete all");
-               textcache.clear();
        }
 
        update();
@@ -356,7 +344,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
        if (buffer_) {
                // Don't forget to update the Layout
                string const layoutname =
-                       bv_->text->cursor.par()->layout()->name();
+                       bv_->text->cursorPar()->layout()->name();
                owner_->setLayout(layoutname);
        }
 
@@ -402,9 +390,9 @@ void BufferView::Pimpl::resizeCurrentBuffer()
 {
        lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
 
-       ParagraphList::iterator par;
-       ParagraphList::iterator selstartpar;
-       ParagraphList::iterator selendpar;
+       int par = -1;
+       int selstartpar = -1;
+       int selendpar = -1;
        UpdatableInset * the_locking_inset = 0;
 
        pos_type pos = 0;
@@ -430,36 +418,11 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                bv_->text->fullRebreak();
                update();
        } else {
-               lyxerr << "text not available!" << endl;
-               // See if we have a text in TextCache that fits
-               // the new buffer_ with the correct width.
-               bv_->text = textcache.findFit(buffer_, workarea().workWidth());
-               if (bv_->text) {
-                       lyxerr << "text in cache!" << endl;
-                       if (lyxerr.debugging()) {
-                               lyxerr << "Found a LyXText that fits:" << endl;
-                               textcache.show(lyxerr, make_pair(buffer_, make_pair(workarea().workWidth(), bv_->text)));
-                       }
-                       // Set the owner of the newly found text
-                       //      bv_->text->owner(bv_);
-                       if (lyxerr.debugging())
-                               textcache.show(lyxerr, "resizeCurrentBuffer");
-               } else {
-                       lyxerr << "no text in cache!" << endl;
                        bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs());
                        bv_->text->init(bv_);
-               }
-
-               par = bv_->text->ownerParagraphs().end();
-               selstartpar = bv_->text->ownerParagraphs().end();
-               selendpar = bv_->text->ownerParagraphs().end();
        }
 
-#warning does not help much
-       bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(),
-               bv_->text->ownerParagraphs().end());
-
-       if (par != bv_->text->ownerParagraphs().end()) {
+       if (par != -1) {
                bv_->text->selection.set(true);
                // At this point just to avoid the Delete-Empty-Paragraph-
                // Mechanism when setting the cursor.
@@ -631,16 +594,6 @@ void BufferView::Pimpl::workAreaResize()
                if (widthChange) {
                        // The visible LyXView need a resize
                        resizeCurrentBuffer();
-
-                       // Remove all texts from the textcache
-                       // This is not _really_ what we want to do. What
-                       // we really want to do is to delete in textcache
-                       // that does not have a BufferView with matching
-                       // width, but as long as we have only one BufferView
-                       // deleting all gives the same result.
-                       if (lyxerr.debugging())
-                               textcache.show(lyxerr, "Expose delete all");
-                       textcache.clear();
                }
        }
 
@@ -655,7 +608,7 @@ void BufferView::Pimpl::workAreaResize()
 
 void BufferView::Pimpl::update()
 {
-       lyxerr << "BufferView::update()" << endl;
+       //lyxerr << "BufferView::update()" << endl;
        // fix cursor coordinate cache in case something went wrong
        if (bv_->getLyXText()) {
                // check needed to survive LyX startup
@@ -697,8 +650,8 @@ Change const BufferView::Pimpl::getCurrentChange()
        if (!text->selection.set())
                return Change(Change::UNCHANGED);
 
-       LyXCursor const & cur = text->selection.start;
-       return cur.par()->lookupChangeFull(cur.pos());
+       return text->getPar(text->selection.start)
+               ->lookupChangeFull(text->selection.start.pos());
 }
 
 
@@ -713,7 +666,7 @@ void BufferView::Pimpl::savePosition(unsigned int i)
        if (i >= saved_positions_num)
                return;
        saved_positions[i] = Position(buffer_->fileName(),
-                                     bv_->text->cursor.par()->id(),
+                                     bv_->text->cursorPar()->id(),
                                      bv_->text->cursor.pos());
        if (i > 0)
                owner_->message(bformat(_("Saved bookmark %1$s"), tostr(i)));
@@ -730,14 +683,14 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
        beforeChange(bv_->text);
 
        if (fname != buffer_->fileName()) {
-               Buffer * b;
+               Buffer * b = 0;
                if (bufferlist.exists(fname))
                        b = bufferlist.getBuffer(fname);
                else {
                        b = bufferlist.newBuffer(fname);
                        ::loadLyXFile(b, fname); // don't ask, just load it
                }
-               if (b != 0)
+               if (b)
                        buffer(b);
        }
 
@@ -835,7 +788,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
        LyXCursor cursor = bv_->getLyXText()->cursor;
        Buffer::inset_iterator it =
                find_if(Buffer::inset_iterator(
-                       cursor.par(), cursor.pos()),
+                       cursorPar(), cursor.pos()),
                        buffer_->inset_iterator_end(),
                        lyx::compare_memfun(&Inset::lyxCode, code));
        return it != buffer_->inset_iterator_end() ? (*it) : 0;
@@ -844,22 +797,22 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
        // should work for now. Better infrastructure is coming. (Lgb)
 
        Buffer * b = bv_->buffer();
-       LyXCursor cursor = bv_->getLyXText()->cursor;
+       LyXText * text =  bv_->getLyXText();
 
        Buffer::inset_iterator beg = b->inset_iterator_begin();
        Buffer::inset_iterator end = b->inset_iterator_end();
 
-       bool cursor_par_seen = false;
+       bool cursorPar_seen = false;
 
        for (; beg != end; ++beg) {
-               if (beg.getPar() == cursor.par()) {
-                       cursor_par_seen = true;
+               if (beg.getPar() == text->cursorPar()) {
+                       cursorPar_seen = true;
                }
-               if (cursor_par_seen) {
-                       if (beg.getPar() == cursor.par()
-                           && beg.getPos() >= cursor.pos()) {
+               if (cursorPar_seen) {
+                       if (beg.getPar() == text->cursorPar()
+                           && beg.getPos() >= text->cursor.pos()) {
                                break;
-                       } else if (beg.getPar() != cursor.par()) {
+                       } else if (beg.getPar() != text->cursorPar()) {
                                break;
                        }
                }
@@ -946,7 +899,7 @@ void BufferView::Pimpl::trackChanges()
                buf->undostack().clear();
        } else {
                update();
-               bv_->text->setCursor(buf->paragraphs().begin(), 0);
+               bv_->text->setCursor(0, 0);
 #warning changes FIXME
                //moveCursorUpdate(false);
 
@@ -1186,7 +1139,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                        // Note that the localDispatch performs updateInset
                        // also.
                        FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument);
-                       inset->localDispatch(fr);
+                       inset->dispatch(fr);
                } else {
                        FuncRequest fr(bv_, LFUN_INSET_INSERT, ev.argument);
                        dispatch(fr);
@@ -1225,7 +1178,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
 
        case LFUN_LAYOUT_PARAGRAPH: {
                string data;
-               params2string(*bv_->getLyXText()->cursor.par(), data);
+               params2string(*bv_->getLyXText()->cursorPar(), data);
 
                data = "show\n" + data;
                bv_->owner()->getDialogs().show("paragraph", data);
@@ -1235,7 +1188,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_PARAGRAPH_UPDATE: {
                if (!bv_->owner()->getDialogs().visible("paragraph"))
                        break;
-               Paragraph const & par = *bv_->getLyXText()->cursor.par();
+               Paragraph const & par = *bv_->getLyXText()->cursorPar();
 
                string data;
                params2string(par, data);
@@ -1284,7 +1237,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                break;
 
        case LFUN_ACCEPT_ALL_CHANGES: {
-               bv_->text->setCursor(bv_->buffer()->paragraphs().begin(), 0);
+               bv_->text->setCursor(0, 0);
 #warning FIXME changes
                //moveCursorUpdate(false);
 
@@ -1296,7 +1249,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        }
 
        case LFUN_REJECT_ALL_CHANGES: {
-               bv_->text->setCursor(bv_->buffer()->paragraphs().begin(), 0);
+               bv_->text->setCursor(0, 0);
 #warning FIXME changes
                //moveCursorUpdate(false);
 
@@ -1324,7 +1277,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                break;
 
        default:
-               return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_));
+               return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_)).dispatched();
        } // end of switch
 
        return true;
@@ -1342,14 +1295,14 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
        }
 
        // not quite sure if we want this...
-       recordUndo(bv_, Undo::ATOMIC);
+       bv_->text->recUndo(bv_->text->cursor.par());
        freezeUndo();
 
        beforeChange(bv_->text);
        if (!lout.empty()) {
                bv_->text->breakParagraph(bv_->buffer()->paragraphs());
 
-               if (!bv_->text->cursor.par()->empty()) {
+               if (!bv_->text->cursorPar()->empty()) {
                        bv_->text->cursorLeft(bv_);
                        bv_->text->breakParagraph(bv_->buffer()->paragraphs());
                }
@@ -1369,8 +1322,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
 
                bv_->text->setLayout(lay);
 
-               bv_->text->setParagraph(0, 0,
-                                  0, 0,
+               bv_->text->setParagraph(
                                   VSpace(VSpace::NONE), VSpace(VSpace::NONE),
                                   Spacing(),
                                   LYX_ALIGN_LAYOUT,
@@ -1394,7 +1346,7 @@ void BufferView::Pimpl::updateInset(InsetOld const * inset)
        bv_->text->redoParagraph(outerPar(*bv_->buffer(), inset));
 
        // this should not be needed, but it is...
-       // bv_->text->redoParagraph(bv_->text->cursor.par());
+       // bv_->text->redoParagraph(bv_->text->cursorPar());
        // bv_->text->fullRebreak();
 
        update();
@@ -1431,10 +1383,10 @@ bool BufferView::Pimpl::ChangeInsets(InsetOld::Code code,
                        // FIXME
 
                        // The test it.size()==1 was needed to prevent crashes.
-                       // How to set the cursor corretly when it.size()>1 ??
+                       // How to set the cursor correctly when it.size()>1 ??
                        if (it.size() == 1) {
-                               bv_->text->setCursorIntern(it.pit(), 0);
-                               bv_->text->redoParagraph(bv_->text->cursor.par());
+                               bv_->text->setCursorIntern(bv_->text->parOffset(it.pit()), 0);
+                               bv_->text->redoParagraph(bv_->text->cursorPar());
                        }
                }
        }