]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
don't rm emergency saves ever
[lyx.git] / src / BufferView.C
index 280315d2a9583c15351e996a311d56d5d1589e41..5e8763cfc0feb34f1df3749de5ffb0a341946d41 100644 (file)
@@ -27,6 +27,7 @@
 #include "lyxtext.h"
 #include "undo_funcs.h"
 #include "changes.h"
+#include "paragraph_funcs.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -43,7 +44,7 @@
 #include "support/lyxfunctional.h" // equal_1st_in_pair
 #include "support/types.h"
 #include "support/lyxalgo.h" // lyx_count
-#include "BoostFormat.h"
+#include "support/BoostFormat.h"
 
 #include <fstream>
 
@@ -222,18 +223,6 @@ int BufferView::workWidth() const
 }
 
 
-void BufferView::showCursor()
-{
-       pimpl_->showCursor();
-}
-
-
-void BufferView::hideCursor()
-{
-       pimpl_->hideCursor();
-}
-
-
 void BufferView::toggleSelection(bool b)
 {
        pimpl_->toggleSelection(b);
@@ -358,7 +347,7 @@ bool BufferView::insertLyXFile(string const & filen)
 bool BufferView::removeAutoInsets()
 {
        // keep track of which pos and par the cursor was on
-       Paragraph * cursor_par = text->cursor.par();
+       Paragraph * cursor_par = &*text->cursor.par();
        Paragraph * cursor_par_prev = cursor_par ? cursor_par->previous() : 0;
        Paragraph * cursor_par_next = cursor_par ? cursor_par->next() : 0;
        pos_type cursor_pos = text->cursor.pos();
@@ -472,7 +461,7 @@ bool BufferView::removeAutoInsets()
        // It is possible that the last line is empty if it was cursor_par
        // and/or only had an error inset on it.  So we set the cursor to the
        // start of the doc to force its removal and ensure a valid saved cursor
-       if (text->setCursor(text->ownerParagraph(), 0)
+       if (text->setCursor(&*text->ownerParagraphs().begin(), 0)
            && 0 == cursor_par_next) {
                cursor_par = cursor_par_prev;
                cursor_pos = cursor_par->size();
@@ -515,10 +504,10 @@ void BufferView::insertErrors(TeXErrors & terr)
                Paragraph * texrowpar = 0;
 
                if (tmpid == -1) {
-                       texrowpar = text->ownerParagraph();
+                       texrowpar = &*text->ownerParagraphs().begin();
                        tmppos = 0;
                } else {
-                       texrowpar = buffer()->getParFromID(tmpid);
+                       texrowpar = &*buffer()->getParFromID(tmpid);
                }
 
                if (texrowpar == 0)
@@ -546,10 +535,10 @@ void BufferView::setCursorFromRow(int row)
        Paragraph * texrowpar;
 
        if (tmpid == -1) {
-               texrowpar = text->ownerParagraph();
+               texrowpar = &*text->ownerParagraphs().begin();
                tmppos = 0;
        } else {
-               texrowpar = buffer()->getParFromID(tmpid);
+               texrowpar = &*buffer()->getParFromID(tmpid);
        }
        text->setCursor(texrowpar, tmppos);
 }
@@ -584,7 +573,6 @@ void BufferView::undo()
                return;
 
        owner()->message(_("Undo"));
-       hideCursor();
        beforeChange(text);
        update(text, BufferView::SELECT);
        if (!textUndo(this))
@@ -601,7 +589,6 @@ void BufferView::redo()
                return;
 
        owner()->message(_("Redo"));
-       hideCursor();
        beforeChange(text);
        update(text, BufferView::SELECT);
        if (!textRedo(this))
@@ -612,25 +599,6 @@ void BufferView::redo()
 }
 
 
-void BufferView::copyEnvironment()
-{
-       if (available()) {
-               text->copyEnvironmentType();
-               owner()->message(_("Paragraph environment type copied"));
-       }
-}
-
-
-void BufferView::pasteEnvironment()
-{
-       if (available()) {
-               text->pasteEnvironmentType();
-               owner()->message(_("Paragraph environment type set"));
-               update(text, BufferView::SELECT);
-       }
-}
-
-
 // these functions are for the spellchecker
 WordLangTuple const BufferView::nextWord(float & value)
 {
@@ -649,7 +617,6 @@ void BufferView::selectLastWord()
                return;
 
        LyXCursor cur = text->selection.cursor;
-       hideCursor();
        beforeChange(text);
        text->selection.cursor = cur;
        text->selectSelectedWord();
@@ -662,7 +629,6 @@ void BufferView::endOfSpellCheck()
 {
        if (!available()) return;
 
-       hideCursor();
        beforeChange(text);
        text->selectSelectedWord();
        text->clearSelection();
@@ -676,7 +642,6 @@ void BufferView::replaceWord(string const & replacestring)
                return;
 
        LyXText * tt = getLyXText();
-       hideCursor();
        update(tt, BufferView::SELECT);
 
        // clear the selection (if there is any)
@@ -712,8 +677,9 @@ bool BufferView::lockInset(UpdatableInset * inset)
        if (!theLockingInset()) {
                // first check if it's the inset under the cursor we want lock
                // should be most of the time
-               char const c = text->cursor.par()->getChar(text->cursor.pos());
-               if (c == Paragraph::META_INSET) {
+               if (text->cursor.pos() < text->cursor.par()->size()
+                   && text->cursor.par()->getChar(text->cursor.pos()) ==
+                   Paragraph::META_INSET) {
                        Inset * in = text->cursor.par()->getInset(text->cursor.pos());
                        if (inset == in) {
                                theLockingInset(inset);
@@ -729,12 +695,12 @@ bool BufferView::lockInset(UpdatableInset * inset)
                        InsetList::iterator end = pit->insetlist.end();
                        for (; it != end; ++it) {
                                if (it.getInset() == inset) {
-                                       text->setCursorIntern(&*pit, it.getPos());
+                                       text->setCursorIntern(pit, it.getPos());
                                        theLockingInset(inset);
                                        return true;
                                }
                                if (it.getInset()->getInsetFromID(id)) {
-                                       text->setCursorIntern(&*pit, it.getPos());
+                                       text->setCursorIntern(pit, it.getPos());
                                        it.getInset()->edit(this);
                                        return theLockingInset()->lockInsetInInset(this, inset);
                                }
@@ -746,44 +712,6 @@ bool BufferView::lockInset(UpdatableInset * inset)
 }
 
 
-void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
-{
-       if (available() && theLockingInset() && !theLockingInset()->nodraw()) {
-               LyXCursor cursor = text->cursor;
-               Inset * locking_inset = theLockingInset()->getLockingInset();
-
-               if ((cursor.pos() - 1 >= 0) &&
-                   cursor.par()->isInset(cursor.pos() - 1) &&
-                   (cursor.par()->getInset(cursor.pos() - 1) ==
-                    locking_inset))
-                       text->setCursor(cursor,
-                                       cursor.par(), cursor.pos() - 1);
-               LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE;
-               LyXText * txt = getLyXText();
-               if (locking_inset->isTextInset() &&
-                   locking_inset->lyxCode() != Inset::ERT_CODE &&
-                   (txt->real_current_font.language() !=
-                    buffer()->params.language
-                    || txt->real_current_font.isVisibleRightToLeft()
-                    != buffer()->params.language->RightToLeft()))
-                       shape = (txt->real_current_font.isVisibleRightToLeft())
-                               ? LyXScreen::REVERSED_L_SHAPE
-                               : LyXScreen::L_SHAPE;
-               y += cursor.iy() + theLockingInset()->insetInInsetY();
-               screen().showManualCursor(text, x, y, asc, desc,
-                                                 shape);
-       }
-}
-
-
-void BufferView::hideLockedInsetCursor()
-{
-       if (theLockingInset() && available()) {
-               screen().hideCursor();
-       }
-}
-
-
 bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 {
        if (theLockingInset() && available()) {
@@ -797,6 +725,12 @@ bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 }
 
 
+void BufferView::hideCursor()
+{
+       screen().hideCursor();
+}
+
+
 int BufferView::unlockInset(UpdatableInset * inset)
 {
        if (!inset)
@@ -830,7 +764,7 @@ void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
                kind = Undo::FINISH;
        setUndo(this, kind,
                text->cursor.par(),
-               text->cursor.par()->next());
+               boost::next(text->cursor.par()));
 }
 
 
@@ -874,7 +808,7 @@ bool BufferView::ChangeInsets(Inset::Code code,
                        if (it.size() == 1) {
                                text->setCursorIntern(par, 0);
                                text->redoParagraphs(text->cursor,
-                                                    text->cursor.par()->next());
+                                                    boost::next(text->cursor.par()));
                                text->fullRebreak();
                        }
                }
@@ -965,8 +899,9 @@ Encoding const * BufferView::getEncoding() const
        if (!t)
                return 0;
 
-       LyXCursor const & c= t->cursor;
-       LyXFont const font = c.par()->getFont(buffer()->params, c.pos());
+       LyXCursor const & c = t->cursor;
+       LyXFont const font = c.par()->getFont(buffer()->params, c.pos(),
+                                             outerFont(c.par(), t->ownerParagraphs()));
        return font.language()->encoding();
 }