]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiApplication.cpp
revert previous commit, it did not compile of course...
[lyx.git] / src / frontends / qt4 / GuiApplication.cpp
index f42c099df3e83584fc5e6b4f681628e037b90651..4656e63a69f5855ce8593e043a099075055a19ab 100644 (file)
@@ -267,7 +267,11 @@ PngMap sorted_png_map[] = {
        { "nvDash", "nvdash2" },
        { "textrm \\AA", "textrm_AA"},
        { "textrm \\O", "textrm_O"},
-       { "vDash", "vdash2" }
+       { "vDash", "vdash2" },
+       { "varPhi", "varphi2" },
+       { "varPi", "varpi2" },
+       { "varSigma", "varsigma2" },
+       { "varTheta", "vartheta2" }
 };
 
 size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);
@@ -1091,8 +1095,8 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
 
        DispatchResult dr;
        // redraw the screen at the end (first of the two drawing steps).
-       //This is done unless explicitly requested otherwise
-       dr.update(Update::FitCursor);
+       // This is done unless explicitly requested otherwise
+       dr.screenUpdate(Update::FitCursor);
        dispatch(cmd, dr);
 
        if (!current_view_)
@@ -1100,15 +1104,32 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
 
        BufferView * bv = current_view_->currentBufferView();
        if (bv) {
-               if (dr.needBufferUpdate()) {
-                       bv->cursor().clearBufferUpdate();
-                       bv->buffer().updateBuffer();
+               Cursor & cursor = bv->cursor();
+               Buffer & buf = bv->buffer();
+
+               // FIXME
+               // This check out to be done somewhere else. It got moved here
+               // from TextMetrics.cpp, where it definitely didn't need to be.
+               // Actually, this test ought not to be done at all, since the
+               // whole InsetBibitem business is a mess. But that is a different
+               // story.
+               if (cursor.inTexted()) {
+                       int const moveCursor = cursor.paragraph().checkBiblio(buf);
+                       if (moveCursor > 0)
+                               cursor.posForward();
+                       else if (moveCursor < 0 && cursor.pos() >= -moveCursor)
+                               cursor.posBackward();
+
+                       if (moveCursor != 0 || dr.needBufferUpdate()) {
+                               cursor.clearBufferUpdate();
+                               buf.updateBuffer();
+                       }
                }
                // BufferView::update() updates the ViewMetricsInfo and
                // also initializes the position cache for all insets in
                // (at least partially) visible top-level paragraphs.
                // We will redraw the screen only if needed.
-               bv->processUpdateFlags(dr.update());
+               bv->processUpdateFlags(dr.screenUpdate());
 
                // Do we have a selection?
                theSelection().haveSelection(bv->cursor().selection());
@@ -1116,18 +1137,21 @@ void GuiApplication::dispatch(FuncRequest const & cmd)
                // update gui
                current_view_->restartCursor();
        }
-       // Some messages may already be translated, so we cannot use _()
-       current_view_->message(makeDispatchMessage(
-                       translateIfPossible(dr.message()), cmd));
+       if (dr.needMessageUpdate()) {
+               // Some messages may already be translated, so we cannot use _()
+               current_view_->message(makeDispatchMessage(
+                               translateIfPossible(dr.message()), cmd));
+       }
 }
 
 
