]> git.lyx.org Git - features.git/commitdiff
* Gui.h: new closeAll() pure virtual method.
authorAbdelrazak Younes <younes@lyx.org>
Tue, 24 Oct 2006 15:01:07 +0000 (15:01 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 24 Oct 2006 15:01:07 +0000 (15:01 +0000)
* qt4/Alert_pimpl.C: make sure the proper Qt attributes are set.

* GuiApplication::quitLyx(): add the "force" argument to the funcRequest.

* GuiImplementation:
  - GuiImplementation(): remove the signal connection. This was triggered after the LastWindowClosed signal so was not useful.
  - cleanupViews(): renamed to unregisterView() and handle the WorkAreas as well.
  - closeAll(): new method (from LyXView).

* GuiView.C
  - clean up the includes order.
  - closeEvent(): make sure that theBufferList().quitWriteAll() is called if last window closed.

* lyx_main.C / LyX::quit():
  - remove noAsk argument
  - delete bufferList::quitWriteAll() call (this is handled in the frontend).
  - delete Session stuff (ditto)

* LyXFunc::dispatch()
  - LFUN_LYX_EXIT: close all window before exiting from user command (as opposed to last window closed).

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

src/frontends/Gui.h
src/frontends/qt4/Alert_pimpl.C
src/frontends/qt4/GuiApplication.C
src/frontends/qt4/GuiImplementation.C
src/frontends/qt4/GuiImplementation.h
src/frontends/qt4/GuiView.C
src/frontends/qt4/GuiView.h
src/lyx_main.C
src/lyx_main.h
src/lyxfunc.C

index c79e5f54abb21a836eb24292fd8ca65e7fbc65e2..442508f7ea0388bc033ec114d90cf35ef7da07fd 100644 (file)
@@ -46,6 +46,8 @@ public:
        virtual int newWorkArea(unsigned int width, unsigned int height, int view_id) = 0;
        ///
        virtual WorkArea & workArea(int id) = 0;
+       ///
+       virtual bool closeAll() = 0;
 
        ///
        std::vector<int> const & viewIds() { return view_ids_; };
index 367b25a4112bcb458cd0351292e41dd92bd460db..82abb1e3fdba7145ead766b844544bb99cced0cf 100644 (file)
 
 #include <algorithm>
 
+using std::pair;
+using std::make_pair;
 
 namespace lyx {
 
 using lyx::support::bformat;
 using lyx::docstring;
 
-using std::pair;
-using std::make_pair;
+namespace {
+
+class MessageBox: public QMessageBox
+{
+public:
+       MessageBox(QWidget * parent = 0): QMessageBox(parent)
+       {
+               setAttribute(Qt::WA_DeleteOnClose, true);
+               setAttribute(Qt::WA_QuitOnClose, false);
+       }
+};
+
+} // anonymous namespace
 
 
 int prompt_pimpl(docstring const & tit, docstring const & question,
@@ -44,8 +57,10 @@ int prompt_pimpl(docstring const & tit, docstring const & question,
 {
        docstring const title = bformat(_("LyX: %1$s"), tit);
 
+       MessageBox mb;
+
        // FIXME replace that with theApp->gui()->currentView()
-       int res = QMessageBox::information(qApp->focusWidget(),
+       int res = mb.information(qApp->focusWidget(),
                                           toqstr(title),
                                           toqstr(formatted(question)),
                                           toqstr(b1),
@@ -63,7 +78,9 @@ int prompt_pimpl(docstring const & tit, docstring const & question,
 void warning_pimpl(docstring const & tit, docstring const & message)
 {
        docstring const title = bformat(_("LyX: %1$s"), tit);
-       QMessageBox::warning(qApp->focusWidget(),
+
+       MessageBox mb;
+       mb.warning(qApp->focusWidget(),
                             toqstr(title),
                             toqstr(formatted(message)));
 }
@@ -72,7 +89,8 @@ void warning_pimpl(docstring const & tit, docstring const & message)
 void error_pimpl(docstring const & tit, docstring const & message)
 {
        docstring const title = bformat(_("LyX: %1$s"), tit);
-       QMessageBox::critical(qApp->focusWidget(),
+       MessageBox mb;
+       mb.critical(qApp->focusWidget(),
                              toqstr(title),
                              toqstr(formatted(message)));
 }
@@ -81,7 +99,8 @@ void error_pimpl(docstring const & tit, docstring const & message)
 void information_pimpl(docstring const & tit, docstring const & message)
 {
        docstring const title = bformat(_("LyX: %1$s"), tit);
-       QMessageBox::information(qApp->focusWidget(),
+       MessageBox mb;
+       mb.information(qApp->focusWidget(),
                                 toqstr(title),
                                 toqstr(formatted(message)));
 }
index bc8405f5d3693f39355487889b46ff6a5a1d2637..08b17a1f09520b68051075e4ba11aaffbf8f8f1a 100644 (file)
@@ -165,7 +165,7 @@ void GuiApplication::quitLyX()
 
        // trigger LFUN_LYX_QUIT instead of QApplication::quit() directly
        // since LFUN_LYX_QUIT may have more cleanup stuff
-       dispatch(FuncRequest(LFUN_LYX_QUIT));
+       dispatch(FuncRequest(LFUN_LYX_QUIT, "force"));
 }
 
 
index 08a80d552165a6064f81d1e4737a2262a8656082..a67d02520f3b043cbdaad7c16081adc2944e6595 100644 (file)
@@ -20,6 +20,7 @@
 #include "GuiWorkArea.h"
 
 #include "BufferView.h"
+#include "bufferlist.h"
 #include "funcrequest.h"
 #include "lyxfunc.h"
 
@@ -42,9 +43,6 @@ int GuiImplementation::newView()
        views_[id] = new GuiView(id);
        view_ids_.push_back(id);
 
-       QObject::connect(views_[id], SIGNAL(destroyed(QObject *)),
-               this, SLOT(cleanupViews(QObject *)));
-
        return id;
 }
 
@@ -57,13 +55,47 @@ LyXView& GuiImplementation::view(int id)
 }
 
 
-void GuiImplementation::cleanupViews(QObject * qobj)
+bool GuiImplementation::closeAll()
+{
+       if (!theBufferList().quitWriteAll())
+               return false;
+
+       // In order to know if it is the last opened window,
+       // GuiView::closeEvent() check for (view_ids_.size() == 1)
+       // We deny this check by setting the vector size to zero.
+       // But we still need the vector, hence the temporary copy.
+       std::vector<int> view_ids_tmp = view_ids_;
+       view_ids_.clear();
+
+       for (size_t i = 0; i < view_ids_tmp.size(); ++i) {
+               // LFUN_LYX_QUIT has already been triggered so we need
+               // to disable the lastWindowClosed() signal before closing
+               // the last window.
+               views_[view_ids_tmp[i]]->setAttribute(Qt::WA_QuitOnClose, false);
+               views_[view_ids_tmp[i]]->close();
+               // The view_ids_ vector is reconstructed in the closeEvent; so
+               // let's clear that out again!
+               view_ids_.clear();
+       }
+
+       views_.clear();
+       view_ids_.clear();
+       work_areas_.clear();
+
+       return true;
+}
+
+
+void GuiImplementation::unregisterView(GuiView * view)
 {
-       GuiView * view = static_cast<GuiView *>(qobj);
        std::map<int, GuiView *>::iterator I;
 
        for (I = views_.begin(); I != views_.end(); ++I) {
                if (I->second == view) {
+                       std::vector<int> const & wa_ids = view->workAreaIds();
+                       for (size_t i = 0; i < wa_ids.size(); ++i)
+                               work_areas_.erase(wa_ids[i]);
+
                        views_.erase(I->first);
                        break;
                }
@@ -76,6 +108,7 @@ void GuiImplementation::cleanupViews(QObject * qobj)
 //             dispatch(FuncRequest(LFUN_LYX_QUIT));
                return;
        }
+
        theLyXFunc().setLyXView(views_.begin()->second);
 }
 
index e73af83132f588b7c84cce0df8d11be38b68c11d..221391988c0a163f56c5adb28924276c514df4ad 100644 (file)
@@ -38,14 +38,15 @@ public:
        GuiImplementation();
        virtual ~GuiImplementation() {}
 
-       int newView();
-       LyXView& view(int id);
-       int newWorkArea(unsigned int width, unsigned int height, int view_id);
-       WorkArea& workArea(int id);
+       virtual int newView();
+       virtual LyXView& view(int id);
+       virtual int newWorkArea(unsigned int width, unsigned int height, int view_id);
+       virtual WorkArea& workArea(int id);
+       virtual bool closeAll();
 
-private Q_SLOTS:
+public Q_SLOTS:
        ///
-       void cleanupViews(QObject * view);
+       void unregisterView(GuiView * view);
 
 private:
        ///
index 0fd093e59f9bdbe9832cea634f1fe0e25099b85f..1868891cb5ea235b83f305f208b9d1c92c7f9701 100644 (file)
 
 #include <config.h>
 
-#include "BufferView.h"
-#include "lyx_cb.h"
-#include "lyxrc.h"
-#include "lyx_main.h"
-#include "session.h"
-#include "lyxfunc.h"
-#include "MenuBackend.h"
-#include "funcrequest.h"
-#include "funcrequest.h"
-
-#include "debug.h"
-
-#include "frontends/WorkArea.h"
-#include "support/filetools.h"
-#include "support/convert.h"
-#include "support/lstrings.h"
-
-// This include must be declared before everything else because
-// of boost/Qt/LyX clash...
 #include "GuiImplementation.h"
 
 #include "GuiView.h"
 #include "QCommandBuffer.h"
 #include "qt_helpers.h"
 
+#include "frontends/Application.h"
+#include "frontends/Gui.h"
+#include "frontends/WorkArea.h"
+
+#include "support/filetools.h"
+#include "support/convert.h"
+#include "support/lstrings.h"
+
+#include "BufferView.h"
+#include "bufferlist.h"
+#include "debug.h"
+#include "funcrequest.h"
+#include "lyx_cb.h"
+#include "lyxrc.h"
+#include "lyx_main.h"
+#include "session.h"
+#include "lyxfunc.h"
+#include "MenuBackend.h"
+
 #include <QAction>
 #include <QApplication>
 #include <QCloseEvent>
 #include <QStatusBar>
 #include <QToolBar>
 
-
 #include <boost/bind.hpp>
 
-
-using std::string;
 using std::endl;
+using std::string;
+using std::vector;
 
 namespace lyx {
 
@@ -264,9 +263,20 @@ void GuiView::moveEvent(QMoveEvent *)
 }
 
 
-void GuiView::closeEvent(QCloseEvent *)
+void GuiView::closeEvent(QCloseEvent * close_event)
 {
+       GuiImplementation & gui 
+               = static_cast<GuiImplementation &>(theApp->gui());
+
+       vector<int> const & view_ids = gui.viewIds();
+
+       if (view_ids.size() == 1 && !theBufferList().quitWriteAll()) {
+               close_event->ignore();
+               return;
+       }
+
        saveGeometry();
+       gui.unregisterView(this);
 }
 
 
index 52ea091bb4d988d7b454cb7fc6b256e1be98cc87..1eec4bb535b9ba8d599dd78495323f141882e395 100644 (file)
@@ -42,6 +42,10 @@ QWidget* mainWindow();
  * GuiView - Qt4 implementation of LyXView
  *
  * qt4-private implementation of the main LyX window.
+ *
+ * Note: any QObject emits a destroyed(QObject *) Qt signal when it
+ *       is deleted.This might be useful for closing other dialogs
+ *       depending on a given GuiView.
  */
 class GuiView : public QMainWindow, public LyXView {
        Q_OBJECT
index edf7031b048429747e518f8d7fb5349a70502ac6..cec8e6314dd913ed4b544de566b4d1a2770f4815 100644 (file)
@@ -393,27 +393,14 @@ void LyX::earlyExit(int status)
 }
 
 
-void LyX::quit(bool noask)
+void LyX::quit()
 {
        lyxerr[Debug::INFO] << "Running QuitLyX." << endl;
 
-       if (use_gui) {
-               if (!noask && !pimpl_->buffer_list_.quitWriteAll())
-                       return;
-
-               // The LyXView Geometry settings are stored when LyXView::close
-               // is called explicitely but a straight quit() command would not
-               // guarante that. So we make sure this is done here:
-               vector<int> const & view_ids = pimpl_->application_->gui().viewIds();
-               for (size_t i = 0; i < view_ids.size(); ++i)
-                       pimpl_->application_->gui().view(view_ids[i]).saveGeometry();
-
-               pimpl_->session_->writeFile();
-       }
-
        prepareExit();
 
        if (use_gui) {
+               pimpl_->session_->writeFile();
                pimpl_->lyx_server_.reset();
                pimpl_->lyx_socket_.reset();
                pimpl_->application_->exit(0);
index 2d82153221c7584119e82a4dce8eb3bef1e53794..944d2c12f091e5c8f857a33e71feba6f612e8a1d 100644 (file)
@@ -66,7 +66,7 @@ public:
        In GUI mode, after this function has been called, application_ leaves
        the main event loop and returns from the call to Application::start().
        */
-       void quit(bool noask);
+       void quit();
 
        ///
        BufferList & bufferList();
index deb7d0a239374747461df04f54f7e3ced30f608a..a1549f8fdee08812620df2e80fca762b1b552355 100644 (file)
@@ -1022,13 +1022,23 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_LYX_QUIT:
+                       if (argument != "force") {
+                               if (!theApp->gui().closeAll())
+                                       break;
+                               lyx_view_ = 0;
+                       }
+
+                       // FIXME: this code needs to be transfered somewhere else
+                       // as lyx_view_ will most certainly be null and a same buffer
+                       // might be visible in more than one LyXView.
                        if (lyx_view_ && lyx_view_->view()->buffer()) {
                                // save cursor Position for opened files to .lyx/session
                                LyX::ref().session().saveFilePosition(lyx_view_->buffer()->fileName(),
                                        boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
                                // save bookmarks to .lyx/session
                                view()->saveSavedPositions();
-                       }                       
+                       }
+
                        LyX::ref().quit(argument == "force");
                        break;