]> git.lyx.org Git - features.git/commitdiff
Color broken citations, xrefs, and includes
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 14 Mar 2020 13:17:30 +0000 (14:17 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:54 +0000 (15:48 +0200)
Fixes #11503

src/Color.cpp
src/ColorCode.h
src/insets/InsetCitation.cpp
src/insets/InsetCommand.cpp
src/insets/InsetCommand.h
src/insets/InsetInclude.cpp
src/insets/InsetRef.cpp
src/insets/RenderButton.cpp
src/insets/RenderButton.h

index dd95e28f70742a99f4666692f77fec657486a0ba..54a4743d91f4eab572c748d4376b9d731fbc52b4 100644 (file)
@@ -254,6 +254,10 @@ ColorSet::ColorSet()
        { Color_command, N_("command inset"), "command", "black", "command" },
        { Color_commandbg, N_("command inset background"), "commandbg", "azure", "commandbg" },
        { Color_commandframe, N_("command inset frame"), "commandframe", "black", "commandframe" },
+       { Color_command_broken, N_("command inset (broken reference)"), "command", "white", "command" },
+       { Color_buttonbg_broken, N_("button background (broken reference)"), "commandbg", "Red", "commandbg_broken" },
+       { Color_buttonframe_broken, N_("button frame (broken reference)"), "commandframe", "Red", "commandframe_broken" },
+       { Color_buttonhoverbg_broken, N_("button background (broken reference) under focus"), "buttonhoverbg", "#DB0B0B", "buttonhoverbg_broken" },
        { Color_special, N_("special character"), "special", "RoyalBlue", "special" },
        { Color_math, N_("math"), "math", "DarkBlue", "math" },
        { Color_mathbg, N_("math background"), "mathbg", "linen", "mathbg" },
index 71a9fda77fdc0f765066c9603753041f7b24bead..24d43428c01abf97f113e7398bdc168d1531d13e 100644 (file)
@@ -207,8 +207,16 @@ enum ColorCode {
        Color_buttonframe,
        /// Color used for bottom background
        Color_buttonbg,
-       /// Color used for buttom under focus
+       /// Color used for button under focus
        Color_buttonhoverbg,
+       /// Text color for broken insets
+       Color_command_broken,
+       /// Background color for broken insets
+       Color_buttonbg_broken,
+       /// Frame color for broken insets
+       Color_buttonframe_broken,
+       /// Color used for broken inset button under focus
+       Color_buttonhoverbg_broken,
        /// Color used for the pilcrow sign to mark the end of a paragraph
        Color_paragraphmarker,
        /// Preview frame color
index 7285009b894e6d1c213e6796d703ec1fe372be5e..f3d4d2a7e6d808fcf07321ce29f1a88bbaba8146 100644 (file)
@@ -364,11 +364,19 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
        if (!buf.isFullyLoaded())
                return docstring();
 
+       docstring const & key = getParam("key");
+
        BiblioInfo const & biblist = buf.masterBibInfo();
+
+       // mark broken citations
+       if (biblist.empty() || biblist.find(key) == biblist.end())
+               setBroken(true);
+       else
+               setBroken(false);
+
        if (biblist.empty())
                return docstring();
 
-       docstring const & key = getParam("key");
        if (key.empty())
                return _("No citations selected!");
 
index 1d67ad97d95d527aec7907d618b4e6ed01b8c5a2..f2f0cd84551d8a047f84839a0fd48f0c46bf63b7 100644 (file)
@@ -60,14 +60,14 @@ namespace lyx {
 // FIXME Would it now be possible to use the InsetCode in
 // place of the mailer name and recover that information?
 InsetCommand::InsetCommand(Buffer * buf, InsetCommandParams const & p)
-       : Inset(buf), p_(p)
+       : Inset(buf), p_(p), broken_(false)
 {}
 
 
 // The sole purpose of this copy constructor is to make sure
 // that the mouse_hover_ map is not copied and remains empty.
 InsetCommand::InsetCommand(InsetCommand const & rhs)
-       : Inset(rhs), p_(rhs.p_)
+       : Inset(rhs), p_(rhs.p_), broken_(false)
 {}
 
 
@@ -80,6 +80,7 @@ InsetCommand & InsetCommand::operator=(InsetCommand const & rhs)
        p_ = rhs.p_;
        mouse_hover_.clear();
        button_ = RenderButton();
+       broken_ = false;
 
        return *this;
 }
@@ -101,7 +102,7 @@ InsetCommand::~InsetCommand()
 void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        button_.update(screenLabel(), editable() || clickable(*mi.base.bv, 0, 0),
-                      inheritFont());
+                      inheritFont(), broken_);
        button_.metrics(mi, dim);
 }
 
