]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView2.C
fix "make dist" target
[lyx.git] / src / BufferView2.C
index 705885486557c3cecc6375bda449f10346d86e5b..d24181d0657af06e8eb4b2fdf652cc584cd2dfff 100644 (file)
@@ -22,7 +22,6 @@
 #include "insets/insetinfo.h"
 #include "insets/insetspecialchar.h"
 #include "LyXView.h"
-#include "minibuffer.h"
 #include "bufferlist.h"
 #include "support/FileInfo.h"
 #include "lyxscreen.h"
@@ -32,6 +31,8 @@
 #include "BufferView_pimpl.h"
 #include "insets/insetcommand.h" //ChangeRefs
 #include "support/lyxfunctional.h" //equal_1st_in_pair
+#include "language.h"
+#include "gettext.h"
 
 extern BufferList bufferlist;
 
@@ -67,7 +68,7 @@ bool BufferView::insertLyXFile(string const & filen)
                return false;
        }
        
-       beforeChange();
+       beforeChange(text);
 
        ifstream ifs(fname.c_str());
        if (!ifs) {
@@ -105,29 +106,23 @@ bool BufferView::removeAutoInsets()
        LyXCursor cursor;
 
        bool a = false;
+
        while (par) {
                // this has to be done before the delete
-#ifndef NEW_INSETS
-               if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
-#endif
-                       text->SetCursor(this, cursor, par, 0);
+               text->SetCursor(this, cursor, par, 0);
                if (par->AutoDeleteInsets()){
                        a = true;
-#ifndef NEW_INSETS
-                       if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
-#endif
-                               text->RedoParagraphs(this, cursor,
-                                                    cursor.par()->Next());
-                               text->FullRebreak(this);
-#ifndef NEW_INSETS
-                       }
-#endif
+                       text->RedoParagraphs(this, cursor,
+                                            cursor.par()->next());
+                       text->FullRebreak(this);
                }
-               par = par->next;
+               par = par->next();
        }
+
        // avoid forbidden cursor positions caused by error removing
-       if (tmpcursor.pos() > tmpcursor.par()->Last())
-               tmpcursor.pos(tmpcursor.par()->Last());
+       if (tmpcursor.pos() > tmpcursor.par()->size())
+               tmpcursor.pos(tmpcursor.par()->size());
+
        text->SetCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
 
        return a;
@@ -139,12 +134,6 @@ void BufferView::insertErrors(TeXErrors & terr)
        // Save the cursor position
        LyXCursor cursor = text->cursor;
 
