]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView2.C
Look for mathed xpms. Doesn't do anything yet due to lack of workable XPMs
[lyx.git] / src / BufferView2.C
index d299b9f0f67f44ffb639ce340ac7a17286fd8b5d..c467f4922ff0060c13b1cf01a5a450235da02a25 100644 (file)
@@ -24,6 +24,8 @@
 #include "undo_funcs.h"
 #include "debug.h"
 #include "iterators.h"
+#include "lyxlex.h"
+#include "WordLangTuple.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -57,11 +59,12 @@ bool BufferView::insertLyXFile(string const & filen)
        // Copyright CHT Software Service GmbH
        // Uwe C. Schroeder
        //
-       // Insert a Lyxformat - file into current buffer
+       // Insert a LyXformat - file into current buffer
        //
        // Moved from lyx_cb.C (Lgb)
 {
-       if (filen.empty()) return false;
+       if (filen.empty())
+               return false;
 
        string const fname = MakeAbsPath(filen);
 
@@ -190,19 +193,20 @@ bool BufferView::removeAutoInsets()
                        }
                }
 
-               Paragraph::inset_iterator pit = par->inset_iterator_begin();
-               Paragraph::inset_iterator pend = par->inset_iterator_end();
+               InsetList::iterator pit = par->insetlist.begin();
+               InsetList::iterator pend = par->insetlist.end();
+
                while (pit != pend) {
-                       if (pit->autoDelete()) {
+                       if (pit.getInset()->autoDelete()) {
                                removed = true;
                                pos_type const pos = pit.getPos();
 
                                par->erase(pos);
                                // We just invalidated par's inset iterators so
                                // we get the next valid iterator position
-                               pit = par->InsetIterator(pos);
+                               pit = par->insetlist.insetIterator(pos);
                                // and ensure we have a valid end iterator.
-                               pend = par->inset_iterator_end();
+                               pend = par->insetlist.end();
 
                                if (cursor_par == par) {
                                        // update the saved cursor position
@@ -274,10 +278,12 @@ void BufferView::insertErrors(TeXErrors & terr)
                if (texrowpar == 0)
                        continue;
 
+               freezeUndo();
                InsetError * new_inset = new InsetError(msgtxt);
                text->setCursorIntern(this, texrowpar, tmppos);
                text->insertInset(this, new_inset);
                text->fullRebreak(this);
+               unFreezeUndo();
        }
        // Restore the cursor position
        text->setCursorIntern(this, cursor.par(), cursor.pos());
@@ -309,17 +315,16 @@ bool BufferView::insertInset(Inset * inset, string const & lout)
 }
 
 
-/* This is also a buffer property (ale) */
+// This is also a buffer property (ale)
 // Not so sure about that. a goto Label function can not be buffer local, just
-// think how this will work in a multiwindo/buffer environment, all the
+// think how this will work in a multiwindow/buffer environment, all the
 // cursors in all the views showing this buffer will move. (Lgb)
 // OK, then no cursor action should be allowed in buffer. (ale)
 bool BufferView::gotoLabel(string const & label)
-
 {
        for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
             it != buffer()->inset_iterator_end(); ++it) {
-               vector<string> labels = (*it)->getLabelList();
+               vector<string> labels = it->getLabelList();
                if (find(labels.begin(),labels.end(),label)
                     != labels.end()) {
                        beforeChange(text);
@@ -335,40 +340,35 @@ bool BufferView::gotoLabel(string const & label)
 
 void BufferView::menuUndo()
 {
-       if (available()) {
-               owner()->message(_("Undo"));
-               hideCursor();
-               beforeChange(text);
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               if (!textUndo(this))
-                       owner()->message(_("No further undo information"));
-               else
-                       update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               switchKeyMap();
-       }
+       if (!available())
+               return;
+
+       owner()->message(_("Undo"));
+       hideCursor();
+       beforeChange(text);
+       update(text, BufferView::SELECT|BufferView::FITCUR);
+       if (!textUndo(this))
+               owner()->message(_("No further undo information"));
+       else
+               update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+       switchKeyMap();
 }
 
 
 void BufferView::menuRedo()
 {
-#if 0 // this should not be here (Jug 20011206)
-       if (theLockingInset()) {
-               owner()->message(_("Redo not yet supported in math mode"));
+       if (!available())
                return;
-       }
-#endif
 
-       if (available()) {
-               owner()->message(_("Redo"));
-               hideCursor();
-               beforeChange(text);
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               if (!textRedo(this))
-                       owner()->message(_("No further redo information"));
-               else
-                       update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               switchKeyMap();
-       }
+       owner()->message(_("Redo"));
+       hideCursor();
+       beforeChange(text);
+       update(text, BufferView::SELECT|BufferView::FITCUR);
+       if (!textRedo(this))
+               owner()->message(_("No further redo information"));
+       else
+               update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+       switchKeyMap();
 }
 
 
@@ -391,62 +391,12 @@ void BufferView::pasteEnvironment()
 }
 
 
-void BufferView::copy()
-{
-       if (available()) {
-               getLyXText()->copySelection(this);
-               owner()->message(_("Copy"));
-       }
-}
-
-
-void BufferView::cut(bool realcut)
-{
-       if (available()) {
-               hideCursor();
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               text->cutSelection(this, true, realcut);
-               update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               owner()->message(_("Cut"));
-       }
-}
-
-
-void BufferView::paste()
-{
-       if (!available())
-               return;
-
-       owner()->message(_("Paste"));
-
-       hideCursor();
-       // clear the selection
-       toggleSelection();
-       text->clearSelection();
-       update(text, BufferView::SELECT|BufferView::FITCUR);
-
-       // paste
-       text->pasteSelection(this);
-       // bug 393
-       text->clearSelection();
-       update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-// why fake a selection only I think it should be a real one and not only
-// a painted one (Jug 20020318).
-#if 0
-       // clear the selection
-       toggleSelection();
-       text->clearSelection();
-       update(text, BufferView::SELECT|BufferView::FITCUR);
-#endif
-}
-
-
-/* these functions are for the spellchecker */
-string const BufferView::nextWord(float & value)
+// these functions are for the spellchecker
+WordLangTuple const BufferView::nextWord(float & value)
 {
        if (!available()) {
                value = 1;
-               return string();
+               return WordLangTuple();
        }
 
        return text->selectNextWordToSpellcheck(this, value);
@@ -455,7 +405,8 @@ string const BufferView::nextWord(float & value)
 
 void BufferView::selectLastWord()
 {
-       if (!available()) return;
+       if (!available())
+               return;
 
        LyXCursor cur = text->selection.cursor;
        hideCursor();
@@ -481,17 +432,18 @@ void BufferView::endOfSpellCheck()
 
 void BufferView::replaceWord(string const & replacestring)
 {
-       if (!available()) return;
+       if (!available())
+               return;
 
        LyXText * tt = getLyXText();
        hideCursor();
        update(tt, BufferView::SELECT|BufferView::FITCUR);
 
-       /* clear the selection (if there is any) */
+       // clear the selection (if there is any)
        toggleSelection(false);
        update(tt, BufferView::SELECT|BufferView::FITCUR);
 
-       /* clear the selection (if there is any) */
+       // clear the selection (if there is any)
        toggleSelection(false);
        tt->replaceSelectionWithString(this, replacestring);
 
@@ -525,26 +477,24 @@ bool BufferView::lockInset(UpdatableInset * inset)
                        }
                }
                // Then do a deep look of the inset and lock the right one
-               Paragraph * par = buffer()->paragraph;
                int const id = inset->id();
-               while(par) {
-                       Paragraph::inset_iterator it =
-                               par->inset_iterator_begin();
-                       Paragraph::inset_iterator const end =
-                               par->inset_iterator_end();
+               ParagraphList::iterator pit = buffer()->paragraphs.begin();
+               ParagraphList::iterator pend = buffer()->paragraphs.end();
+               for (; pit != pend; ++pit) {
+                       InsetList::iterator it = pit->insetlist.begin();
+                       InsetList::iterator end = pit->insetlist.end();
                        for (; it != end; ++it) {
-                               if ((*it) == inset) {
-                                       text->setCursorIntern(this, par, it.getPos());
+                               if (it.getInset() == inset) {
+                                       text->setCursorIntern(this, &*pit, it.getPos());
                                        theLockingInset(inset);
                                        return true;
                                }
-                               if ((*it)->getInsetFromID(id)) {
-                                       text->setCursorIntern(this, par, it.getPos());
-                                       (*it)->edit(this);
+                               if (it.getInset()->getInsetFromID(id)) {
+                                       text->setCursorIntern(this, &*pit, it.getPos());
+                                       it.getInset()->edit(this);
                                        return theLockingInset()->lockInsetInInset(this, inset);
                                }
                        }
-                       par = par->next();
                }
                return false;
        }
@@ -613,13 +563,13 @@ int BufferView::unlockInset(UpdatableInset * inset)
                // make sure we update the combo !
                owner()->setLayout(getLyXText()->cursor.par()->layout()->name());
                // Tell the paragraph dialog that we changed paragraph
-               owner()->getDialogs()->updateParagraph();
+               owner()->getDialogs().updateParagraph();
                finishUndo();
                return 0;
        } else if (inset && theLockingInset() &&
                   theLockingInset()->unlockInsetInInset(this, inset)) {
                // Tell the paragraph dialog that we changed paragraph
-               owner()->getDialogs()->updateParagraph();
+               owner()->getDialogs().updateParagraph();
                // owner inset has updated the layout combo
                finishUndo();
                return 0;
@@ -660,10 +610,10 @@ bool BufferView::ChangeInsets(Inset::Code code,
             it != end; ++it) {
                Paragraph * par = *it;
                bool changed_inset = false;
-               for (Paragraph::inset_iterator it2 = par->inset_iterator_begin();
-                    it2 != par->inset_iterator_end(); ++it2) {
-                       if ((*it2)->lyxCode() == code) {
-                               InsetCommand * inset = static_cast<InsetCommand *>(*it2);
+               for (InsetList::iterator it2 = par->insetlist.begin();
+                    it2 != par->insetlist.end(); ++it2) {
+                       if (it2.getInset()->lyxCode() == code) {
+                               InsetCommand * inset = static_cast<InsetCommand *>(it2.getInset());
                                if (inset->getContents() == from) {
                                        inset->setContents(to);
                                        changed_inset = true;