Listening to toolbar buttons click events


#1

I know how to make a toolbar and add buttons using a toolbaritemfactory like this:

   class CustomToolbarItemFactory : public juce::ToolbarItemFactory {

public:
	CustomToolbarItemFactory() {};

	void getAllToolbarItemIds(juce::Array<int>& ids) override {
		ids.add(1);
		ids.add(separatorBarId);
		ids.add(flexibleSpacerId);
	}

	void getDefaultItemSet(juce::Array<int>& ids) override {
		ids.add(1);
		ids.add(separatorBarId);
		ids.add(separatorBarId);
		ids.add(separatorBarId);
		ids.add(1);
		ids.add(1);
	}

	juce::ToolbarItemComponent* createItem(int itemid) override {
		if (itemid == 1) {				
			return new juce::ToolbarButton(itemid, "", juce::Drawable::createFromImageData(BinaryDataStorage::open_png, BinaryDataStorage::open_pngSize), 0);
		}

		return nullptr;
	}

};

However, I don’t know how to listen to the click events of each toolbar event. Please help me.


#2

HI, I’m on the same scenario right now, and i found this thread

It seems like adding appropriate method to set listeners inside our [TollbarItemFactory] is the right way to do it.