]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
Alfredo's second patch
[lyx.git] / src / BufferView.C
index a041a3d7164bbef0d799625c54e6f39731e64636..b6e81d75690bf7a742ac795f3b77de21f3b6c515 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,6 +44,7 @@
 #include "support/lyxfunctional.h" // equal_1st_in_pair
 #include "support/types.h"
 #include "support/lyxalgo.h" // lyx_count
+#include "support/BoostFormat.h"
 
 #include <fstream>
 
@@ -106,7 +108,7 @@ void BufferView::buffer(Buffer * b)
 void BufferView::reload()
 {
        string const fn = buffer()->fileName();
-       if (bufferlist.close(buffer()))
+       if (bufferlist.close(buffer(), false))
                buffer(bufferlist.loadLyXFile(fn));
 }
 
@@ -302,9 +304,16 @@ bool BufferView::insertLyXFile(string const & filen)
        FileInfo const fi(fname);
 
        if (!fi.readable()) {
-               Alert::alert(_("Error!"),
-                          _("Specified file is unreadable: "),
-                          MakeDisplayPath(fname, 50));
+               string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+               boost::format fmt(_("The specified document\n%1$s\ncould not be read."));
+               fmt % file;
+               string text = fmt.str();
+#else
+               string text = _("The specified document\n");
+               text += file + _(" could not be read.");
+#endif
+               Alert::error(_("Could not read document"), text);
                return false;
        }
 
@@ -312,8 +321,16 @@ bool BufferView::insertLyXFile(string const & filen)
 
        ifstream ifs(fname.c_str());
        if (!ifs) {
-               Alert::err_alert(_("Error! Cannot open specified file:"),
-                          MakeDisplayPath(fname, 50));
+               string const file = MakeDisplayPath(fname, 50);
+#if USE_BOOST_FORMAT
+               boost::format fmt(_("Could not open the specified document\n%1$s."));
+               fmt % file;
+               string text = fmt.str();
+#else
+               string text = _("Could not open the specified document\n");
+               text += file + ".";
+#endif
+               Alert::error(_("Could not open file"), text);
                return false;
        }
 
@@ -342,7 +359,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();
@@ -456,7 +473,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();
@@ -499,10 +516,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)
@@ -530,10 +547,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);
 }
@@ -545,12 +562,7 @@ bool BufferView::insertInset(Inset * inset, string const & lout)
 }
 
 
-// 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 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)
+void BufferView::gotoLabel(string const & label)
 {
        for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
             it != buffer()->inset_iterator_end(); ++it) {
@@ -561,10 +573,9 @@ bool BufferView::gotoLabel(string const & label)
                        text->setCursor(it.getPar(), it.getPos());
                        text->selection.cursor = text->cursor;
                        update(text, BufferView::SELECT);
-                       return true;
+                       return;
                }
        }
-       return false;
 }
 
 
@@ -602,25 +613,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)
 {
@@ -702,8 +694,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);
@@ -820,7 +813,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()));
 }
 
 
@@ -955,8 +948,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();
 }