]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
* Call metrics of the parameters with the correct font in MathMacros, for example
[lyx.git] / src / BufferView.cpp
index a98fcfe095f47159b7c1a97056bfa80f22c2b98c..cea5b723c6d890a1c0e60e68bc9f1ec7bd906b31 100644 (file)
@@ -533,6 +533,10 @@ docstring BufferView::toolTip(int x, int y) const
 
 docstring BufferView::contextMenu(int x, int y) const
 {
+       //If there is a selection, return the containing inset menu
+       if (d->cursor_.selection())
+               return d->cursor_.inset().contextMenu(*this, x, y);
+
        // Get inset under mouse, if there is one.
        Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
        if (covering_inset)
@@ -602,31 +606,28 @@ void BufferView::setCursorFromScrollbar()
        int const height = 2 * defaultRowHeight();
        int const first = height;
        int const last = height_ - height;
-       Cursor & cur = d->cursor_;
+       int newy = 0;
+       Cursor const & oldcur = d->cursor_;
 
-       switch (cursorStatus(cur)) {
+       switch (cursorStatus(oldcur)) {
        case CUR_ABOVE:
-               // We reset the cursor because cursorStatus() does not
-               // work when the cursor is within mathed.
-               cur.reset(buffer_.inset());
-               tm.setCursorFromCoordinates(cur, 0, first);
-               cur.clearSelection();
+               newy = first;
                break;
        case CUR_BELOW:
-               // We reset the cursor because cursorStatus() does not
-               // work when the cursor is within mathed.
-               cur.reset(buffer_.inset());
-               tm.setCursorFromCoordinates(cur, 0, last);
-               cur.clearSelection();
+               newy = last;
                break;
        case CUR_INSIDE:
-               int const y = getPos(cur, cur.boundary()).y_;
-               int const newy = min(last, max(y, first));
-               if (y != newy) {
-                       cur.reset(buffer_.inset());
-                       tm.setCursorFromCoordinates(cur, 0, newy);
-               }
+               int const y = getPos(oldcur, oldcur.boundary()).y_;
+               newy = min(last, max(y, first));
+               if (y == newy) 
+                       return;
        }
+       // We reset the cursor because cursorStatus() does not
+       // work when the cursor is within mathed.
+       Cursor cur(*this);
+       cur.reset(buffer_.inset());
+       tm.setCursorFromCoordinates(cur, 0, newy);
+       mouseSetCursor(cur);
 }
 
 
@@ -872,7 +873,6 @@ 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:
@@ -1188,6 +1188,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
@@ -1220,7 +1224,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;
@@ -1228,10 +1232,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();
@@ -1426,21 +1430,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;
-               //view()->cursor().recordUndoFullDocument(); let inset-apply do that job
-               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);
@@ -1483,6 +1477,7 @@ docstring const BufferView::requestSelection()
 {
        Cursor & cur = d->cursor_;
 
+       LYXERR(Debug::SELECTION, "requestSelection: cur.selection: " << cur.selection());
        if (!cur.selection()) {
                d->xsel_cache_.set = false;
                return docstring();
@@ -1570,7 +1565,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.
@@ -1617,6 +1612,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
@@ -1629,6 +1626,8 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
        if (!inset || !cur.result().dispatched())
                cur.dispatch(cmd);
 
+       cur.endUndoGroup();
+
        // Notify left insets
        if (cur != old) {
                old.fixIfBroken();
@@ -1740,6 +1739,26 @@ void BufferView::setCursorFromRow(int row)
 }
 
 
+bool BufferView::setCursorFromInset(Inset const * inset)
+{
+       // are we already there?
+       if (cursor().nextInset() == inset)
+               return true;
+
+       // Inset is not at cursor position. Find it in the document.
+       Cursor cur(*this);
+       cur.reset(buffer().inset());
+       while (cur && cur.nextInset() != inset)
+               cur.forwardInset();
+
+       if (cur) {
+               setCursor(cur);
+               return true;
+       }
+       return false;
+}
+
+
 void BufferView::gotoLabel(docstring const & label)
 {
        Toc & toc = buffer().tocBackend().toc("label");
@@ -1791,7 +1810,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);
 }