]> git.lyx.org Git - features.git/blobdiff - src/BufferView.cpp
move updateLables to buffer
[features.git] / src / BufferView.cpp
index fc3163b7848302efbc0570d59d24af90050362c9..b463778ef31567e31ec08a0b7a50da8be749f9be 100644 (file)
@@ -4,10 +4,10 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Alfredo Braunstein
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author John Levon
- * \author André Pönitz
- * \author Jürgen Vigna
+ * \author André Pönitz
+ * \author Jürgen Vigna
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -549,9 +549,14 @@ docstring BufferView::contextMenu(int x, int y) const
 void BufferView::scrollDocView(int value)
 {
        int const offset = value - d->scrollbarParameters_.position;
+
+       // No scrolling at all? No need to redraw anything
+       if (offset == 0)
+               return;
+
        // If the offset is less than 2 screen height, prefer to scroll instead.
        if (abs(offset) <= 2 * height_) {
-               scroll(offset);
+               d->anchor_ypos_ -= offset;
                updateMetrics();
                buffer_.changed();
                return;
@@ -627,7 +632,14 @@ void BufferView::setCursorFromScrollbar()
        Cursor cur(*this);
        cur.reset(buffer_.inset());
        tm.setCursorFromCoordinates(cur, 0, newy);
+
+       // update the bufferview cursor and notify insets
+       // FIXME: Care about the d->cursor_ flags to redraw if needed
+       Cursor old = d->cursor_;
        mouseSetCursor(cur);
+       bool badcursor = notifyCursorLeavesOrEnters(old, d->cursor_);
+       if (badcursor)
+               d->cursor_.fixIfBroken();
 }
 
 
@@ -866,6 +878,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
        case LFUN_NOTE_NEXT:
        case LFUN_REFERENCE_NEXT:
        case LFUN_WORD_FIND:
+       case LFUN_WORD_FINDADV:
        case LFUN_WORD_REPLACE:
        case LFUN_MARK_OFF:
        case LFUN_MARK_ON:
@@ -873,13 +886,17 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
        case LFUN_SCREEN_RECENTER:
        case LFUN_BIBTEX_DATABASE_ADD:
        case LFUN_BIBTEX_DATABASE_DEL:
-       case LFUN_GRAPHICS_GROUPS_UNIFY:
        case LFUN_NOTES_MUTATE:
        case LFUN_ALL_INSETS_TOGGLE:
        case LFUN_STATISTICS:
                flag.setEnabled(true);
                break;
 
+       // @todo Test if current WorkArea is the search WorkArea
+       case LFUN_REGEXP_MODE:
+               flag.setEnabled(! this->cursor().inRegexped());
+               break;
+
        case LFUN_NEXT_INSET_TOGGLE: 
        case LFUN_NEXT_INSET_MODIFY: {
                // this is the real function we want to invoke
@@ -1155,11 +1172,15 @@ bool BufferView::dispatch(FuncRequest const & cmd)
 
        case LFUN_CHANGE_NEXT:
                findNextChange(this);
+               // FIXME: Move this LFUN to Buffer so that we don't have to do this:
+               processUpdateFlags(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_CHANGES_MERGE:
-               if (findNextChange(this))
+               if (findNextChange(this)) {
+                       processUpdateFlags(Update::Force | Update::FitCursor);
                        showDialog("changes");
+               }
                break;
 
        case LFUN_ALL_CHANGES_ACCEPT:
@@ -1189,6 +1210,10 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                FuncRequest req = cmd;
                if (cmd.argument().empty() && !d->search_request_cache_.argument().empty())
                        req = d->search_request_cache_;
+               if (req.argument().empty()) {
+                       theLyXFunc().dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
+                       break;
+               }
                if (find(this, req))
                        showCursor();
                else
@@ -1213,6 +1238,10 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_WORD_FINDADV:
+               findAdv(this, cmd);
+               break;
+
        case LFUN_MARK_OFF:
                cur.clearSelection();
                cur.resetAnchor();
@@ -1221,7 +1250,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
 
        case LFUN_MARK_ON:
                cur.clearSelection();
-               cur.mark() = true;
+               cur.setMark(true);
                cur.resetAnchor();
                cur.message(from_utf8(N_("Mark on")));
                break;
@@ -1229,10 +1258,10 @@ bool BufferView::dispatch(FuncRequest const & cmd)
        case LFUN_MARK_TOGGLE:
                cur.clearSelection();
                if (cur.mark()) {
-                       cur.mark() = false;
+                       cur.setMark(false);
                        cur.message(from_utf8(N_("Mark removed")));
                } else {
-                       cur.mark() = true;
+                       cur.setMark(true);
                        cur.message(from_utf8(N_("Mark set")));
                }
                cur.resetAnchor();
@@ -1427,20 +1456,11 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                processUpdateFlags(Update::Force);
                break;
 
-       // These two could be rewriten using some command like forall <insetname> <command>
+       // This could be rewriten using some command like forall <insetname> <command>
        // once the insets refactoring is done.
-       case LFUN_GRAPHICS_GROUPS_UNIFY: {
-               if (cmd.argument().empty())
-                       break;
-               graphics::unifyGraphicsGroups(cur.buffer(), to_utf8(cmd.argument()));
-               processUpdateFlags(Update::Force | Update::FitCursor);
-               break;
-       }
-
        case LFUN_NOTES_MUTATE: {
                if (cmd.argument().empty())
                        break;
-               cur.recordUndoFullDocument();
 
                if (mutateNotes(cur, cmd.getArg(0), cmd.getArg(1))) {
                        processUpdateFlags(Update::Force);
@@ -1571,7 +1591,7 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
        Cursor old = cursor();
        Cursor cur(*this);
        cur.push(buffer_.inset());
-       cur.selection() = d->cursor_.selection();
+       cur.setSelection(d->cursor_.selection());
 
        // Either the inset under the cursor or the
        // surrounding Text will handle this event.
@@ -1618,6 +1638,8 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
        // Put anchor at the same position.
        cur.resetAnchor();
 
+       cur.beginUndoGroup();
+
        // Try to dispatch to an non-editable inset near this position
        // via the temp cursor. If the inset wishes to change the real
        // cursor it has to do so explicitly by using
@@ -1630,10 +1652,12 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
        if (!inset || !cur.result().dispatched())
                cur.dispatch(cmd);
 
+       cur.endUndoGroup();
+
        // Notify left insets
        if (cur != old) {
                old.fixIfBroken();
-               bool badcursor = notifyCursorLeaves(old, cur);
+               bool badcursor = notifyCursorLeavesOrEnters(old, cur);
                if (badcursor)
                        cursor().fixIfBroken();
        }
@@ -1750,9 +1774,8 @@ bool BufferView::setCursorFromInset(Inset const * inset)
        // Inset is not at cursor position. Find it in the document.
        Cursor cur(*this);
        cur.reset(buffer().inset());
-       do 
+       while (cur && cur.nextInset() != inset)
                cur.forwardInset();
-       while (cur && cur.nextInset() != inset);
 
        if (cur) {
                setCursor(cur);
@@ -1813,7 +1836,7 @@ void BufferView::setCursor(DocIterator const & dit)
                dit[i].inset().edit(d->cursor_, true);
 
        d->cursor_.setCursor(dit);
-       d->cursor_.selection() = false;
+       d->cursor_.setSelection(false);
 }
 
 
@@ -1835,7 +1858,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old)
 
        d->cursor_ = cur;
 
-       updateLabels(buffer_);
+       buffer_.updateLabels();
 
        updateMetrics();
        buffer_.changed();
@@ -1853,14 +1876,9 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
                cap::saveSelection(cursor());
 
        // Has the cursor just left the inset?
-       bool badcursor = false;
        bool leftinset = (&d->cursor_.inset() != &cur.inset());
-       if (leftinset) {
+       if (leftinset)
                d->cursor_.fixIfBroken();
-               badcursor = notifyCursorLeaves(d->cursor_, cur);
-               if (badcursor)
-                       cur.fixIfBroken();
-       }
 
        // FIXME: shift-mouse selection doesn't work well across insets.
        bool do_selection = select && &d->cursor_.anchor().inset() == &cur.inset();
@@ -1870,7 +1888,7 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
        // FIXME: (2) if we had a working InsetText::notifyCursorLeaves,
        // the leftinset bool would not be necessary (badcursor instead).
        bool update = leftinset;
-       if (!do_selection && !badcursor && d->cursor_.inTexted())
+       if (!do_selection && d->cursor_.inTexted())
                update |= checkDepm(cur, d->cursor_);
 
        d->cursor_.setCursor(cur);
@@ -2189,6 +2207,7 @@ void BufferView::draw(frontend::Painter & pain)
        if (height_ == 0 || width_ == 0)
                return;
        LYXERR(Debug::PAINTING, "\t\t*** START DRAWING ***");
+
        Text & text = buffer_.text();
        TextMetrics const & tm = d->text_metrics_[&text];
        int const y = tm.first().second->position();
@@ -2223,7 +2242,7 @@ void BufferView::draw(frontend::Painter & pain)
 
                // Clear background.
                pain.fillRectangle(0, 0, width_, height_,
-                       buffer_.inset().backgroundColor());
+                       pi.backgroundColor(&buffer_.inset()));
 
                // Draw everything.
                tm.draw(pi, 0, y);