]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiApplication.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiApplication.cpp
index eac82e48431e03fe7c2ca1fe946798abc7f096da..e25211b0b69712889783e248407e1a710088d429 100644 (file)
@@ -36,6 +36,7 @@
 #include "Session.h"
 #include "version.h"
 
+#include "support/assert.h"
 #include "support/debug.h"
 #include "support/ExceptionMessage.h"
 #include "support/FileName.h"
@@ -168,7 +169,7 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        if (lyxrc.quit_on_last_window_closed)
                setQuitOnLastWindowClosed(false);
        */
-#ifdef Q_WS_MAC
+#ifdef Q_WS_MACX
        // FIXME: Do we need a lyxrc setting for this on Mac? This behaviour
        // seems to be the default case for applications like LyX.
        setQuitOnLastWindowClosed(false);
@@ -296,7 +297,8 @@ bool GuiApplication::dispatch(FuncRequest const & cmd)
        case LFUN_LYX_QUIT:
                // quitting is triggered by the gui code
                // (leaving the event loop).
-               current_view_->message(from_utf8(N_("Exiting.")));
+               if (current_view_)
+                       current_view_->message(from_utf8(N_("Exiting.")));
                if (closeAllViews())
                        quit();
                break;
@@ -320,9 +322,13 @@ bool GuiApplication::dispatch(FuncRequest const & cmd)
 
        case LFUN_BUFFER_NEW:
                if (viewCount() == 0
-                   || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0))
-                       createView();
-               current_view_->newDocument(to_utf8(cmd.argument()), false);
+                   || (!lyxrc.open_buffers_in_tabs && current_view_->buffer() != 0)) {
+                       createView(QString(), false); // keep hidden
+                       current_view_->newDocument(to_utf8(cmd.argument()), false);
+                       current_view_->show();
+                       setActiveWindow(current_view_);
+               } else
+                       current_view_->newDocument(to_utf8(cmd.argument()), false);
                break;
 
        case LFUN_BUFFER_NEW_TEMPLATE:
@@ -376,7 +382,7 @@ static void updateIds(map<int, GuiView *> const & stdmap, vector<int> & ids)
 }
 
 
-void GuiApplication::createView(QString const & geometry_arg)
+void GuiApplication::createView(QString const & geometry_arg, bool autoShow)
 {
        // release the keyboard which might have been grabed by the global
        // menubar on Mac to catch shortcuts even without any GuiView.
@@ -398,7 +404,11 @@ void GuiApplication::createView(QString const & geometry_arg)
        views_[id] = view;
        updateIds(views_, view_ids_);
 
-       view->show();
+       if (autoShow) {
+               view->show();
+               setActiveWindow(view);
+       }
+
        if (!geometry_arg.isEmpty()) {
 #ifdef Q_WS_WIN
                int x, y;
@@ -413,8 +423,7 @@ void GuiApplication::createView(QString const & geometry_arg)
 #endif
        }
        view->setFocus();
-       setActiveWindow(view);
-       setCurrentView(*view);
+       setCurrentView(view);
 }
 
 
@@ -558,14 +567,14 @@ bool GuiApplication::notify(QObject * receiver, QEvent * event)
                        docstring details = e.details_ + '\n';
                        details += theBufferList().emergencyWrite(buf);
                        theBufferList().release(buf);
-                       details += _("\nThe current document was closed.");
+                       details += "\n" + _("The current document was closed.");
                        Alert::error(e.title_, details);
                        return false;
                }
                case WarningException:
                        Alert::warning(e.title_, e.details_);
                        return false;
-               };
+               }
        }
        catch (exception const & e) {
                docstring s = _("LyX has caught an exception, it will now "
@@ -658,8 +667,8 @@ void GuiApplication::addMenuTranslator()
 bool GuiApplication::unregisterView(int id)
 {
        updateIds(views_, view_ids_);
-       BOOST_ASSERT(views_.find(id) != views_.end());
-       BOOST_ASSERT(views_[id]);
+       LASSERT(views_.find(id) != views_.end(), /**/);
+       LASSERT(views_[id], /**/);
 
        map<int, GuiView *>::iterator it;
        for (it = views_.begin(); it != views_.end(); ++it) {
@@ -694,7 +703,7 @@ bool GuiApplication::closeAllViews()
 
 GuiView & GuiApplication::view(int id) const
 {
-       BOOST_ASSERT(views_.find(id) != views_.end());
+       LASSERT(views_.find(id) != views_.end(), /**/);
        return *views_.find(id)->second;
 }
 
@@ -738,7 +747,7 @@ bool GuiApplication::searchMenu(FuncRequest const & func,
 void GuiApplication::initGlobalMenu()
 {
        if (global_menubar_)
-               menus().fillMenuBar(global_menubar_, 0);
+               menus().fillMenuBar(global_menubar_, 0, true);
 }
 
 
@@ -748,8 +757,11 @@ void GuiApplication::onLastWindowClosed()
                global_menubar_->grabKeyboard();
 }
 
+
 ////////////////////////////////////////////////////////////////////////
+//
 // X11 specific stuff goes here...
+
 #ifdef Q_WS_X11
 bool GuiApplication::x11EventFilter(XEvent * xev)
 {
@@ -786,6 +798,13 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
 } // namespace frontend
 
 
+void hideDialogs(std::string const & name, Inset * inset)
+{
+       if (theApp())
+               theApp()->hideDialogs(name, inset);
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //
 // Font stuff
@@ -794,7 +813,7 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
 
 frontend::FontLoader & theFontLoader()
 {
-       BOOST_ASSERT(frontend::guiApp);
+       LASSERT(frontend::guiApp, /**/);
        return frontend::guiApp->fontLoader();
 }
 
@@ -807,21 +826,27 @@ frontend::FontMetrics const & theFontMetrics(Font const & f)
 
 frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
 {
-       BOOST_ASSERT(frontend::guiApp);
+       LASSERT(frontend::guiApp, /**/);
        return frontend::guiApp->fontLoader().metrics(f);
 }
 
 
+////////////////////////////////////////////////////////////////////
+//
+// Misc stuff
+//
+////////////////////////////////////////////////////////////////////
+
 frontend::Clipboard & theClipboard()
 {
-       BOOST_ASSERT(frontend::guiApp);
+       LASSERT(frontend::guiApp, /**/);
        return frontend::guiApp->clipboard();
 }
 
 
 frontend::Selection & theSelection()
 {
-       BOOST_ASSERT(frontend::guiApp);
+       LASSERT(frontend::guiApp, /**/);
        return frontend::guiApp->selection();
 }