diff --git a/src/Text3.cpp b/src/Text3.cpp index e145e1a7f3..f9d622cff5 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1134,51 +1134,63 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; // Single-click on work area - case LFUN_MOUSE_PRESS: { - // Right click on a footnote flag opens float menu - // FIXME: Why should we clear the selection in this case? - if (cmd.button() == mouse_button::button3) - cur.clearSelection(); + case LFUN_MOUSE_PRESS: + // We are not marking a selection with the keyboard in any case. + cur.bv().cursor().mark() = false; + switch (cmd.button()) { + case mouse_button::button1: + // Set the cursor + if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select")) + cur.updateFlags(Update::SinglePar | Update::FitCursor); + break; - bool do_selection = cmd.button() == mouse_button::button1 - && cmd.argument() == "region-select"; - // Set the cursor - bool update = bv->mouseSetCursor(cur, do_selection); - - // Insert primary selection with middle mouse - // if there is a local selection in the current buffer, - // insert this - if (cmd.button() == mouse_button::button2) { - if (cap::selection()) { - // Copy the selection buffer to the clipboard - // stack, because we want it to appear in the - // "Edit->Paste recent" menu. - cap::copySelectionToStack(); - - cap::pasteSelection(bv->cursor(), - bv->buffer().errorList("Paste")); - bv->buffer().errors("Paste"); - bv->buffer().markDirty(); - bv->cursor().finishUndo(); - } else { - lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph")); + case mouse_button::button2: + // Middle mouse pasting. + if (!cap::selection()) { + // There is no local selection in the current buffer, so try to + // paste primary selection instead. + lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, + "paragraph")); + // Nothing else to do. + cur.noUpdate(); + return; } - } + // Copy the selection buffer to the clipboard stack, because we want it + // to appear in the "Edit->Paste recent" menu. + cap::copySelectionToStack(); + cap::pasteSelection(bv->cursor(), bv->buffer().errorList("Paste")); + cur.updateFlags(Update::Force | Update::FitCursor); + bv->buffer().errors("Paste"); + bv->buffer().markDirty(); + bv->cursor().finishUndo(); + break; - // we have to update after dEPM triggered - if (!update && cmd.button() == mouse_button::button1) { - needsUpdate = false; - cur.noUpdate(); + case mouse_button::button3: + if (cur.selection()) { + DocIterator const selbeg = cur.selectionBegin(); + DocIterator const selend = cur.selectionEnd(); + Cursor tmpcur = cur; + tm.setCursorFromCoordinates(tmpcur, cmd.x, cmd.y); + // Don't do anything if we right-click a selection, a selection + // context menu should popup instead. + if (tmpcur < selbeg || tmpcur >= selend) { + cur.noUpdate(); + return; + } + } + if (!bv->mouseSetCursor(cur, false)) { + cur.noUpdate(); + return; + } + return; } - break; - } - case LFUN_MOUSE_MOTION: { - // Only use motion with button 1 - //if (cmd.button() != mouse_button::button1) - // return false; - + // Mouse motion with right or middle mouse do nothing for now. + if (cmd.button() != mouse_button::button1) { + cur.noUpdate(); + return; + } // ignore motions deeper nested than the real anchor Cursor & bvcur = cur.bv().cursor(); if (!bvcur.anchor_.hasPart(cur)) { @@ -1203,42 +1215,52 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) else if (cmd.y < 0) lyx::dispatch(FuncRequest(LFUN_UP_SELECT)); } - - if (cur.top() == old) - cur.noUpdate(); - else { - // FIXME: This is brute force! But without it the selected - // area is not corrected updated while moving the mouse. - cur.updateFlags(Update::Force | Update::FitCursor); - // don't set anchor_ - bvcur.setCursor(cur); - bvcur.selection() = true; - //lyxerr << "MOTION: " << bv->cursor() << endl; + // We continue with our existing selection or start a new one, so don't + // reset the anchor. + bvcur.setCursor(cur); + bvcur.selection() = true; + if (cur.top() == old) { + // We didn't move one iota, so no need to update the screen. + cur.updateFlags(Update::SinglePar | Update::FitCursor); + //cur.noUpdate(); + return; } break; } - case LFUN_MOUSE_RELEASE: { - if (cmd.button() == mouse_button::button2) - break; - - if (cmd.button() == mouse_button::button1) { - // if there is new selection, update persistent - // selection, otherwise, single click does not - // clear persistent selection buffer + case LFUN_MOUSE_RELEASE: + switch (cmd.button()) { + case mouse_button::button1: + // Cursor was set at LFUN_MOUSE_PRESS or LFUN_MOUSE_MOTION time. + // If there is a new selection, update persistent selection; + // otherwise, single click does not clear persistent selection + // buffer. if (cur.selection()) { - // finish selection - // if double click, cur is moved to the end of word by selectWord - // but bvcur is current mouse position - Cursor & bvcur = cur.bv().cursor(); - bvcur.selection() = true; + // Finish selection. + // If double click, cur is moved to the end of word by selectWord + // but bvcur is current mouse position. + cur.bv().cursor().selection() = true; } - needsUpdate = false; + // FIXME: We could try to handle drag and drop of selection here. cur.noUpdate(); - } + return; + + case mouse_button::button2: + // Middle mouse pasting is handled at mouse press time, + // see LFUN_MOUSE_PRESS. + cur.noUpdate(); + return; + + case mouse_button::button3: + // Cursor was set at LFUN_MOUSE_PRESS time. + // FIXME: If there is a selection we could try to handle a special + // drag & drop context menu. + cur.noUpdate(); + return; + + } // switch (cmd.button()) break; - } case LFUN_SELF_INSERT: { if (cmd.argument().empty()) diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 024208f107..11e6ee0fd4 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -198,14 +198,6 @@ void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd) InsetBoxMailer(*this).updateDialog(&cur.bv()); break; - case LFUN_MOUSE_RELEASE: - if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetBoxMailer(*this).showDialog(&cur.bv()); - break; - } - InsetCollapsable::doDispatch(cur, cmd); - break; - default: InsetCollapsable::doDispatch(cur, cmd); break; diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 852b04fc0c..a261897cf8 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -130,14 +130,6 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) InsetBranchMailer(*this).updateDialog(&cur.bv()); break; - case LFUN_MOUSE_RELEASE: - if (cmd.button() == mouse_button::button3 && hitButton(cmd)) - InsetBranchMailer(*this).showDialog(&cur.bv()); - else - InsetCollapsable::doDispatch(cur, cmd); - break; - - case LFUN_INSET_TOGGLE: if (cmd.argument() == "assign") { // The branch inset uses "assign". diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 32e8b26f30..4764f174c6 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -497,21 +497,25 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) switch (cmd.action) { case LFUN_MOUSE_PRESS: - if (cmd.button() == mouse_button::button1 - && hitButton(cmd) - && geometry() != NoButton) { - // reset selection if necessary (see bug 3060) - if (cur.selection()) - cur.bv().cursor().clearSelection(); - else - cur.noUpdate(); - cur.dispatched(); - break; + if (hitButton(cmd) && geometry() != NoButton) { + switch (cmd.button()) { + case mouse_button::button1: + // reset selection if necessary (see bug 3060) + if (cur.selection()) + cur.bv().cursor().clearSelection(); + else + cur.noUpdate(); + cur.dispatched(); + return; + case mouse_button::button2: + case mouse_button::button3: + // Nothing to do. + cur.undispatched(); + return; + } } - if (geometry() == NoButton) - InsetText::doDispatch(cur, cmd); - else if (geometry() != ButtonOnly - && !hitButton(cmd)) + if (geometry() == NoButton + || (geometry() != ButtonOnly && !hitButton(cmd))) InsetText::doDispatch(cur, cmd); else cur.undispatched(); @@ -530,26 +534,6 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) break; case LFUN_MOUSE_RELEASE: - if (cmd.button() == mouse_button::button3) { - // There is no button to right click: - if (decoration() == InsetLayout::Minimalistic || - geometry() == Corners || - geometry() == SubLabel || - geometry() == NoButton - ) { - if (status_ == Open) - setStatus(cur, Collapsed); - else - setStatus(cur, Open); - break; - } else { - // Open the Inset - // configuration dialog - showInsetDialog(&cur.bv()); - break; - } - } - if (geometry() == NoButton) { // The mouse click has to be within the inset! InsetText::doDispatch(cur, cmd); diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index d0114141fa..ade0a22f49 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -107,16 +107,6 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd) Layout const layout = bp.documentClass().emptyLayout(); //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl; switch (cmd.action) { - - case LFUN_MOUSE_PRESS: - if (cmd.button() != mouse_button::button3) - InsetCollapsable::doDispatch(cur, cmd); - else - // This makes the cursor leave the - // inset when it collapses on mouse-3 - cur.undispatched(); - break; - case LFUN_QUOTE_INSERT: { // We need to bypass the fancy quotes in Text FuncRequest f(LFUN_SELF_INSERT, "\""); diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index fcfef733c8..c385add251 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -471,7 +471,7 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd) break; case LFUN_MOUSE_RELEASE: - if (!cur.selection()) + if (!cur.selection() && cmd.button() == mouse_button::button1) InsetExternalMailer(*this).showDialog(&cur.bv()); break; diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index df970d3de9..ffa99288ce 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -146,17 +146,6 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd) break; } - case LFUN_MOUSE_RELEASE: { - if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - if (params_.subfloat) - break; - InsetFloatMailer(*this).showDialog(&cur.bv()); - break; - } - InsetCollapsable::doDispatch(cur, cmd); - break; - } - default: InsetCollapsable::doDispatch(cur, cmd); break; diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index af7a279ec9..eb98501ee8 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -197,7 +197,7 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd) break; case LFUN_MOUSE_RELEASE: - if (!cur.selection()) + if (!cur.selection() && cmd.button() == mouse_button::button1) InsetGraphicsMailer(*this).showDialog(&cur.bv()); break; diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 99d8552b74..2ff3afd811 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -214,14 +214,6 @@ void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_DIALOG_UPDATE: InsetListingsMailer(*this).updateDialog(&cur.bv()); break; - case LFUN_MOUSE_RELEASE: { - if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetListingsMailer(*this).showDialog(&cur.bv()); - break; - } - InsetCollapsable::doDispatch(cur, cmd); - break; - } default: InsetCollapsable::doDispatch(cur, cmd); break; diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index 0f954f41e2..603998f674 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -132,7 +132,7 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_MOUSE_RELEASE: - if (!cur.selection()) + if (!cur.selection() && cmd.button() == mouse_button::button1) InsetSpaceMailer(*this).showDialog(&cur.bv()); break; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 986aaf3714..1f521f6a5b 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3179,12 +3179,6 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) } break; - case LFUN_MOUSE_RELEASE: - //lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl; - if (cmd.button() == mouse_button::button3) - InsetTabularMailer(*this).showDialog(&cur.bv()); - break; - case LFUN_CELL_BACKWARD: movePrevCell(cur); cur.selection() = false; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 06105c83e5..2a596c0138 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -424,6 +424,11 @@ ParagraphList & InsetText::paragraphs() } +//void InsetInclude::addToToc(ParConstIterator const & cpit) const +//{ +//} + + void InsetText::updateLabels(ParIterator const & it) { ParIterator it2 = it; diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp index 5b40341d8c..b352fec43b 100644 --- a/src/insets/InsetVSpace.cpp +++ b/src/insets/InsetVSpace.cpp @@ -62,7 +62,7 @@ void InsetVSpace::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_MOUSE_RELEASE: - if (!cur.selection()) + if (!cur.selection() && cmd.button() == mouse_button::button1) InsetVSpaceMailer(*this).showDialog(&cur.bv()); break; diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index 8fcadf9458..244467ac86 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -74,15 +74,6 @@ void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd) InsetWrapMailer(*this).updateDialog(&cur.bv()); break; - case LFUN_MOUSE_RELEASE: { - if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetWrapMailer(*this).showDialog(&cur.bv()); - break; - } - InsetCollapsable::doDispatch(cur, cmd); - break; - } - default: InsetCollapsable::doDispatch(cur, cmd); break;