]> git.lyx.org Git - features.git/commitdiff
Extend saveBufferIsNeeded with a parameter indicating whether the buffer is going...
authorVincent van Ravesteijn <vfr@lyx.org>
Fri, 14 Aug 2009 23:12:21 +0000 (23:12 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Fri, 14 Aug 2009 23:12:21 +0000 (23:12 +0000)
Now, the option "Hide Tab" uses closeBuffer and asks for saving intead of instantly removing the workArea.

This is part of bug #5893: we try to make sure that there are no dirty hidden buffers.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31043 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/frontends/qt4/GuiWorkArea.cpp

index 0f7adbda8a67509ccfd179b53f5142f9d380da2f..034e9c55892cf93abcac88e0b0720c6186d4e51a 100644 (file)
@@ -1925,6 +1925,13 @@ bool GuiView::saveBuffer(Buffer & b)
 }
 
 
+bool GuiView::hideBuffer()
+{
+       Buffer * buf = buffer();
+       return buf && closeBuffer(*buf, false);
+}
+
+
 bool GuiView::closeBuffer()
 {
        Buffer * buf = buffer();
@@ -1941,7 +1948,7 @@ bool GuiView::closeBuffer(Buffer & buf, bool close_buffer,
        for (size_t i = 0; i < theSession().bookmarks().size(); ++i)
                theLyXFunc().gotoBookmark(i+1, false, false);
 
-       if (saveBufferIfNeeded(buf)) {
+       if (saveBufferIfNeeded(buf, !close_buffer)) {
                // save in sessions if requested
                // do not save childs if their master
                // is opened as well
@@ -1957,7 +1964,7 @@ bool GuiView::closeBuffer(Buffer & buf, bool close_buffer,
 }
 
 
-bool GuiView::saveBufferIfNeeded(Buffer & buf)
+bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
 {
        if (buf.isClean() || buf.paragraphs().empty())
                return true;
@@ -1976,10 +1983,21 @@ bool GuiView::saveBufferIfNeeded(Buffer & buf)
        raise();
        activateWindow();
 
-       docstring const text = bformat(_("The document %1$s has unsaved changes."
-               "\n\nDo you want to save the document or discard the changes?"), file);
-       int const ret = Alert::prompt(_("Save changed document?"),
-               text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
+       int ret;
+       if (hiding && buf.isUnnamed()) {
+               docstring const text = bformat(_("The document %1$s has not been "
+                                            "saved yet.\n\nDo you want to save "
+                                            "the document?"), file);
+               ret = Alert::prompt(_("Save new document?"), 
+                       text, 0, 1, _("&Save"), _("&Cancel"));
+               if (ret == 1)
+                       ++ret;
+       } else {
+               docstring const text = bformat(_("The document %1$s has unsaved changes."
+                       "\n\nDo you want to save the document or discard the changes?"), file);
+               ret = Alert::prompt(_("Save changed document?"),
+                       text, 0, 2, _("&Save"), _("&Discard"), _("&Cancel"));
+       }
 
        switch (ret) {
        case 0:
@@ -1991,6 +2009,11 @@ bool GuiView::saveBufferIfNeeded(Buffer & buf)
                // have no autosave file but I guess
                // this is really improbable (Jug)
                buf.removeAutosaveFile();
+               if (hiding) {
+                       // revert all changes
+                       buf.loadLyXFile(buf.fileName());
+                       buf.markClean();
+               }
                break;
        case 2:
                return false;
index fe57bd1e75b55628abfc0c96ec62a4081cb1760f..29e3021298e02c19e672efdccd4f9503177cf90d 100644 (file)
@@ -91,6 +91,8 @@ public:
        void setBuffer(Buffer * b); ///< \c Buffer to set.
        ///
        bool closeBuffer();
+       /// hides the buffer and makes sure it is clean
+       bool hideBuffer();
        /// load a document into the current workarea.
        Buffer * loadDocument(support::FileName const &  name, ///< File to load.
                bool tolastfiles = true);  ///< append to the "Open recent" menu?
@@ -296,8 +298,10 @@ private:
        ///
        bool closeBuffer(Buffer & buf, bool close_buffer,
                bool tolastopened = false, bool mark_active = false);
-       ///
-       bool saveBufferIfNeeded(Buffer & buf);
+       /// gives the user the possibility to save his work 
+       /// or to discard the changes. If hiding is true, the
+       /// document will be reloaded.
+       bool saveBufferIfNeeded(Buffer & buf, bool hiding);
        ///
        bool closeBufferAll(bool tolastopened = false);
        ///
index 4ec9c0ed892fbeb14795da3d317257764594bfa4..4c93a33a52509d6556b15f82faf496f24220376b 100644 (file)
@@ -1532,13 +1532,14 @@ void TabWorkArea::closeCurrentBuffer()
 
 void TabWorkArea::closeCurrentTab()
 {
+       GuiWorkArea * wa;
        if (clicked_tab_ == -1)
-               removeWorkArea(currentWorkArea());
+               wa = currentWorkArea();
        else {
-               GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+               wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
                LASSERT(wa, /**/);
-               removeWorkArea(wa);
        }
+       wa->view().hideBuffer();
 }
 
 ///