2003-08-17 11:28:23 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetBranch.cpp
|
2003-08-17 11:28:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Martin Vermeer
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-08-17 11:28:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetBranch.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "BufferView.h"
|
2003-12-14 16:33:56 +00:00
|
|
|
#include "BranchList.h"
|
2009-02-09 23:30:24 +00:00
|
|
|
#include "ColorSet.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "Counters.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2009-11-21 23:24:21 +00:00
|
|
|
#include "output_xhtml.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2008-05-30 13:59:29 +00:00
|
|
|
#include "TocBackend.h"
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2009-04-11 07:11:37 +00:00
|
|
|
#include "support/lstrings.h"
|
2008-03-27 22:26:24 +00:00
|
|
|
|
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-09-09 18:52:00 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
namespace lyx {
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetBranch::InsetBranch(Buffer * buf, InsetBranchParams const & params)
|
2009-04-04 19:34:14 +00:00
|
|
|
: InsetCollapsable(buf, InsetText::DefaultLayout), params_(params)
|
|
|
|
{}
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetBranch::write(ostream & os) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2010-03-11 12:56:25 +00:00
|
|
|
os << "Branch ";
|
2003-08-17 11:28:23 +00:00
|
|
|
params_.write(os);
|
2010-03-10 20:56:45 +00:00
|
|
|
os << '\n';
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::write(os);
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetBranch::read(Lexer & lex)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
params_.read(lex);
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::read(lex);
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-17 17:25:22 +00:00
|
|
|
docstring InsetBranch::toolTip(BufferView const & bv, int, int) const
|
2008-02-12 09:11:06 +00:00
|
|
|
{
|
2009-04-11 07:11:37 +00:00
|
|
|
docstring const status = isBranchSelected() ?
|
|
|
|
_("active") : _("non-active");
|
2009-05-07 18:04:05 +00:00
|
|
|
docstring const heading =
|
|
|
|
support::bformat(_("Branch (%1$s): %2$s"), status, params_.branch);
|
2010-11-17 17:25:22 +00:00
|
|
|
if (isOpen(bv))
|
2009-05-07 18:04:05 +00:00
|
|
|
return heading;
|
2010-11-17 17:25:22 +00:00
|
|
|
return toolTipText(heading + from_ascii("\n"));
|
2008-02-12 09:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-25 22:35:41 +00:00
|
|
|
docstring const InsetBranch::buttonLabel(BufferView const & bv) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring s = _("Branch: ") + params_.branch;
|
2009-03-27 11:44:40 +00:00
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
|
|
|
BranchList const & branchlist = realbuffer.params().branchlist();
|
2009-07-09 11:45:19 +00:00
|
|
|
if (!branchlist.find(params_.branch)
|
|
|
|
&& buffer().params().branchlist().find(params_.branch))
|
2009-03-27 11:44:40 +00:00
|
|
|
s = _("Branch (child only): ") + params_.branch;
|
2009-07-09 11:45:19 +00:00
|
|
|
else if (!branchlist.find(params_.branch))
|
|
|
|
s = _("Branch (undefined): ") + params_.branch;
|
2005-11-02 13:54:33 +00:00
|
|
|
if (!params_.branch.empty()) {
|
2006-11-03 15:16:45 +00:00
|
|
|
// FIXME UNICODE
|
2007-10-25 12:41:02 +00:00
|
|
|
ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
|
2008-05-31 22:39:52 +00:00
|
|
|
if (c == Color_none)
|
2006-10-08 09:36:16 +00:00
|
|
|
s = _("Undef: ") + s;
|
2007-06-12 13:45:49 +00:00
|
|
|
}
|
2009-03-31 10:31:28 +00:00
|
|
|
s = char_type(isBranchSelected() ? 0x2714 : 0x2716) + s;
|
2008-10-25 13:41:02 +00:00
|
|
|
if (decoration() == InsetLayout::CLASSIC)
|
2009-02-25 22:35:41 +00:00
|
|
|
return isOpen(bv) ? s : getNewLabel(s);
|
2007-09-02 08:38:09 +00:00
|
|
|
else
|
2009-02-25 22:35:41 +00:00
|
|
|
return params_.branch + ": " + getNewLabel(s);
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-17 14:09:37 +00:00
|
|
|
ColorCode InsetBranch::backgroundColor(PainterInfo const & pi) const
|
2007-06-12 13:45:49 +00:00
|
|
|
{
|
2008-05-31 22:39:52 +00:00
|
|
|
if (params_.branch.empty())
|
2009-12-17 14:09:37 +00:00
|
|
|
return Inset::backgroundColor(pi);
|
2008-05-31 22:39:52 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
|
|
|
|
if (c == Color_none)
|
|
|
|
c = Color_error;
|
|
|
|
return c;
|
2007-06-12 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-11-03 19:52:47 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
2003-08-17 11:28:23 +00:00
|
|
|
InsetBranchParams params;
|
2008-03-27 22:26:24 +00:00
|
|
|
InsetBranch::string2params(to_utf8(cmd.argument()), params);
|
2010-12-08 09:24:04 +00:00
|
|
|
|
|
|
|
cur.recordUndoInset(ATOMIC_UNDO, this);
|
2003-08-17 11:28:23 +00:00
|
|
|
params_.branch = params.branch;
|
2010-07-09 14:37:00 +00:00
|
|
|
// what we really want here is a TOC update, but that means
|
|
|
|
// a full buffer update
|
|
|
|
cur.forceBufferUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-11-03 19:52:47 +00:00
|
|
|
}
|
2009-03-31 09:38:07 +00:00
|
|
|
case LFUN_BRANCH_ACTIVATE:
|
|
|
|
case LFUN_BRANCH_DEACTIVATE: {
|
|
|
|
// FIXME: I do not like this cast, but have no other idea...
|
2009-05-06 13:41:35 +00:00
|
|
|
Buffer const * buf = buffer().masterBuffer();
|
|
|
|
BranchList const & branchlist = buf->params().branchlist();
|
|
|
|
Branch * our_branch = const_cast<Branch *>(branchlist.find(params_.branch));
|
2009-07-11 00:11:59 +00:00
|
|
|
if (!our_branch) {
|
|
|
|
// child only?
|
|
|
|
our_branch = buffer().params().branchlist().find(params_.branch);
|
|
|
|
if (!our_branch)
|
|
|
|
break;
|
|
|
|
}
|
2010-11-29 16:50:22 +00:00
|
|
|
bool const activate = (cmd.action() == LFUN_BRANCH_ACTIVATE);
|
|
|
|
if (our_branch->isSelected() != activate) {
|
|
|
|
our_branch->setSelected(activate);
|
|
|
|
cur.forceBufferUpdate();
|
|
|
|
}
|
2009-03-31 09:38:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-30 12:36:33 +00:00
|
|
|
case LFUN_INSET_TOGGLE:
|
2009-03-30 12:45:33 +00:00
|
|
|
if (cmd.argument() == "assign")
|
|
|
|
setStatus(cur, isBranchSelected() ? Open : Collapsed);
|
2005-10-24 09:42:20 +00:00
|
|
|
else
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-03-30 12:36:33 +00:00
|
|
|
break;
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetBranch::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2005-04-22 08:57:22 +00:00
|
|
|
break;
|
|
|
|
|
2009-03-31 09:38:07 +00:00
|
|
|
case LFUN_BRANCH_ACTIVATE:
|
|
|
|
flag.setEnabled(!isBranchSelected());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BRANCH_DEACTIVATE:
|
|
|
|
flag.setEnabled(isBranchSelected());
|
|
|
|
break;
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_TOGGLE:
|
2009-03-31 09:38:07 +00:00
|
|
|
if (cmd.argument() == "assign")
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2009-03-31 09:38:07 +00:00
|
|
|
else
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
2010-11-30 00:21:08 +00:00
|
|
|
break;
|
2005-04-22 08:57:22 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
bool InsetBranch::isBranchSelected() const
|
2003-12-14 16:33:56 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
Buffer const & realbuffer = *buffer().masterBuffer();
|
2005-10-25 15:21:49 +00:00
|
|
|
BranchList const & branchlist = realbuffer.params().branchlist();
|
2008-05-27 18:57:16 +00:00
|
|
|
Branch const * ourBranch = branchlist.find(params_.branch);
|
2009-07-11 00:10:18 +00:00
|
|
|
|
|
|
|
if (!ourBranch) {
|
|
|
|
// this branch is defined in child only
|
|
|
|
ourBranch = buffer().params().branchlist().find(params_.branch);
|
|
|
|
if (!ourBranch)
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-21 19:27:20 +00:00
|
|
|
return ourBranch->isSelected();
|
2003-12-14 16:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
int InsetBranch::latex(otexstream & os, OutputParams const & runparams) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
return isBranchSelected() ? InsetText::latex(os, runparams) : 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetBranch::plaintext(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
if (!isBranchSelected())
|
2007-02-16 09:28:25 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
os << '[' << buffer().B_("branch") << ' ' << params_.branch << ":\n";
|
|
|
|
InsetText::plaintext(os, runparams);
|
2007-02-16 09:28:25 +00:00
|
|
|
os << "\n]";
|
|
|
|
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetBranch::docbook(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
return isBranchSelected() ? InsetText::docbook(os, runparams) : 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 23:24:21 +00:00
|
|
|
docstring InsetBranch::xhtml(XHTMLStream & xs, OutputParams const & rp) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2009-06-12 16:11:33 +00:00
|
|
|
if (isBranchSelected())
|
2009-11-21 23:24:21 +00:00
|
|
|
return InsetText::xhtml(xs, rp);
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
2009-06-05 17:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-15 01:34:04 +00:00
|
|
|
void InsetBranch::toString(odocstream & os) const
|
2007-01-19 16:23:47 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
if (isBranchSelected())
|
2010-12-15 01:34:04 +00:00
|
|
|
InsetCollapsable::toString(os);
|
2007-01-19 16:23:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 21:55:09 +00:00
|
|
|
void InsetBranch::forToc(docstring & os, size_t maxlen) const
|
|
|
|
{
|
|
|
|
if (isBranchSelected())
|
|
|
|
InsetCollapsable::forToc(os, maxlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
void InsetBranch::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2008-12-12 15:38:52 +00:00
|
|
|
if (isBranchSelected())
|
|
|
|
InsetCollapsable::validate(features);
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-29 21:27:25 +00:00
|
|
|
docstring InsetBranch::contextMenuName() const
|
2009-03-31 09:38:07 +00:00
|
|
|
{
|
|
|
|
return from_ascii("context-branch");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
bool InsetBranch::isMacroScope() const
|
2007-12-21 20:42:46 +00:00
|
|
|
{
|
|
|
|
// Its own scope if not selected by buffer
|
2008-02-27 20:43:16 +00:00
|
|
|
return !isBranchSelected();
|
2007-12-21 20:42:46 +00:00
|
|
|
}
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
string InsetBranch::params2string(InsetBranchParams const & params)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
return data.str();
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
void InsetBranch::string2params(string const & in, InsetBranchParams & params)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
params = InsetBranchParams();
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-08-17 11:28:23 +00:00
|
|
|
lex.setStream(data);
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetBranch::string2params");
|
2003-08-17 11:28:23 +00:00
|
|
|
params.read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-12 22:23:27 +00:00
|
|
|
void InsetBranch::addToToc(DocIterator const & cpit) const
|
2008-05-30 13:59:29 +00:00
|
|
|
{
|
|
|
|
DocIterator pit = cpit;
|
2011-01-12 22:23:27 +00:00
|
|
|
pit.push_back(CursorSlice(const_cast<InsetBranch &>(*this)));
|
2008-05-30 13:59:29 +00:00
|
|
|
|
|
|
|
Toc & toc = buffer().tocBackend().toc("branch");
|
2010-12-20 21:55:09 +00:00
|
|
|
docstring str = params_.branch + ": ";
|
|
|
|
text().forToc(str, TOC_ENTRY_LENGTH);
|
2010-12-22 01:29:17 +00:00
|
|
|
toc.push_back(TocItem(pit, 0, str, toolTipText(docstring(), 3, 60)));
|
2008-06-03 11:33:13 +00:00
|
|
|
// Proceed with the rest of the inset.
|
|
|
|
InsetCollapsable::addToToc(cpit);
|
2008-05-30 13:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
void InsetBranchParams::write(ostream & os) const
|
|
|
|
{
|
2010-03-11 12:56:25 +00:00
|
|
|
os << to_utf8(branch);
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void InsetBranchParams::read(Lexer & lex)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2010-03-11 21:11:03 +00:00
|
|
|
lex >> branch;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|