getTipFor could be virtual

In TooltipWindow getTipFor being virtual would let me use component id’s to load tooltips from a file, something like this:

class JTooltipWindowUsingXml : public TooltipWindow
	JTooltipWindowUsingXml(const File & tooltipFile)
		ScopedPointer<XmlElement> x = XmlDocument(tooltipFile).getDocumentElement();


		if (!x)

		forEachXmlChildElement(*x, e)
			auto id = e->getChildElementAllSubText("component", {});
			auto tip = e->getChildElementAllSubText("tooltip", {});

			jassert(id.isNotEmpty() && tip.isNotEmpty());

			tooltips[id] = tip;

	String getTipFor (Component* comp) override
		if (comp == nullptr)

		auto id = comp->getComponentID();

		auto it = tooltips.find(id);

		if (it == tooltips.end())
			return TooltipWindow::getTipFor(comp);

		return it->second;

	std::unordered_map<String, String> tooltips;

And then I can delegate all the debate about tooltips to the product management team!


1 Like

Yeah, good request! (and easy too - will add it shortly…)

And you could pop this in too somewhere, so that unordered_map worked … unless I’m missing something subtle :slight_smile:

namespace std {

	template <>
	struct hash<String>
		std::size_t operator()(const String& string) const
			return string.hash();


oh, OK. Also a good request, ta.

Maybe it’ll need to be outside the JUCE namespace tho …

I think i had a few more of these for other things you might want in an unordered_map, e.g. Identifier…