2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetlabel.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetlabel.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
#include "buffer.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-02-27 16:24:14 +00:00
|
|
|
|
#include "funcrequest.h"
|
2004-02-13 11:05:29 +00:00
|
|
|
|
#include "InsetList.h"
|
|
|
|
|
#include "iterators.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "paragraph.h"
|
2003-02-27 16:24:14 +00:00
|
|
|
|
|
2003-10-12 18:54:12 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2004-02-13 11:05:29 +00:00
|
|
|
|
#include "support/lyxalgo.h"
|
2003-10-10 21:08:55 +00:00
|
|
|
|
#include "support/std_ostream.h"
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::escape;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
using std::vector;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetLabel::InsetLabel(InsetCommandParams const & p)
|
2003-12-11 15:23:15 +00:00
|
|
|
|
: InsetCommand(p, "label")
|
2000-08-04 13:12:30 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-12 18:54:12 +00:00
|
|
|
|
std::auto_ptr<InsetBase> InsetLabel::clone() const
|
|
|
|
|
{
|
|
|
|
|
return std::auto_ptr<InsetBase>(new InsetLabel(params()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 20:18:39 +00:00
|
|
|
|
void InsetLabel::getLabelList(Buffer const &, std::vector<string> & list) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-06-16 11:49:38 +00:00
|
|
|
|
list.push_back(getContents());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-12 18:54:12 +00:00
|
|
|
|
string const InsetLabel::getScreenLabel(Buffer const &) const
|
|
|
|
|
{
|
|
|
|
|
return getContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
void changeRefsIfUnique(BufferView & bv, string const & from, string const & to)
|
|
|
|
|
{
|
|
|
|
|
// Check if the label 'from' appears more than once
|
|
|
|
|
vector<string> labels;
|
|
|
|
|
bv.buffer()->getLabelList(labels);
|
|
|
|
|
|
|
|
|
|
if (lyx::count(labels.begin(), labels.end(), from) > 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
InsetBase::Code code = InsetBase::REF_CODE;
|
|
|
|
|
|
|
|
|
|
ParIterator it = bv.buffer()->par_iterator_begin();
|
|
|
|
|
ParIterator end = bv.buffer()->par_iterator_end();
|
|
|
|
|
for ( ; it != end; ++it) {
|
|
|
|
|
bool changed_inset = false;
|
|
|
|
|
for (InsetList::iterator it2 = it->insetlist.begin();
|
|
|
|
|
it2 != it->insetlist.end(); ++it2) {
|
|
|
|
|
if (it2->inset->lyxCode() == code) {
|
|
|
|
|
InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
|
|
|
|
|
if (inset->getContents() == from) {
|
|
|
|
|
inset->setContents(to);
|
|
|
|
|
//inset->setButtonLabel();
|
|
|
|
|
changed_inset = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
void InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
2003-02-27 16:24:14 +00:00
|
|
|
|
{
|
2003-03-07 21:44:48 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetCommandParams p;
|
2003-12-11 15:23:15 +00:00
|
|
|
|
InsetCommandMailer::string2params("label", cmd.argument, p);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (p.getCmdName().empty()) {
|
|
|
|
|
cur.notdispatched();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (p.getContents() != params().getContents())
|
2004-02-13 11:05:29 +00:00
|
|
|
|
changeRefsIfUnique(cur.bv(), params().getContents(),
|
2003-10-12 18:54:12 +00:00
|
|
|
|
p.getContents());
|
2003-03-07 21:44:48 +00:00
|
|
|
|
setParams(p);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 21:44:48 +00:00
|
|
|
|
}
|
2003-03-09 09:38:47 +00:00
|
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
|
default:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
InsetCommand::priv_dispatch(cur, cmd);
|
|
|
|
|
break;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetLabel::latex(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << escape(getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-11 11:52:05 +00:00
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
int InsetLabel::plaintext(Buffer const &, ostream & os,
|
|
|
|
|
OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '<' << getContents() << '>';
|
2000-04-24 20:58:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetLabel::linuxdoc(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
os << "<label id=\"" << getContents() << "\" >";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetLabel::docbook(Buffer const &, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2002-04-03 17:44:05 +00:00
|
|
|
|
os << "<anchor id=\"" << getContents() << "\">";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|