void leaveView();
#endif
///
- bool ChangeRefs(string const & from, string const & to);
+ bool ChangeInsets(Inset::Code code, string const & from,
+ string const & to);
///
bool ChangeRefsIfUnique(string const & from, string const & to);
///
+ bool ChangeCitationsIfUnique(string const & from, string const & to);
+ ///
void pasteClipboard(bool asPara);
///
void stuffClipboard(string const &) const;
#include "LaTeX.h"
#include "BufferView_pimpl.h"
#include "insets/insetcommand.h" //ChangeRefs
+#include "support/lyxfunctional.h" //equal_1st_in_pair
extern BufferList bufferlist;
using std::vector;
using std::find;
using std::count;
+using std::count_if;
// Inserts a file into current document
bool BufferView::insertLyXFile(string const & filen)
}
-bool BufferView::ChangeRefs(string const & from, string const & to)
+bool BufferView::ChangeInsets(Inset::Code code, string const & from, string const & to)
{
bool flag = false;
LyXParagraph * par = buffer()->paragraph;
bool flag2 = false;
for (LyXParagraph::inset_iterator it = par->inset_iterator_begin();
it != par->inset_iterator_end(); ++it) {
- if ((*it)->LyxCode() == Inset::REF_CODE) {
+ if ((*it)->LyxCode() == code) {
InsetCommand * inset = static_cast<InsetCommand *>(*it);
if (inset->getContents() == from) {
inset->setContents(to);
if (count(labels.begin(), labels.end(), from) > 1)
return false;
- return ChangeRefs(from, to);
+ return ChangeInsets(Inset::REF_CODE, from, to);
}
+bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
+{
+
+ vector<pair<string,string> > keys = buffer()->getBibkeyList();
+ if (count_if(keys.begin(), keys.end(),
+ equal_1st_in_pair<string,string>(from))
+ > 1)
+ return false;
+
+ return ChangeInsets(Inset::CITE_CODE, from, to);
+}
+
UpdatableInset * BufferView::theLockingInset() const
{
// If NULL is not allowed we should put an Assert here. (Lgb)
2001-01-31 Dekel Tsur <dekelts@tau.ac.il>
+ * BufferView2.C (ChangeInsets): Renamed from ChangeRefs. Accept a
+ new argument (code).
+ (ChangeCitationsIfUnique): New method.
+
* paragraph.C (GetPositionOfInset): Handle bibkey.
2001-01-29 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
+2001-01-31 Dekel Tsur <dekelts@tau.ac.il>
+
+ * insetbib.C (callback): Update citations if the key has changed.
+
2001-01-31 Dekel Tsur <dekelts@tau.ac.il>
* insetbib.C (InsetBibKey): Better computation of default key.
{
switch (data) {
case 1:
+ {
// Do NOT change this to
// holder.view->buffer() as this code is used by both
// InsetBibKey and InsetBibtex! Ughhhhhhh!!!!
- if (!current_view->buffer()->isReadonly()) {
- setContents(fl_get_input(form->key));
- setOptions(fl_get_input(form->label));
- // shouldn't mark the buffer dirty unless
- // something was actually altered
- current_view->updateInset( this, true );
+ if (current_view->buffer()->isReadonly()) {
+ WarnReadonly(current_view->buffer()->fileName());
+ break;
+ }
+
+ string key = fl_get_input(form->key);
+ string label = fl_get_input(form->label);
+ if (key != getContents())
+ current_view->ChangeCitationsIfUnique(getContents(),
+ key);
+
+ if (key != getContents() || label != getOptions()) {
+ setContents(key);
+ setOptions(label);
+ current_view->updateInset(this, true);
// We need to do a redraw becuase the maximum
// InsetBibKey width could have changed.
current_view->redraw();
+ current_view->fitCursor(getLyXText(current_view));
} // fall through to Cancel
+ }
case 0:
fl_hide_form(form->bibitem_form);
break;
string const getScreenLabel() const;
///
EDITABLE Editable() const { return IS_EDITABLE; }
+ ///
+ Inset::Code LyxCode() const { return Inset::CITE_CODE; }
///
void Edit(BufferView *, int, int, unsigned int);
};
///
MATHMACRO_CODE,
///
- ERROR_CODE
+ ERROR_CODE,
+ ///
+ CITE_CODE
};
///