-void GuiApplication::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
+void GuiApplication::gotoBookmark(unsigned int idx, bool openFile,
+       bool switchToBuffer)
 {
-       LASSERT(current_view_, /**/);
        if (!theSession().bookmarks().isValid(idx))
                return;
-       BookmarksSection::Bookmark const & bm = theSession().bookmarks().bookmark(idx);
+       BookmarksSection::Bookmark const & bm =
+               theSession().bookmarks().bookmark(idx);
        LASSERT(!bm.filename.empty(), /**/);
        string const file = bm.filename.absFileName();
        // if the file is not opened, open it.
@@ -1149,16 +1173,18 @@ void GuiApplication::gotoBookmark(unsigned int idx, bool openFile, bool switchTo
                dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
 
        // if the current buffer is not that one, switch to it.
-       if (!current_view_->documentBufferView()
-               || current_view_->documentBufferView()->buffer().fileName() != tmp.filename) {
-               if (!switchToBuffer)
+       BufferView * doc_bv = current_view_->documentBufferView();
+       if (!doc_bv || doc_bv->buffer().fileName() != tmp.filename) {
+               if (switchToBuffer) {
+                       dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
+                       doc_bv = current_view_->documentBufferView();
+               } else
                        return;
-               dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
        }
 
        // moveToPosition try paragraph id first and then paragraph (pit, pos).
-       if (!current_view_->documentBufferView()->moveToPosition(
-               tmp.bottom_pit, tmp.bottom_pos, tmp.top_id, tmp.top_pos))
+       if (!doc_bv->moveToPosition(
+                       tmp.bottom_pit, tmp.bottom_pos, tmp.top_id, tmp.top_pos))
                return;
 
        // bm changed
@@ -1166,7 +1192,7 @@ void GuiApplication::gotoBookmark(unsigned int idx, bool openFile, bool switchTo
                return;
 
        // Cursor jump succeeded!
-       Cursor const & cur = current_view_->documentBufferView()->cursor();
+       Cursor const & cur = doc_bv->cursor();
        pit_type new_pit = cur.pit();
        pos_type new_pos = cur.pos();
        int new_id = cur.paragraph().id();
@@ -1237,7 +1263,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                dr.setMessage(flag.message());
                dr.setError(true);
                dr.dispatched(false);
-               dr.update(Update::None);
+               dr.screenUpdate(Update::None);
                dr.clearBufferUpdate();
                return;
        };
@@ -1308,11 +1334,11 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                }
                break;
 
-       case LFUN_FILE_OPEN:
+       case LFUN_FILE_OPEN: {
                // FIXME: create a new method shared with LFUN_HELP_OPEN.
-               if (d->views_.empty()
-                       || (!lyxrc.open_buffers_in_tabs && current_view_->documentBufferView() != 0)) {
-                       string const fname = to_utf8(cmd.argument());
+               string const fname = to_utf8(cmd.argument());
+               if (d->views_.empty() || (!lyxrc.open_buffers_in_tabs 
+                         && current_view_->documentBufferView() != 0)) {
                        // We want the ui session to be saved per document and not per
                        // window number. The filename crc is a good enough identifier.
                        boost::crc_32_type crc;
@@ -1322,8 +1348,9 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        if (current_view_ && !current_view_->documentBufferView())
                                current_view_->close();
                } else
-                       current_view_->openDocument(to_utf8(cmd.argument()));
+                       current_view_->openDocument(fname);
                break;
+       }
 
        case LFUN_HELP_OPEN: {
                // FIXME: create a new method shared with LFUN_FILE_OPEN.
@@ -1346,13 +1373,13 @@ 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);
-               if (buf) {
-                       current_view_->setBuffer(buf);
+
 #ifndef DEVEL_VERSION
+               if (buf)
                        buf->setReadonly(true);
+#else
+               (void) buf;
 #endif
-                       buf->errors("Parse");
-               }
                break;
        }
 
@@ -1360,7 +1387,8 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                string lyx_name;
                string const x11_name = split(to_utf8(cmd.argument()), lyx_name, ' ');
                if (lyx_name.empty() || x11_name.empty()) {
-                       current_view_->message(
+                       if (current_view_)
+                               current_view_->message(
                                        _("Syntax: set-color <lyx_name> <x11_name>"));
                        break;
                }
@@ -1421,7 +1449,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                GuiView * gv = currentView();
                if (gv && gv->currentBufferView())
                        // cancel any selection
-                       lyx::dispatch(FuncRequest(LFUN_MARK_OFF));
+                       processFuncRequest(FuncRequest(LFUN_MARK_OFF));
                dr.setMessage(from_ascii(N_("Cancel")));
                break;
        }
@@ -1564,7 +1592,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        case LFUN_BOOKMARK_GOTO:
                // go to bookmark, open unopened file and switch to buffer if necessary
                gotoBookmark(convert<unsigned int>(to_utf8(cmd.argument())), true, true);
-               dr.update(Update::Force | Update::FitCursor);
+               dr.screenUpdate(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_BOOKMARK_CLEAR:
@@ -1589,6 +1617,10 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                BufferView * bv = current_view_->currentBufferView();
                LASSERT(bv, /**/);
        
+               // Avoid a screen redraw in the middle of a dispatch operation just
+               // because a warning or an error was displayed.
+               current_view_->setBusy(true);
+
                // Let the current BufferView dispatch its own actions.
                bv->dispatch(cmd, dr);
                if (dr.dispatched())
@@ -1619,11 +1651,16 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                bv->cursor().dispatch(cmd);
        
                // notify insets we just left
+               // FIXME: move this code to Cursor::dispatch
                if (bv->cursor() != old) {
+                       old.beginUndoGroup();
                        old.fixIfBroken();
                        bool badcursor = notifyCursorLeavesOrEnters(old, bv->cursor());
-                       if (badcursor)
+                       if (badcursor) {
                                bv->cursor().fixIfBroken();
+                               bv->fixInlineCompletionPos();
+                       }
+                       old.endUndoGroup();
                }
        
                // update completion. We do it here and not in
@@ -1640,6 +1677,8 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                }
        
                dr = bv->cursor().result();
+
+               current_view_->setBusy(false);
        }
        
        // if we executed a mutating lfun, mark the buffer as dirty
@@ -1685,7 +1724,6 @@ void GuiApplication::handleKeyFunc(FuncCode action)
        d->keyseq.clear();
        // copied verbatim from do_accent_char
        bv->cursor().resetAnchor();
-       bv->processUpdateFlags(Update::FitCursor);
 }
 
 
