Considering multiview, I'd prefer a solution based on signal/slot. Maybe static signal member in InsetLabel? See attached, untested.

OK. I wasn't thinking that the different views had different BufferList's.

In any event, the SignalSlot machinery seems to be unused at present, so I can't find an example of its use. But the moment I try to use it, I get linking errors. It's enough to add this:
   static Signal modified;
   ~InsetLabel() { modified.fire()
to InsetLabel.h (with the #include, of course), and then:

support/.libs/liblyxsupport.a(SignalSlot.o): In function `SlotImpl':
/cvs/lyx-devel/trunk/src/support/../../src/support/SignalSlotPrivate.h:37: undefined reference to `vtable for lyx::SlotImpl'
support/.libs/liblyxsupport.a(SignalSlot.o): In function `SignalImpl':
/cvs/lyx-devel/trunk/src/support/../../src/support/SignalSlotPrivate.h:23: undefined reference to `vtable for lyx::SignalImpl' support/.libs/liblyxsupport.a(SignalSlot.o): In function `lyx::Signal::fire()': /cvs/lyx-devel/trunk/src/support/SignalSlot.cpp:38: undefined reference to `lyx::SignalImpl::fire()'
support/.libs/liblyxsupport.a(SignalSlot.o): In function `SlotImpl':
/cvs/lyx-devel/trunk/src/support/../../src/support/SignalSlotPrivate.h:37: undefined reference to `vtable for lyx::SlotImpl'
support/.libs/liblyxsupport.a(SignalSlot.o): In function `SignalImpl':
/cvs/lyx-devel/trunk/src/support/../../src/support/SignalSlotPrivate.h:23: undefined reference to `vtable for lyx::SignalImpl'
collect2: ld returned 1 exit status


Removing the "static" keyword doesn't help (not that we'd want to do that). I'm not sure what's wrong here.

The whole patch causing this issue is below.

rh



Index: insets/InsetLabel.cpp
===================================================================
--- insets/InsetLabel.cpp       (revision 22329)
+++ insets/InsetLabel.cpp       (working copy)
@@ -30,7 +30,9 @@

InsetLabel::InsetLabel(InsetCommandParams const & p)
       : InsetCommand(p, "label")
-{}
+{
+       //modified.fire();
+}


CommandInfo const * InsetLabel::findInfo(string const & /* cmdName */)
@@ -76,6 +78,7 @@
cur.bv().buffer().changeRefsIfUnique(params()["name"],
                                       p["name"], REF_CODE);
               setParams(p);
+               //modified.fire();
               break;
       }

Index: insets/InsetLabel.h
===================================================================
--- insets/InsetLabel.h (revision 22329)
+++ insets/InsetLabel.h (working copy)
@@ -13,8 +13,8 @@
#define INSET_LABEL_H

#include "InsetCommand.h"
+#include "support/SignalSlot.h"

-
namespace lyx {

class InsetLabel : public InsetCommand {
@@ -22,6 +22,8 @@
       ///
       InsetLabel(InsetCommandParams const &);
       ///
+       ~InsetLabel() { modified.fire(); }
+       ///
       docstring const getScreenLabel(Buffer const &) const;
       ///
       EDITABLE editable() const { return IS_EDITABLE; }
@@ -42,10 +44,12 @@
       ///
       static bool isCompatibleCommand(std::string const & s)
               { return s == "label"; }
+       ///
protected:
       virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
private:
       virtual Inset * clone() const;
+       static Signal modified;
};


Index: frontends/qt4/GuiRef.cpp
===================================================================
--- frontends/qt4/GuiRef.cpp    (revision 22329)
+++ frontends/qt4/GuiRef.cpp    (working copy)
@@ -37,6 +37,8 @@

namespace lyx {
namespace frontend {
+
+bool GuiRef::labelsModified_ = true;

GuiRef::GuiRef(GuiView & lv)
       : GuiCommand(lv, "ref")
@@ -166,6 +168,7 @@

void GuiRef::updateClicked()
{
+       labelsModified_ = true; //force update
       updateRefs();
}

@@ -338,10 +341,13 @@

void GuiRef::updateRefs()
{
+       if (!labelsModified_)
+               return;
       refs_.clear();
string const name = theBufferList().getFileNames()[bufferCO->currentIndex()]; Buffer const * buf = theBufferList().getBuffer(makeAbsPath(name).absFilename());
       buf->getLabelList(refs_);
+       labelsModified_ = false;
       sortCB->setEnabled(!refs_.empty());
       refsLW->setEnabled(!refs_.empty());
       gotoPB->setEnabled(!refs_.empty());
Index: frontends/qt4/GuiRef.h
===================================================================
--- frontends/qt4/GuiRef.h      (revision 22329)
+++ frontends/qt4/GuiRef.h      (working copy)
@@ -16,6 +16,7 @@
#include "Dialog.h"
#include "ui_RefUi.h"
#include "insets/InsetCommandParams.h"
+#include "support/SignalSlot.h"

#include <vector>

@@ -30,6 +31,7 @@

public:
       GuiRef(GuiView & lv);
+       static void markLabelsModified() { labelsModified_ = true; }

private Q_SLOTS:
       void changed_adaptor();
@@ -75,6 +77,11 @@
       /// update references
       void updateRefs();

+       class GuiRefSlot : public Slot
+       {
+               virtual void called() { GuiRef::markLabelsModified(); }
+       };
+
       /// sort or not persistent state
       bool sort_;
       /// went to a reference ?
@@ -85,6 +92,10 @@
       int restored_buffer_;
       /// the references
       std::vector<docstring> refs_;
+       /// whether labels have been modified and need regenerating
+       static bool labelsModified_;
+       ///
+       static GuiRefSlot guirefslot;
};

} // namespace frontend

Reply via email to