You can do it like this:
import sublime_plugin
CHOICES = [
('First', ['A', 'B', 'C']),
('Second', ['X', 'Y', 'Z']),
]
class ExampleTestCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.show_quick_panel(
[key for key, values in CHOICES],
self.on_done_1
)
def on_done_1(self, id):
if id >= 0:
key, values = CHOICES[id]
self.window.show_quick_panel(values, lambda id: self.on_done_2(values, id))
def on_done_2(self, values, id):
if id >= 0:
value = values[id]
print(value)
Alternatively, sublime_lib has a show_selection_panel
method that removes some of the boilerplate:
import sublime_plugin
from sublime_lib import show_selection_panel
CHOICES = [
('First', ['A', 'B', 'C']),
('Second', ['X', 'Y', 'Z']),
]
class ExampleTestCommand(sublime_plugin.WindowCommand):
def run(self):
show_selection_panel(
self.window,
items=[value for key, value in CHOICES],
labels=[key for key, value in CHOICES],
on_select=self.on_done_1
)
def on_done_1(self, values):
show_selection_panel(
self.window,
items=values,
on_select=self.on_done_2,
)
def on_done_2(self, value):
print(value)
If you want a more complex hierarchy, you can do it like this:
import sublime_plugin
from sublime_lib import show_selection_panel
CHOICES = [
('First', [
('A', 'You chose A'),
('B', 'You chose B'),
('C', 'You chose C'),
]),
('Second', [
('X', 'You chose X'),
('Y', [
('Y1', 'You chose Y1'),
('Y2', 'You chose Y2'),
('Y3', 'You chose Y3'),
]),
('Z', 'You chose Z'),
]),
]
class ExampleTestCommand(sublime_plugin.WindowCommand):
def run(self):
self.select(CHOICES)
def select(self, choices):
show_selection_panel(
self.window,
items=[value for key, value in choices],
labels=[key for key, value in choices],
on_select=self.on_select
)
def on_select(self, choice):
if isinstance(choice, str):
print(choice)
else:
self.select(choice)