-#ifndef NEW_INSETS
-       // This is drastic, but it's the only fix, I could find. (Asger)
-       allFloats(1, 0);
-       allFloats(1, 1);
-#endif
-
        for (TeXErrors::Errors::const_iterator cit = terr.begin();
             cit != terr.end();
             ++cit) {
@@ -217,13 +206,13 @@ bool BufferView::insertInset(Inset * inset, string const & lout,
        text->SetCursorParUndo(buffer());
        text->FreezeUndo();
        
-       beforeChange();
+       beforeChange(text);
        if (!lout.empty()) {
                update(text, BufferView::SELECT|BufferView::FITCUR);
                text->BreakParagraph(this);
                update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               
-               if (text->cursor.par()->Last()) {
+
+               if (text->cursor.par()->size()) {
                        text->CursorLeft(this);
                        
                        text->BreakParagraph(this);
@@ -263,23 +252,6 @@ bool BufferView::insertInset(Inset * inset, string const & lout,
 }
 
 
-// Open and lock an updatable inset
-bool BufferView::open_new_inset(UpdatableInset * new_inset, bool behind)
-{
-       beforeChange();
-       text->FinishUndo();
-       if (!insertInset(new_inset)) {
-               delete new_inset;
-               return false;
-       }
-       if (behind) {
-               LyXFont & font = getLyXText()->real_current_font;
-               new_inset->Edit(this, new_inset->width(this, font), 0, 0);
-       } else
-               new_inset->Edit(this, 0, 0, 0);
-       return true;
-}
-
 /* 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
@@ -293,7 +265,7 @@ bool BufferView::gotoLabel(string const & label)
                vector<string> labels = (*it)->getLabelList();
                if (find(labels.begin(),labels.end(),label)
                     != labels.end()) {
-                       beforeChange();
+                       beforeChange(text);
                        text->SetCursor(this, it.getPar(), it.getPos());
                        text->sel_cursor = text->cursor;
                        update(text, BufferView::SELECT|BufferView::FITCUR);
@@ -304,142 +276,15 @@ bool BufferView::gotoLabel(string const & label)
 }
 
 
-#ifndef NEW_INSETS
-void BufferView::allFloats(char flag, char figmar)
-{
-       if (!available()) return;
-
-       LyXCursor cursor = text->cursor;
-
-       if (!flag
-           && cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE
-           && ((figmar 
-                && cursor.par()->footnotekind != LyXParagraph::FOOTNOTE 
-                && cursor.par()->footnotekind != LyXParagraph::MARGIN
-                   )
-               || (!figmar
-                   && cursor.par()->footnotekind != LyXParagraph::FIG 
-                   && cursor.par()->footnotekind != LyXParagraph::TAB
-                   && cursor.par()->footnotekind != LyXParagraph::WIDE_FIG 
-                   && cursor.par()->footnotekind != LyXParagraph::WIDE_TAB
-                   && cursor.par()->footnotekind != LyXParagraph::ALGORITHM)))
-               toggleFloat();
-       else
-               beforeChange();
-
-       LyXCursor tmpcursor = cursor;
-       cursor.par(tmpcursor.par()->ParFromPos(tmpcursor.pos()));
-       cursor.pos(tmpcursor.par()->PositionInParFromPos(tmpcursor.pos()));
-
-       LyXParagraph *par = buffer()->paragraph;
-       while (par) {
-               if (flag) {
-                       if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
-                           && ((figmar 
-                                && par->footnotekind != LyXParagraph::FOOTNOTE 
-                                && par->footnotekind !=  LyXParagraph::MARGIN)
-                               || (!figmar
-                                   && par->footnotekind != LyXParagraph::FIG 
-                                   && par->footnotekind != LyXParagraph::TAB
-                                   && par->footnotekind != LyXParagraph::WIDE_FIG 
-                                   && par->footnotekind != LyXParagraph::WIDE_TAB
-                                   && par->footnotekind != LyXParagraph::ALGORITHM
-                                       )
-                                   )
-                               ) {
-                               if (par->previous
-                                   && par->previous->footnoteflag != 
-                                   LyXParagraph::CLOSED_FOOTNOTE){ /* should be */ 
-                                       text->SetCursorIntern(this, 
-                                                             par->previous,
-                                                             0);
-                                       text->OpenFootnote(this);
-                               }
-                       }
-               } else {
-                       if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
-                           && (
-                                   (figmar 
-                                    &&
-                                    par->footnotekind != LyXParagraph::FOOTNOTE 
-                                    &&
-                                    par->footnotekind !=  LyXParagraph::MARGIN
-                                           )
-                                   ||
-                                   (!figmar
-                                    &&
-                                    par->footnotekind != LyXParagraph::FIG 
-                                    &&
-                                    par->footnotekind != LyXParagraph::TAB
-                                    &&
-                                    par->footnotekind != LyXParagraph::WIDE_FIG 
-                                    &&
-                                    par->footnotekind != LyXParagraph::WIDE_TAB
-                                    &&
-                                    par->footnotekind != LyXParagraph::ALGORITHM
-                                           )
-                                   )
-                               ) {
-                               text->SetCursorIntern(this, par, 0);
-                               text->CloseFootnote(this);
-                       }
-               }
-               par = par->next;
-       }
-
-       text->SetCursorIntern(this, cursor.par(), cursor.pos());
-       redraw();
-       fitCursor(text);
-}
-#endif
-
-
-void BufferView::insertNote()
-{
-       InsetInfo * new_inset = new InsetInfo();
-       insertInset(new_inset);
-       new_inset->Edit(this, 0, 0, 0);
-}
-
-
-#ifndef NEW_INSETS
-void BufferView::openStuff()
-{
-       if (available()) {
-               owner()->getMiniBuffer()->Set(_("Open/Close..."));
-               hideCursor();
-               beforeChange();
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               text->OpenStuff(this);
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               setState();
-       }
-}
-
-
-void BufferView::toggleFloat()
-{
-       if (available()) {
-               owner()->getMiniBuffer()->Set(_("Open/Close..."));
-               hideCursor();
-               beforeChange();
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               text->ToggleFootnote(this);
-               update(text, BufferView::SELECT|BufferView::FITCUR);
-               setState();
-       }
-}
-#endif
-
 void BufferView::menuUndo()
 {
        if (available()) {
-               owner()->getMiniBuffer()->Set(_("Undo"));
+               owner()->message(_("Undo"));
                hideCursor();
-               beforeChange();
+               beforeChange(text);
                update(text, BufferView::SELECT|BufferView::FITCUR);
                if (!text->TextUndo(this))
-                       owner()->getMiniBuffer()->Set(_("No further undo information"));
+                       owner()->message(_("No forther undo information"));
                else
                        update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                setState();
@@ -450,17 +295,17 @@ void BufferView::menuUndo()
 void BufferView::menuRedo()
 {
        if (theLockingInset()) {
-               owner()->getMiniBuffer()->Set(_("Redo not yet supported in math mode"));
+               owner()->message(_("Redo not yet supported in math mode"));
                return;
        }    
    
        if (available()) {
-               owner()->getMiniBuffer()->Set(_("Redo"));
+               owner()->message(_("Redo"));
                hideCursor();
-               beforeChange();
+               beforeChange(text);
                update(text, BufferView::SELECT|BufferView::FITCUR);
                if (!text->TextRedo(this))
-                       owner()->getMiniBuffer()->Set(_("No further redo information"));
+                       owner()->message(_("No further redo information"));
                else
                        update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                setState();
@@ -552,15 +397,16 @@ void BufferView::hfill()
        }
 }
 
+
 void BufferView::copyEnvironment()
 {
        if (available()) {
                text->copyEnvironmentType();
                // clear the selection, even if mark_set
                toggleSelection();
-               text->ClearSelection();
+               text->ClearSelection(this);
                update(text, BufferView::SELECT|BufferView::FITCUR);
-               owner()->getMiniBuffer()->Set(_("Paragraph environment type copied"));
+               owner()->message(_("Paragraph environment type copied"));
        }
 }
 
@@ -569,7 +415,7 @@ void BufferView::pasteEnvironment()
 {
        if (available()) {
                text->pasteEnvironmentType(this);
-               owner()->getMiniBuffer()->Set(_("Paragraph environment type set"));
+               owner()->message(_("Paragraph environment type set"));
                update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
        }
 }
@@ -581,9 +427,9 @@ void BufferView::copy()
                text->CopySelection(this);
                // clear the selection, even if mark_set
                toggleSelection();
-               text->ClearSelection();
+               text->ClearSelection(this);
                update(text, BufferView::SELECT|BufferView::FITCUR);
-               owner()->getMiniBuffer()->Set(_("Copy"));
+               owner()->message(_("Copy"));
        }
 }
 
