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-08-17 11:28:23 +00:00
|
|
|
#include "BufferView.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
#include "funcrequest.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
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
#include "support/std_sstream.h"
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
|
|
|
|
: InsetCollapsable(bp)
|
|
|
|
{
|
|
|
|
params_.branch = label;
|
|
|
|
// Hack: stash the list of all allowable branch labels from this
|
|
|
|
// buffer into inset's parm list as a "stowaway":
|
2003-09-09 17:00:19 +00:00
|
|
|
params_.branchlist = bp.branchlist();
|
2003-08-17 11:28:23 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetBranch::InsetBranch(InsetBranch const & in)
|
|
|
|
: InsetCollapsable(in), params_(in.params_)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetBranch::~InsetBranch()
|
|
|
|
{
|
|
|
|
InsetBranchMailer mailer("branch", *this);
|
|
|
|
mailer.hideDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto_ptr<InsetBase> InsetBranch::clone() const
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
params_.branch = lex.getString();
|
|
|
|
}
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
setButtonLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranch::setButtonLabel()
|
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.decSize();
|
|
|
|
font.decSize();
|
|
|
|
|
2003-09-03 09:29:07 +00:00
|
|
|
setLabel("Branch: " + params_.branch);
|
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
|
|
|
|
{
|
|
|
|
InsetBranchMailer("branch", const_cast<InsetBranch &>(*this)).showDialog(bv);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-17 18:01:15 +00:00
|
|
|
dispatch_result
|
|
|
|
InsetBranch::priv_dispatch(FuncRequest const & cmd,
|
|
|
|
idx_type & idx, pos_type & pos)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
BufferView * bv = cmd.view();
|
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
{
|
|
|
|
InsetBranchParams params;
|
|
|
|
InsetBranchMailer::string2params(cmd.argument, params);
|
|
|
|
params_.branch = params.branch;
|
|
|
|
setButtonLabel();
|
2003-08-27 13:51:18 +00:00
|
|
|
bv->updateInset(this);
|
2003-08-17 11:28:23 +00:00
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
case LFUN_INSET_EDIT:
|
2003-08-28 07:41:31 +00:00
|
|
|
if (cmd.button() != mouse_button::button3)
|
2003-10-17 18:01:15 +00:00
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2003-09-09 18:27:24 +00:00
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
return UNDISPATCHED;
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
InsetBranchMailer("branch", *this).updateDialog(bv);
|
|
|
|
return DISPATCHED;
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
|
|
|
|
InsetBranchMailer("branch", *this).showDialog(bv);
|
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
// fallthrough:
|
|
|
|
default:
|
2003-10-17 18:01:15 +00:00
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
int InsetBranch::latex(Buffer const & buf, ostream & os,
|
2003-08-17 11:28:23 +00:00
|
|
|
LatexRunParams const & runparams) const
|
|
|
|
{
|
2003-09-09 17:00:19 +00:00
|
|
|
string const branch_sel = buf.params().branchlist().allSelected();
|
2003-08-17 11:28:23 +00:00
|
|
|
if (branch_sel.find(params_.branch, 0) != string::npos)
|
|
|
|
return inset.latex(buf, os, runparams);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-01 15:15:02 +00:00
|
|
|
int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os) const
|
2003-08-28 07:41:31 +00:00
|
|
|
{
|
2003-10-01 15:15:02 +00:00
|
|
|
string const branch_sel = buf.params().branchlist().allSelected();
|
|
|
|
if (branch_sel.find(params_.branch, 0) != string::npos)
|
|
|
|
return inset.linuxdoc(buf, os);
|
2003-10-06 15:43:21 +00:00
|
|
|
return 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-09-09 17:00:19 +00:00
|
|
|
string const branch_sel = buf.params().branchlist().allSelected();
|
2003-08-28 07:41:31 +00:00
|
|
|
if (branch_sel.find(params_.branch, 0) != string::npos)
|
2003-08-17 11:28:23 +00:00
|
|
|
return inset.docbook(buf, os, mixcont);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-09-09 17:00:19 +00:00
|
|
|
string const branch_sel = buf.params().branchlist().allSelected();
|
2003-08-17 11:28:23 +00:00
|
|
|
if (branch_sel.find(params_.branch, 0) != string::npos) {
|
|
|
|
return inset.ascii(buf, os, ll);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranch::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
inset.validate(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBranchMailer::InsetBranchMailer(string const & name,
|
|
|
|
InsetBranch & inset)
|
|
|
|
: name_(name), inset_(inset)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBranchMailer::inset2string(Buffer const & buf) const
|
|
|
|
{
|
|
|
|
InsetBranchParams params = inset_.params();
|
2003-09-09 17:00:19 +00:00
|
|
|
params.branchlist = buf.params().branchlist();
|
2003-08-17 11:28:23 +00:00
|
|
|
inset_.setParams(params);
|
|
|
|
return params2string(name_, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetBranchMailer::params2string(string const & name,
|
2003-09-09 17:00:19 +00:00
|
|
|
InsetBranchParams const & params)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
|
|
|
data << name << ' ';
|
|
|
|
params.write(data);
|
|
|
|
// Add all_branches parameter to data:
|
|
|
|
data << params.branchlist.allBranches() << "\n";
|
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,
|
|
|
|
InsetBranchParams & params)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
params.read(lex);
|
|
|
|
// Process all_branches here:
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
params.branchlist.add(lex.getString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranchParams::write(ostream & os) const
|
|
|
|
{
|
|
|
|
os << "Branch" << " " << branch << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetBranchParams::read(LyXLex & lex)
|
|
|
|
{
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string token = lex.getString();
|
|
|
|
}
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string token = lex.getString();
|
|
|
|
}
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
branch = lex.getString();
|
|
|
|
}
|
|
|
|
}
|