Remove all saveSelection calls and unify theSelection().setSelection. This is the common, housekeeping part of JMarc's and my patches. Fixes of bug 3877 will come later

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19003 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-07-06 17:03:45 +00:00
parent 2caa734edf
commit 252ec84acd
5 changed files with 18 additions and 81 deletions

View File

@ -565,7 +565,6 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
// need a valid cursor. (Lgb)
cur.clearSelection();
updateLabels(cur.buffer());
theSelection().haveSelection(false);
// tell tabular that a recent copy happened
dirtyTabularStack(false);
@ -672,24 +671,15 @@ void copySelection(Cursor & cur, docstring const & plaintext)
void saveSelection(Cursor & cur)
{
LYXERR(Debug::ACTION) << BOOST_CURRENT_FUNCTION << ": `"
<< to_utf8(cur.selectionAsString(true)) << "'."
<< endl;
#if 0
// FIXME: The two lines below would allow middle-mouse
// pasting that preserves the LyX formatting when the selection
// is internal. They would also allow to use the feature on
// Windows and Mac. In the future, we may want to optionally enable
// this feature via a rc setting.
// This is currently disabled because it eats too much resources
// while selecting (cf. bug 3877)
if (cur.selection())
// This function is called, not when a selection is formed, but when
// a selection is cleared. Therefore, multiple keyboard selection
// will not repeatively trigger this function (bug 3877).
if (cur.selection()) {
LYXERR(Debug::ACTION) << BOOST_CURRENT_FUNCTION << ": `"
<< to_utf8(cur.selectionAsString(true)) << "'."
<< endl;
copySelectionToStack(cur, selectionBuffer);
#endif
// tell X whether we now have a valid selection
theSelection().haveSelection(cur.selection());
}
}
@ -746,7 +736,6 @@ void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index)
pasteParagraphList(cur, theCuts[sel_index].first,
theCuts[sel_index].second, errorList);
cur.setSelection();
saveSelection(cur);
}
@ -825,7 +814,6 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwa
cur.setSelection(selbeg, -int(str.length()));
} else
cur.setSelection(selbeg, str.length());
saveSelection(cur);
}

View File

@ -86,6 +86,7 @@
#include "frontends/LyXView.h"
#include "frontends/Menubar.h"
#include "frontends/Toolbars.h"
#include "frontends/Selection.h"
#include "support/environment.h"
#include "support/FileFilterList.h"
@ -218,6 +219,10 @@ void LyXFunc::initKeySequences(KeyMap * kb)
void LyXFunc::setLyXView(LyXView * lv)
{
if (lyx_view_ && lyx_view_ != lv)
// save current selection to the selection buffer to allow
// middle-button paste in another window
cap::saveSelection(lyx_view_->view()->cursor());
lyx_view_ = lv;
}
@ -1824,6 +1829,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
&& !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
view()->buffer()->markDirty();
//Do we have a selection?
theSelection().haveSelection(view()->cursor().selection());
if (view()->cursor().inTexted()) {
lyx_view_->updateLayoutChoice();
}

View File

@ -119,7 +119,6 @@ namespace {
{
if (selecting || cur.mark())
cur.setSelection();
saveSelection(cur);
}
@ -488,8 +487,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
&& cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
} else if (cur.selection())
saveSelection(cur);
}
break;
case LFUN_CHAR_BACKWARD:
@ -506,8 +504,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
if (cur.selection())
saveSelection(cur);
break;
case LFUN_UP_SELECT:
@ -532,9 +528,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
} else
cur.undispatched();
// save new selection
if (cur.selection())
saveSelection(cur);
break;
}
@ -542,16 +535,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_PARAGRAPH_UP_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_UP_SELECT);
needsUpdate |= cursorUpParagraph(cur);
if (cur.selection())
saveSelection(cur);
break;
case LFUN_PARAGRAPH_DOWN:
case LFUN_PARAGRAPH_DOWN_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_PARAGRAPH_DOWN_SELECT);
needsUpdate |= cursorDownParagraph(cur);
if (cur.selection())
saveSelection(cur);
break;
case LFUN_SCREEN_UP:
@ -562,8 +551,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
else {
cursorPrevious(cur);
}
if (cur.selection())
saveSelection(cur);
break;
case LFUN_SCREEN_DOWN:
@ -575,8 +562,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
else {
cursorNext(cur);
}
if (cur.selection())
saveSelection(cur);
break;
case LFUN_LINE_BEGIN:
@ -589,8 +574,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_LINE_END_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_END_SELECT);
needsUpdate |= cursorEnd(cur);
if (cur.selection())
saveSelection(cur);
break;
case LFUN_WORD_FORWARD:
@ -600,8 +583,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
needsUpdate |= cursorLeftOneWord(cur);
else
needsUpdate |= cursorRightOneWord(cur);
if (cur.selection())
saveSelection(cur);
break;
case LFUN_WORD_BACKWARD:
@ -611,8 +592,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
needsUpdate |= cursorRightOneWord(cur);
else
needsUpdate |= cursorLeftOneWord(cur);
if (cur.selection())
saveSelection(cur);
break;
case LFUN_WORD_SELECT: {
@ -1033,7 +1012,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cursorEnd(cur);
cur.setSelection();
bv->cursor() = cur;
saveSelection(cur);
}
break;
@ -1145,7 +1123,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// but bvcur is current mouse position
Cursor & bvcur = cur.bv().cursor();
bvcur.selection() = true;
saveSelection(bvcur);
}
needsUpdate = false;
cur.noUpdate();
@ -1589,7 +1566,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_ESCAPE:
if (cur.selection()) {
cur.selection() = false;
saveSelection(cur);
} else {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);

