]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
Allow use of Tab keys when no document's open.
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index 21a323efb608c8e30f1a8ddbe6a981e39fecf2b8..c07aa04ec0aedc20424c0bd294ad51f41dbb3bdd 100644 (file)
@@ -20,9 +20,9 @@
 #include "GuiApplication.h"
 #include "GuiWorkArea.h"
 #include "GuiKeySymbol.h"
-#include "GuiMenubar.h"
 #include "GuiToolbar.h"
 #include "GuiToolbars.h"
+#include "Menus.h"
 
 #include "qt_helpers.h"
 
@@ -45,7 +45,6 @@
 #include "LyX.h"
 #include "LyXRC.h"
 #include "LyXVC.h"
-#include "MenuBackend.h"
 #include "Paragraph.h"
 #include "TextClass.h"
 #include "Text.h"
@@ -55,6 +54,7 @@
 #include "support/FileFilterList.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
+#include "support/ForkedCalls.h"
 #include "support/lstrings.h"
 #include "support/os.h"
 #include "support/Package.h"
@@ -165,7 +165,6 @@ struct GuiView::GuiViewPrivate
                delete splitter_;
                delete bg_widget_;
                delete stack_widget_;
-               delete menubar_;
                delete toolbars_;
        }
 
@@ -242,8 +241,6 @@ public:
        QSplitter * splitter_;
        QStackedWidget * stack_widget_;
        BackgroundWidget * bg_widget_;
-       /// view's menubar
-       GuiMenubar * menubar_;
        /// view's toolbars
        GuiToolbars * toolbars_;
        /// The main layout box.
@@ -280,9 +277,11 @@ public:
 GuiView::GuiView(int id)
        : d(*new GuiViewPrivate), id_(id)
 {
-       // GuiToolbars *must* be initialised before GuiMenubar.
+       // GuiToolbars *must* be initialised before the menu bar.
        d.toolbars_ = new GuiToolbars(*this);
-       d.menubar_ = new GuiMenubar(this, menubackend);
+
+       // Fill up the menu bar.
+       guiApp->menus().fillMenuBar(this);
 
        setCentralWidget(d.stack_widget_);
 
@@ -451,7 +450,7 @@ void GuiView::dropEvent(QDropEvent* event)
 
        LYXERR(Debug::GUI, "GuiView::dropEvent: got URLs!");
        for (int i = 0; i != files.size(); ++i) {
-               string const file = support::os::internal_path(fromqstr(
+               string const file = os::internal_path(fromqstr(
                        files.at(i).toLocalFile()));
                if (!file.empty())
                        lyx::dispatch(FuncRequest(LFUN_FILE_OPEN, file));
@@ -461,6 +460,9 @@ void GuiView::dropEvent(QDropEvent* event)
 
 void GuiView::message(docstring const & str)
 {
+       if (ForkedProcess::iAmAChild())
+               return;
+
        statusBar()->showMessage(toqstr(str));
        d.statusbar_timer_.stop();
        d.statusbar_timer_.start(3000);
@@ -576,24 +578,30 @@ bool GuiView::event(QEvent * e)
                }
                return QMainWindow::event(e);
        }
+
        case QEvent::ShortcutOverride: {
+               if (d.current_work_area_)
+                       // Nothing special to do.
+                       return QMainWindow::event(e);
+
                QKeyEvent * ke = static_cast<QKeyEvent*>(e);
-               if (!d.current_work_area_) {
-                       theLyXFunc().setLyXView(this);
-                       KeySymbol sym;
-                       setKeySymbol(&sym, ke);
-                       theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
-                       e->accept();
-                       return true;
-               }
-               if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
-                       KeySymbol sym;
-                       setKeySymbol(&sym, ke);
-                       d.current_work_area_->processKeySym(sym, NoModifier);
-                       e->accept();
-                       return true;
-               }
+
+               // Let Qt handle menu access and the Tab keys to navigate keys to navigate
+               // between controls.
+               if (ke->modifiers() & Qt::AltModifier || ke->key() == Qt::Key_Tab 
+                       || ke->key() == Qt::Key_Backtab)
+                       return QMainWindow::event(e);
+
+               // Allow processing of shortcuts that are allowed even when no Buffer
+               // is viewed.
+               theLyXFunc().setLyXView(this);
+               KeySymbol sym;
+               setKeySymbol(&sym, ke);
+               theLyXFunc().processKeySym(sym, q_key_state(ke->modifiers()));
+               e->accept();
+               return true;
        }
+
        default:
                return QMainWindow::event(e);
        }
@@ -787,10 +795,12 @@ void GuiView::updateToolbars()
                bool const review =
                        lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
                        lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true);
+               bool const mathmacrotemplate =
+                       lyx::getStatus(FuncRequest(LFUN_IN_MATHMACROTEMPLATE)).enabled();
 
-               d.toolbars_->update(math, table, review);
+               d.toolbars_->update(math, table, review, mathmacrotemplate);
        } else
-               d.toolbars_->update(false, false, false);
+               d.toolbars_->update(false, false, false, false);
 
        // update read-only status of open dialogs.
        checkStatus();
@@ -1065,6 +1075,8 @@ void GuiView::newDocument(string const & filename, bool from_template)
 
        if (b)
                setBuffer(b);
+       // Ensure the cursor is correctly positionned on screen.
+       view()->showCursor();
 }
 
 
@@ -1176,10 +1188,10 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
                dlg.setButton2(_("Templates|#T#t"), from_utf8(lyxrc.template_path));
 
-               if (!support::isLyXFilename(fname.absFilename()))
+               if (!isLyXFilename(fname.absFilename()))
                        fname.changeExtension(".lyx");
 
-               support::FileFilterList const filter(_("LyX Documents (*.lyx)"));
+               FileFilterList const filter(_("LyX Documents (*.lyx)"));
 
                FileDialog::Result result =
                        dlg.save(from_utf8(fname.onlyPath().absFilename()),
@@ -1194,7 +1206,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                if (fname.empty())
                        return false;
 
-               if (!support::isLyXFilename(fname.absFilename()))
+               if (!isLyXFilename(fname.absFilename()))
                        fname.changeExtension(".lyx");
        }
 
@@ -1362,7 +1374,8 @@ bool GuiView::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_MENU_OPEN:
-                       d.menubar_->openByName(toqstr(cmd.argument()));
+                       if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument())))
+                               menu->exec(QCursor::pos());
                        break;
 
                case LFUN_FILE_INSERT:
@@ -1592,7 +1605,7 @@ void GuiView::resetDialogs()
        // Make sure that no LFUN uses any LyXView.
        theLyXFunc().setLyXView(0);
        d.toolbars_->init();
-       d.menubar_->init();
+       guiApp->menus().fillMenuBar(this);
        if (d.layout_)
                d.layout_->updateContents(true);
        // Now update controls with current buffer.