2003-02-21 09:20:18 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetBibitem.cpp
|
2003-02-21 09:20:18 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-21 09:20:18 +00:00
|
|
|
*/
|
2003-10-21 16:15:14 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetBibitem.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2007-08-16 11:12:56 +00:00
|
|
|
#include "BufferParams.h"
|
2006-10-09 14:21:11 +00:00
|
|
|
#include "BufferView.h"
|
2007-08-16 11:12:56 +00:00
|
|
|
#include "Counters.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2007-08-14 16:50:51 +00:00
|
|
|
#include "InsetIterator.h"
|
2007-10-24 15:32:43 +00:00
|
|
|
#include "InsetList.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Paragraph.h"
|
2006-03-23 20:11:06 +00:00
|
|
|
#include "ParagraphList.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2005-01-06 16:39:35 +00:00
|
|
|
#include "support/convert.h"
|
2003-02-21 09:20:18 +00:00
|
|
|
|
2007-11-06 21:45:24 +00:00
|
|
|
#include <ostream>
|
2006-10-21 00:16:43 +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;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
int InsetBibitem::key_counter = 0;
|
2007-08-30 18:03:17 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
docstring const key_prefix = from_ascii("key-");
|
2003-02-21 09:20:18 +00:00
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
InsetBibitem::InsetBibitem(InsetCommandParams const & p)
|
2007-08-16 11:12:56 +00:00
|
|
|
: InsetCommand(p, "bibitem")
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
if (getParam("key").empty())
|
|
|
|
setParam("key", key_prefix + convert<docstring>(++key_counter));
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
CommandInfo const * InsetBibitem::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
|
|
|
static const char * const paramnames[] = {"label", "key", ""};
|
|
|
|
static const bool isoptional[] = {true, false};
|
|
|
|
static const CommandInfo info = {2, paramnames, isoptional};
|
|
|
|
return &info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetBibitem::clone() const
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
InsetBibitem * b = new InsetBibitem(params());
|
2007-08-16 11:12:56 +00:00
|
|
|
b->autolabel_ = autolabel_;
|
2007-08-30 18:03:17 +00:00
|
|
|
return b;
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-02-26 19:28:38 +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(BIBITEM_CODE);
|
2006-10-21 00:16:43 +00:00
|
|
|
InsetCommandMailer::string2params("bibitem", to_utf8(cmd.argument()), p);
|
2006-10-09 14:21:11 +00:00
|
|
|
if (p.getCmdName().empty()) {
|
2007-05-28 22:27:45 +00:00
|
|
|
cur.noUpdate();
|
2006-10-09 14:21:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-20 16:12:49 +00:00
|
|
|
if (p["key"] != params()["key"])
|
2007-08-21 13:03:55 +00:00
|
|
|
cur.bv().buffer().changeRefsIfUnique(params()["key"],
|
2007-10-13 09:04:52 +00:00
|
|
|
p["key"], CITE_CODE);
|
2006-10-09 14:21:11 +00:00
|
|
|
setParams(p);
|
2003-03-07 21:44:48 +00:00
|
|
|
}
|
2003-05-16 07:44:00 +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;
|
2003-02-26 19:28:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void InsetBibitem::read(Buffer const & buf, Lexer & lex)
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
InsetCommand::read(buf, lex);
|
2003-02-21 09:20:18 +00:00
|
|
|
|
2007-12-12 19:57:42 +00:00
|
|
|
if (prefixIs(getParam("key"), key_prefix)) {
|
2006-10-20 16:12:49 +00:00
|
|
|
int const key = convert<int>(getParam("key").substr(key_prefix.length()));
|
2007-12-12 19:28:07 +00:00
|
|
|
key_counter = max(key_counter, key);
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
docstring const InsetBibitem::getBibLabel() const
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
docstring const & label = getParam("label");
|
2007-08-16 11:12:56 +00:00
|
|
|
return label.empty() ? autolabel_ : label;
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
docstring const InsetBibitem::getScreenLabel(Buffer const &) const
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
2006-10-20 16:12:49 +00:00
|
|
|
return getParam("key") + " [" + getBibLabel() + ']';
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
int InsetBibitem::plaintext(Buffer const &, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const &) const
|
2004-08-14 18:41:27 +00:00
|
|
|
{
|
2007-02-17 16:36:45 +00:00
|
|
|
odocstringstream oss;
|
2007-08-16 11:12:56 +00:00
|
|
|
oss << '[' << getBibLabel() << "] ";
|
2007-02-17 16:36:45 +00:00
|
|
|
|
|
|
|
docstring const str = oss.str();
|
|
|
|
os << str;
|
|
|
|
|
|
|
|
return str.size();
|
2004-08-14 18:41:27 +00:00
|
|
|
}
|
2003-02-21 09:20:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ale070405
|
2006-10-11 19:40:50 +00:00
|
|
|
docstring const bibitemWidest(Buffer const & buffer)
|
2003-02-21 09:20:18 +00:00
|
|
|
{
|
|
|
|
int w = 0;
|
|
|
|
|
2003-05-27 22:41:04 +00:00
|
|
|
InsetBibitem const * bitem = 0;
|
2006-10-14 15:31:50 +00:00
|
|
|
|
2006-10-14 15:22:08 +00:00
|
|
|
// FIXME: this font is used unitialized for now but should be set to
|
2006-10-14 15:31:50 +00:00
|
|
|
// a proportional font. Here is what Georg Baum has to say about it:
|
2006-10-14 15:22:08 +00:00
|
|
|
/*
|
2007-05-28 22:27:45 +00:00
|
|
|
bibitemWidest() is supposed to find the bibitem with the widest label in the
|
|
|
|
output, because that is needed as an argument of the bibliography
|
|
|
|
environment to dtermine the correct indentation. To be 100% correct we
|
|
|
|
would need the metrics of the font that is used in the output, but usually
|
2006-10-14 15:22:08 +00:00
|
|
|
we don't have access to these.
|
2007-05-28 22:27:45 +00:00
|
|
|
In practice, any proportional font is probably good enough, since we don't
|
|
|
|
need to know the final with, we only need to know the which label is the
|
2006-10-14 15:22:08 +00:00
|
|
|
widest.
|
2007-05-28 22:27:45 +00:00
|
|
|
Unless there is an easy way to get the metrics of the output font I suggest
|
2006-10-14 15:22:08 +00:00
|
|
|
to use a hardcoded font like "Times" or so.
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
It is very important that the result of this function is the same both with
|
|
|
|
and without GUI. After thinking about this it is clear that no Font
|
|
|
|
metrics should be used here, since these come from the gui. If we can't
|
2007-10-28 18:51:54 +00:00
|
|
|
easily get the LaTeX font metrics we should make our own poor mans font
|
2007-05-28 22:27:45 +00:00
|
|
|
metrics replacement, e.g. by hardcoding the metrics of the standard TeX
|
2006-10-14 15:22:08 +00:00
|
|
|
font.
|
|
|
|
*/
|
2003-02-21 09:20:18 +00:00
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
ParagraphList::const_iterator it = buffer.paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator end = buffer.paragraphs().end();
|
2003-05-28 06:47:15 +00:00
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
for (; it != end; ++it) {
|
2007-10-24 15:32:43 +00:00
|
|
|
if (it->insetList().empty())
|
|
|
|
continue;
|
|
|
|
Inset * inset = it->insetList().begin()->inset;
|
|
|
|
if (inset->lyxCode() != BIBITEM_CODE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bitem = static_cast<InsetBibitem const *>(inset);
|
|
|
|
docstring const label = bitem->getBibLabel();
|
|
|
|
|
|
|
|
// FIXME: we can't be sure using the following that the GUI
|
|
|
|
// version and the command-line version will give the same
|
|
|
|
// result.
|
|
|
|
//
|
|
|
|
//int const wx = use_gui?
|
|
|
|
// theFontMetrics(font).width(label): label.size();
|
|
|
|
//
|
|
|
|
// So for now we just use the label size in order to be sure
|
|
|
|
// that GUI and no-GUI gives the same bibitem (even if that is
|
|
|
|
// potentially the wrong one.
|
|
|
|
int const wx = label.size();
|
|
|
|
|
|
|
|
if (wx > w)
|
|
|
|
w = wx;
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bitem && !bitem->getBibLabel().empty())
|
|
|
|
return bitem->getBibLabel();
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
return from_ascii("99");
|
2003-02-21 09:20:18 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2007-08-14 16:50:51 +00:00
|
|
|
void InsetBibitem::fillWithBibKeys(Buffer const & buf,
|
2007-08-20 16:30:02 +00:00
|
|
|
BiblioInfo & keys, InsetIterator const & it) const
|
2007-08-14 16:50:51 +00:00
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
docstring const key = getParam("key");
|
|
|
|
BibTeXInfo keyvalmap;
|
2007-08-16 01:59:20 +00:00
|
|
|
keyvalmap[from_ascii("label")] = getParam("label");
|
2007-08-14 16:50:51 +00:00
|
|
|
DocIterator doc_it(it);
|
|
|
|
doc_it.forwardPos();
|
2007-08-20 16:30:02 +00:00
|
|
|
keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString(buf, false);
|
2007-08-16 01:59:20 +00:00
|
|
|
keyvalmap.isBibTeX = false;
|
|
|
|
keys[key] = keyvalmap;
|
2007-08-14 16:50:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-16 11:12:56 +00:00
|
|
|
|
|
|
|
/// Update the counters of this inset and of its contents
|
2007-08-16 12:42:56 +00:00
|
|
|
void InsetBibitem::updateLabels(Buffer const &buf, ParIterator const &)
|
2007-08-16 11:12:56 +00:00
|
|
|
{
|
|
|
|
Counters & counters = buf.params().getTextClass().counters();
|
|
|
|
docstring const bibitem = from_ascii("bibitem");
|
|
|
|
if (counters.hasCounter(bibitem) && getParam("label").empty()) {
|
|
|
|
counters.step(bibitem);
|
|
|
|
autolabel_ = counters.theCounter(bibitem);
|
|
|
|
} else
|
|
|
|
autolabel_ = from_ascii("??");
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|