index d450a663471c14cf7481b5a178f3d1d30112831d..f959d19921b1a0ee5afbc4bd6add51510a5b1e91 100644 (file)
@@ -62,6 +62,8 @@ public:
        void setParam(std::string const & name, docstring const & value);
        /// FIXME Remove
        docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
+       ///
+       void setBroken(bool const b) const { broken_ = b; }
 
        /// \name Public functions inherited from Inset class
        //@{
@@ -147,6 +149,8 @@ private:
        mutable std::map<BufferView const *, bool> mouse_hover_;
        ///
        mutable RenderButton button_;
+       ///
+       mutable bool broken_;
 };
 
 /// Decode InsetCommand considering Inset name and data.
index 9912695c362317f076f9194ebe4480b08a2b9611..c4b2b3f1454b861c1288334502963c984b65bbdc 100644 (file)
@@ -1186,7 +1186,7 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
        } else {
                if (!set_label_) {
                        set_label_ = true;
-                       button_.update(screenLabel(), true, false);
+                       button_.update(screenLabel(), true, false, !file_exist_);
                }
                button_.metrics(mi, dim);
        }
@@ -1377,7 +1377,7 @@ void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype, bool c
 {
        file_exist_ = includedFileExist();
 
-       button_.update(screenLabel(), true, false);
+       button_.update(screenLabel(), true, false, !file_exist_);
 
        Buffer const * const childbuffer = getChildBuffer();
        if (childbuffer) {
index fbcea451051754542a0c995400cb37bb8c6ed985..8f12dbaa50e7e53290eb79195809c33406598ce5 100644 (file)
@@ -443,6 +443,7 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*del
 
        screen_label_ = label;
        broken_ = false;
+       setBroken(broken_);
 }
 
 
@@ -458,6 +459,7 @@ void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
        docstring const & label = getParam("reference");
        if (buffer().insetLabel(label)) {
                broken_ = !buffer().activeLabel(label);
+               setBroken(broken_);
                // This InsetRef has already been taken care of in InsetLabel::addToToc().
                return;
        }
@@ -465,6 +467,7 @@ void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
        // It seems that this reference does not point to any valid label.
 
        broken_ = true;
+       setBroken(broken_);
        shared_ptr<Toc> toc = backend.toc("label");
        toc->push_back(TocItem(cpit, 0, screenLabel(), output_active));
 }
index 44fd17a1b87c390246e9ccdadfd1f4536f94433b..a00a4c5a73577ffc4bc9eae8f3417d2d667b0cfa 100644 (file)
@@ -22,7 +22,7 @@ namespace lyx {
 
 
 RenderButton::RenderButton()
-       : editable_(false), inherit_font_(false)
+       : editable_(false), broken_(false), inherit_font_(false)
 {}
 
 
@@ -33,11 +33,12 @@ RenderBase * RenderButton::clone(Inset const *) const
 
 
 void RenderButton::update(docstring const & text, bool editable,
-                          bool inherit)
+                          bool inherit, bool broken)
 {
        text_ = text;
        editable_ = editable;
        inherit_font_ = inherit;
+       broken_ = broken;
 }
 
 
@@ -60,7 +61,12 @@ void RenderButton::draw(PainterInfo & pi, int x, int y) const
        font.setColor(Color_command);
        font.decSize();
 
-       if (editable_) {
+       if (broken_) {
+               font.setColor(Color_command_broken);
+               pi.pain.buttonText(x, y, text_, font,
+                                  renderState() ? Color_buttonhoverbg_broken : Color_buttonbg_broken,
+                                  Color_buttonframe_broken, Inset::textOffset(pi.base.bv));
+       } else if (editable_) {
                pi.pain.buttonText(x, y, text_, font,
                                   renderState() ? Color_buttonhoverbg : Color_buttonbg,
                                   Color_buttonframe, Inset::textOffset(pi.base.bv));
index a0436404cf745c833f4218eeea7e2d40afce26d3..2dc2da6c9ed4ff47e51f59a1f84a538df7fed69e 100644 (file)
@@ -33,7 +33,8 @@ public:
        virtual void draw(PainterInfo & pi, int x, int y) const;
 
        /// Provide the text for the button
-       void update(docstring const &, bool editable, bool inherit);
+       void update(docstring const &, bool editable,
+                   bool inherit, bool broken = false);
 
        /// The "sensitive area" box, i.e., the button area
        Box box() const { return button_box_; }
@@ -47,6 +48,7 @@ private:
        /// The stored data.
        docstring text_;
        bool editable_;
+       bool broken_;
        bool inherit_font_;
        Box button_box_;
 };