]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
whitespace changes;
[lyx.git] / src / buffer.C
index 38c0739b7d5d51715e574162907f03849cdfd482..d58ef540abba0bab9621b472228b1c90bf14e4af 100644 (file)
@@ -97,8 +97,8 @@
 #include "lyxtext.h"
 #include "gettext.h"
 #include "language.h"
-#include "lyx_gui_misc.h"      // WarnReadonly()
 #include "frontends/Dialogs.h"
+#include "frontends/Alert.h"
 #include "encoding.h"
 #include "exporter.h"
 #include "Lsstream.h"
@@ -123,6 +123,8 @@ using std::set;
 using std::stack;
 using std::list;
 
+using lyx::pos_type;
+
 // all these externs should eventually be removed.
 extern BufferList bufferlist;
 
@@ -234,9 +236,6 @@ void Buffer::setReadonly(bool flag)
                updateTitles();
                users->owner()->getDialogs()->updateBufferDependent(false);
        }
-       if (read_only) {
-               WarnReadonly(filename);
-       }
 }
 
 
@@ -286,6 +285,7 @@ ErtComp ert_comp;
 
 #warning And _why_ is this here? (Lgb)
 int unknown_layouts;
+int unknown_tokens;
 
 } // anon
 
@@ -301,6 +301,7 @@ int unknown_layouts;
 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
 {
        unknown_layouts = 0;
+       unknown_tokens = 0;
 #ifndef NO_COMPABILITY
        ert_comp.contents.erase();
        ert_comp.active = false;
@@ -363,9 +364,21 @@ bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
                        s += tostr(unknown_layouts);
                        s += _(" paragraphs");
                }
-               WriteAlert(_("Textclass Loading Error!"), s,
+               Alert::alert(_("Textclass Loading Error!"), s,
                           _("When reading " + fileName()));
-       }       
+       }
+
+       if (unknown_tokens > 0) {
+               string s = _("Encountered ");
+               if (unknown_tokens == 1) {
+                       s += _("one unknown token");
+               } else {
+                       s += tostr(unknown_tokens);
+                       s += _(" unknown tokens");
+               }
+               Alert::alert(_("Textclass Loading Error!"), s,
+                          _("When reading " + fileName()));
+       }
 
        return the_end_read;
 }
@@ -520,6 +533,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                                        + textclasslist.NameOfLayout(params.textclass, par->layout);
                                InsetError * new_inset = new InsetError(s);
                                par->insertInset(0, new_inset);
+                               par->setFont(0, LyXFont(LyXFont::ALL_INHERIT,
+                                                       params.language));
                        }
                        // Test whether the layout is obsolete.
                        LyXLayout const & layout =
