Abdelrazak Younes wrote:
Probably something like the bibfiles cache?
Probably a good idea.
All right, I had a quick look at this. The analogy is reasonable enough,
but it's not quite right. In that case, we basically keep a list of
timestamps and check whether the files have been modified. In this case,
what we need is a kind of "labelsChanged" boolean that we can set to
false whenever we generate the list of labels (in
Buffer::getLabelList()), and then have set to true whenever a label gets
created or deleted. This can be checked then in GuiRef::updateRefs()
before the actual updating is done. Roughly. Something like that will work.
But there are two issues. The first is simply that I don't know where
labels can be created and deleted. Part of this can be done in the
InsetLabel ctor and dtor, but it looks as if InsetMathHull creates and
destroys its own sort of labels, so I'll need some help there, but
that's not a huge problem. The second issue arises just with
InsetLabel::InsetLabel(). We want to tell the buffer that labelsChanged
needs to be set to true. But we don't have access to the buffer. I
suppose there could be just a global labelsChanged---probably there
should be, since the labels that need recalculating may be in a child
document---but, if so, where should that global variable be put?
Well, the attached is one approach: I've put the variable in BufferList,
because it does kind of seem to go with the BufferList: at least, we
should markLabelsChanged() when buffers are created and destroyed. I've
done my best with InsetMathHull.
Comments Welcome.
Richard
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revision 22326)
+++ src/Buffer.cpp (working copy)
@@ -1371,6 +1371,7 @@
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
it.nextInset()->getLabelList(*this, list);
+ theBufferList().clearLabelsChanged();
}
Index: src/BufferList.h
===================================================================
--- src/BufferList.h (revision 22326)
+++ src/BufferList.h (working copy)
@@ -98,6 +98,12 @@
/// reset current author for all buffers
void setCurrentAuthor(docstring const & name, docstring const & email);
+ ///
+ void markLabelsChanged() { labelsChanged_ = true; }
+ ///
+ void clearLabelsChanged() { labelsChanged_ = false; }
+ ///
+ bool labelsChanged() { return labelsChanged_; };
private:
/// noncopiable
BufferList(BufferList const &);
@@ -110,6 +116,10 @@
/// save emergency file for the given buffer
void emergencyWrite(Buffer * buf);
+
+ /// whether the labels have changed in any of the buffers, in which
+ /// case we'll need to regenerate.
+ bool labelsChanged_;
};
/// Implementation is in LyX.cpp
Index: src/BufferList.cpp
===================================================================
--- src/BufferList.cpp (revision 22326)
+++ src/BufferList.cpp (working copy)
@@ -44,7 +44,7 @@
namespace Alert = lyx::frontend::Alert;
-BufferList::BufferList()
+BufferList::BufferList() : labelsChanged_(true)
{}
@@ -89,6 +89,7 @@
bstore.erase(it);
delete tmp;
}
+ markLabelsChanged();
}
@@ -108,6 +109,7 @@
tmpbuf->params().useClassDefaults();
LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size());
bstore.push_back(tmpbuf.get());
+ markLabelsChanged();
return tmpbuf.release();
}
Index: src/frontends/qt4/GuiRef.cpp
===================================================================
--- src/frontends/qt4/GuiRef.cpp (revision 22326)
+++ src/frontends/qt4/GuiRef.cpp (working copy)
@@ -338,6 +338,8 @@
void GuiRef::updateRefs()
{
+ if (!theBufferList().labelsChanged())
+ return;
refs_.clear();
string const name = theBufferList().getFileNames()[bufferCO->currentIndex()];
Buffer const * buf = theBufferList().getBuffer(makeAbsPath(name).absFilename());
Index: src/insets/InsetLabel.h
===================================================================
--- src/insets/InsetLabel.h (revision 22326)
+++ src/insets/InsetLabel.h (working copy)
@@ -22,6 +22,8 @@
///
InsetLabel(InsetCommandParams const &);
///
+ ~InsetLabel();
+ ///
docstring const getScreenLabel(Buffer const &) const;
///
EDITABLE editable() const { return IS_EDITABLE; }
Index: src/insets/InsetLabel.cpp
===================================================================
--- src/insets/InsetLabel.cpp (revision 22326)
+++ src/insets/InsetLabel.cpp (working copy)
@@ -13,6 +13,7 @@
#include "InsetLabel.h"
#include "Buffer.h"
+#include "BufferList.h"
#include "BufferView.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
@@ -30,9 +31,16 @@
InsetLabel::InsetLabel(InsetCommandParams const & p)
: InsetCommand(p, "label")
-{}
+{
+ theBufferList().markLabelsChanged();
+}
+InsetLabel::~InsetLabel()
+{
+ theBufferList().markLabelsChanged();
+}
+
CommandInfo const * InsetLabel::findInfo(string const & /* cmdName */)
{
static const char * const paramnames[] = {"name", ""};
@@ -76,6 +84,7 @@
cur.bv().buffer().changeRefsIfUnique(params()["name"],
p["name"], REF_CODE);
setParams(p);
+ theBufferList().markLabelsChanged();
break;
}
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revision 22326)
+++ src/mathed/InsetMathHull.cpp (working copy)
@@ -26,6 +26,7 @@
#include "InsetMathRef.h"
#include "Buffer.h"
+#include "BufferList.h"
#include "BufferParams.h"
#include "BufferView.h"
#include "CutAndPaste.h"
@@ -165,11 +166,15 @@
: InsetMathGrid(other),
type_(other.type_), nonum_(other.nonum_), label_(other.label_),
preview_(new RenderPreview(*other.preview_, this))
-{}
+{
+ theBufferList().markLabelsChanged();
+}
InsetMathHull::~InsetMathHull()
-{}
+{
+ theBufferList().markLabelsChanged();
+}
Inset * InsetMathHull::clone() const
@@ -423,14 +428,17 @@
{
//lyxerr << "setting label '" << label << "' for row " << row << endl;
label_[row] = label;
+ theBufferList().markLabelsChanged();
}
void InsetMathHull::numbered(row_type row, bool num)
{
nonum_[row] = !num;
- if (nonum_[row])
+ if (nonum_[row]) {
label_[row].clear();
+ theBufferList().markLabelsChanged();
+ }
}
@@ -625,6 +633,7 @@
swap(nonum_[row], nonum_[row + 1]);
swap(label_[row], label_[row + 1]);
InsetMathGrid::swapRow(row);
+ theBufferList().markLabelsChanged();
}
@@ -639,6 +648,7 @@
row--;
nonum_.erase(nonum_.begin() + row);
label_.erase(label_.begin() + row);
+ theBufferList().markLabelsChanged();
}
@@ -821,6 +831,7 @@
for (row_type row = 0; row < nrows(); ++row) {
if (!label_[row].empty()) {
label = label_[row];
+ theBufferList().markLabelsChanged();
break;
}
}
@@ -828,6 +839,7 @@
glueall();
nonum_[0] = allnonum;
label_[0] = label;
+ theBufferList().markLabelsChanged();
mutate(newtype);
} else { // align & Co.
changeCols(2);