]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
* activate the view from the constructor. This makes sure that the
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index 4ff601ef91cbd078c0923fd8b312439b84490120..ba6b33dd0c7f6c7893996710ecffbc9c1e77f21f 100644 (file)
@@ -277,6 +277,11 @@ GuiView::GuiView(int id)
        // GuiToolbars *must* be initialised before the menu bar.
        d.toolbars_ = new GuiToolbars(*this);
 
+       // set ourself as the current view. This is needed for the menu bar
+       // filling, at least for the static special menu item on Mac. Otherwise
+       // they are greyed out.
+       theLyXFunc().setLyXView(this);
+       
        // Fill up the menu bar.
        guiApp->menus().fillMenuBar(menuBar(), this);
 
@@ -366,6 +371,10 @@ void GuiView::showEvent(QShowEvent * e)
 
 void GuiView::closeEvent(QCloseEvent * close_event)
 {
+       // it can happen that this event arrives without selecting the view,
+       // e.g. when clicking the close button on a background window.
+       theLyXFunc().setLyXView(this);
+
        while (Buffer * b = buffer()) {
                if (b->parent()) {
                        // This is a child document, just close the tab after saving
@@ -407,8 +416,8 @@ void GuiView::closeEvent(QCloseEvent * close_event)
 
        // Save toolbars configuration
        if (isFullScreen()) {
-        d.toolbars_->toggleFullScreen(!isFullScreen());
-        updateToolbars();
+               d.toolbars_->toggleFullScreen(!isFullScreen());
+               updateToolbars();
        }
 
        // Make sure the timer time out will not trigger a statusbar update.
@@ -534,6 +543,22 @@ void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa)
 }
 
 
+void GuiView::on_lastWorkAreaRemoved()
+{
+#ifdef Q_WS_MAC
+       // On Mac close the view if there is no Tab open anymore,
+       // but only if no splitter is visible
+       if (!lyxrc.open_buffers_in_tabs && d.splitter_->count() == 1) {
+               TabWorkArea * twa = qobject_cast<TabWorkArea *>(d.splitter_->widget(0));
+               if (twa && twa->count() == 0) {
+                       // close the view, as no tab is open anymore
+                       QTimer::singleShot(0, this, SLOT(close()));
+               }
+       }
+#endif
+}
+
+
 void GuiView::updateStatusBar()
 {
        // let the user see the explicit message
@@ -716,6 +741,9 @@ TabWorkArea * GuiView::addTabWorkArea()
        TabWorkArea * twa = new TabWorkArea;
        QObject::connect(twa, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
                this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
+       QObject::connect(twa, SIGNAL(lastWorkAreaRemoved()),
+                        this, SLOT(on_lastWorkAreaRemoved()));
+
        d.splitter_->addWidget(twa);
        d.stack_widget_->setCurrentWidget(d.splitter_);
        return twa;
@@ -1108,7 +1136,7 @@ Buffer * GuiView::loadDocument(FileName const & filename, bool tolastfiles)
                setBusy(false);
                return 0;
        }
-
+       
        setBuffer(newBuffer);
 
        // scroll to the position when the file was last closed
@@ -1184,6 +1212,7 @@ void GuiView::openDocument(string const & fname)
        Buffer * buf = loadDocument(fullname);
        if (buf) {
                updateLabels(*buf);
+               
                setBuffer(buf);
                buf->errors("Parse");
                str2 = bformat(_("Document %1$s opened."), disp_fn);
@@ -1638,10 +1667,6 @@ bool GuiView::dispatch(FuncRequest const & cmd)
                bv->cursor().updateFlags(Update::None);
 
        switch(cmd.action) {
-               case LFUN_FILE_OPEN:
-                       openDocument(to_utf8(cmd.argument()));
-                       break;
-
                case LFUN_BUFFER_IMPORT:
                        importDocument(to_utf8(cmd.argument()));
                        break;