]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiApplication.cpp
The core is now clean enough that we don't need the NoGuiFontLoader/Metrics anymore...
[lyx.git] / src / frontends / qt4 / GuiApplication.cpp
index a84e5ae3168e42981a67fbf04942de6348070a05..705b9acec70637c38ead3a4fc019e3f5074535fc 100644 (file)
 
 #include "frontends/alert.h"
 #include "frontends/Application.h"
-#include "frontends/NoGuiFontLoader.h"
-#include "frontends/NoGuiFontMetrics.h"
 #include "frontends/FontLoader.h"
 #include "frontends/FontMetrics.h"
 
 #include "support/ExceptionMessage.h"
 #include "support/FileName.h"
+#include "support/ForkedCalls.h"
 #include "support/lstrings.h"
 #include "support/os.h"
 #include "support/Package.h"
@@ -51,6 +50,7 @@
 #include <QFileOpenEvent>
 #include <QLocale>
 #include <QLibraryInfo>
+#include <QMenuBar>
 #include <QPixmapCache>
 #include <QRegExp>
 #include <QSessionManager>
@@ -72,6 +72,7 @@
 #include <exception>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -127,8 +128,6 @@ public:
 ///////////////////////////////////////////////////////////////
 
 
-using support::FileName;
-
 GuiApplication * guiApp;
 
 
@@ -171,6 +170,8 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
                        << fromqstr(language_name));
 
 #ifdef Q_WS_MACX
+       // all windows in a Mac application share the same menu bar.
+       QMenuBar *menuBar = new QMenuBar(0);
        // This allows to translate the strings that appear in the LyX menu.
        addMenuTranslator();
 #endif
@@ -199,6 +200,11 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
 
        if (lyxrc.typewriter_font_name.empty())
                lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
+
+       general_timer_.setInterval(500);
+       connect(&general_timer_, SIGNAL(timeout()),
+               this, SLOT(handleRegularEvents()));
+       general_timer_.start();
 }
 
 
@@ -370,6 +376,24 @@ void GuiApplication::execBatchCommands()
 }
 
 
+void GuiApplication::restoreGuiSession()
+{
+       if (!lyxrc.load_session)
+               return;
+
+       Session & session = LyX::ref().session();
+       vector<FileName> const & lastopened = session.lastOpened().getfiles();
+       // do not add to the lastfile list since these files are restored from
+       // last session, and should be already there (regular files), or should
+       // not be added at all (help files).
+       for_each(lastopened.begin(), lastopened.end(),
+               bind(&GuiView::loadDocument, current_view_, _1, false));
+
+       // clear this list to save a few bytes of RAM
+       session.lastOpened().clear();
+}
+
+
 QString const GuiApplication::romanFontName()
 {
        QFont font;
@@ -403,6 +427,12 @@ QString const GuiApplication::typewriterFontName()
 }
 
 
+void GuiApplication::handleRegularEvents()
+{
+       ForkedCallsController::handleCompletedProcesses();
+}
+
+
 bool GuiApplication::event(QEvent * e)
 {
        switch(e->type()) {
@@ -415,7 +445,7 @@ bool GuiApplication::event(QEvent * e)
                        // So we acknowledge the event and delay the file opening
                        // until LyX is ready.
                        // FIXME UNICODE: FileName accept an utf8 encoded string.
-                       LyX::ref().addFileToLoad(FileName(fromqstr(foe->file())));
+                       LyX::ref().addFileToLoad(fromqstr(foe->file()));
                else
                        lyx::dispatch(FuncRequest(LFUN_FILE_OPEN,
                                qstring_to_ucs4(foe->file())));
@@ -434,31 +464,28 @@ bool GuiApplication::notify(QObject * receiver, QEvent * event)
        try {
                return QApplication::notify(receiver, event);
        }
-       catch (support::ExceptionMessage const & e) {
-               if (e.type_ == support::ErrorException) {
+       catch (ExceptionMessage const & e) {
+               if (e.type_ == ErrorException) {
                        Alert::error(e.title_, e.details_);
-                       LyX::cref().emergencyCleanup();
-                       QApplication::exit(1);
-               } else if (e.type_ == support::WarningException) {
+                       LyX::cref().exit(1);
+               } else if (e.type_ == WarningException) {
                        Alert::warning(e.title_, e.details_);
                        return false;
                }
        }
-       catch (std::exception const & e) {
+       catch (exception const & e) {
                docstring s = _("LyX has caught an exception, it will now "
                        "attempt to save all unsaved documents and exit."
                        "\n\nException: ");
                s += from_ascii(e.what());
                Alert::error(_("Software exception Detected"), s);
-               LyX::cref().emergencyCleanup();
-               QApplication::exit(1);
+               LyX::cref().exit(1);
        }
        catch (...) {
                docstring s = _("LyX has caught some really weird exception, it will "
                        "now attempt to save all unsaved documents and exit.");
                Alert::error(_("Software exception Detected"), s);
-               LyX::cref().emergencyCleanup();
-               QApplication::exit(1);
+               LyX::cref().exit(1);
        }
 
        return false;
@@ -483,7 +510,7 @@ bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
 
 string const GuiApplication::hexName(ColorCode col)
 {
-       return support::ltrim(fromqstr(color_cache_.get(col).name()), "#");
+       return ltrim(fromqstr(color_cache_.get(col).name()), "#");
 }
 
 
@@ -652,11 +679,6 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
 
 frontend::FontLoader & theFontLoader()
 {
-       static frontend::NoGuiFontLoader no_gui_font_loader;
-
-       if (!use_gui)
-               return no_gui_font_loader;
-
        BOOST_ASSERT(frontend::guiApp);
        return frontend::guiApp->fontLoader();
 }
@@ -670,11 +692,6 @@ frontend::FontMetrics const & theFontMetrics(Font const & f)
 
 frontend::FontMetrics const & theFontMetrics(FontInfo const & f)
 {
-       static frontend::NoGuiFontMetrics no_gui_font_metrics;
-
-       if (!use_gui)
-               return no_gui_font_metrics;
-
        BOOST_ASSERT(frontend::guiApp);
        return frontend::guiApp->fontLoader().metrics(f);
 }