[LyX/master] Color broken citations, xrefs, and includes
Juergen Spitzmueller
spitz at lyx.org
Sat Mar 14 12:58:39 UTC 2020
commit 4ddc9e2501400f8bdc35d4d1fe56f39c49e82115
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Sat Mar 14 14:17:30 2020 +0100
Color broken citations, xrefs, and includes
Fixes #11503
---
src/Color.cpp | 4 ++++
src/ColorCode.h | 10 +++++++++-
src/insets/InsetCitation.cpp | 10 +++++++++-
src/insets/InsetCommand.cpp | 7 ++++---
src/insets/InsetCommand.h | 4 ++++
src/insets/InsetInclude.cpp | 4 ++--
src/insets/InsetRef.cpp | 3 +++
src/insets/RenderButton.cpp | 12 +++++++++---
src/insets/RenderButton.h | 4 +++-
9 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/src/Color.cpp b/src/Color.cpp
index dd95e28..54a4743 100644
--- a/src/Color.cpp
+++ b/src/Color.cpp
@@ -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" },
diff --git a/src/ColorCode.h b/src/ColorCode.h
index 71a9fda..24d4342 100644
--- a/src/ColorCode.h
+++ b/src/ColorCode.h
@@ -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
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 7285009..f3d4d2a 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -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!");
diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp
index 1d67ad9..f2f0cd8 100644
--- a/src/insets/InsetCommand.cpp
+++ b/src/insets/InsetCommand.cpp
@@ -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);
}
diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h
index d450a66..f959d19 100644
--- a/src/insets/InsetCommand.h
+++ b/src/insets/InsetCommand.h
@@ -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.
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 9912695..c4b2b3f 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -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) {
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index fbcea45..8f12dba 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -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));
}
diff --git a/src/insets/RenderButton.cpp b/src/insets/RenderButton.cpp
index 44fd17a..a00a4c5 100644
--- a/src/insets/RenderButton.cpp
+++ b/src/insets/RenderButton.cpp
@@ -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));
diff --git a/src/insets/RenderButton.h b/src/insets/RenderButton.h
index a043640..2dc2da6 100644
--- a/src/insets/RenderButton.h
+++ b/src/insets/RenderButton.h
@@ -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_;
};
More information about the lyx-cvs
mailing list