]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
don't rm emergency saves ever
[lyx.git] / src / buffer.C
index aa481e4815a8906edbad2c62fae13c0dba104d6f..731e538c1c756f3e3345ebea7db34efdbd7a957a 100644 (file)
@@ -501,7 +501,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
        // language is set and used in the gui.
        // If you know of a better place to put this, please tell me. (Lgb)
        updateDocLang(params.language);
-       
+
        return ret;
 }
 
@@ -1037,7 +1037,7 @@ void Buffer::makeLaTeXFile(ostream & os,
        texrow.reset();
        // The starting paragraph of the coming rows is the
        // first paragraph of the document. (Asger)
-       texrow.start(&*(paragraphs.begin()), 0);
+       texrow.start(paragraphs.begin()->id(), 0);
 
        if (!only_body && nice) {
                os << "%% " << lyx_docversion << " created this file.  "
@@ -1319,7 +1319,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                        break;
                }
 
-               simpleLinuxDocOnePar(ofs, &*pit, depth);
+               simpleLinuxDocOnePar(ofs, pit, depth);
 
                ofs << "\n";
                // write closing SGML tags
@@ -1412,8 +1412,8 @@ void reset(PAR_TAG & p1, PAR_TAG const & p2)
 
 // Handle internal paragraph parsing -- layout already processed.
 void Buffer::simpleLinuxDocOnePar(ostream & os,
-       Paragraph * par,
-       Paragraph::depth_type /*depth*/)
+       ParagraphList::iterator par,
+       Paragraph::depth_type /*depth*/) const
 {
        LyXLayout_ptr const & style = par->layout();
 
@@ -2215,7 +2215,7 @@ void Buffer::redraw()
 void Buffer::changeLanguage(Language const * from, Language const * to)
 {
        lyxerr << "Changing Language!" << endl;
-       
+
        // Take care of l10n/i18n
        updateDocLang(to);
 
@@ -2224,10 +2224,10 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
                (*it)->changeLanguage(params, from, to);
 }
 
-       
+
 void Buffer::updateDocLang(Language const * nlang)
 {
-       messages_.reset(new Messages(nlang->code(), "/usr/local/share/locale"));
+       messages_.reset(new Messages(nlang->code()));
 }
 
 
@@ -2268,22 +2268,24 @@ Inset * Buffer::getInsetFromID(int id_arg) const
 }
 
 
-Paragraph * Buffer::getParFromID(int id) const
+ParagraphList::iterator Buffer::getParFromID(int id) const
 {
-       if (id < 0)
-               return 0;
-
-       // why should we allow < 0 ??
-       //lyx::Assert(id >= 0);
+#warning FIXME: const correctness! (Andre)
+       ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
+       ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
 
-       ParConstIterator it(par_iterator_begin());
-       ParConstIterator end(par_iterator_end());
+#warning FIXME, perhaps this func should return a ParIterator? (Lgb)
+       if (id < 0) {
+               // John says this is called with id == -1 from undo
+               lyxerr << "getParFromID(), id: " << id << endl;
+               return 0;
+       }
 
        for (; it != end; ++it) {
                // go on then, show me how to remove
                // the cast
                if ((*it)->id() == id) {
-                       return const_cast<Paragraph*>(*it);
+                       return *it;
                }
        }
 
@@ -2291,6 +2293,25 @@ Paragraph * Buffer::getParFromID(int id) const
 }
 
 
+bool Buffer::hasParWithID(int id) const
+{
+       ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
+       ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
+
+       if (id < 0) {
+               // John says this is called with id == -1 from undo
+               lyxerr << "hasParWithID(), id: " << id << endl;
+               return 0;
+       }
+
+       for (; it != end; ++it)
+               if ((*it)->id() == id)
+                       return true;
+
+       return false;
+}
+
+
 ParIterator Buffer::par_iterator_begin()
 {
        return ParIterator(&*(paragraphs.begin()));
@@ -2338,7 +2359,7 @@ string const Buffer::B_(string const & l10n) const
        if (messages_.get()) {
                return messages_->get(l10n);
        }
-       
+
        return _(l10n);
 }
 
@@ -2477,9 +2498,9 @@ Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
 }
 
 
-Paragraph * Buffer::inset_iterator::getPar()
+ParagraphList::iterator Buffer::inset_iterator::getPar() const
 {
-       return &(*pit);
+       return pit;
 }