How to create such menu button?

You'd have to click the button twice.

When you click a button with FLATVIEW=toggle,mixednofolders Opus says to itself, "Am I already in flat-mixed-no-folders mode?":[ul][li]If it is already in that mode then Opus turns off Flat View;[/li]
[li]If it isn't already in that mode then Opus changes to that mode.[/li][/ul]The second rule applies when Flat View is off completely and also when Flat View is on but in a different mode.

This, combined with the fact I often switch between the various Flat View modes when I'm using them, is more or less why I opted for a Flat View toolbar after trying a button-menu similar to yours for a while.