@@ -594,7 +440,7 @@ void BufferView::cut()
                update(text, BufferView::SELECT|BufferView::FITCUR);
                text->CutSelection(this);
                update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-               owner()->getMiniBuffer()->Set(_("Cut"));
+               owner()->message(_("Cut"));
        }
 }
 
@@ -602,12 +448,13 @@ void BufferView::cut()
 void BufferView::paste()
 {
        if (!available()) return;
-       
-       owner()->getMiniBuffer()->Set(_("Paste"));
+
+       owner()->message(_("Paste"));
+
        hideCursor();
        // clear the selection
        toggleSelection();
-       text->ClearSelection();
+       text->ClearSelection(this);
        update(text, BufferView::SELECT|BufferView::FITCUR);
        
        // paste
@@ -616,7 +463,7 @@ void BufferView::paste()
        
        // clear the selection 
        toggleSelection();
-       text->ClearSelection();
+       text->ClearSelection(this);
        update(text, BufferView::SELECT|BufferView::FITCUR);
 }
 
@@ -627,7 +474,7 @@ void BufferView::gotoInset(std::vector<Inset::Code> const & codes,
        if (!available()) return;
    
        hideCursor();
-       beforeChange();
+       beforeChange(text);
        update(text, BufferView::SELECT|BufferView::FITCUR);
 
        string contents;
@@ -648,10 +495,10 @@ void BufferView::gotoInset(std::vector<Inset::Code> const & codes,
                                text->cursor.pos(0);
                                if (!text->GotoNextInset(this, codes, contents)) {
                                        text->cursor = tmp;
-                                       owner()->getMiniBuffer()->Set(_("No more insets"));
+                                       owner()->message(_("No more insets"));
                                }
                        } else {
-                               owner()->getMiniBuffer()->Set(_("No more insets"));
+                               owner()->message(_("No more insets"));
                        }
        }
        update(text, BufferView::SELECT|BufferView::FITCUR);
@@ -695,7 +542,7 @@ void BufferView::selectLastWord()
        if (!available()) return;
    
        hideCursor();
-       beforeChange();
+       beforeChange(text);
        text->SelectSelectedWord(this);
        toggleSelection(false);
        update(text, BufferView::SELECT|BufferView::FITCUR);
