]> git.lyx.org Git - features.git/commitdiff
* create global menubar on Mac without a parent. It will be shown if no GuiView exists.
authorStefan Schimanski <sts@lyx.org>
Fri, 14 Mar 2008 23:25:11 +0000 (23:25 +0000)
committerStefan Schimanski <sts@lyx.org>
Fri, 14 Mar 2008 23:25:11 +0000 (23:25 +0000)
* fill global menubar with the normal actions
* capture the keyboard on the menubar if no GuiView exists. This
  enables the shortcuts on Mac in those cases.

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

src/LyX.cpp
src/frontends/Application.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h

index 7de306c0d2ff05df806c38430ad9c823632d05d4..04970c9e39befd102f283003f8a80e3cf4d3ae6a 100644 (file)
@@ -877,7 +877,12 @@ bool LyX::init()
        // This must happen after package initialization and after lyxrc is
        // read, therefore it can't be done by a static object.
        ConverterCache::init();
-
+       
+       // init the global menubar on Mac. This must be done after the session
+       // was recovered to know the "last files".
+       if (use_gui)
+               theApp()->initGlobalMenu();
+       
        return true;
 }
 
index 0cc2ed00f69eef03e37bcfa262035469e4d083a3..ab08ace6189e0851aa2484f247353ca4e95ca6be 100644 (file)
@@ -219,6 +219,11 @@ public:
        */
        virtual void readMenus(Lexer & lex) = 0;
 
+       /**
+       * initialize the global menubar on Mac
+       */
+       virtual void initGlobalMenu() = 0;
+       
        /**
        * add a callback for socket read notification
        * @param fd socket descriptor (file/socket/etc)
index 704533d4af6e53d843ba06365170d4dd5d06a1aa..b3ba440f41beaea0864fbe553f20d1e3322b0f84 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "qt_helpers.h"
 #include "GuiImage.h"
+#include "GuiKeySymbol.h"
 #include "GuiView.h"
 
 #include "frontends/alert.h"
@@ -121,6 +122,27 @@ public:
        }
 };
 
+class GlobalMenuBar : public QMenuBar
+{
+public:
+       ///
+       GlobalMenuBar() : QMenuBar(0) {}
+       
+       ///
+       bool event(QEvent * e)
+       {
+               if (e->type() == QEvent::ShortcutOverride) {
+                       //          && activeWindow() == 0) {
+                       QKeyEvent * ke = static_cast<QKeyEvent*>(e);
+                       KeySymbol sym;
+                       setKeySymbol(&sym, ke);
+                       theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
+                       e->accept();
+                       return true;
+               }
+               return false;
+       }
+};
 
 ///////////////////////////////////////////////////////////////
 // You can find more platform specific stuff
@@ -132,7 +154,7 @@ GuiApplication * guiApp;
 
 
 GuiApplication::GuiApplication(int & argc, char ** argv)
-       : QApplication(argc, argv), Application(), current_view_(0)
+       : QApplication(argc, argv), Application(), current_view_(0), global_menubar_(0)
 {
        QString app_name = "LyX";
        QCoreApplication::setOrganizationName(app_name);
@@ -146,7 +168,10 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        if (lyxrc.quit_on_last_window_closed)
                setQuitOnLastWindowClosed(false);
        */
-
+#ifdef Q_WS_MAC
+       setQuitOnLastWindowClosed(false);
+#endif
+       
 #ifdef Q_WS_X11
        // doubleClickInterval() is 400 ms on X11 which is just too long.
        // On Windows and Mac OS X, the operating system's value is used.
@@ -175,11 +200,10 @@ 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
+       connect(this, SIGNAL(lastWindowClosed()), this, SLOT(onLastWindowClosed()));
 
        using namespace lyx::graphics;
 
@@ -210,6 +234,14 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        connect(&general_timer_, SIGNAL(timeout()),
                this, SLOT(handleRegularEvents()));
        general_timer_.start();
+       
+#ifdef Q_WS_MACX
+       if (global_menubar_ == 0) {
+               // Create the global default menubar which is shown for the dialogs
+               // and if no GuiView is visible.
+               global_menubar_ = new GlobalMenuBar();
+       }
+#endif 
 }
 
 
@@ -697,6 +729,19 @@ bool GuiApplication::searchMenu(FuncRequest const & func,
 }
 
 
+void GuiApplication::initGlobalMenu()
+{
+       if (global_menubar_)
+               menus().fillMenuBar(global_menubar_, 0);
+}
+
+
+void GuiApplication::onLastWindowClosed()
+{
+       if (global_menubar_)
+               global_menubar_->grabKeyboard();
+}
+
 ////////////////////////////////////////////////////////////////////////
 // X11 specific stuff goes here...
 #ifdef Q_WS_X11
index f9a770a3ab910dee1b01c4413607f0d4f8fd6da9..c6695cc131f66fcccf96babc69cea4bfd11c991d 100644 (file)
@@ -39,6 +39,7 @@ namespace frontend {
 
 class GuiView;
 class LyXView;
+class GlobalMenuBar;
 class GuiWorkArea;
 class SocketNotifier;
 
@@ -72,6 +73,7 @@ public:
        virtual std::string const hexName(ColorCode col);
        virtual void updateColor(ColorCode col);
        virtual void readMenus(Lexer & lex);
+       virtual void initGlobalMenu();
        virtual void registerSocketCallback(int fd, SocketCallback func);
        void unregisterSocketCallback(int fd);
        bool searchMenu(FuncRequest const & func, std::vector<docstring> & names) const;
@@ -87,7 +89,7 @@ public:
 
        /// Create the main window with given geometry settings.
        /// \param geometry_arg: only for Windows platform.
-       void createView(QString const & geometry_arg);
+       void createView(QString const & geometry_arg = QString());
        ///
        GuiView const * currentView() const { return current_view_; }
        ///
@@ -128,7 +130,9 @@ private Q_SLOTS:
        void socketDataReceived(int fd);
        /// events to be triggered by general_timer_ should go here
        void handleRegularEvents();
-
+       ///
+       void onLastWindowClosed();
+       
 private:
        ///
        bool closeAllViews();
@@ -171,6 +175,8 @@ public:
        /// This LyXView is the one receiving Clipboard and Selection
        /// events
        GuiView * current_view_;
+       /// only used on mac
+       GlobalMenuBar * global_menubar_;
 }; // GuiApplication
 
 extern GuiApplication * guiApp;