2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetLabel.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* 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>
|
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetLabel.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2008-02-27 15:23:22 +00:00
|
|
|
|
#include "ParIterator.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
#include "sgml.h"
|
2008-02-27 15:23:22 +00:00
|
|
|
|
#include "Text.h"
|
|
|
|
|
#include "TocBackend.h"
|
2003-02-27 16:24:14 +00:00
|
|
|
|
|
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
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
|
ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
|
static ParamInfo param_info_;
|
|
|
|
|
if (param_info_.empty()) {
|
Per Abdel's suggestion that we focus on bug-fixing at this point, this will be the last patch in this series for a bit. But I wanted to get this done before I forget what it is I was doing, so here it is.
The idea behind this patch is to make real key-value support for InsetCommand parameters possible. This should be particularly useful for the listings version of InsetInclude, though we would need some kind of UI for it before it would really be helpful. (See below for some thoughts.) This doesn't substantially change anything else, though some things do get re-arranged a bit.
Basically, the idea is this. First, we introduce a whole range of parameter types: Normal LaTeX optional and required parameters; ones for LyX's internal use (like embed); and finally, in connection with keyval, ones that represent keys and ones that represent optional and required arguments where the keyval stuff will appear. (I'm assuming here that there will always be exactly one of those, and that it will accept only keyval-type material.) The parameters themselves are stored in a map, so it's really only the output routines that need to care about the different types of parameters.
Regarding the frontend, it seems to me that something like the following would work:
(i) scan the parameter list for LATEX_KEY type parameters
(ii) the dialog will have a series of lines, each of which has a combo box listing the acceptable keys and a QLineEdit for entering its value, as well as a "delete" button of some sort for removing this key and its value
(iii) there should be an "add line" button to add a new line, activated only when all other lines are filled with values
Probably not even too hard.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23235 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-25 22:13:45 +00:00
|
|
|
|
param_info_.add("name", ParamInfo::LATEX_REQUIRED);
|
2008-02-23 22:01:02 +00:00
|
|
|
|
}
|
|
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetLabel::getLabelList(vector<docstring> & list) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
|
list.push_back(getParam("name"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
docstring InsetLabel::screenLabel() const
|
2003-10-12 18:54:12 +00:00
|
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
|
return getParam("name");
|
2003-10-12 18:54:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetLabel::addToToc(ParConstIterator const & cpit) const
|
2008-02-27 15:23:22 +00:00
|
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
|
Toc & toc = buffer().tocBackend().toc("label");
|
|
|
|
|
toc.push_back(TocItem(cpit, 0, screenLabel()));
|
2008-02-27 15:23:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetLabel::doDispatch(Cursor & cur, FuncRequest & 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: {
|
2007-10-19 17:22:55 +00:00
|
|
|
|
InsetCommandParams p(LABEL_CODE);
|
2006-11-02 10:16:21 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (p.getCmdName().empty()) {
|
2005-05-17 11:11:45 +00:00
|
|
|
|
cur.noUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-10-20 16:12:49 +00:00
|
|
|
|
if (p["name"] != params()["name"])
|
2007-08-21 13:03:55 +00:00
|
|
|
|
cur.bv().buffer().changeRefsIfUnique(params()["name"],
|
2007-10-13 09:04:52 +00:00
|
|
|
|
p["name"], REF_CODE);
|
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-11-24 21:58:42 +00:00
|
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
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
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetLabel::latex(odocstream & os, OutputParams const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
|
os << escape(getCommand());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-11 11:52:05 +00:00
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetLabel::plaintext(odocstream & os, OutputParams const &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
|
{
|
2007-02-24 14:35:38 +00:00
|
|
|
|
docstring const str = getParam("name");
|
2007-02-15 23:44:33 +00:00
|
|
|
|
os << '<' << str << '>';
|
|
|
|
|
return 2 + str.size();
|
2000-04-24 20:58:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetLabel::docbook(odocstream & os, OutputParams const & runparams) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
2006-10-19 21:00:33 +00:00
|
|
|
|
os << "<!-- anchor id=\""
|
2008-02-27 20:43:16 +00:00
|
|
|
|
<< sgml::cleanID(buffer(), runparams, getParam("name"))
|
2007-05-28 22:27:45 +00:00
|
|
|
|
<< "\" -->";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|