2003-08-17 11:28:23 +00:00
|
|
|
/**
|
|
|
|
* \file insetbranch.C
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include "insetbranch.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "bufferparams.h"
|
2003-12-14 16:33:56 +00:00
|
|
|
#include "BranchList.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
#include "cursor.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
#include "dispatchresult.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
#include "funcrequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
#include "FuncStatus.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "gettext.h"
|
2003-09-16 10:30:59 +00:00
|
|
|
#include "LColor.h"
|
2003-08-17 11:28:23 +00:00
|
|
|
#include "lyxlex.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
#include "paragraph.h"
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2003-08-17 11:28:23 +00:00
|
|
|
using std::auto_ptr;
|
2003-09-05 18:02:24 +00:00
|
|
|
using std::istringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
using std::ostringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
|
|
void InsetBranch::init()
|
|
|
|
{
|
|
|
|
setInsetName("Branch");
|
2003-09-22 07:46:27 +00:00
|
|
|
setButtonLabel();
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
InsetBranch::InsetBranch(BufferParams const & bp,
|
|
|
|
InsetBranchParams const & params)
|
|
|
|
: InsetCollapsable(bp), params_(params)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetBranch::InsetBranch(InsetBranch const & in)
|
|
|
|
: InsetCollapsable(in), params_(in.params_)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetBranch::~InsetBranch()
|
|
|
|
{
|
2003-12-10 14:49:51 +00:00
|
|
|
InsetBranchMailer(*this).hideDialog();
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
auto_ptr<InsetBase> InsetBranch::doClone() const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
return auto_ptr<InsetBase>(new InsetBranch(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBranch::editMessage() const
|
|
|
|
{
|
|
|
|
return _("Opened Branch Inset");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
void InsetBranch::write(Buffer const & buf, ostream & os) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
params_.write(os);
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
void InsetBranch::read(Buffer const & buf, LyXLex & lex)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
params_.read(lex);
|
2003-08-17 11:28:23 +00:00
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
setButtonLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranch::setButtonLabel()
|
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.decSize();
|
|
|
|
font.decSize();
|
|
|
|
|
2004-04-07 05:28:51 +00:00
|
|
|
string s = "Branch: " + params_.branch;
|
|
|
|
setLabel(isOpen() ? s : getNewLabel(s) );
|
2003-08-17 11:28:23 +00:00
|
|
|
font.setColor(LColor::foreground);
|
2003-09-22 07:46:27 +00:00
|
|
|
if (!params_.branch.empty())
|
2003-08-17 11:28:23 +00:00
|
|
|
setBackgroundColor(lcolor.getFromLyXName(params_.branch));
|
2003-09-22 07:46:27 +00:00
|
|
|
else
|
2003-08-17 11:28:23 +00:00
|
|
|
setBackgroundColor(LColor::background);
|
|
|
|
setLabelFont(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetBranch::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
2003-12-10 14:49:51 +00:00
|
|
|
InsetBranchMailer(const_cast<InsetBranch &>(*this)).showDialog(bv);
|
2003-08-17 11:28:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2003-08-17 11:28:23 +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;
|
|
|
|
InsetBranchMailer::string2params(cmd.argument, params);
|
|
|
|
params_.branch = params.branch;
|
|
|
|
setButtonLabel();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-11-03 19:52:47 +00:00
|
|
|
}
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2003-08-28 07:41:31 +00:00
|
|
|
if (cmd.button() != mouse_button::button3)
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
else
|
2004-03-01 17:12:09 +00:00
|
|
|
cur.undispatched();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-11-03 19:52:47 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2004-01-20 14:25:24 +00:00
|
|
|
InsetBranchMailer(*this).updateDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-11-03 19:52:47 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
case LFUN_MOUSE_RELEASE:
|
2004-02-16 11:58:51 +00:00
|
|
|
if (cmd.button() == mouse_button::button3 && hitButton(cmd))
|
2004-01-20 14:25:24 +00:00
|
|
|
InsetBranchMailer(*this).showDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
else
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2004-01-05 17:33:57 +00:00
|
|
|
|
2004-03-30 12:36:33 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_TOGGLE:
|
|
|
|
// We assume that this lfun is indeed going to be dispatched.
|
|
|
|
cur.dispatched();
|
|
|
|
|
|
|
|
if (cmd.argument == "open")
|
|
|
|
setStatus(Open);
|
2004-03-31 08:43:47 +00:00
|
|
|
else if (cmd.argument == "close") {
|
2004-03-30 12:36:33 +00:00
|
|
|
setStatus(Collapsed);
|
2004-03-31 09:24:43 +00:00
|
|
|
leaveInset(cur, *this);
|
2004-10-05 10:11:42 +00:00
|
|
|
} else if (cmd.argument == "toggle") {
|
2004-04-07 05:28:51 +00:00
|
|
|
if (isOpen()) {
|
|
|
|
setStatus(Collapsed);
|
|
|
|
leaveInset(cur, *this);
|
|
|
|
} else
|
|
|
|
setStatus(Open);
|
2004-03-30 12:36:33 +00:00
|
|
|
|
2004-04-07 05:28:51 +00:00
|
|
|
// The branch inset uses "assign".
|
|
|
|
} else if (cmd.argument == "assign"
|
2004-03-31 08:43:47 +00:00
|
|
|
|| cmd.argument.empty()) {
|
2004-03-30 12:36:33 +00:00
|
|
|
BranchList const & branchlist =
|
2004-04-08 15:03:33 +00:00
|
|
|
cur.buffer().params().branchlist();
|
2004-03-30 12:36:33 +00:00
|
|
|
if (isBranchSelected(branchlist)) {
|
|
|
|
if (status() != Open)
|
|
|
|
setStatus(Open);
|
|
|
|
else
|
|
|
|
cur.undispatched();
|
|
|
|
} else {
|
2004-03-31 08:43:47 +00:00
|
|
|
if (status() != Collapsed) {
|
2004-03-30 12:36:33 +00:00
|
|
|
setStatus(Collapsed);
|
2004-03-31 09:24:43 +00:00
|
|
|
leaveInset(cur, *this);
|
2004-03-31 08:43:47 +00:00
|
|
|
} else
|
2004-03-30 12:36:33 +00:00
|
|
|
cur.undispatched();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
flag.enabled(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_INSET_TOGGLE:
|
|
|
|
if (cmd.argument == "open" || cmd.argument == "close" ||
|
|
|
|
cmd.argument == "toggle")
|
|
|
|
flag.enabled(true);
|
|
|
|
else if (cmd.argument == "assign"
|
|
|
|
|| cmd.argument.empty()) {
|
|
|
|
BranchList const & branchlist =
|
|
|
|
cur.buffer().params().branchlist();
|
|
|
|
if (isBranchSelected(branchlist)) {
|
|
|
|
if (status() != Open)
|
|
|
|
flag.enabled(true);
|
|
|
|
else
|
|
|
|
flag.enabled(false);
|
|
|
|
} else {
|
|
|
|
if (status() != Collapsed)
|
|
|
|
flag.enabled(true);
|
|
|
|
else
|
|
|
|
flag.enabled(false);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
flag.enabled(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
bool InsetBranch::isBranchSelected(BranchList const & branchlist) const
|
|
|
|
{
|
|
|
|
BranchList::const_iterator const end = branchlist.end();
|
2004-01-05 17:33:57 +00:00
|
|
|
BranchList::const_iterator it =
|
|
|
|
std::find_if(branchlist.begin(), end,
|
|
|
|
BranchNamesEqual(params_.branch));
|
2003-12-14 16:33:56 +00:00
|
|
|
if (it == end)
|
|
|
|
return false;
|
|
|
|
return it->getSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
int InsetBranch::latex(Buffer const & buf, ostream & os,
|
2003-12-14 16:33:56 +00:00
|
|
|
OutputParams const & runparams) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
return isBranchSelected(buf.params().branchlist()) ?
|
2004-03-25 09:16:36 +00:00
|
|
|
InsetText::latex(buf, os, runparams) : 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
OutputParams const & runparams) const
|
2003-08-28 07:41:31 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
return isBranchSelected(buf.params().branchlist()) ?
|
2004-03-25 09:16:36 +00:00
|
|
|
InsetText::linuxdoc(buf, os, runparams) : 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
int InsetBranch::docbook(Buffer const & buf, std::ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
OutputParams const & runparams) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
return isBranchSelected(buf.params().branchlist()) ?
|
2004-03-25 09:16:36 +00:00
|
|
|
InsetText::docbook(buf, os, runparams) : 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
int InsetBranch::plaintext(Buffer const & buf, std::ostream & os,
|
2003-12-14 16:33:56 +00:00
|
|
|
OutputParams const & runparams) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
return isBranchSelected(buf.params().branchlist()) ?
|
2004-03-25 09:16:36 +00:00
|
|
|
InsetText::plaintext(buf, os, runparams): 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranch::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
InsetText::validate(features);
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
string const InsetBranchMailer::name_("branch");
|
2003-12-10 14:49:51 +00:00
|
|
|
|
|
|
|
InsetBranchMailer::InsetBranchMailer(InsetBranch & inset)
|
|
|
|
: inset_(inset)
|
|
|
|
{}
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
string const InsetBranchMailer::inset2string(Buffer const &) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
return params2string(inset_.params());
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-10 14:49:51 +00:00
|
|
|
string const InsetBranchMailer::params2string(InsetBranchParams const & params)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2003-12-10 14:49:51 +00:00
|
|
|
data << name_ << ' ';
|
2003-08-17 11:28:23 +00:00
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
return data.str();
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranchMailer::string2params(string const & in,
|
2003-12-10 14:49:51 +00:00
|
|
|
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);
|
2003-08-17 11:28:23 +00:00
|
|
|
LyXLex lex(0,0);
|
|
|
|
lex.setStream(data);
|
2003-12-10 14:49:51 +00:00
|
|
|
|
|
|
|
string name;
|
|
|
|
lex >> name;
|
|
|
|
if (name != name_)
|
2003-12-11 15:23:15 +00:00
|
|
|
return print_mailer_error("InsetBranchMailer", in, 1, name_);
|
2003-12-10 14:49:51 +00:00
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
// by LyXText::readInset
|
|
|
|
string id;
|
|
|
|
lex >> id;
|
|
|
|
if (!lex || id != "Branch")
|
|
|
|
return print_mailer_error("InsetBranchMailer", in, 2, "Branch");
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
params.read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranchParams::write(ostream & os) const
|
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
os << "Branch " << branch << '\n';
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranchParams::read(LyXLex & lex)
|
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
lex >> branch;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|