mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-13 06:20:28 +00:00
* src/insets/InsetLabel.[cpp,h}:
* src/insets/InsetCommand{.cpp,h}: - rename update to updateCommand * src/CutAndPaste.cpp: * src/insets/InsetBibitem{cpp,h}: - add duplicate check. There's a remaining glitch: the warning message after setting a bibitem key in the dialog to a duplicate pops up twice. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23420 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
cbb7b9a0a4
commit
5fce07a02b
@ -225,7 +225,7 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
|
|||||||
// check for duplicates
|
// check for duplicates
|
||||||
InsetCommand & lab = static_cast<InsetCommand &>(*it);
|
InsetCommand & lab = static_cast<InsetCommand &>(*it);
|
||||||
docstring const oldname = lab.getParam("name");
|
docstring const oldname = lab.getParam("name");
|
||||||
lab.update(oldname, false);
|
lab.updateCommand(oldname, false);
|
||||||
docstring const newname = lab.getParam("name");
|
docstring const newname = lab.getParam("name");
|
||||||
if (oldname != newname) {
|
if (oldname != newname) {
|
||||||
// adapt the references
|
// adapt the references
|
||||||
@ -240,6 +240,25 @@ pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case BIBITEM_CODE: {
|
||||||
|
// check for duplicates
|
||||||
|
InsetCommand & bib = static_cast<InsetCommand &>(*it);
|
||||||
|
docstring const oldkey = bib.getParam("key");
|
||||||
|
bib.updateCommand(oldkey, false);
|
||||||
|
docstring const newkey = bib.getParam("key");
|
||||||
|
if (oldkey != newkey) {
|
||||||
|
// adapt the references
|
||||||
|
for (InsetIterator itt = inset_iterator_begin(in); itt != i_end; ++itt) {
|
||||||
|
if (itt->lyxCode() == CITE_CODE) {
|
||||||
|
InsetCommand & ref = dynamic_cast<InsetCommand &>(*itt);
|
||||||
|
if (ref.getParam("key") == oldkey)
|
||||||
|
ref.setParam("key", newkey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break; // nothing
|
break; // nothing
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
|
|
||||||
#include "InsetBibitem.h"
|
#include "InsetBibitem.h"
|
||||||
|
|
||||||
|
#include "BiblioInfo.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#include "buffer_funcs.h"
|
||||||
#include "BufferParams.h"
|
#include "BufferParams.h"
|
||||||
#include "BufferView.h"
|
#include "BufferView.h"
|
||||||
#include "Counters.h"
|
#include "Counters.h"
|
||||||
@ -25,8 +27,11 @@
|
|||||||
#include "ParagraphList.h"
|
#include "ParagraphList.h"
|
||||||
#include "TextClass.h"
|
#include "TextClass.h"
|
||||||
|
|
||||||
|
#include "frontends/alert.h"
|
||||||
|
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
#include "support/docstream.h"
|
#include "support/docstream.h"
|
||||||
|
#include "support/gettext.h"
|
||||||
#include "support/convert.h"
|
#include "support/convert.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@ -49,6 +54,40 @@ InsetBibitem::InsetBibitem(InsetCommandParams const & p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void InsetBibitem::initView()
|
||||||
|
{
|
||||||
|
updateCommand(getParam("key"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void InsetBibitem::updateCommand(docstring const & new_key, bool)
|
||||||
|
{
|
||||||
|
docstring const old_key = getParam("key");
|
||||||
|
docstring key = new_key;
|
||||||
|
|
||||||
|
BiblioInfo keys;
|
||||||
|
keys.fillWithBibKeys(&buffer());
|
||||||
|
vector<docstring> bibkeys = keys.getKeys();
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
if (find(bibkeys.begin(), bibkeys.end(), key) != bibkeys.end()) {
|
||||||
|
// generate unique label
|
||||||
|
key = new_key + '-' + convert<docstring>(i);
|
||||||
|
while (find(bibkeys.begin(), bibkeys.end(), key) != bibkeys.end()) {
|
||||||
|
++i;
|
||||||
|
key = new_key + '-' + convert<docstring>(i);
|
||||||
|
}
|
||||||
|
frontend::Alert::warning(_("Keys must be unique!"),
|
||||||
|
bformat(_("The key %1$s already exists,\n"
|
||||||
|
"it will be changed to %2$s."), new_key, key));
|
||||||
|
}
|
||||||
|
setParam("key", key);
|
||||||
|
|
||||||
|
lyx::updateLabels(buffer());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ParamInfo const & InsetBibitem::findInfo(string const & /* cmdName */)
|
ParamInfo const & InsetBibitem::findInfo(string const & /* cmdName */)
|
||||||
{
|
{
|
||||||
static ParamInfo param_info_;
|
static ParamInfo param_info_;
|
||||||
@ -71,10 +110,12 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
cur.noUpdate();
|
cur.noUpdate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (p["key"] != params()["key"])
|
docstring old_key = params()["key"];
|
||||||
cur.bv().buffer().changeRefsIfUnique(params()["key"],
|
setParam("label", p["label"]);
|
||||||
p["key"], CITE_CODE);
|
updateCommand(p["key"]);
|
||||||
setParams(p);
|
if (params()["key"] != old_key)
|
||||||
|
cur.bv().buffer().changeRefsIfUnique(old_key,
|
||||||
|
params()["key"], CITE_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -28,6 +28,11 @@ class InsetBibitem : public InsetCommand {
|
|||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
InsetBibitem(InsetCommandParams const &);
|
InsetBibitem(InsetCommandParams const &);
|
||||||
|
/// verify label and update references.
|
||||||
|
/**
|
||||||
|
* Overloaded from Inset::initView.
|
||||||
|
**/
|
||||||
|
void initView();
|
||||||
///
|
///
|
||||||
void read(Lexer & lex);
|
void read(Lexer & lex);
|
||||||
///
|
///
|
||||||
@ -51,6 +56,8 @@ public:
|
|||||||
///
|
///
|
||||||
static bool isCompatibleCommand(std::string const & s)
|
static bool isCompatibleCommand(std::string const & s)
|
||||||
{ return s == "bibitem"; }
|
{ return s == "bibitem"; }
|
||||||
|
///
|
||||||
|
void updateCommand(docstring const & new_key, bool dummy = false);
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
|
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||||
|
@ -82,8 +82,8 @@ public:
|
|||||||
/// Whether this is a command this inset can represent.
|
/// Whether this is a command this inset can represent.
|
||||||
/// Not implemented here. Must be implemented in derived class.
|
/// Not implemented here. Must be implemented in derived class.
|
||||||
static bool isCompatibleCommand(std::string const & cmd);
|
static bool isCompatibleCommand(std::string const & cmd);
|
||||||
/// update label and references. Currently used by InsetLabel.
|
/// update label and references.
|
||||||
virtual void update(docstring const &, bool) {};
|
virtual void updateCommand(docstring const &, bool) {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
|
@ -45,11 +45,11 @@ InsetLabel::InsetLabel(InsetCommandParams const & p)
|
|||||||
|
|
||||||
void InsetLabel::initView()
|
void InsetLabel::initView()
|
||||||
{
|
{
|
||||||
update(getParam("name"));
|
updateCommand(getParam("name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetLabel::update(docstring const & new_label, bool updaterefs)
|
void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
|
||||||
{
|
{
|
||||||
docstring const old_label = getParam("name");
|
docstring const old_label = getParam("name");
|
||||||
docstring label = new_label;
|
docstring label = new_label;
|
||||||
@ -148,7 +148,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
cur.noUpdate();
|
cur.noUpdate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
update(p["name"]);
|
updateCommand(p["name"]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
///
|
///
|
||||||
void addToToc(ParConstIterator const &) const;
|
void addToToc(ParConstIterator const &) const;
|
||||||
///
|
///
|
||||||
void update(docstring const & new_label, bool updaterefs = true);
|
void updateCommand(docstring const & new_label, bool updaterefs = true);
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||||
|
Loading…
Reference in New Issue
Block a user