Sublime Forum

[SOLVED] Quick panel recursively?

#1

Exists any way to show a quick panel recursively? It means, that depending on the first selection, the same command that has shown the quick panel first, will be called again with the selected value.
I’ve tried it. But it seems that the panel is blocked from the first call.
The following sample code shows the problem. On the second call I’ve got the message: “Quick panel unavailable”.

# call: {"caption": "QPanel Recursively", "command": "quick_panel_recursively", "args": {"param_dynamic": "Test"}}
class QuickPanelRecursivelyCommand(sublime_plugin.WindowCommand):
    list_master = None
    def run(self, param_dynamic):
        n, self.list_master = self.get_list_dynamic(param_dynamic)
        if n > 0:
            sublime.active_window().show_quick_panel(
                self.list_master, self.on_selection)

    def get_list_dynamic(self, dynamic):
        # create a list depending on parameter "dynamic", i.e.
        created_list = ]
        for s in 'alpha','beta','gamma','delta']:
            created_list.append('%s_%s' % (dynamic, s))
        return len(created_list), created_list

    def on_selection(self, selection):
        if selection > -1:
            # with selected value should call this command again,
            # but error occurs: "Quick panel unavailable"
            sublime.active_window().run_command("quick_panel_recursively",
                {"param_dynamic": self.list_master[selection]})
0 Likes

#2

Call asynchronously your command.
Not tested but something like

sublime.set_timeout_async(lambda: sublime.active_window().run_command("quick_panel_recursively", {"param_dynamic": self.list_master[selection]}), 0)
0 Likes

#3

Thank you - that is the solution.

0 Likes