]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
GuiExternal: use proper model/view separation and sort the templates
[lyx.git] / src / BufferView.cpp
index ad40dd6b2828afd9a101572577380c9929488c4f..a6ae1d40a3ff235c7cc23048e8f6fa6cf1d97796 100644 (file)
@@ -495,9 +495,7 @@ void BufferView::processUpdateFlags(Update::flags flags)
 
        // updateMetrics() does not update paragraph position
        // This is done at draw() time. So we need a redraw!
-       // We pass true so that metrics are computed for the sake
-       // of having MacroData updated.
-       buffer_.changed(true);
+       buffer_.changed(false);
 
        if (needsFitCursor()) {
                // The cursor is off screen so ensure it is visible.
@@ -1030,7 +1028,10 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        if (buffer_.isReadonly()
            && !lyxaction.funcHasFlag(act, LyXAction::ReadOnly)
            && !lyxaction.funcHasFlag(act, LyXAction::NoBuffer)) {
-               flag.message(from_utf8(N_("Document is read-only")));
+               if (buffer_.hasReadonlyFlag())
+                       flag.message(from_utf8(N_("Document is read-only")));
+               else
+                       flag.message(from_utf8(N_("Document has been modified externally")));
                flag.setEnabled(false);
                return true;
        }
@@ -1413,7 +1414,11 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
        case LFUN_PARAGRAPH_GOTO: {
                int const id = convert<int>(cmd.getArg(0));
-               int const pos = convert<int>(cmd.getArg(1));
+               pos_type const pos = convert<int>(cmd.getArg(1));
+               if (id < 0)
+                       break;
+               string const str_id_end = cmd.getArg(2);
+               string const str_pos_end = cmd.getArg(3);
                int i = 0;
                for (Buffer * b = &buffer_; i == 0 || b != &buffer_;
                        b = theBufferList().next(b)) {
@@ -1430,10 +1435,20 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                                << b->absFileName() << "'.");
 
                        if (b == &buffer_) {
-                               // Set the cursor
-                               cur.pos() = pos;
-                               mouseSetCursor(cur);
-                               dr.screenUpdate(Update::Force | Update::FitCursor);
+                               bool success;
+                               if (str_id_end.empty() || str_pos_end.empty()) {
+                                       // Set the cursor
+                                       cur.pos() = pos;
+                                       mouseSetCursor(cur);
+                                       success = true;
+                               } else {
+                                       int const id_end = convert<int>(str_id_end);
+                                       pos_type const pos_end = convert<int>(str_pos_end);
+                                       success = setCursorFromEntries({id, pos},
+                                                                      {id_end, pos_end});
+                               }
+                               if (success)
+                                       dr.screenUpdate(Update::Force | Update::FitCursor);
                        } else {
                                // Switch to other buffer view and resend cmd
                                lyx::dispatch(FuncRequest(
@@ -2167,9 +2182,7 @@ void BufferView::updateHoveredInset() const
 
                // This event (moving without mouse click) is not passed further.
                // This should be changed if it is further utilized.
-               // We pass true so that metrics are computed for the sake
-               // of having MacroData updated.
-               buffer_.changed(true);
+               buffer_.changed(false);
        }
 }
 
@@ -2333,36 +2346,35 @@ int BufferView::scrollUp(int offset)
 }
 
 
-void BufferView::setCursorFromRow(int row)
+bool BufferView::setCursorFromRow(int row)
 {
-       setCursorFromRow(row, buffer_.texrow());
+       TexRow::TextEntry start, end;
+       tie(start,end) = buffer_.texrow().getEntriesFromRow(row);
+       LYXERR(Debug::LATEX,
+              "setCursorFromRow: for row " << row << ", TexRow has found "
+              "start (id=" << start.id << ",pos=" << start.pos << "), "
+              "end (id=" << end.id << ",pos=" << end.pos << ")");
+       return setCursorFromEntries(start, end);
 }
 
 
-void BufferView::setCursorFromRow(int row, TexRow const & texrow)
+bool BufferView::setCursorFromEntries(TexRow::TextEntry start,
+                                      TexRow::TextEntry end)
 {
-       DocIterator start, end;
-       tie(start,end) = texrow.getDocIteratorFromRow(row, buffer_);
-       // we need to make sure that the DocIterators
-       // we got back are valid, because the buffer may well
-       // have changed since we last generated the LaTeX.
-       if (!start) {
-               LYXERR(Debug::LATEX,
-                      "setCursorFromRow: invalid position for row " << row);
-               frontend::Alert::error(_("Inverse Search Failed"),
-                                      _("Invalid position requested by inverse search.\n"
-                                        "You may need to update the viewed document."));
-               return;
-       }
+       DocIterator dit_start, dit_end;
+       tie(dit_start,dit_end) =
+               TexRow::getDocIteratorsFromEntries(start, end, buffer_);
+       if (!dit_start)
+               return false;
        // Setting selection start
        d->cursor_.clearSelection();
-       setCursor(start);
+       setCursor(dit_start);
        // Setting selection end
-       if (end) {
+       if (dit_end) {
                d->cursor_.resetAnchor();
-               setCursorSelectionTo(end);
+               setCursorSelectionTo(dit_end);
        }
-       recenter();
+       return true;
 }
 
 
@@ -2795,19 +2807,7 @@ Point BufferView::coordOffset(DocIterator const & dit) const
                }
 
                // remember width for the case that sl.inset() is positioned in an RTL inset
-               if (i && dit[i - 1].text()) {
-                       // If this Inset is inside a Text Inset, retrieve the Dimension
-                       // from the containing text instead of using Inset::dimension() which
-                       // might not be implemented.
-                       // FIXME (Abdel 23/09/2007): this is a bit messy because of the
-                       // elimination of Inset::dim_ cache. This coordOffset() method needs
-                       // to be rewritten in light of the new design.
-                       Dimension const & dim = coordCache().getInsets().dim(&sl.inset());
-                       lastw = dim.wid;
-               } else {
-                       Dimension const dim = sl.inset().dimension(*this);
-                       lastw = dim.wid;
-               }
+               lastw = sl.inset().dimension(*this).wid;
 
                //lyxerr << "Cursor::getPos, i: "
                // << i << " x: " << xx << " y: " << y << endl;
@@ -2882,7 +2882,7 @@ bool BufferView::paragraphVisible(DocIterator const & dit) const
 void BufferView::cursorPosAndHeight(Point & p, int & h) const
 {
        Cursor const & cur = cursor();
-       Font const font = cur.getFont();
+       Font const font = cur.real_current_font;
        frontend::FontMetrics const & fm = theFontMetrics(font);
        int const asc = fm.maxAscent();
        int const des = fm.maxDescent();