]> 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 5752fb8948b7f6f4e3cec89b70bc52ec577cb7b5..c07aa04ec0aedc20424c0bd294ad51f41dbb3bdd 100644 (file)
 #include "GuiApplication.h"
 #include "GuiWorkArea.h"
 #include "GuiKeySymbol.h"
-#include "GuiMenubar.h"
 #include "GuiToolbar.h"
 #include "GuiToolbars.h"
-#include "GuiProgress.h"
+#include "Menus.h"
 
 #include "qt_helpers.h"
 
@@ -46,7 +45,6 @@
 #include "LyX.h"
 #include "LyXRC.h"
 #include "LyXVC.h"
-#include "MenuBackend.h"
 #include "Paragraph.h"
 #include "TextClass.h"
 #include "Text.h"
@@ -56,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"
@@ -93,9 +92,8 @@
 # include <unistd.h>
 #endif
 
-using std::endl;
-using std::string;
-using std::vector;
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -103,16 +101,6 @@ extern bool quitting;
 
 namespace frontend {
 
-using support::addPath;
-using support::bformat;
-using support::FileFilterList;
-using support::FileName;
-using support::makeAbsPath;
-using support::makeDisplayPath;
-using support::package;
-using support::removeAutosaveFile;
-using support::trim;
-
 namespace {
 
 class BackgroundWidget : public QWidget
@@ -177,7 +165,6 @@ struct GuiView::GuiViewPrivate
                delete splitter_;
                delete bg_widget_;
                delete stack_widget_;
-               delete menubar_;
                delete toolbars_;
        }
 
@@ -254,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.
@@ -270,10 +255,10 @@ public:
        GuiLayoutBox * layout_;
 
        ///
-       std::map<std::string, Inset *> open_insets_;
+       map<string, Inset *> open_insets_;
 
        ///
-       std::map<std::string, DialogPtr> dialogs_;
+       map<string, DialogPtr> dialogs_;
 
        unsigned int smallIconSize;
        unsigned int normalIconSize;
@@ -292,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_);
 
@@ -421,6 +408,10 @@ void GuiView::closeEvent(QCloseEvent * close_event)
 #endif
                settings.setValue(key + "/icon_size", iconSize());
                d.toolbars_->saveToolbarInfo();
+               // Now take care of all other dialogs:
+               map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
+               for (; it!= d.dialogs_.end(); ++it)
+                       it->second->saveSession();
        }
 
        guiApp->unregisterView(id_);
@@ -459,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));
@@ -469,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);
@@ -584,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);
        }
@@ -795,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();
@@ -881,7 +883,7 @@ void GuiView::updateDialog(string const & name, string const & data)
        if (!isDialogVisible(name))
                return;
 
-       std::map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
+       map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
        if (it == d.dialogs_.end())
                return;
 
@@ -1073,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();
 }
 
 
@@ -1184,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()),
@@ -1202,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");
        }
 
@@ -1370,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:
@@ -1570,7 +1575,7 @@ char const * const dialognames[] = {
 "thesaurus",
 #endif
 
-"texinfo", "toc", "href", "view-source", "latex-progress", "vspace", "wrap", "listings" };
+"texinfo", "toc", "href", "view-source", "vspace", "wrap", "listings" };
 
 char const * const * const end_dialognames =
        dialognames + (sizeof(dialognames) / sizeof(char *));
@@ -1588,7 +1593,7 @@ private:
 
 bool isValidName(string const & name)
 {
-       return std::find_if(dialognames, end_dialognames,
+       return find_if(dialognames, end_dialognames,
                            cmpCStr(name.c_str())) != end_dialognames;
 }
 
@@ -1600,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.
@@ -1614,13 +1619,16 @@ Dialog * GuiView::find_or_build(string const & name)
        if (!isValidName(name))
                return 0;
 
-       std::map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
+       map<string, DialogPtr>::iterator it = d.dialogs_.find(name);
 
        if (it != d.dialogs_.end())
                return it->second.get();
 
-       d.dialogs_[name].reset(build(name));
-       return d.dialogs_[name].get();
+       Dialog * dialog = build(name);
+       d.dialogs_[name].reset(dialog);
+       if (lyxrc.allow_geometry_session)
+               dialog->restoreSession();
+       return dialog;
 }
 
 
