]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiApplication.cpp
Upstreaming compilation patch needed for Gentoo.
[lyx.git] / src / frontends / qt4 / GuiApplication.cpp
index c27f4c87e3a032147b335bce36fba34158213922..35b639c9ac490e27e09ee25c123afce961eb9840 100644 (file)
@@ -188,6 +188,12 @@ frontend::Application * createApplication(int & argc, char * argv[])
                }
        }
 #endif
+
+#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
+       // On Windows, allow bringing the LyX window to top
+       AllowSetForegroundWindow(ASFW_ANY);
+#endif
+
        frontend::GuiApplication * guiApp = new frontend::GuiApplication(argc, argv);
        // I'd rather do that in the constructor, but I do not think that
        // the palette is accessible there.
@@ -468,7 +474,7 @@ QString findImg(QString const & name)
        return img_name;
 }
 
-} // namespace anon
+} // namespace
 
 
 QString themeIconName(QString const & action)
@@ -592,7 +598,7 @@ QPixmap getPixmap(QString const & path, QString const & name, QString const & ex
        if (getPixmap(pixmap, fpath)) {
                return pixmap;
        }
-       
+
        QStringList exts = ext.split(",");
        fpath = ":/" + path + name + ".";
        for (int i = 0; i < exts.size(); ++i) {
@@ -1401,7 +1407,7 @@ DispatchResult const & GuiApplication::dispatch(FuncRequest const & cmd)
        updateCurrentView(cmd, dr);
 
        // the buffer may have been closed by one action
-       if (theBufferList().isLoaded(buffer))
+       if (theBufferList().isLoaded(buffer) || theBufferList().isInternal(buffer))
                buffer->undo().endUndoGroup();
 
        d->dispatch_result_ = dr;
@@ -1640,7 +1646,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
        case LFUN_BUFFER_NEW:
                validateCurrentView();
-               if (d->views_.empty()
+               if (!current_view_
                   || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) {
                        createView(QString(), false); // keep hidden
                        current_view_->newDocument(to_utf8(cmd.argument()), false);
@@ -1653,7 +1659,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
        case LFUN_BUFFER_NEW_TEMPLATE:
                validateCurrentView();
-               if (d->views_.empty()
+               if (!current_view_
                   || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) {
                        createView();
                        current_view_->newDocument(to_utf8(cmd.argument()), true);
@@ -1665,12 +1671,14 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                break;
 
        case LFUN_FILE_OPEN: {
+               // FIXME: normally the code below is not needed, since getStatus makes sure that
+               //   current_view_ is not null.
                validateCurrentView();
                // FIXME: create a new method shared with LFUN_HELP_OPEN.
                string const fname = to_utf8(cmd.argument());
                bool const is_open = FileName::isAbsolute(fname)
                        && theBufferList().getBuffer(FileName(fname));
-               if (d->views_.empty()
+               if (!current_view_
                    || (!lyxrc.open_buffers_in_tabs
                        && current_view_->documentBufferView() != 0
                        && !is_open)) {
@@ -1679,9 +1687,6 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        boost::crc_32_type crc;
                        crc = for_each(fname.begin(), fname.end(), crc);
                        createView(crc.checksum());
-                       // we know current_view_ is non-null, because createView sets it.
-                       // but let's make sure
-                       LASSERT(current_view_, break);
                        current_view_->openDocument(fname);
                        if (!current_view_->documentBufferView())
                                current_view_->close();
@@ -1691,9 +1696,6 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                current_view_->showNormal();
                        }
                } else {
-                       // we know !d->views.empty(), so this should be ok
-                       // but let's make sure
-                       LASSERT(current_view_, break);
                        current_view_->openDocument(fname);
                        if (cmd.origin() == FuncRequest::LYXSERVER) {
                                current_view_->raise();
@@ -1725,13 +1727,8 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                current_view_->message(bformat(_("Opening help file %1$s..."),
                                               makeDisplayPath(fname.absFileName())));
                Buffer * buf = current_view_->loadDocument(fname, false);
-
-#ifndef DEVEL_VERSION
                if (buf)
-                       buf->setReadonly(true);
-#else
-               (void) buf;
-#endif
+                       buf->setReadonly(!current_view_->develMode());
                break;
        }
 
@@ -1858,8 +1855,15 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                string countstr;
                string rest = split(argument, countstr, ' ');
                int const count = convert<int>(countstr);
-               for (int i = 0; i < count; ++i)
-                       dispatch(lyxaction.lookupFunc(rest));
+               // an arbitrary number to limit number of iterations
+               int const max_iter = 10000;
+               if (count > max_iter) {
+                       dr.setMessage(bformat(_("Cannot iterate more than %1$d times"), max_iter));
+                       dr.setError(true);
+               } else {
+                       for (int i = 0; i < count; ++i)
+                               dispatch(lyxaction.lookupFunc(rest));
+               }
                break;
        }
 
@@ -1879,7 +1883,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        dispatch(func);
                }
                // the buffer may have been closed by one action
-               if (theBufferList().isLoaded(buffer))
+               if (theBufferList().isLoaded(buffer) || theBufferList().isInternal(buffer))
                        buffer->undo().endUndoGroup();
                break;
        }
@@ -2066,9 +2070,8 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        if (current_view_ == 0)
                                createView();
                }
-               // fall through
        }
-
+       // fall through
        default:
                // The LFUN must be for one of GuiView, BufferView, Buffer or Cursor;
                // let's try that:
@@ -2286,8 +2289,12 @@ void GuiApplication::processFuncRequestAsync(FuncRequest const & func)
 void GuiApplication::processFuncRequestQueue()
 {
        while (!d->func_request_queue_.empty()) {
-               processFuncRequest(d->func_request_queue_.front());
+               // take the item from the stack _before_ processing the
+               // request in order to avoid race conditions from nested
+               // or parallel requests (see #10406)
+               FuncRequest const fr(d->func_request_queue_.front());
                d->func_request_queue_.pop();
+               processFuncRequest(fr);
        }
 }
 
@@ -2350,6 +2357,8 @@ void GuiApplication::createView(QString const & geometry_arg, bool autoShow,
 
        LYXERR(Debug::GUI, "About to create new window with ID " << id);
        GuiView * view = new GuiView(id);
+       // `view' is the new current_view_. Tell coverity that is is not 0.
+       LATTEST(current_view_);
        // register view
        d->views_[id] = view;
 
@@ -2399,6 +2408,15 @@ void GuiApplication::createView(QString const & geometry_arg, bool autoShow,
 }
 
 
+bool GuiApplication::unhide(Buffer * buf)
+{
+       if (!currentView())
+               return false;
+       currentView()->setBuffer(buf, false);
+       return true;
+}
+
+
 Clipboard & GuiApplication::clipboard()
 {
        return d->clipboard_;
@@ -2581,7 +2599,7 @@ void GuiApplication::restoreGuiSession()
        // not be added at all (help files).
        for (size_t i = 0; i < lastopened.size(); ++i) {
                FileName const & file_name = lastopened[i].file_name;
-               if (d->views_.empty() || (!lyxrc.open_buffers_in_tabs
+               if (!current_view_ || (!lyxrc.open_buffers_in_tabs
                          && current_view_->documentBufferView() != 0)) {
                        boost::crc_32_type crc;
                        string const & fname = file_name.absFileName();
@@ -2637,7 +2655,7 @@ namespace {
                const QFontInfo fi(font);
                return fi.fixedPitch();
        }
-}
+} // namespace
 
 
 QFont const GuiApplication::typewriterSystemFont()
@@ -2709,7 +2727,8 @@ bool GuiApplication::notify(QObject * receiver, QEvent * event)
 #endif
                        // In release mode, try to exit gracefully.
                        this->exit(1);
-
+                       // FIXME: GCC 7 thinks we can fall through here. Can we?
+                       // fall through
                case BufferException: {
                        if (!current_view_ || !current_view_->documentBufferView())
                                return false;