@@ -652,19 +667,19 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                if (pp.first) {
                        params.textclass = pp.second;
                } else {
-                       WriteAlert(string(_("Textclass error")), 
+                       Alert::alert(string(_("Textclass error")), 
                                string(_("The document uses an unknown textclass \"")) + 
                                lex.getString() + string("\"."),
                                string(_("LyX will not be able to produce output correctly.")));
                        params.textclass = 0;
                }
                if (!textclasslist.Load(params.textclass)) {
-                               // if the textclass wasn't loaded properly
-                               // we need to either substitute another
-                               // or stop loading the file.
-                               // I can substitute but I don't see how I can
-                               // stop loading... ideas??  ARRae980418
-                       WriteAlert(_("Textclass Loading Error!"),
+                       // if the textclass wasn't loaded properly
+                       // we need to either substitute another
+                       // or stop loading the file.
+                       // I can substitute but I don't see how I can
+                       // stop loading... ideas??  ARRae980418
+                       Alert::alert(_("Textclass Loading Error!"),
                                   string(_("Can't load textclass ")) +
                                   textclasslist.NameOfClass(params.textclass),
                                   _("-- substituting default"));
@@ -1151,14 +1166,16 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                } else {
 #endif
                // This should be insurance for the future: (Asger)
-               lex.printError("Unknown token `$$Token'. "
-                              "Inserting as text.");
-               string::const_iterator cit = token.begin();
-               string::const_iterator end = token.end();
-               for (; cit != end; ++cit) {
-                       par->insertChar(pos, (*cit), font);
-                       ++pos;
-               }
+               ++unknown_tokens;
+               lex.eatLine();
+               string const s = _("Unknown token: ") + token
+                       + " " + lex.text()  + "\n";
+
+               InsetError * new_inset = new InsetError(s);
+               par->insertInset(pos, new_inset);
+               par->setFont(pos, LyXFont(LyXFont::ALL_INHERIT,
+                                         params.language));
+
 #ifndef NO_COMPABILITY
                }
 #endif
@@ -1323,7 +1340,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 }
 
 // needed to insert the selection
-void Buffer::insertStringAsLines(Paragraph *& par, Paragraph::size_type & pos,
+void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
                                  LyXFont const & fn,string const & str) const
 {
        LyXLayout const & layout = textclasslist.Style(params.textclass, 
@@ -1357,9 +1374,8 @@ void Buffer::insertStringAsLines(Paragraph *& par, Paragraph::size_type & pos,
                                ++pos;
                                space_inserted = true;
                        } else {
-                               const Paragraph::size_type nb = 8 - pos % 8;
-                               for (Paragraph::size_type a = 0; 
-                                    a < nb ; ++a) {
+                               const pos_type nb = 8 - pos % 8;
+                               for (pos_type a = 0; a < nb ; ++a) {
                                        par->insertChar(pos, ' ', font);
                                        ++pos;
                                }
@@ -1523,14 +1539,14 @@ bool Buffer::readFile(LyXLex & lex, Paragraph * par)
                                // current format
                        } else if (file_format > LYX_FORMAT) {
                                // future format
-                               WriteAlert(_("Warning!"),
+                               Alert::alert(_("Warning!"),
                                           _("LyX file format is newer that what"),
                                           _("is supported in this LyX version. Expect some problems."));
                                
                        } else if (file_format < LYX_FORMAT) {
                                // old formats
                                if (file_format < 200) {
-                                       WriteAlert(_("ERROR!"),
+                                       Alert::alert(_("ERROR!"),
                                                   _("Old LyX file format found. "
                                                     "Use LyX 0.10.x to read this!"));
                                        return false;
@@ -1542,16 +1558,17 @@ bool Buffer::readFile(LyXLex & lex, Paragraph * par)
                        if (file_format < 213)
                                the_end = true;
 
-                       if (!the_end)
-                               WriteAlert(_("Warning!"),
+                       if (!the_end) {
+                               Alert::alert(_("Warning!"),
                                           _("Reading of document is not complete"),
                                           _("Maybe the document is truncated"));
+                       }
                        return true;
                } else { // "\\lyxformat" not found
-                       WriteAlert(_("ERROR!"), _("Not a LyX file!"));
+                       Alert::alert(_("ERROR!"), _("Not a LyX file!"));
                }
        } else
-               WriteAlert(_("ERROR!"), _("Unable to read file!"));
+               Alert::alert(_("ERROR!"), _("Unable to read file!"));
        return false;
 }
                    
@@ -1647,7 +1664,7 @@ bool Buffer::writeFile(string const & fname, bool flag) const
                        lyxerr << _("Error! Document is read-only: ")
                               << fname << endl;
                else
-                       WriteAlert(_("Error! Document is read-only: "),
+                       Alert::alert(_("Error! Document is read-only: "),
                                   fname);
                return false;
        }
@@ -1660,7 +1677,7 @@ bool Buffer::writeFile(string const & fname, bool flag) const
                        lyxerr << _("Error! Cannot write file: ")
                               << fname << endl;
                else
-                       WriteFSAlert(_("Error! Cannot write file: "),
+                       Alert::err_alert(_("Error! Cannot write file: "),
                                     fname);
                return false;
        }
@@ -1671,7 +1688,7 @@ bool Buffer::writeFile(string const & fname, bool flag) const
                        lyxerr << _("Error! Cannot open file: ")
                               << fname << endl;
                else
-                       WriteFSAlert(_("Error! Cannot open file: "),
+                       Alert::err_alert(_("Error! Cannot open file: "),
                                     fname);
                return false;
        }
@@ -1796,7 +1813,7 @@ string const Buffer::asciiParagraph(Paragraph const * par,
                lyxerr << "Should this ever happen?" << endl;
        }
 
-       for (Paragraph::size_type i = 0; i < par->size(); ++i) {
+       for (pos_type i = 0; i < par->size(); ++i) {
                if (!i && !noparbreak) {
                        if (linelen > 0)
                                buffer << "\n\n";
@@ -1908,7 +1925,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
 {
        ofstream ofs(fname.c_str());
        if (!ofs) {
-               WriteFSAlert(_("Error: Cannot write file:"), fname);
+               Alert::err_alert(_("Error: Cannot write file:"), fname);
                return;
        }
        writeFileAscii(ofs, linelen);
@@ -1942,7 +1959,7 @@ void Buffer::makeLaTeXFile(string const & fname,
 
        ofstream ofs(fname.c_str());
        if (!ofs) {
-               WriteFSAlert(_("Error: Cannot open file: "), fname);
+               Alert::err_alert(_("Error: Cannot open file: "), fname);
                return;
        }
        
@@ -2521,7 +2538,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
        ofstream ofs(fname.c_str());
 
        if (!ofs) {
-               WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
+               Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
                return;
        }
 
@@ -2574,7 +2591,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                                            par->layout);
 
                // treat <toc> as a special case for compatibility with old code
-               if (par->getChar(0) == Paragraph::META_INSET) {
+               if (par->isInset(0)) {
                        Inset * inset = par->getInset(0);
                        Inset::Code lyx_code = inset->lyxCode();
                        if (lyx_code == Inset::TOC_CODE){
@@ -2779,7 +2796,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
 
        stack<PAR_TAG> tag_state;
        // parsing main loop
-       for (Paragraph::size_type i = 0; i < par->size(); ++i) {
+       for (pos_type i = 0; i < par->size(); ++i) {
 
                PAR_TAG tag_close = NONE;
                list < PAR_TAG > tag_open;
@@ -2952,6 +2969,7 @@ void Buffer::sgmlError(Paragraph * par, int pos,
        // insert an error marker in text
        InsetError * new_inset = new InsetError(message);
        par->insertInset(pos, new_inset);
+       par->setFont(pos, LyXFont(LyXFont::ALL_INHERIT, params.language));
 }
 
 
@@ -2959,7 +2977,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 {
        ofstream ofs(fname.c_str());
        if (!ofs) {
-               WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
+               Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
                return;
        }
 
@@ -3105,7 +3123,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 
                        // treat label as a special case for
                        // more WYSIWYM handling.
-                       if (par->getChar(0) == Paragraph::META_INSET) {
+                       if (par->isInset(0)) {
                                Inset * inset = par->getInset(0);
                                Inset::Code lyx_code = inset->lyxCode();
                                if (lyx_code == Inset::LABEL_CODE){
@@ -3271,8 +3289,7 @@ void Buffer::simpleDocBookOnePar(ostream & os,
        //      os << string(depth,' ');
 
        // parsing main loop
-       for (Paragraph::size_type i = 0;
-            i < par->size(); ++i) {
+       for (pos_type i = 0; i < par->size(); ++i) {
                LyXFont font = par->getFont(params, i);
 
                // handle <emphasis> tag
@@ -3355,7 +3372,7 @@ int Buffer::runChktex()
        int res = chktex.run(terr); // run chktex
 
        if (res == -1) {
-               WriteAlert(_("chktex did not work!"),
+               Alert::alert(_("chktex did not work!"),
                           _("Could not run with file:"), name);
        } else if (res > 0) {
                // Insert all errors as errors boxes
@@ -3681,8 +3698,7 @@ bool Buffer::isMultiLingual()
 }
 
 
-Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
-                                      Paragraph::size_type pos)
+Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
        : par(paragraph)
 {
        it = par->InsetIterator(pos);