View File

@ -3241,28 +3241,18 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_MOUSE_RELEASE:
//lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl;
if (cmd.button() == mouse_button::button1) {
if (bvcur.selection()) {
// Bug3238: disable persistent selection for table cells for now
if (tablemode(bvcur))
theSelection().haveSelection(true);
else
saveSelection(bvcur);
}
} else if (cmd.button() == mouse_button::button3)
if (cmd.button() == mouse_button::button3)
InsetTabularMailer(*this).showDialog(&cur.bv());
break;
case LFUN_CELL_BACKWARD:
movePrevCell(cur);
cur.selection() = false;
saveSelection(cur);
break;
case LFUN_CELL_FORWARD:
moveNextCell(cur);
cur.selection() = false;
saveSelection(cur);
break;
case LFUN_CHAR_FORWARD_SELECT:
@ -3270,12 +3260,6 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cell(cur.idx())->dispatch(cur, cmd);
if (!cur.result().dispatched()) {
isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
// The second case happens when LFUN_CHAR_FORWARD_SELECT
// is called, but the cursor is undispatched with cmd modified
// to LFUN_FINISHED_RIGHT (e.g. a case in bug 3782)
if (cmd.action == LFUN_CHAR_FORWARD_SELECT ||
cmd.action == LFUN_FINISHED_RIGHT)
saveSelection(cur);
if (sl == cur.top())
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
else
@ -3288,8 +3272,6 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cell(cur.idx())->dispatch(cur, cmd);
if (!cur.result().dispatched()) {
isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
if (cmd.action == LFUN_CHAR_BACKWARD_SELECT)
saveSelection(cur);
if (sl == cur.top())
cmd = FuncRequest(LFUN_FINISHED_LEFT);
else
@ -3311,13 +3293,6 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
TextMetrics const & tm =
cur.bv().textMetrics(cell(cur.idx())->getText(0));
cur.pos() = tm.x2pos(cur.pit(), 0, cur.targetX());
if (cmd.action == LFUN_DOWN_SELECT) {
// Bug3238: disable persistent selection for table cells for now
if (tablemode(cur))
theSelection().haveSelection(true);
else
saveSelection(cur);
}
}
if (sl == cur.top()) {
// we trick it to go to the RIGHT after leaving the
@ -3343,13 +3318,6 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
ParagraphMetrics const & pm =
tm.parMetrics(cur.lastpit());
cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, cur.targetX());
if (cmd.action == LFUN_UP_SELECT) {
// Bug3238: disable persistent selection for table cells for now
if (tablemode(cur))
theSelection().haveSelection(true);
else
saveSelection(cur);
}
}
if (sl == cur.top()) {
cmd = FuncRequest(LFUN_UP);
@ -4645,7 +4613,6 @@ void InsetTabular::cutSelection(Cursor & cur)
if (cur.pos() > cur.lastpos())
cur.pos() = cur.lastpos();
cur.clearSelection();
theSelection().haveSelection(false);
}

View File

@ -582,7 +582,6 @@ goto_char_backwards:
cur.selection() = true;
cur.pos() = cur.lastpos();
cur.idx() = cur.lastidx();
cap::saveSelection(cur);
break;
case LFUN_PARAGRAPH_UP:
@ -1207,7 +1206,6 @@ void InsetMathNest::lfunMouseRelease(Cursor & cur, FuncRequest & cmd)
else {
Cursor & bvcur = cur.bv().cursor();
bvcur.selection() = true;
cap::saveSelection(bvcur);
}
return;
}