Sublime Forum

Update show_quick_panel

#1

Hello.

>>> window.show_quick_panel([str(i) for i in range(4)]);window.show_quick_panel([str(i) for i in range(20)], None, 0, 10) Quick panel unavailable
My plugin should be able to switch back and forth on the history, switching the view and quick_panel.
If quick_panel is already open, then sublime fails “Quick panel is unavailable” and the panel remains with the old data.
Any suggestions?

0 Likes

#2

You can not update the quick panel.

You must close the quick panel and reopen it (with selected_index parameter on ST3) to emulate this behavior somewhat.

0 Likes

#3

How to close using the api?

0 Likes

#4

From the default bindings:

	{ "keys": "escape"], "command": "hide_panel", "args": {"cancel": true},
		"context":
		
			{ "key": "panel_visible", "operator": "equal", "operand": true }
		]
	},

So, window.run_command("hide_panel", {"cancel": True}) should do.

0 Likes

#5

Thank you very much for the help.

0 Likes

#6

Closes all of the panels, but not quick_panel

[code]#{ “keys”: “f10”], “command”: “example” },

{ “keys”: “ctrl+f10”], “command”: “example”, “args”: { “back”: true} },

import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.WindowCommand):
items = “test”,“bar”]
def run(self, back=False):
if back:
self.items.pop()
else:
self.items.append(“item %s”%len(self.items))

	self.show_panel(self.items)

def show_panel(self, items, index=0):
	self.window.run_command("hide_panel", {"cancel": True})
	if items:
		sublime.set_timeout(lambda:	self.window.show_quick_panel(items, None, 0, index), 10)[/code]
0 Likes

#7

Sorry, I didn’t test this. I wasn’t too sure myself.

Then it was the other one: window.run_command("hide_overlay"), which you could have found in the default bindings as well.

0 Likes

#8

Thank you. It works.

[code]#{ “keys”: “f10”], “command”: “example” },
#{ “keys”: “ctrl+f10”], “command”: “example”, “args”: { “back”: true} },

import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.WindowCommand):
items = “test”,“bar”]
def run(self, back=False):
if back:
self.items.pop()
else:
self.items.append(“item %s”%len(self.items))

	self.show_panel(self.items, len(self.items)-1)

def show_panel(self, items, index=0):
	self.window.run_command("hide_overlay")
	self.window.show_quick_panel(items, None, 0, index)[/code]
0 Likes