@@ -1643,7 +1651,7 @@ void GuiView::showDialog(string const & name, string const & data,
 
 bool GuiView::isDialogVisible(string const & name) const
 {
-       std::map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
+       map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
        if (it == d.dialogs_.end())
                return false;
        return it->second.get()->isVisibleView();
@@ -1659,7 +1667,7 @@ void GuiView::hideDialog(string const & name, Inset * inset)
        if (quitting)
                return;
 
-       std::map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
+       map<string, DialogPtr>::const_iterator it = d.dialogs_.find(name);
        if (it == d.dialogs_.end())
                return;
 
@@ -1668,7 +1676,7 @@ void GuiView::hideDialog(string const & name, Inset * inset)
 
        Dialog * const dialog = it->second.get();
        if (dialog->isVisibleView())
-               dialog->hide();
+               dialog->hideView();
        d.open_insets_[name] = 0;
 }
 
@@ -1688,38 +1696,38 @@ Inset * GuiView::getOpenInset(string const & name) const
        if (!isValidName(name))
                return 0;
 
-       std::map<string, Inset *>::const_iterator it = d.open_insets_.find(name);
+       map<string, Inset *>::const_iterator it = d.open_insets_.find(name);
        return it == d.open_insets_.end() ? 0 : it->second;
 }
 
 
 void GuiView::hideAll() const
 {
-       std::map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
-       std::map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
+       map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
+       map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
 
        for(; it != end; ++it)
-               it->second->hide();
+               it->second->hideView();
 }
 
 
 void GuiView::hideBufferDependent() const
 {
-       std::map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
-       std::map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
+       map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
+       map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
 
        for(; it != end; ++it) {
                Dialog * dialog = it->second.get();
                if (dialog->isBufferDependent())
-                       dialog->hide();
+                       dialog->hideView();
        }
 }
 
 
 void GuiView::updateBufferDependent(bool switched) const
 {
-       std::map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
-       std::map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
+       map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
+       map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
 
        for(; it != end; ++it) {
                Dialog * dialog = it->second.get();
@@ -1729,7 +1737,7 @@ void GuiView::updateBufferDependent(bool switched) const
                        if (dialog->initialiseParams(""))
                                dialog->updateView();
                        else
-                               dialog->hide();
+                               dialog->hideView();
                } else {
                        // A bit clunky, but the dialog will request
                        // that the kernel provides it with the necessary
@@ -1742,8 +1750,8 @@ void GuiView::updateBufferDependent(bool switched) const
 
 void GuiView::checkStatus()
 {
-       std::map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
-       std::map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
+       map<string, DialogPtr>::const_iterator it  = d.dialogs_.begin();
+       map<string, DialogPtr>::const_iterator end = d.dialogs_.end();
 
        for(; it != end; ++it) {
                Dialog * const dialog = it->second.get();
@@ -1794,7 +1802,6 @@ Dialog * createGuiThesaurus(GuiView & lv);
 Dialog * createGuiHyperlink(GuiView & lv);
 Dialog * createGuiVSpace(GuiView & lv);
 Dialog * createGuiViewSource(GuiView & lv);
-Dialog * createGuiProgress(GuiView & lv);
 Dialog * createGuiWrap(GuiView & lv);
 
 
@@ -1846,8 +1853,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiLog(*this);
        if (name == "view-source")
                return createGuiViewSource(*this);
-       if (name == "latex-progress")
-               return createGuiProgress(*this);
        if (name == "mathdelimiter")
                return createGuiDelimiter(*this);
        if (name == "mathmatrix")