Tree view: expand to a specific directory


I’m essentially trying to create bookmarks Toolbar/Flex Toolbar. I’m trying to create a command that when run, will expand the tree view to a specific directory.

For example, clicking on a button should take the directory path “application/controllers/users” and should expand the ‘application’ directory, the ‘controllers’ directory, and then the ‘users’ directory.

Is this possible to do?

Thank you.


The tree-view package doesn’t have a public API. So there isn’t anything built-in that you can just call to do this kind of thing, no. You could take a look at the source for the tree-view package and maybe figure something out … but it would probably be pretty hacky.

The only other suggestion I have is to submit a feature request on the tree-view package to add the API that you need.


You could do something like this in your

# path is a string with a directory
# relative to the 1st project directory
showPathInTree = (path) ->
  # remove starting and trailing slashes
  path = path.replace /(^\/|\/$)/g, ''

  # get the tree view's model
  treeView = atom.packages.getActivePackage('tree-view').mainModule.createView()

  # only supports 1st project directory
  dir = atom.project.getPaths()[0]

  # loop through all directories
  for part in path.split '/'
    dir += '/' + part
    # expand the directory if it is in the tree view

# usage


It might need some alterations, and it isn’t documented API, so it may break at any time…