]> git.lyx.org Git - lyx.git/blobdiff - src/buffer_funcs.cpp
fix warning on possibly(?) unused precompiled headers due to different -fPic settings...
[lyx.git] / src / buffer_funcs.cpp
index fd0a4c32e0aa357d775e81920a0d518e30b41f11..1f1cd7917c1c6c8490b875be1af000d27d1e990f 100644 (file)
@@ -49,6 +49,9 @@
 #include <boost/bind.hpp>
 #include <boost/filesystem/operations.hpp>
 
+using std::min;
+using std::string;
+
 
 namespace lyx {
 
@@ -63,9 +66,6 @@ using support::onlyFilename;
 using support::onlyPath;
 using support::unlink;
 
-using std::min;
-using std::string;
-
 namespace Alert = frontend::Alert;
 namespace fs = boost::filesystem;
 
@@ -181,20 +181,29 @@ bool loadLyXFile(Buffer * b, FileName const & s)
 }
 
 
+bool checkIfLoaded(FileName const & fn)
+{
+       return theBufferList().getBuffer(fn.absFilename());
+}
+
+
 Buffer * checkAndLoadLyXFile(FileName const & filename)
 {
        // File already open?
-       if (theBufferList().exists(filename.absFilename())) {
+       Buffer * checkBuffer = theBufferList().getBuffer(filename.absFilename());
+       if (checkBuffer) {
+               if (checkBuffer->isClean())
+                       return checkBuffer;
                docstring const file = makeDisplayPath(filename.absFilename(), 20);
-               docstring text = bformat(_("The document %1$s is already "
-                                                    "loaded.\n\nDo you want to revert "
-                                                    "to the saved version?"), file);
-               if (Alert::prompt(_("Revert to saved document?"),
-                               text, 0, 1,  _("&Revert"), _("&Switch to document")))
-                       return theBufferList().getBuffer(filename.absFilename());
+               docstring text = bformat(_(
+                               "The document %1$s is already loaded and has unsaved changes.\n"
+                               "Do you want to abandon your changes and reload the version on disk?"), file);
+               if (Alert::prompt(_("Reload saved document?"),
+                               text, 0, 1,  _("&Reload"), _("&Keep Changes")))
+                       return checkBuffer;
 
                // FIXME: should be LFUN_REVERT
-               if (theBufferList().close(theBufferList().getBuffer(filename.absFilename()), false))
+               if (theBufferList().close(checkBuffer, false))
                        // Load it again.
                        return checkAndLoadLyXFile(filename);
                else
@@ -474,16 +483,13 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
        Layout_ptr const & layout = par.layout();
        Counters & counters = textclass.counters();
 
-       if (it.pit() == 0) {
-               par.params().appendix(par.params().startOfAppendix());
-       } else {
-               par.params().appendix(it.plist()[it.pit() - 1].params().appendix());
-               if (!par.params().appendix() &&
-                   par.params().startOfAppendix()) {
-                       par.params().appendix(true);
-                       textclass.counters().reset();
-               }
+       if (par.params().startOfAppendix()) {
+               // FIXME: only the counter corresponding to toplevel
+               // sectionning should be reset
+               counters.reset();
+               counters.appendix(true);
        }
+       par.params().appendix(counters.appendix());
 
        // Compute the item depth of the paragraph
        par.itemdepth = getItemDepth(it);
@@ -639,70 +645,14 @@ void setLabel(Buffer const & buf, ParIterator & it, TextClass const & textclass)
 } // anon namespace
 
 
-bool updateCurrentLabel(Buffer const & buf,
-       ParIterator & it)
-{
-    if (it == par_iterator_end(buf.inset()))
-       return false;
-
-//     if (it.lastpit == 0 && Text::isMainText(buf))
-//             return false;
-
-       switch (it->layout()->labeltype) {
-
-       case LABEL_NO_LABEL:
-       case LABEL_MANUAL:
-       case LABEL_BIBLIO:
-       case LABEL_TOP_ENVIRONMENT:
-       case LABEL_CENTERED_TOP_ENVIRONMENT:
-       case LABEL_STATIC:
-       case LABEL_ITEMIZE:
-               setLabel(buf, it, buf.params().getTextClass());
-               return true;
-
-       case LABEL_SENSITIVE:
-       case LABEL_COUNTER:
-       // do more things with enumerate later
-       case LABEL_ENUMERATE:
-               return false;
-       }
-
-       // This is dead code which get rid of a warning:
-       return true;
-}
-
-
-void updateLabels(Buffer const & buf,
-       ParIterator & from, ParIterator & to, bool childonly)
-{
-       for (ParIterator it = from; it != to; ++it) {
-               if (it.pit() > it.lastpit())
-                       return;
-               if (!updateCurrentLabel (buf, it)) {
-                       updateLabels(buf, childonly);
-                       return;
-               }
-       }
-}
-
-
-void updateLabels(Buffer const & buf, ParIterator & iter, bool childonly)
-{
-       if (updateCurrentLabel(buf, iter))
-               return;
-
-       updateLabels(buf, childonly);
-}
-
-
 void updateLabels(Buffer const & buf, bool childonly)
 {
+       Buffer const * const master = buf.getMasterBuffer();
        // Use the master text class also for child documents
-       TextClass const & textclass = buf.params().getTextClass();
+       TextClass const & textclass = master->params().getTextClass();
 
        if (!childonly) {
                // If this is a child document start with the master
-               Buffer const * const master = buf.getMasterBuffer();
                if (master != &buf) {
                        updateLabels(*master);
                        return;