@@ -707,9 +554,9 @@ void BufferView::endOfSpellCheck()
        if (!available()) return;
    
        hideCursor();
-       beforeChange();
+       beforeChange(text);
        text->SelectSelectedWord(this);
-       text->ClearSelection();
+       text->ClearSelection(this);
        update(text, BufferView::SELECT|BufferView::FITCUR);
 }
 
@@ -822,16 +669,8 @@ void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
        if (kind == Undo::EDIT) // in this case insets would not be stored!
                kind = Undo::FINISH;
        text->SetUndo(buffer(), kind,
-#ifndef NEW_INSETS
-                     text->cursor.par()->
-                     ParFromPos(text->cursor.pos())->previous, 
-                     text->cursor.par()->
-                     ParFromPos(text->cursor.pos())->next
-#else
-                     text->cursor.par()->previous, 
-                     text->cursor.par()->next
-#endif
-               );
+                     text->cursor.par()->previous(), 
+                     text->cursor.par()->next());
 }
 
 
@@ -846,9 +685,6 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
                        if (text->UpdateInset(this, inset)) {
                                update();
                                if (mark_dirty) {
-                                       if (buffer()->isLyxClean())
-                                               owner()->getMiniBuffer()->
-                                                       setTimer(4);
                                        buffer()->markDirty();
                                }
                                updateScrollbar();
@@ -858,9 +694,6 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
                        if (text->UpdateInset(this, theLockingInset())) {
                                update();
                                if (mark_dirty){
-                                       if (buffer()->isLyxClean())
-                                               owner()->getMiniBuffer()->
-                                                       setTimer(4);
                                        buffer()->markDirty();
                                }
                                updateScrollbar();
@@ -884,19 +717,15 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
 }
 
 
-bool BufferView::ChangeInsets(Inset::Code code, string const & from, string const & to)
+bool BufferView::ChangeInsets(Inset::Code code,
+                             string const & from, string const & to)
 {
        bool flag = false;
        LyXParagraph * par = buffer()->paragraph;
        LyXCursor cursor = text->cursor;
        LyXCursor tmpcursor = cursor;
-#ifndef NEW_INSETS
-       cursor.par(tmpcursor.par()->ParFromPos(tmpcursor.pos()));
-       cursor.pos(tmpcursor.par()->PositionInParFromPos(tmpcursor.pos()));
-#else
        cursor.par(tmpcursor.par());
        cursor.pos(tmpcursor.pos());
-#endif
 
        while (par) {
                bool flag2 = false;
@@ -912,20 +741,14 @@ bool BufferView::ChangeInsets(Inset::Code code, string const & from, string cons
                }
                if (flag2) {
                        flag = true;
-#ifndef NEW_INSETS
-                       if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
-#endif
-                               // this is possible now, since SetCursor takes
-                               // care about footnotes
-                               text->SetCursorIntern(this, par, 0);
-                               text->RedoParagraphs(this, text->cursor,
-                                                    text->cursor.par()->Next());
-                               text->FullRebreak(this);
-#ifndef NEW_INSETS
-                       }
-#endif
+                       // this is possible now, since SetCursor takes
+                       // care about footnotes
+                       text->SetCursorIntern(this, par, 0);
+                       text->RedoParagraphs(this, text->cursor,
+                                            text->cursor.par()->next());
+                       text->FullRebreak(this);
                }
-               par = par->next;
+               par = par->next();
        }
        text->SetCursorIntern(this, cursor.par(), cursor.pos());
        return flag;
@@ -948,7 +771,7 @@ bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
 
        vector<pair<string,string> > keys = buffer()->getBibkeyList();  
        if (count_if(keys.begin(), keys.end(), 
-                    equal_1st_in_pair<string,string>(from)) 
+                    lyx::equal_1st_in_pair<string,string>(from)) 
            > 1)
                return false;
 
@@ -966,14 +789,14 @@ UpdatableInset * BufferView::theLockingInset() const
 
 void BufferView::theLockingInset(UpdatableInset * inset)
 {
-    text->the_locking_inset = inset;
+       text->the_locking_inset = inset;
 }
 
 
 LyXText * BufferView::getLyXText() const
 {
        if (theLockingInset()) {
-               LyXText * txt = theLockingInset()->getLyXText(this);
+               LyXText * txt = theLockingInset()->getLyXText(this, true);
                if (txt)
                        return txt;
        }
@@ -994,6 +817,7 @@ LyXText * BufferView::getParentText(Inset * inset) const
        return text;
 }
 
+
 Language const * BufferView::getParentLanguage(Inset * inset) const
 {
        LyXText * text = getParentText(inset);