rgheck schreef:

I meant on buffer hiding. If I hide a dirty buffer with this new patch, LyX
just hides it without asking me if I want to save it.

Yes, that is right. The new patch doesn't try to ask about that: Vincent didn't like where I was doing it, and I can't see any other place;

Like this ?

I'm not sure whether the reloading is ok like this..

Vincent
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp       (revision 30994)
+++ src/frontends/qt4/GuiView.cpp       (working copy)
@@ -1923,6 +1923,13 @@
 }
 
 
+bool GuiView::hideBuffer()
+{
+       Buffer * buf = buffer();
+       return buf && closeBuffer(*buf, false);
+}
+
+
 bool GuiView::closeBuffer()
 {
        Buffer * buf = buffer();
@@ -1939,7 +1946,7 @@
        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
@@ -1955,7 +1962,7 @@
 }
 
 
-bool GuiView::saveBufferIfNeeded(Buffer & buf)
+bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
 {
        if (buf.isClean() || buf.paragraphs().empty())
                return true;
@@ -1974,10 +1981,21 @@
        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:
@@ -1989,6 +2007,11 @@
                // 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: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (revision 30994)
+++ src/frontends/qt4/GuiView.h (working copy)
@@ -91,6 +91,8 @@
        void setBuffer(Buffer * b); ///< \c Buffer to set.
        ///
        bool closeBuffer();
+       ///
+       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?
@@ -297,7 +299,7 @@
        bool closeBuffer(Buffer & buf, bool close_buffer,
                bool tolastopened = false, bool mark_active = false);
        ///
-       bool saveBufferIfNeeded(Buffer & buf);
+       bool saveBufferIfNeeded(Buffer & buf, bool hiding);
        ///
        bool closeBufferAll(bool tolastopened = false);
        ///
Index: src/frontends/qt4/GuiWorkArea.cpp
===================================================================
--- src/frontends/qt4/GuiWorkArea.cpp   (revision 30991)
+++ src/frontends/qt4/GuiWorkArea.cpp   (working copy)
@@ -1532,13 +1532,14 @@
 
 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();
 }
 
 ///

Reply via email to