Sublime Forum

Programmatically adding folders to SideBar causes the existing ones to be removed

#1

I have an example plugin as follows:

class ExampleCommand(sublime_plugin.WindowCommand):

	def run(self):
		self.window.show_input_panel("Enter path: ", "", self.on_done, None, None)

	def on_done(self, name):
		current_data = self.window.project_data()["folders"]
		current_data.append({
			"path": name
		})
		self.window.set_project_data(current_data)

If I type the full path name of folder on disk in the input panel that pops up, I expect that folder to be added in the SideBar but all it does is remove the existing folders from the SideBar (untracking them). So what’s wrong ?
Assume that the name is a valid full path name to a directory that exists on the disk.

0 Likes

#2

because you no longer have a folders key… its no longer a valid project json presumably, you turn the top level item into an array instead of an object

1 Like

#3

You should not destroy the project data, but only append your folder to the “folders” dictionary. :wink:

class ExampleCommand(sublime_plugin.WindowCommand):

    def run(self):
        self.window.show_input_panel("Enter path: ", "", self.on_done, None, None)

    def on_done(self, name):
        current_data = self.window.project_data()
        folders = current_data["folders"]
        folders.append({
            "path": name
        })
        self.window.set_project_data(current_data)
1 Like

#4

Thanks. Silly mistake on my part. It works as expected now.

0 Likes