Use Alfredo's getOutOfInset suggestion, but use it in the inset::dispatch

functions as suggested by Andre. Squashes the bug beautifully.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8567 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-03-31 08:43:47 +00:00
parent 7ae6332b03
commit 3666618138
6 changed files with 44 additions and 15 deletions

View File

@ -1,3 +1,8 @@
2004-03-31 Angus Leeming <leeming@lyx.org>
* lyxfunc.C (dispatch): remove the cursor-manipulation code from
the LFUN_ALL_INSETS_TOGGLE code.
2004-03-30 Angus Leeming <leeming@lyx.org> 2004-03-30 Angus Leeming <leeming@lyx.org>
* lyxfunc.C (dispatch): the specialization Dialogs::showDocument * lyxfunc.C (dispatch): the specialization Dialogs::showDocument

View File

@ -1,3 +1,13 @@
2004-03-31 Angus Leeming <leeming@lyx.org>
* insetcollapsable.[Ch] (getOutOfInset): new function which pushes
the cursor out of an inset.
* insetbranch.C (priv_dispatch):
* insetcollapsable.C (priv_dispatch): in the LFUN_INSET_TOGGLE code,
use getOutOfInset to push the cursor out of the inset when
collapsing it.
2004-03-30 Angus Leeming <leeming@lyx.org> 2004-03-30 Angus Leeming <leeming@lyx.org>
* insetbase.[Ch] (translate): new static member function, returns * insetbase.[Ch] (translate): new static member function, returns

View File

@ -147,11 +147,12 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
if (cmd.argument == "open") if (cmd.argument == "open")
setStatus(Open); setStatus(Open);
else if (cmd.argument == "close") else if (cmd.argument == "close") {
setStatus(Collapsed); setStatus(Collapsed);
getOutOfInset(cur, *this);
// The branch inset specialises its behaviour on "toggle". // The branch inset specialises its behaviour on "toggle".
else if (cmd.argument == "toggle" } else if (cmd.argument == "toggle"
|| cmd.argument.empty()) { || cmd.argument.empty()) {
BranchList const & branchlist = BranchList const & branchlist =
cur.bv().buffer()->params().branchlist(); cur.bv().buffer()->params().branchlist();
@ -161,9 +162,10 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
else else
cur.undispatched(); cur.undispatched();
} else { } else {
if (status() != Collapsed) if (status() != Collapsed) {
setStatus(Collapsed); setStatus(Collapsed);
else getOutOfInset(cur, *this);
} else
cur.undispatched(); cur.undispatched();
} }
} }

View File

@ -39,6 +39,17 @@ using std::min;
using std::ostream; using std::ostream;
void getOutOfInset(LCursor & cur, InsetBase const & in)
{
for (unsigned int i = 0; i != cur.size(); ++i) {
if (&cur[i].inset() == &in) {
cur.resize(i);
return;
}
}
}
InsetCollapsable::InsetCollapsable(BufferParams const & bp, InsetCollapsable::InsetCollapsable(BufferParams const & bp,
CollapseStatus status) CollapseStatus status)
: InsetText(bp), label("Label"), status_(status), openinlined_(false) : InsetText(bp), label("Label"), status_(status), openinlined_(false)
@ -302,13 +313,15 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
if (cmd.argument == "open") if (cmd.argument == "open")
setStatus(Open); setStatus(Open);
else if (cmd.argument == "close") else if (cmd.argument == "close") {
setStatus(Collapsed); setStatus(Collapsed);
else if (cmd.argument == "toggle" getOutOfInset(cur, *this);
} else if (cmd.argument == "toggle"
|| cmd.argument.empty()) { || cmd.argument.empty()) {
if (isOpen()) if (isOpen()) {
setStatus(Collapsed); setStatus(Collapsed);
else getOutOfInset(cur, *this);
} else
setStatus(Open); setStatus(Open);
} }
cur.dispatched(); cur.dispatched();

View File

@ -123,4 +123,7 @@ private:
mutable Dimension textdim_; mutable Dimension textdim_;
}; };
// A helper function that pushes the cursor out of the inset.
void getOutOfInset(LCursor & cur, InsetBase const & in);
#endif #endif

View File

@ -1270,12 +1270,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
InsetIterator const end = inset_iterator_end(inset); InsetIterator const end = inset_iterator_end(inset);
for (; it != end; ++it) { for (; it != end; ++it) {
if (inset_code == InsetBase::NO_CODE if (inset_code == InsetBase::NO_CODE
|| inset_code == it->lyxCode()) { || inset_code == it->lyxCode())
it->dispatch(cur, fr); it->dispatch(cur, fr);
if (&cur.inset() == &*it
&& cur.disp_.dispatched())
cur.pop();
}
} }
break; break;
} }