From 9f61659c00969c917b4e2b8bcd66870a628d4542 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Fri, 2 Dec 2011 21:30:40 +0000 Subject: [PATCH] Backport fix for #7872. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@40335 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 33 --------------------------- src/BufferView.cpp | 46 ++++++++++++++++++++++++++++++++++++++ src/insets/InsetBranch.cpp | 18 ++++++++++----- 3 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 709bc0ac17..e43a8cec76 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2028,14 +2028,6 @@ bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag) enable = params().isExportable("program"); break; - case LFUN_BRANCH_ACTIVATE: - case LFUN_BRANCH_DEACTIVATE: { - BranchList const & branchList = params().branchlist(); - docstring const branchName = cmd.argument(); - enable = !branchName.empty() && branchList.find(branchName); - break; - } - case LFUN_BRANCH_ADD: case LFUN_BRANCHES_RENAME: case LFUN_BUFFER_PRINT: @@ -2187,31 +2179,6 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) break; } - case LFUN_BRANCH_ACTIVATE: - case LFUN_BRANCH_DEACTIVATE: { - BranchList & branchList = params().branchlist(); - docstring const branchName = func.argument(); - // the case without a branch name is handled elsewhere - if (branchName.empty()) { - dispatched = false; - break; - } - Branch * branch = branchList.find(branchName); - if (!branch) { - LYXERR0("Branch " << branchName << " does not exist."); - dr.setError(true); - docstring const msg = - bformat(_("Branch \"%1$s\" does not exist."), branchName); - dr.setMessage(msg); - } else { - branch->setSelected(func.action() == LFUN_BRANCH_ACTIVATE); - dr.setError(false); - dr.screenUpdate(Update::Force); - dr.forceBufferUpdate(); - } - break; - } - case LFUN_BRANCHES_RENAME: { if (func.argument().empty()) break; diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 6098b250cf..5e7da53ba3 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1162,6 +1162,17 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag) break; } + // FIXME We do not really want this here, but at present we need to + // handle their dispatch here, for reasons explained there, so we'll + // handle this here, too, for consistency. + case LFUN_BRANCH_ACTIVATE: + case LFUN_BRANCH_DEACTIVATE: { + BranchList const & branchList = buffer().params().branchlist(); + docstring const branchName = cmd.argument(); + flag.setEnabled(!branchName.empty() && branchList.find(branchName)); + break; + } + default: return false; } @@ -1906,6 +1917,41 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) break; } + // FIXME We do not really want this here, but it has to be at present + // because we need a cursor for the recordUndoFullDocument call. What + // we would really like is a recordUndoBufferParams call that did not + // need a cursor, but we do not have that yet. + // So, if this does get fixed, this code can be moved back to Buffer.cpp, + // and the corresponding code in getStatus() should be moved back, too. + case LFUN_BRANCH_ACTIVATE: + case LFUN_BRANCH_DEACTIVATE: { + BranchList & branch_list = buffer().params().branchlist(); + docstring const branch_name = cmd.argument(); + // the case without a branch name is handled elsewhere + if (branch_name.empty()) { + dispatched = false; + break; + } + Branch * branch = branch_list.find(branch_name); + if (!branch) { + LYXERR0("Branch " << branch_name << " does not exist."); + dr.setError(true); + docstring const msg = + bformat(_("Branch \"%1$s\" does not exist."), branch_name); + dr.setMessage(msg); + break; + } + bool activate = cmd.action() == LFUN_BRANCH_ACTIVATE; + if (branch->isSelected() != activate) { + branch->setSelected(activate); + cur.recordUndoFullDocument(); + dr.setError(false); + dr.screenUpdate(Update::Force); + dr.forceBufferUpdate(); + } + break; + } + default: // OK, so try the Buffer itself... buffer_.dispatch(cmd, dr); diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 3a158e93d5..9b06c5ecef 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -126,18 +126,26 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_BRANCH_ACTIVATE: case LFUN_BRANCH_DEACTIVATE: { - // FIXME: I do not like this cast, but have no other idea... - Buffer const * buf = buffer().masterBuffer(); - BranchList const & branchlist = buf->params().branchlist(); - Branch * our_branch = const_cast(branchlist.find(params_.branch)); - if (!our_branch) { + Buffer * buf = const_cast(buffer().masterBuffer()); + // is the branch in our master buffer? + bool branch_in_master = (buf != &buffer()); + + Branch * our_branch = buf->params().branchlist().find(params_.branch); + if (branch_in_master && !our_branch) { // child only? our_branch = buffer().params().branchlist().find(params_.branch); if (!our_branch) break; + branch_in_master = false; } bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE); if (our_branch->isSelected() != activate) { + // FIXME If the branch is in the master document, we cannot + // call recordUndo..., becuase the master may be hidden, and + // the code presently assumes that hidden documents can never + // be dirty. See GuiView::closeBufferAll(), for example. + if (!branch_in_master) + buffer().undo().recordUndoFullDocument(cur); our_branch->setSelected(activate); cur.forceBufferUpdate(); } -- 2.39.5