getTipFor could be virtual


#1

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
{
public:
	JTooltipWindowUsingXml(const File & tooltipFile)
	{
		ScopedPointer<XmlElement> x = XmlDocument(tooltipFile).getDocumentElement();

		jassert(x); 

		if (!x)
			return;

		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)
			return;

		auto id = comp->getComponentID();

		auto it = tooltips.find(id);

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

		return it->second;
	}

private:
	std::unordered_map<String, String> tooltips;
};

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

:slight_smile:


#2

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


#3

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();
		}
	};

}

#4

oh, OK. Also a good request, ta.


#5

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…