@@ -1696,7 +1734,8 @@ void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state)
        // Do nothing if we have nothing (JMarc)
        if (!keysym.isOK()) {
                LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
-               current_view_->restartCursor();
+               if (current_view_)
+                       current_view_->restartCursor();
                return;
        }
 
@@ -1739,7 +1778,7 @@ void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state)
        // why not return already here if action == -1 and
        // num_bytes == 0? (Lgb)
 
-       if (d->keyseq.length() > 1)
+       if (d->keyseq.length() > 1 && current_view_)
                current_view_->message(d->keyseq.print(KeySequence::ForGui));
 
 
@@ -1761,8 +1800,10 @@ void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state)
                                           FuncRequest::KEYBOARD);
                } else {
                        LYXERR(Debug::KEY, "Unknown, !isText() - giving up");
-                       current_view_->message(_("Unknown function."));
-                       current_view_->restartCursor();
+                       if (current_view_) {
+                               current_view_->message(_("Unknown function."));
+                               current_view_->restartCursor();
+                       }
                        return;
                }
        }
@@ -1770,19 +1811,46 @@ void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state)
        if (func.action() == LFUN_SELF_INSERT) {
                if (encoded_last_key != 0) {
                        docstring const arg(1, encoded_last_key);
-                       lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
+                       processFuncRequest(FuncRequest(LFUN_SELF_INSERT, arg,
                                             FuncRequest::KEYBOARD));
                        LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
                }
        } else
-               lyx::dispatch(func);
+               processFuncRequest(func);
+}
+
+
+void GuiApplication::processFuncRequest(FuncRequest const & func)
+{
+       lyx::dispatch(func);
+}
+
+
+void GuiApplication::processFuncRequestAsync(FuncRequest const & func)
+{
+       addToFuncRequestQueue(func);
+       processFuncRequestQueueAsync();
+}
+
+
+void GuiApplication::processFuncRequestQueue()
+{
+       while (!d->func_request_queue_.empty()) {
+               processFuncRequest(d->func_request_queue_.front());
+               d->func_request_queue_.pop();
+       }
+}
+
+
+void GuiApplication::processFuncRequestQueueAsync()
+{
+       QTimer::singleShot(0, this, SLOT(slotProcessFuncRequestQueue()));
 }
 
 
-void GuiApplication::dispatchDelayed(FuncRequest const & func)
+void GuiApplication::addToFuncRequestQueue(FuncRequest const & func)
 {
        d->func_request_queue_.push(func);
-       QTimer::singleShot(0, this, SLOT(processFuncRequestQueue()));
 }
 
 
@@ -1807,7 +1875,7 @@ void GuiApplication::resetGui()
                gv->resetDialogs();
        }
 
-       lyx::dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
+       processFuncRequest(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
 }
 
 
@@ -1967,15 +2035,6 @@ void GuiApplication::setGuiLanguage()
 }
 
 
-void GuiApplication::processFuncRequestQueue()
-{
-       while (!d->func_request_queue_.empty()) {
-               lyx::dispatch(d->func_request_queue_.back());
-               d->func_request_queue_.pop();
-       }
-}
-
-
 void GuiApplication::execBatchCommands()
 {
        setGuiLanguage();
@@ -2125,7 +2184,8 @@ bool GuiApplication::event(QEvent * e)
                // commands are not executed here yet and the gui is not ready
                // therefore.
                QFileOpenEvent * foe = static_cast<QFileOpenEvent *>(e);
-               dispatchDelayed(FuncRequest(LFUN_FILE_OPEN, qstring_to_ucs4(foe->file())));
+               FuncRequest const fr(LFUN_FILE_OPEN, qstring_to_ucs4(foe->file()));
+               processFuncRequestAsync(fr);
                e->accept();
                return true;
        }
@@ -2240,8 +2300,13 @@ void GuiApplication::commitData(QSessionManager & sm)
        /// interaction.
        /// We are changing that to close all wiew one by one.
        /// FIXME: verify if the default implementation is enough now.
-       if (sm.allowsInteraction() && !closeAllViews())
-               sm.cancel();
+       #ifdef QT_NO_SESSIONMANAGER
+               #warning Qt is compiled without session manager
+               (void) sm;
+       #else
+               if (sm.allowsInteraction() && !closeAllViews())
+                       sm.cancel();
+       #endif
 }