* BufferView.cpp (setCursorFromInset): new method, useful to find
	an inset that is known to be in the document.

	* frontends/qt4/GuiView.cpp (dispatch): do a proper recordUndo
	befire appplying changes to an inset. The insets are responsible
	for recording additional undo steps that could be needed.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26428 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2008-09-17 14:51:27 +00:00
parent 9bbe7251af
commit d585528d50
3 changed files with 30 additions and 1 deletions

View File

@ -1742,6 +1742,27 @@ 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());
do
cur.forwardInset();
while (cur && cur.nextInset() != inset);
if (cur) {
setCursor(cur);
return true;
}
return false;
}
void BufferView::gotoLabel(docstring const & label)
{
Toc & toc = buffer().tocBackend().toc("label");

View File

@ -144,6 +144,9 @@ public:
/// set the cursor based on the given TeX source row.
void setCursorFromRow(int row);
/// set cursor to the given inset. Return true if found.
bool setCursorFromInset(Inset const *);
/// Ensure that the BufferView cursor is visible.
/// This method will automatically scroll and update the BufferView
/// if needed.

View File

@ -1960,13 +1960,18 @@ bool GuiView::dispatch(FuncRequest const & cmd)
}
case LFUN_INSET_APPLY: {
view()->cursor().recordUndoFullDocument();
string const name = cmd.getArg(0);
Inset * inset = getOpenInset(name);
if (inset) {
// put cursor in front of inset.
if (!view()->setCursorFromInset(inset))
LASSERT(false, /**/);
view()->cursor().recordUndo();
FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
inset->dispatch(view()->cursor(), fr);
} else {
view()->cursor().recordUndo();
FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
lyx::dispatch(fr);
}