mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-21 17:51:03 +00:00
This commit is contained in:
parent
066e35fc9d
commit
e26635bfb9
@ -53,6 +53,12 @@ To set the default language and paper size for new documents, use the
|
||||
|
||||
The following new LyX functions have been introduced:
|
||||
|
||||
- LFUN_BRANCH_MASTER_ACTIVATE <branch>:
|
||||
LFUN_BRANCH_MASTER_DEACTIVATE <branch>:
|
||||
Activates or deactivates a branch in a master document from within
|
||||
a child (as opposed to the existing LFUN_BRANCH_[DE]ACTIVATE, which
|
||||
toggle the branch in the document itself).
|
||||
|
||||
- LFUN_BUFFER_EXPORT_AS <format> <filename>
|
||||
Equivalent to the new -export-to command-line switch (see above).
|
||||
|
||||
|
@ -441,6 +441,8 @@ Menuset
|
||||
Menu "context-branch"
|
||||
OptItem "Activate Branch|A" "branch-activate"
|
||||
OptItem "Deactivate Branch|e" "branch-deactivate"
|
||||
OptItem "Activate Branch in Master|M" "branch-master-activate"
|
||||
OptItem "Deactivate Branch in Master|v" "branch-master-deactivate"
|
||||
End
|
||||
|
||||
#
|
||||
|
@ -1188,8 +1188,13 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
|
||||
// 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();
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE: {
|
||||
bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
|
||||
BranchList const & branchList = master ? buffer().masterBuffer()->params().branchlist()
|
||||
: buffer().params().branchlist();
|
||||
docstring const branchName = cmd.argument();
|
||||
flag.setEnabled(!branchName.empty() && branchList.find(branchName));
|
||||
break;
|
||||
@ -1969,15 +1974,21 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
// 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();
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE: {
|
||||
bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
|
||||
Buffer * buf = master ? const_cast<Buffer *>(buffer().masterBuffer())
|
||||
: &buffer();
|
||||
|
||||
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);
|
||||
Branch * branch = buf->params().branchlist().find(branch_name);
|
||||
if (!branch) {
|
||||
LYXERR0("Branch " << branch_name << " does not exist.");
|
||||
dr.setError(true);
|
||||
@ -1986,7 +1997,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
dr.setMessage(msg);
|
||||
break;
|
||||
}
|
||||
bool activate = cmd.action() == LFUN_BRANCH_ACTIVATE;
|
||||
bool activate = (cmd.action() == LFUN_BRANCH_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE);
|
||||
if (branch->isSelected() != activate) {
|
||||
branch->setSelected(activate);
|
||||
cur.recordUndoFullDocument();
|
||||
|
@ -450,6 +450,8 @@ enum FuncCode
|
||||
LFUN_SCRIPT_INSERT, // gb, 20101123
|
||||
LFUN_BUFFER_EXPORT_AS, // tommaso 20111006
|
||||
// 350
|
||||
LFUN_BRANCH_MASTER_ACTIVATE, // spitz 20120930
|
||||
LFUN_BRANCH_MASTER_DEACTIVATE, // spitz 20120930
|
||||
LFUN_LASTACTION // end of the table
|
||||
};
|
||||
|
||||
|
@ -3525,6 +3525,27 @@ void LyXAction::init()
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_BRANCH_DEACTIVATE, "branch-deactivate", AtPoint, Buffer },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_BRANCH_MASTER_ACTIVATE
|
||||
* \li Action: Activate the branch in the master buffer.
|
||||
* \li Syntax: branch-master-activate <BRANCH>
|
||||
* \li Params: <BRANCH>: The branch to activate
|
||||
* \li Sample: lyx -x "branch-activate answers" -e pdf2 finalexam.lyx \n
|
||||
could be used to export a pdf with the answers branch included
|
||||
without one's having to open LyX and activate the branch manually.
|
||||
* \li Origin: spitz, 30 Sep 2012
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_BRANCH_MASTER_ACTIVATE, "branch-master-activate", AtPoint, Buffer },
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_BRANCH_MASTER_DEACTIVATE
|
||||
* \li Action: De-activate the branch in the master buffer.
|
||||
* \li Syntax: branch-master-deactivate <BRANCH>
|
||||
* \li Params: <BRANCH>: The branch to deactivate
|
||||
* \li Origin: spitz, 30 Sep 2012
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_BRANCH_MASTER_DEACTIVATE, "branch-master-deactivate", AtPoint, Buffer },
|
||||
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_BRANCHES_RENAME
|
||||
|
@ -64,8 +64,14 @@ void InsetBranch::read(Lexer & lex)
|
||||
|
||||
docstring InsetBranch::toolTip(BufferView const & bv, int, int) const
|
||||
{
|
||||
docstring const status = isBranchSelected() ?
|
||||
docstring const masterstatus = isBranchSelected() ?
|
||||
_("active") : _("non-active");
|
||||
docstring const childstatus = isBranchSelected(true) ?
|
||||
_("active") : _("non-active");
|
||||
docstring const status = (masterstatus == childstatus) ?
|
||||
masterstatus :
|
||||
support::bformat(_("master: %1$s, child: %2$s"),
|
||||
masterstatus, childstatus);
|
||||
docstring const heading =
|
||||
support::bformat(_("Branch (%1$s): %2$s"), status, params_.branch);
|
||||
if (isOpen(bv))
|
||||
@ -79,10 +85,13 @@ docstring const InsetBranch::buttonLabel(BufferView const & bv) const
|
||||
docstring s = _("Branch: ") + params_.branch;
|
||||
Buffer const & realbuffer = *buffer().masterBuffer();
|
||||
BranchList const & branchlist = realbuffer.params().branchlist();
|
||||
if (!branchlist.find(params_.branch)
|
||||
&& buffer().params().branchlist().find(params_.branch))
|
||||
bool const inmaster = branchlist.find(params_.branch);
|
||||
bool const inchild = buffer().params().branchlist().find(params_.branch);
|
||||
if (!inmaster && inchild)
|
||||
s = _("Branch (child only): ") + params_.branch;
|
||||
else if (!branchlist.find(params_.branch))
|
||||
else if (inmaster && !inchild)
|
||||
s = _("Branch (master only): ") + params_.branch;
|
||||
else if (!inmaster)
|
||||
s = _("Branch (undefined): ") + params_.branch;
|
||||
if (!params_.branch.empty()) {
|
||||
// FIXME UNICODE
|
||||
@ -90,7 +99,12 @@ docstring const InsetBranch::buttonLabel(BufferView const & bv) const
|
||||
if (c == Color_none)
|
||||
s = _("Undef: ") + s;
|
||||
}
|
||||
s = char_type(isBranchSelected() ? 0x2714 : 0x2716) + s;
|
||||
bool const master_selected = isBranchSelected();
|
||||
bool const child_selected = isBranchSelected(true);
|
||||
docstring symb = docstring(1, char_type(master_selected ? 0x2714 : 0x2716));
|
||||
if (inchild && master_selected != child_selected)
|
||||
symb += char_type(child_selected ? 0x2714 : 0x2716);
|
||||
s = symb + s;
|
||||
if (decoration() == InsetLayout::CLASSIC)
|
||||
return isOpen(bv) ? s : getNewLabel(s);
|
||||
else
|
||||
@ -125,26 +139,26 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||
break;
|
||||
}
|
||||
case LFUN_BRANCH_ACTIVATE:
|
||||
case LFUN_BRANCH_DEACTIVATE: {
|
||||
Buffer * buf = const_cast<Buffer *>(buffer().masterBuffer());
|
||||
// is the branch in our master buffer?
|
||||
bool branch_in_master = (buf != &buffer());
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE: {
|
||||
bool const master = (cmd.action() == LFUN_BRANCH_MASTER_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_DEACTIVATE);
|
||||
Buffer * buf = master ? const_cast<Buffer *>(buffer().masterBuffer())
|
||||
: &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)
|
||||
break;
|
||||
|
||||
bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE
|
||||
|| cmd.action() == LFUN_BRANCH_MASTER_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
|
||||
// call recordUndo..., because 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)
|
||||
if (!master)
|
||||
buffer().undo().recordUndoFullDocument(cur);
|
||||
our_branch->setSelected(activate);
|
||||
cur.forceBufferUpdate();
|
||||
@ -174,11 +188,19 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
break;
|
||||
|
||||
case LFUN_BRANCH_ACTIVATE:
|
||||
flag.setEnabled(!isBranchSelected());
|
||||
flag.setEnabled(!isBranchSelected(true));
|
||||
break;
|
||||
|
||||
case LFUN_BRANCH_DEACTIVATE:
|
||||
flag.setEnabled(isBranchSelected());
|
||||
flag.setEnabled(isBranchSelected(true));
|
||||
break;
|
||||
|
||||
case LFUN_BRANCH_MASTER_ACTIVATE:
|
||||
flag.setEnabled(buffer().parent() && !isBranchSelected());
|
||||
break;
|
||||
|
||||
case LFUN_BRANCH_MASTER_DEACTIVATE:
|
||||
flag.setEnabled(buffer().parent() && isBranchSelected());
|
||||
break;
|
||||
|
||||
case LFUN_INSET_TOGGLE:
|
||||
@ -195,9 +217,9 @@ bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
}
|
||||
|
||||
|
||||
bool InsetBranch::isBranchSelected() const
|
||||
bool InsetBranch::isBranchSelected(bool const child) const
|
||||
{
|
||||
Buffer const & realbuffer = *buffer().masterBuffer();
|
||||
Buffer const & realbuffer = child ? buffer() : *buffer().masterBuffer();
|
||||
BranchList const & branchlist = realbuffer.params().branchlist();
|
||||
Branch const * ourBranch = branchlist.find(params_.branch);
|
||||
|
||||
|
@ -88,9 +88,9 @@ private:
|
||||
void setParams(InsetBranchParams const & params) { params_ = params; }
|
||||
|
||||
/** \returns true if params_.branch is listed as 'selected' in
|
||||
\c buffer. This handles the case of child documents.
|
||||
\c buffer. \p child only checks within child documents.
|
||||
*/
|
||||
bool isBranchSelected() const;
|
||||
bool isBranchSelected(bool const child = false) const;
|
||||
/*!
|
||||
* Is the content of this inset part of the output document?
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user